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 void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1064 struct ath10k_vif *arvif,
1065 struct ieee80211_sta *sta,
1066 struct ieee80211_bss_conf *bss_conf,
1067 struct wmi_peer_assoc_complete_arg *arg)
1069 lockdep_assert_held(&ar->conf_mutex);
1071 ether_addr_copy(arg->addr, sta->addr);
1072 arg->vdev_id = arvif->vdev_id;
1073 arg->peer_aid = sta->aid;
1074 arg->peer_flags |= WMI_PEER_AUTH;
1076 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1078 * Seems FW have problems with Power Save in STA
1079 * mode when we setup this parameter to high (eg. 5).
1080 * Often we see that FW don't send NULL (with clean P flags)
1081 * frame even there is info about buffered frames in beacons.
1082 * Sometimes we have to wait more than 10 seconds before FW
1083 * will wakeup. Often sending one ping from AP to our device
1084 * just fail (more than 50%).
1086 * Seems setting this FW parameter to 1 couse FW
1087 * will check every beacon and will wakup immediately
1088 * after detection buffered data.
1090 arg->peer_listen_intval = 1;
1092 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1094 arg->peer_num_spatial_streams = 1;
1097 * The assoc capabilities are available only in managed mode.
1099 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1100 arg->peer_caps = bss_conf->assoc_capability;
1103 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1104 struct ath10k_vif *arvif,
1105 struct wmi_peer_assoc_complete_arg *arg)
1107 struct ieee80211_vif *vif = arvif->vif;
1108 struct ieee80211_bss_conf *info = &vif->bss_conf;
1109 struct cfg80211_bss *bss;
1110 const u8 *rsnie = NULL;
1111 const u8 *wpaie = NULL;
1113 lockdep_assert_held(&ar->conf_mutex);
1115 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1116 info->bssid, NULL, 0, 0, 0);
1118 const struct cfg80211_bss_ies *ies;
1121 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1123 ies = rcu_dereference(bss->ies);
1125 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1126 WLAN_OUI_TYPE_MICROSOFT_WPA,
1130 cfg80211_put_bss(ar->hw->wiphy, bss);
1133 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1134 if (rsnie || wpaie) {
1135 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1136 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1140 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1141 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1145 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1146 struct ieee80211_sta *sta,
1147 struct wmi_peer_assoc_complete_arg *arg)
1149 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1150 const struct ieee80211_supported_band *sband;
1151 const struct ieee80211_rate *rates;
1155 lockdep_assert_held(&ar->conf_mutex);
1157 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1158 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1159 rates = sband->bitrates;
1161 rateset->num_rates = 0;
1163 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1164 if (!(ratemask & 1))
1167 rateset->rates[rateset->num_rates] = rates->hw_value;
1168 rateset->num_rates++;
1172 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1173 struct ieee80211_sta *sta,
1174 struct wmi_peer_assoc_complete_arg *arg)
1176 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1180 lockdep_assert_held(&ar->conf_mutex);
1182 if (!ht_cap->ht_supported)
1185 arg->peer_flags |= WMI_PEER_HT;
1186 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1187 ht_cap->ampdu_factor)) - 1;
1189 arg->peer_mpdu_density =
1190 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1192 arg->peer_ht_caps = ht_cap->cap;
1193 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1195 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1196 arg->peer_flags |= WMI_PEER_LDPC;
1198 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1199 arg->peer_flags |= WMI_PEER_40MHZ;
1200 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1203 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1204 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1206 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1207 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1209 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1210 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1211 arg->peer_flags |= WMI_PEER_STBC;
1214 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1215 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1216 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1217 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1218 arg->peer_rate_caps |= stbc;
1219 arg->peer_flags |= WMI_PEER_STBC;
1222 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1223 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1224 else if (ht_cap->mcs.rx_mask[1])
1225 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1227 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1228 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1229 arg->peer_ht_rates.rates[n++] = i;
1232 * This is a workaround for HT-enabled STAs which break the spec
1233 * and have no HT capabilities RX mask (no HT RX MCS map).
1235 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1236 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1238 * Firmware asserts if such situation occurs.
1241 arg->peer_ht_rates.num_rates = 8;
1242 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1243 arg->peer_ht_rates.rates[i] = i;
1245 arg->peer_ht_rates.num_rates = n;
1246 arg->peer_num_spatial_streams = sta->rx_nss;
1249 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1251 arg->peer_ht_rates.num_rates,
1252 arg->peer_num_spatial_streams);
1255 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1256 struct ath10k_vif *arvif,
1257 struct ieee80211_sta *sta)
1263 lockdep_assert_held(&ar->conf_mutex);
1265 if (sta->wme && sta->uapsd_queues) {
1266 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1267 sta->uapsd_queues, sta->max_sp);
1269 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1270 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1271 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1272 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1273 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1274 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1275 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1276 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1277 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1278 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1279 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1280 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1282 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1283 max_sp = sta->max_sp;
1285 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1287 WMI_AP_PS_PEER_PARAM_UAPSD,
1290 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1291 arvif->vdev_id, ret);
1295 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1297 WMI_AP_PS_PEER_PARAM_MAX_SP,
1300 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1301 arvif->vdev_id, ret);
1305 /* TODO setup this based on STA listen interval and
1306 beacon interval. Currently we don't know
1307 sta->listen_interval - mac80211 patch required.
1308 Currently use 10 seconds */
1309 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1310 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1313 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1314 arvif->vdev_id, ret);
1322 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1323 struct ieee80211_sta *sta,
1324 struct wmi_peer_assoc_complete_arg *arg)
1326 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1329 if (!vht_cap->vht_supported)
1332 arg->peer_flags |= WMI_PEER_VHT;
1333 arg->peer_vht_caps = vht_cap->cap;
1335 ampdu_factor = (vht_cap->cap &
1336 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1337 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1339 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1340 * zero in VHT IE. Using it would result in degraded throughput.
1341 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1342 * it if VHT max_mpdu is smaller. */
1343 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1344 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1345 ampdu_factor)) - 1);
1347 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1348 arg->peer_flags |= WMI_PEER_80MHZ;
1350 arg->peer_vht_rates.rx_max_rate =
1351 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1352 arg->peer_vht_rates.rx_mcs_set =
1353 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1354 arg->peer_vht_rates.tx_max_rate =
1355 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1356 arg->peer_vht_rates.tx_mcs_set =
1357 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1359 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1360 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1363 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1364 struct ath10k_vif *arvif,
1365 struct ieee80211_sta *sta,
1366 struct ieee80211_bss_conf *bss_conf,
1367 struct wmi_peer_assoc_complete_arg *arg)
1369 switch (arvif->vdev_type) {
1370 case WMI_VDEV_TYPE_AP:
1372 arg->peer_flags |= WMI_PEER_QOS;
1374 if (sta->wme && sta->uapsd_queues) {
1375 arg->peer_flags |= WMI_PEER_APSD;
1376 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1379 case WMI_VDEV_TYPE_STA:
1381 arg->peer_flags |= WMI_PEER_QOS;
1388 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1389 struct ath10k_vif *arvif,
1390 struct ieee80211_sta *sta,
1391 struct wmi_peer_assoc_complete_arg *arg)
1393 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1395 switch (ar->hw->conf.chandef.chan->band) {
1396 case IEEE80211_BAND_2GHZ:
1397 if (sta->ht_cap.ht_supported) {
1398 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1399 phymode = MODE_11NG_HT40;
1401 phymode = MODE_11NG_HT20;
1407 case IEEE80211_BAND_5GHZ:
1411 if (sta->vht_cap.vht_supported) {
1412 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1413 phymode = MODE_11AC_VHT80;
1414 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1415 phymode = MODE_11AC_VHT40;
1416 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1417 phymode = MODE_11AC_VHT20;
1418 } else if (sta->ht_cap.ht_supported) {
1419 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1420 phymode = MODE_11NA_HT40;
1422 phymode = MODE_11NA_HT20;
1432 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1433 sta->addr, ath10k_wmi_phymode_str(phymode));
1435 arg->peer_phymode = phymode;
1436 WARN_ON(phymode == MODE_UNKNOWN);
1439 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1440 struct ath10k_vif *arvif,
1441 struct ieee80211_sta *sta,
1442 struct ieee80211_bss_conf *bss_conf,
1443 struct wmi_peer_assoc_complete_arg *arg)
1445 lockdep_assert_held(&ar->conf_mutex);
1447 memset(arg, 0, sizeof(*arg));
1449 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1450 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1451 ath10k_peer_assoc_h_rates(ar, sta, arg);
1452 ath10k_peer_assoc_h_ht(ar, sta, arg);
1453 ath10k_peer_assoc_h_vht(ar, sta, arg);
1454 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1455 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
1460 static const u32 ath10k_smps_map[] = {
1461 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1462 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1463 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1464 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1467 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1469 const struct ieee80211_sta_ht_cap *ht_cap)
1473 if (!ht_cap->ht_supported)
1476 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1477 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1479 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1482 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1483 WMI_PEER_SMPS_STATE,
1484 ath10k_smps_map[smps]);
1487 /* can be called only in mac80211 callbacks due to `key_count` usage */
1488 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1489 struct ieee80211_vif *vif,
1490 struct ieee80211_bss_conf *bss_conf)
1492 struct ath10k *ar = hw->priv;
1493 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1494 struct ieee80211_sta_ht_cap ht_cap;
1495 struct wmi_peer_assoc_complete_arg peer_arg;
1496 struct ieee80211_sta *ap_sta;
1499 lockdep_assert_held(&ar->conf_mutex);
1503 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1505 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1506 bss_conf->bssid, arvif->vdev_id);
1511 /* ap_sta must be accessed only within rcu section which must be left
1512 * before calling ath10k_setup_peer_smps() which might sleep. */
1513 ht_cap = ap_sta->ht_cap;
1515 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1516 bss_conf, &peer_arg);
1518 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1519 bss_conf->bssid, arvif->vdev_id, ret);
1526 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1528 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1529 bss_conf->bssid, arvif->vdev_id, ret);
1533 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1535 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1536 arvif->vdev_id, ret);
1540 ath10k_dbg(ar, ATH10K_DBG_MAC,
1541 "mac vdev %d up (associated) bssid %pM aid %d\n",
1542 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1544 arvif->aid = bss_conf->aid;
1545 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1547 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1549 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1550 arvif->vdev_id, ret);
1554 arvif->is_up = true;
1560 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1561 struct ieee80211_vif *vif)
1563 struct ath10k *ar = hw->priv;
1564 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1567 lockdep_assert_held(&ar->conf_mutex);
1570 * For some reason, calling VDEV-DOWN before VDEV-STOP
1571 * makes the FW to send frames via HTT after disassociation.
1572 * No idea why this happens, even though VDEV-DOWN is supposed
1573 * to be analogous to link down, so just stop the VDEV.
1575 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1578 /* FIXME: check return value */
1579 ret = ath10k_vdev_stop(arvif);
1582 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1583 * report beacons from previously associated network through HTT.
1584 * This in turn would spam mac80211 WARN_ON if we bring down all
1585 * interfaces as it expects there is no rx when no interface is
1588 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1590 /* FIXME: why don't we print error if wmi call fails? */
1591 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1593 arvif->def_wep_key_idx = 0;
1595 arvif->is_started = false;
1596 arvif->is_up = false;
1599 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1600 struct ieee80211_sta *sta, bool reassoc)
1602 struct wmi_peer_assoc_complete_arg peer_arg;
1605 lockdep_assert_held(&ar->conf_mutex);
1607 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1609 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1610 sta->addr, arvif->vdev_id, ret);
1614 peer_arg.peer_reassoc = reassoc;
1615 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1617 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1618 sta->addr, arvif->vdev_id, ret);
1622 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1624 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1625 arvif->vdev_id, ret);
1629 if (!sta->wme && !reassoc) {
1630 arvif->num_legacy_stations++;
1631 ret = ath10k_recalc_rtscts_prot(arvif);
1633 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1634 arvif->vdev_id, ret);
1639 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1641 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1642 arvif->vdev_id, ret);
1646 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1648 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1649 sta->addr, arvif->vdev_id, ret);
1656 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1657 struct ieee80211_sta *sta)
1661 lockdep_assert_held(&ar->conf_mutex);
1664 arvif->num_legacy_stations--;
1665 ret = ath10k_recalc_rtscts_prot(arvif);
1667 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1668 arvif->vdev_id, ret);
1673 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1675 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1676 arvif->vdev_id, ret);
1687 static int ath10k_update_channel_list(struct ath10k *ar)
1689 struct ieee80211_hw *hw = ar->hw;
1690 struct ieee80211_supported_band **bands;
1691 enum ieee80211_band band;
1692 struct ieee80211_channel *channel;
1693 struct wmi_scan_chan_list_arg arg = {0};
1694 struct wmi_channel_arg *ch;
1700 lockdep_assert_held(&ar->conf_mutex);
1702 bands = hw->wiphy->bands;
1703 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1707 for (i = 0; i < bands[band]->n_channels; i++) {
1708 if (bands[band]->channels[i].flags &
1709 IEEE80211_CHAN_DISABLED)
1716 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1717 arg.channels = kzalloc(len, GFP_KERNEL);
1722 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1726 for (i = 0; i < bands[band]->n_channels; i++) {
1727 channel = &bands[band]->channels[i];
1729 if (channel->flags & IEEE80211_CHAN_DISABLED)
1732 ch->allow_ht = true;
1734 /* FIXME: when should we really allow VHT? */
1735 ch->allow_vht = true;
1738 !(channel->flags & IEEE80211_CHAN_NO_IR);
1741 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1744 !!(channel->flags & IEEE80211_CHAN_RADAR);
1746 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1747 ch->passive = passive;
1749 ch->freq = channel->center_freq;
1750 ch->band_center_freq1 = channel->center_freq;
1752 ch->max_power = channel->max_power * 2;
1753 ch->max_reg_power = channel->max_reg_power * 2;
1754 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1755 ch->reg_class_id = 0; /* FIXME */
1757 /* FIXME: why use only legacy modes, why not any
1758 * HT/VHT modes? Would that even make any
1760 if (channel->band == IEEE80211_BAND_2GHZ)
1761 ch->mode = MODE_11G;
1763 ch->mode = MODE_11A;
1765 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1768 ath10k_dbg(ar, ATH10K_DBG_WMI,
1769 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1770 ch - arg.channels, arg.n_channels,
1771 ch->freq, ch->max_power, ch->max_reg_power,
1772 ch->max_antenna_gain, ch->mode);
1778 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1779 kfree(arg.channels);
1784 static enum wmi_dfs_region
1785 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1787 switch (dfs_region) {
1788 case NL80211_DFS_UNSET:
1789 return WMI_UNINIT_DFS_DOMAIN;
1790 case NL80211_DFS_FCC:
1791 return WMI_FCC_DFS_DOMAIN;
1792 case NL80211_DFS_ETSI:
1793 return WMI_ETSI_DFS_DOMAIN;
1794 case NL80211_DFS_JP:
1795 return WMI_MKK4_DFS_DOMAIN;
1797 return WMI_UNINIT_DFS_DOMAIN;
1800 static void ath10k_regd_update(struct ath10k *ar)
1802 struct reg_dmn_pair_mapping *regpair;
1804 enum wmi_dfs_region wmi_dfs_reg;
1805 enum nl80211_dfs_regions nl_dfs_reg;
1807 lockdep_assert_held(&ar->conf_mutex);
1809 ret = ath10k_update_channel_list(ar);
1811 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1813 regpair = ar->ath_common.regulatory.regpair;
1815 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1816 nl_dfs_reg = ar->dfs_detector->region;
1817 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1819 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1822 /* Target allows setting up per-band regdomain but ath_common provides
1823 * a combined one only */
1824 ret = ath10k_wmi_pdev_set_regdomain(ar,
1825 regpair->reg_domain,
1826 regpair->reg_domain, /* 2ghz */
1827 regpair->reg_domain, /* 5ghz */
1828 regpair->reg_2ghz_ctl,
1829 regpair->reg_5ghz_ctl,
1832 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1835 static void ath10k_reg_notifier(struct wiphy *wiphy,
1836 struct regulatory_request *request)
1838 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1839 struct ath10k *ar = hw->priv;
1842 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1844 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1845 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1846 request->dfs_region);
1847 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1848 request->dfs_region);
1850 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1851 request->dfs_region);
1854 mutex_lock(&ar->conf_mutex);
1855 if (ar->state == ATH10K_STATE_ON)
1856 ath10k_regd_update(ar);
1857 mutex_unlock(&ar->conf_mutex);
1864 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1866 if (ieee80211_is_mgmt(hdr->frame_control))
1867 return HTT_DATA_TX_EXT_TID_MGMT;
1869 if (!ieee80211_is_data_qos(hdr->frame_control))
1870 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1872 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1873 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1875 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1878 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
1881 return ath10k_vif_to_arvif(vif)->vdev_id;
1883 if (ar->monitor_started)
1884 return ar->monitor_vdev_id;
1886 ath10k_warn(ar, "failed to resolve vdev id\n");
1890 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1891 * Control in the header.
1893 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1895 struct ieee80211_hdr *hdr = (void *)skb->data;
1896 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1899 if (!ieee80211_is_data_qos(hdr->frame_control))
1902 qos_ctl = ieee80211_get_qos_ctl(hdr);
1903 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1904 skb->data, (void *)qos_ctl - (void *)skb->data);
1905 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1907 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1908 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1909 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1910 * it is safe to downgrade to NullFunc.
1912 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1913 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1914 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1918 static void ath10k_tx_wep_key_work(struct work_struct *work)
1920 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1922 struct ath10k *ar = arvif->ar;
1923 int ret, keyidx = arvif->def_wep_key_newidx;
1925 mutex_lock(&arvif->ar->conf_mutex);
1927 if (arvif->ar->state != ATH10K_STATE_ON)
1930 if (arvif->def_wep_key_idx == keyidx)
1933 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1934 arvif->vdev_id, keyidx);
1936 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1938 arvif->ar->wmi.vdev_param->def_keyid,
1941 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
1947 arvif->def_wep_key_idx = keyidx;
1950 mutex_unlock(&arvif->ar->conf_mutex);
1953 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1954 struct ieee80211_key_conf *key,
1955 struct sk_buff *skb)
1957 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1958 struct ath10k *ar = arvif->ar;
1959 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1961 if (!ieee80211_has_protected(hdr->frame_control))
1967 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1968 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1971 if (key->keyidx == arvif->def_wep_key_idx)
1974 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1975 * queueing frames until key index is updated is not an option because
1976 * sk_buff may need more processing to be done, e.g. offchannel */
1977 arvif->def_wep_key_newidx = key->keyidx;
1978 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1981 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1982 struct ieee80211_vif *vif,
1983 struct sk_buff *skb)
1985 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1986 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1988 /* This is case only for P2P_GO */
1989 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1990 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1993 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1994 spin_lock_bh(&ar->data_lock);
1995 if (arvif->u.ap.noa_data)
1996 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1998 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1999 arvif->u.ap.noa_data,
2000 arvif->u.ap.noa_len);
2001 spin_unlock_bh(&ar->data_lock);
2005 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2007 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2010 if (ar->htt.target_version_major >= 3) {
2011 /* Since HTT 3.0 there is no separate mgmt tx command */
2012 ret = ath10k_htt_tx(&ar->htt, skb);
2016 if (ieee80211_is_mgmt(hdr->frame_control)) {
2017 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2019 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2020 ATH10K_MAX_NUM_MGMT_PENDING) {
2021 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2026 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2027 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2029 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2031 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2033 ieee80211_is_nullfunc(hdr->frame_control)) {
2034 /* FW does not report tx status properly for NullFunc frames
2035 * unless they are sent through mgmt tx path. mac80211 sends
2036 * those frames when it detects link/beacon loss and depends
2037 * on the tx status to be correct. */
2038 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2040 ret = ath10k_htt_tx(&ar->htt, skb);
2045 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2047 ieee80211_free_txskb(ar->hw, skb);
2051 void ath10k_offchan_tx_purge(struct ath10k *ar)
2053 struct sk_buff *skb;
2056 skb = skb_dequeue(&ar->offchan_tx_queue);
2060 ieee80211_free_txskb(ar->hw, skb);
2064 void ath10k_offchan_tx_work(struct work_struct *work)
2066 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2067 struct ath10k_peer *peer;
2068 struct ieee80211_hdr *hdr;
2069 struct sk_buff *skb;
2070 const u8 *peer_addr;
2074 /* FW requirement: We must create a peer before FW will send out
2075 * an offchannel frame. Otherwise the frame will be stuck and
2076 * never transmitted. We delete the peer upon tx completion.
2077 * It is unlikely that a peer for offchannel tx will already be
2078 * present. However it may be in some rare cases so account for that.
2079 * Otherwise we might remove a legitimate peer and break stuff. */
2082 skb = skb_dequeue(&ar->offchan_tx_queue);
2086 mutex_lock(&ar->conf_mutex);
2088 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2091 hdr = (struct ieee80211_hdr *)skb->data;
2092 peer_addr = ieee80211_get_DA(hdr);
2093 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2095 spin_lock_bh(&ar->data_lock);
2096 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2097 spin_unlock_bh(&ar->data_lock);
2100 /* FIXME: should this use ath10k_warn()? */
2101 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2102 peer_addr, vdev_id);
2105 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2107 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2108 peer_addr, vdev_id, ret);
2111 spin_lock_bh(&ar->data_lock);
2112 reinit_completion(&ar->offchan_tx_completed);
2113 ar->offchan_tx_skb = skb;
2114 spin_unlock_bh(&ar->data_lock);
2116 ath10k_tx_htt(ar, skb);
2118 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2121 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2125 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2127 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2128 peer_addr, vdev_id, ret);
2131 mutex_unlock(&ar->conf_mutex);
2135 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2137 struct sk_buff *skb;
2140 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2144 ieee80211_free_txskb(ar->hw, skb);
2148 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2150 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2151 struct sk_buff *skb;
2155 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2159 ret = ath10k_wmi_mgmt_tx(ar, skb);
2161 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2163 ieee80211_free_txskb(ar->hw, skb);
2172 void __ath10k_scan_finish(struct ath10k *ar)
2174 lockdep_assert_held(&ar->data_lock);
2176 switch (ar->scan.state) {
2177 case ATH10K_SCAN_IDLE:
2179 case ATH10K_SCAN_RUNNING:
2180 case ATH10K_SCAN_ABORTING:
2181 if (ar->scan.is_roc)
2182 ieee80211_remain_on_channel_expired(ar->hw);
2184 ieee80211_scan_completed(ar->hw,
2186 ATH10K_SCAN_ABORTING));
2188 case ATH10K_SCAN_STARTING:
2189 ar->scan.state = ATH10K_SCAN_IDLE;
2190 ar->scan_channel = NULL;
2191 ath10k_offchan_tx_purge(ar);
2192 cancel_delayed_work(&ar->scan.timeout);
2193 complete_all(&ar->scan.completed);
2198 void ath10k_scan_finish(struct ath10k *ar)
2200 spin_lock_bh(&ar->data_lock);
2201 __ath10k_scan_finish(ar);
2202 spin_unlock_bh(&ar->data_lock);
2205 static int ath10k_scan_stop(struct ath10k *ar)
2207 struct wmi_stop_scan_arg arg = {
2208 .req_id = 1, /* FIXME */
2209 .req_type = WMI_SCAN_STOP_ONE,
2210 .u.scan_id = ATH10K_SCAN_ID,
2214 lockdep_assert_held(&ar->conf_mutex);
2216 ret = ath10k_wmi_stop_scan(ar, &arg);
2218 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2222 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2224 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2226 } else if (ret > 0) {
2231 /* Scan state should be updated upon scan completion but in case
2232 * firmware fails to deliver the event (for whatever reason) it is
2233 * desired to clean up scan state anyway. Firmware may have just
2234 * dropped the scan completion event delivery due to transport pipe
2235 * being overflown with data and/or it can recover on its own before
2236 * next scan request is submitted.
2238 spin_lock_bh(&ar->data_lock);
2239 if (ar->scan.state != ATH10K_SCAN_IDLE)
2240 __ath10k_scan_finish(ar);
2241 spin_unlock_bh(&ar->data_lock);
2246 static void ath10k_scan_abort(struct ath10k *ar)
2250 lockdep_assert_held(&ar->conf_mutex);
2252 spin_lock_bh(&ar->data_lock);
2254 switch (ar->scan.state) {
2255 case ATH10K_SCAN_IDLE:
2256 /* This can happen if timeout worker kicked in and called
2257 * abortion while scan completion was being processed.
2260 case ATH10K_SCAN_STARTING:
2261 case ATH10K_SCAN_ABORTING:
2262 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2263 ath10k_scan_state_str(ar->scan.state),
2266 case ATH10K_SCAN_RUNNING:
2267 ar->scan.state = ATH10K_SCAN_ABORTING;
2268 spin_unlock_bh(&ar->data_lock);
2270 ret = ath10k_scan_stop(ar);
2272 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2274 spin_lock_bh(&ar->data_lock);
2278 spin_unlock_bh(&ar->data_lock);
2281 void ath10k_scan_timeout_work(struct work_struct *work)
2283 struct ath10k *ar = container_of(work, struct ath10k,
2286 mutex_lock(&ar->conf_mutex);
2287 ath10k_scan_abort(ar);
2288 mutex_unlock(&ar->conf_mutex);
2291 static int ath10k_start_scan(struct ath10k *ar,
2292 const struct wmi_start_scan_arg *arg)
2296 lockdep_assert_held(&ar->conf_mutex);
2298 ret = ath10k_wmi_start_scan(ar, arg);
2302 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2304 ret = ath10k_scan_stop(ar);
2306 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2311 /* Add a 200ms margin to account for event/command processing */
2312 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2313 msecs_to_jiffies(arg->max_scan_time+200));
2317 /**********************/
2318 /* mac80211 callbacks */
2319 /**********************/
2321 static void ath10k_tx(struct ieee80211_hw *hw,
2322 struct ieee80211_tx_control *control,
2323 struct sk_buff *skb)
2325 struct ath10k *ar = hw->priv;
2326 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2327 struct ieee80211_vif *vif = info->control.vif;
2328 struct ieee80211_key_conf *key = info->control.hw_key;
2329 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2331 /* We should disable CCK RATE due to P2P */
2332 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2333 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2335 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2336 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2337 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2339 /* it makes no sense to process injected frames like that */
2340 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2341 ath10k_tx_h_nwifi(hw, skb);
2342 ath10k_tx_h_update_wep_key(vif, key, skb);
2343 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2344 ath10k_tx_h_seq_no(vif, skb);
2347 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2348 spin_lock_bh(&ar->data_lock);
2349 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2350 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2351 spin_unlock_bh(&ar->data_lock);
2353 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2356 skb_queue_tail(&ar->offchan_tx_queue, skb);
2357 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2361 ath10k_tx_htt(ar, skb);
2364 /* Must not be called with conf_mutex held as workers can use that also. */
2365 static void ath10k_drain_tx(struct ath10k *ar)
2367 /* make sure rcu-protected mac80211 tx path itself is drained */
2370 ath10k_offchan_tx_purge(ar);
2371 ath10k_mgmt_over_wmi_tx_purge(ar);
2373 cancel_work_sync(&ar->offchan_tx_work);
2374 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2377 void ath10k_halt(struct ath10k *ar)
2379 struct ath10k_vif *arvif;
2381 lockdep_assert_held(&ar->conf_mutex);
2383 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2384 ar->filter_flags = 0;
2385 ar->monitor = false;
2387 if (ar->monitor_started)
2388 ath10k_monitor_stop(ar);
2390 ar->monitor_started = false;
2392 ath10k_scan_finish(ar);
2393 ath10k_peer_cleanup_all(ar);
2394 ath10k_core_stop(ar);
2395 ath10k_hif_power_down(ar);
2397 spin_lock_bh(&ar->data_lock);
2398 list_for_each_entry(arvif, &ar->arvifs, list)
2399 ath10k_mac_vif_beacon_cleanup(arvif);
2400 spin_unlock_bh(&ar->data_lock);
2403 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2405 struct ath10k *ar = hw->priv;
2407 mutex_lock(&ar->conf_mutex);
2409 if (ar->cfg_tx_chainmask) {
2410 *tx_ant = ar->cfg_tx_chainmask;
2411 *rx_ant = ar->cfg_rx_chainmask;
2413 *tx_ant = ar->supp_tx_chainmask;
2414 *rx_ant = ar->supp_rx_chainmask;
2417 mutex_unlock(&ar->conf_mutex);
2422 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2426 lockdep_assert_held(&ar->conf_mutex);
2428 ar->cfg_tx_chainmask = tx_ant;
2429 ar->cfg_rx_chainmask = rx_ant;
2431 if ((ar->state != ATH10K_STATE_ON) &&
2432 (ar->state != ATH10K_STATE_RESTARTED))
2435 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2438 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2443 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2446 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2454 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2456 struct ath10k *ar = hw->priv;
2459 mutex_lock(&ar->conf_mutex);
2460 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2461 mutex_unlock(&ar->conf_mutex);
2465 static int ath10k_start(struct ieee80211_hw *hw)
2467 struct ath10k *ar = hw->priv;
2471 * This makes sense only when restarting hw. It is harmless to call
2472 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2473 * commands will be submitted while restarting.
2475 ath10k_drain_tx(ar);
2477 mutex_lock(&ar->conf_mutex);
2479 switch (ar->state) {
2480 case ATH10K_STATE_OFF:
2481 ar->state = ATH10K_STATE_ON;
2483 case ATH10K_STATE_RESTARTING:
2485 ar->state = ATH10K_STATE_RESTARTED;
2487 case ATH10K_STATE_ON:
2488 case ATH10K_STATE_RESTARTED:
2489 case ATH10K_STATE_WEDGED:
2493 case ATH10K_STATE_UTF:
2498 ret = ath10k_hif_power_up(ar);
2500 ath10k_err(ar, "Could not init hif: %d\n", ret);
2504 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2506 ath10k_err(ar, "Could not init core: %d\n", ret);
2507 goto err_power_down;
2510 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2512 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2516 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2518 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2522 if (ar->cfg_tx_chainmask)
2523 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2524 ar->cfg_rx_chainmask);
2527 * By default FW set ARP frames ac to voice (6). In that case ARP
2528 * exchange is not working properly for UAPSD enabled AP. ARP requests
2529 * which arrives with access category 0 are processed by network stack
2530 * and send back with access category 0, but FW changes access category
2531 * to 6. Set ARP frames access category to best effort (0) solves
2535 ret = ath10k_wmi_pdev_set_param(ar,
2536 ar->wmi.pdev_param->arp_ac_override, 0);
2538 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2543 ar->num_started_vdevs = 0;
2544 ath10k_regd_update(ar);
2546 ath10k_spectral_start(ar);
2548 mutex_unlock(&ar->conf_mutex);
2552 ath10k_core_stop(ar);
2555 ath10k_hif_power_down(ar);
2558 ar->state = ATH10K_STATE_OFF;
2561 mutex_unlock(&ar->conf_mutex);
2565 static void ath10k_stop(struct ieee80211_hw *hw)
2567 struct ath10k *ar = hw->priv;
2569 ath10k_drain_tx(ar);
2571 mutex_lock(&ar->conf_mutex);
2572 if (ar->state != ATH10K_STATE_OFF) {
2574 ar->state = ATH10K_STATE_OFF;
2576 mutex_unlock(&ar->conf_mutex);
2578 cancel_delayed_work_sync(&ar->scan.timeout);
2579 cancel_work_sync(&ar->restart_work);
2582 static int ath10k_config_ps(struct ath10k *ar)
2584 struct ath10k_vif *arvif;
2587 lockdep_assert_held(&ar->conf_mutex);
2589 list_for_each_entry(arvif, &ar->arvifs, list) {
2590 ret = ath10k_mac_vif_setup_ps(arvif);
2592 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2600 static const char *chandef_get_width(enum nl80211_chan_width width)
2603 case NL80211_CHAN_WIDTH_20_NOHT:
2605 case NL80211_CHAN_WIDTH_20:
2607 case NL80211_CHAN_WIDTH_40:
2609 case NL80211_CHAN_WIDTH_80:
2611 case NL80211_CHAN_WIDTH_80P80:
2613 case NL80211_CHAN_WIDTH_160:
2615 case NL80211_CHAN_WIDTH_5:
2617 case NL80211_CHAN_WIDTH_10:
2623 static void ath10k_config_chan(struct ath10k *ar)
2625 struct ath10k_vif *arvif;
2628 lockdep_assert_held(&ar->conf_mutex);
2630 ath10k_dbg(ar, ATH10K_DBG_MAC,
2631 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2632 ar->chandef.chan->center_freq,
2633 ar->chandef.center_freq1,
2634 ar->chandef.center_freq2,
2635 chandef_get_width(ar->chandef.width));
2637 /* First stop monitor interface. Some FW versions crash if there's a
2638 * lone monitor interface. */
2639 if (ar->monitor_started)
2640 ath10k_monitor_stop(ar);
2642 list_for_each_entry(arvif, &ar->arvifs, list) {
2643 if (!arvif->is_started)
2649 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2652 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2654 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2655 arvif->vdev_id, ret);
2660 /* all vdevs are downed now - attempt to restart and re-up them */
2662 list_for_each_entry(arvif, &ar->arvifs, list) {
2663 if (!arvif->is_started)
2666 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2669 ret = ath10k_vdev_restart(arvif);
2671 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2672 arvif->vdev_id, ret);
2679 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2682 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2683 arvif->vdev_id, ret);
2688 ath10k_monitor_recalc(ar);
2691 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2693 struct ath10k *ar = hw->priv;
2694 struct ieee80211_conf *conf = &hw->conf;
2698 mutex_lock(&ar->conf_mutex);
2700 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2701 ath10k_dbg(ar, ATH10K_DBG_MAC,
2702 "mac config channel %dMHz flags 0x%x radar %d\n",
2703 conf->chandef.chan->center_freq,
2704 conf->chandef.chan->flags,
2705 conf->radar_enabled);
2707 spin_lock_bh(&ar->data_lock);
2708 ar->rx_channel = conf->chandef.chan;
2709 spin_unlock_bh(&ar->data_lock);
2711 ar->radar_enabled = conf->radar_enabled;
2712 ath10k_recalc_radar_detection(ar);
2714 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2715 ar->chandef = conf->chandef;
2716 ath10k_config_chan(ar);
2720 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2721 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
2722 hw->conf.power_level);
2724 param = ar->wmi.pdev_param->txpower_limit2g;
2725 ret = ath10k_wmi_pdev_set_param(ar, param,
2726 hw->conf.power_level * 2);
2728 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2729 hw->conf.power_level, ret);
2731 param = ar->wmi.pdev_param->txpower_limit5g;
2732 ret = ath10k_wmi_pdev_set_param(ar, param,
2733 hw->conf.power_level * 2);
2735 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2736 hw->conf.power_level, ret);
2739 if (changed & IEEE80211_CONF_CHANGE_PS)
2740 ath10k_config_ps(ar);
2742 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2743 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2744 ret = ath10k_monitor_recalc(ar);
2746 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2749 mutex_unlock(&ar->conf_mutex);
2755 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2756 * because we will send mgmt frames without CCK. This requirement
2757 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2760 static int ath10k_add_interface(struct ieee80211_hw *hw,
2761 struct ieee80211_vif *vif)
2763 struct ath10k *ar = hw->priv;
2764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2765 enum wmi_sta_powersave_param param;
2771 mutex_lock(&ar->conf_mutex);
2773 memset(arvif, 0, sizeof(*arvif));
2778 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2779 INIT_LIST_HEAD(&arvif->list);
2781 if (ar->free_vdev_map == 0) {
2782 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2786 bit = __ffs64(ar->free_vdev_map);
2788 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2789 bit, ar->free_vdev_map);
2791 arvif->vdev_id = bit;
2792 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2795 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2797 switch (vif->type) {
2798 case NL80211_IFTYPE_UNSPECIFIED:
2799 case NL80211_IFTYPE_STATION:
2800 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2802 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2804 case NL80211_IFTYPE_ADHOC:
2805 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2807 case NL80211_IFTYPE_AP:
2808 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2811 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2813 case NL80211_IFTYPE_MONITOR:
2814 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2821 /* Some firmware revisions don't wait for beacon tx completion before
2822 * sending another SWBA event. This could lead to hardware using old
2823 * (freed) beacon data in some cases, e.g. tx credit starvation
2824 * combined with missed TBTT. This is very very rare.
2826 * On non-IOMMU-enabled hosts this could be a possible security issue
2827 * because hw could beacon some random data on the air. On
2828 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2829 * device would crash.
2831 * Since there are no beacon tx completions (implicit nor explicit)
2832 * propagated to host the only workaround for this is to allocate a
2833 * DMA-coherent buffer for a lifetime of a vif and use it for all
2834 * beacon tx commands. Worst case for this approach is some beacons may
2835 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2837 if (vif->type == NL80211_IFTYPE_ADHOC ||
2838 vif->type == NL80211_IFTYPE_AP) {
2839 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2840 IEEE80211_MAX_FRAME_LEN,
2841 &arvif->beacon_paddr,
2843 if (!arvif->beacon_buf) {
2845 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2851 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2852 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2853 arvif->beacon_buf ? "single-buf" : "per-skb");
2855 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2856 arvif->vdev_subtype, vif->addr);
2858 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
2859 arvif->vdev_id, ret);
2863 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
2864 list_add(&arvif->list, &ar->arvifs);
2866 vdev_param = ar->wmi.vdev_param->def_keyid;
2867 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2868 arvif->def_wep_key_idx);
2870 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
2871 arvif->vdev_id, ret);
2872 goto err_vdev_delete;
2875 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2876 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2877 ATH10K_HW_TXRX_NATIVE_WIFI);
2878 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2879 if (ret && ret != -EOPNOTSUPP) {
2880 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
2881 arvif->vdev_id, ret);
2882 goto err_vdev_delete;
2885 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2886 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2888 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
2889 arvif->vdev_id, ret);
2890 goto err_vdev_delete;
2893 ret = ath10k_mac_set_kickout(arvif);
2895 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
2896 arvif->vdev_id, ret);
2897 goto err_peer_delete;
2901 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2902 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2903 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2904 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2907 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
2908 arvif->vdev_id, ret);
2909 goto err_peer_delete;
2912 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2913 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2914 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2917 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
2918 arvif->vdev_id, ret);
2919 goto err_peer_delete;
2922 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2923 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2924 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2927 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
2928 arvif->vdev_id, ret);
2929 goto err_peer_delete;
2933 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2935 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
2936 arvif->vdev_id, ret);
2937 goto err_peer_delete;
2940 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2942 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
2943 arvif->vdev_id, ret);
2944 goto err_peer_delete;
2947 mutex_unlock(&ar->conf_mutex);
2951 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2952 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2955 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2956 ar->free_vdev_map |= 1LL << arvif->vdev_id;
2957 list_del(&arvif->list);
2960 if (arvif->beacon_buf) {
2961 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
2962 arvif->beacon_buf, arvif->beacon_paddr);
2963 arvif->beacon_buf = NULL;
2966 mutex_unlock(&ar->conf_mutex);
2971 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2972 struct ieee80211_vif *vif)
2974 struct ath10k *ar = hw->priv;
2975 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2978 mutex_lock(&ar->conf_mutex);
2980 cancel_work_sync(&arvif->wep_key_work);
2982 spin_lock_bh(&ar->data_lock);
2983 ath10k_mac_vif_beacon_cleanup(arvif);
2984 spin_unlock_bh(&ar->data_lock);
2986 ret = ath10k_spectral_vif_stop(arvif);
2988 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
2989 arvif->vdev_id, ret);
2991 ar->free_vdev_map |= 1LL << arvif->vdev_id;
2992 list_del(&arvif->list);
2994 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2995 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2997 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
2998 arvif->vdev_id, ret);
3000 kfree(arvif->u.ap.noa_data);
3003 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3006 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3008 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3009 arvif->vdev_id, ret);
3011 ath10k_peer_cleanup(ar, arvif->vdev_id);
3013 mutex_unlock(&ar->conf_mutex);
3017 * FIXME: Has to be verified.
3019 #define SUPPORTED_FILTERS \
3020 (FIF_PROMISC_IN_BSS | \
3025 FIF_BCN_PRBRESP_PROMISC | \
3029 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3030 unsigned int changed_flags,
3031 unsigned int *total_flags,
3034 struct ath10k *ar = hw->priv;
3037 mutex_lock(&ar->conf_mutex);
3039 changed_flags &= SUPPORTED_FILTERS;
3040 *total_flags &= SUPPORTED_FILTERS;
3041 ar->filter_flags = *total_flags;
3043 ret = ath10k_monitor_recalc(ar);
3045 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3047 mutex_unlock(&ar->conf_mutex);
3050 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3051 struct ieee80211_vif *vif,
3052 struct ieee80211_bss_conf *info,
3055 struct ath10k *ar = hw->priv;
3056 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3058 u32 vdev_param, pdev_param, slottime, preamble;
3060 mutex_lock(&ar->conf_mutex);
3062 if (changed & BSS_CHANGED_IBSS)
3063 ath10k_control_ibss(arvif, info, vif->addr);
3065 if (changed & BSS_CHANGED_BEACON_INT) {
3066 arvif->beacon_interval = info->beacon_int;
3067 vdev_param = ar->wmi.vdev_param->beacon_interval;
3068 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3069 arvif->beacon_interval);
3070 ath10k_dbg(ar, ATH10K_DBG_MAC,
3071 "mac vdev %d beacon_interval %d\n",
3072 arvif->vdev_id, arvif->beacon_interval);
3075 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3076 arvif->vdev_id, ret);
3079 if (changed & BSS_CHANGED_BEACON) {
3080 ath10k_dbg(ar, ATH10K_DBG_MAC,
3081 "vdev %d set beacon tx mode to staggered\n",
3084 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3085 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3086 WMI_BEACON_STAGGERED_MODE);
3088 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3089 arvif->vdev_id, ret);
3092 if (changed & BSS_CHANGED_BEACON_INFO) {
3093 arvif->dtim_period = info->dtim_period;
3095 ath10k_dbg(ar, ATH10K_DBG_MAC,
3096 "mac vdev %d dtim_period %d\n",
3097 arvif->vdev_id, arvif->dtim_period);
3099 vdev_param = ar->wmi.vdev_param->dtim_period;
3100 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3101 arvif->dtim_period);
3103 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3104 arvif->vdev_id, ret);
3107 if (changed & BSS_CHANGED_SSID &&
3108 vif->type == NL80211_IFTYPE_AP) {
3109 arvif->u.ap.ssid_len = info->ssid_len;
3111 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3112 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3116 * Firmware manages AP self-peer internally so make sure to not create
3117 * it in driver. Otherwise AP self-peer deletion may timeout later.
3119 if (changed & BSS_CHANGED_BSSID &&
3120 vif->type != NL80211_IFTYPE_AP) {
3121 if (!is_zero_ether_addr(info->bssid)) {
3122 if (vif->type == NL80211_IFTYPE_STATION) {
3123 ath10k_dbg(ar, ATH10K_DBG_MAC,
3124 "mac vdev %d create peer %pM\n",
3125 arvif->vdev_id, info->bssid);
3127 ret = ath10k_peer_create(ar, arvif->vdev_id,
3130 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
3131 info->bssid, arvif->vdev_id,
3134 * this is never erased as we it for crypto key
3135 * clearing; this is FW requirement
3137 ether_addr_copy(arvif->bssid, info->bssid);
3139 ath10k_dbg(ar, ATH10K_DBG_MAC,
3140 "mac vdev %d start %pM\n",
3141 arvif->vdev_id, info->bssid);
3143 ret = ath10k_vdev_start(arvif);
3145 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3146 arvif->vdev_id, ret);
3150 arvif->is_started = true;
3154 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3155 * so driver need to store it. It is needed when leaving
3156 * IBSS in order to remove BSSID peer.
3158 if (vif->type == NL80211_IFTYPE_ADHOC)
3159 memcpy(arvif->bssid, info->bssid,
3164 if (changed & BSS_CHANGED_BEACON_ENABLED)
3165 ath10k_control_beaconing(arvif, info);
3167 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3168 arvif->use_cts_prot = info->use_cts_prot;
3169 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3170 arvif->vdev_id, info->use_cts_prot);
3172 ret = ath10k_recalc_rtscts_prot(arvif);
3174 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3175 arvif->vdev_id, ret);
3178 if (changed & BSS_CHANGED_ERP_SLOT) {
3179 if (info->use_short_slot)
3180 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3183 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3185 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3186 arvif->vdev_id, slottime);
3188 vdev_param = ar->wmi.vdev_param->slot_time;
3189 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3192 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3193 arvif->vdev_id, ret);
3196 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3197 if (info->use_short_preamble)
3198 preamble = WMI_VDEV_PREAMBLE_SHORT;
3200 preamble = WMI_VDEV_PREAMBLE_LONG;
3202 ath10k_dbg(ar, ATH10K_DBG_MAC,
3203 "mac vdev %d preamble %dn",
3204 arvif->vdev_id, preamble);
3206 vdev_param = ar->wmi.vdev_param->preamble;
3207 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3210 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3211 arvif->vdev_id, ret);
3214 if (changed & BSS_CHANGED_ASSOC) {
3216 /* Workaround: Make sure monitor vdev is not running
3217 * when associating to prevent some firmware revisions
3218 * (e.g. 10.1 and 10.2) from crashing.
3220 if (ar->monitor_started)
3221 ath10k_monitor_stop(ar);
3222 ath10k_bss_assoc(hw, vif, info);
3223 ath10k_monitor_recalc(ar);
3228 mutex_unlock(&ar->conf_mutex);
3231 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3232 struct ieee80211_vif *vif,
3233 struct ieee80211_scan_request *hw_req)
3235 struct ath10k *ar = hw->priv;
3236 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3237 struct cfg80211_scan_request *req = &hw_req->req;
3238 struct wmi_start_scan_arg arg;
3242 mutex_lock(&ar->conf_mutex);
3244 spin_lock_bh(&ar->data_lock);
3245 switch (ar->scan.state) {
3246 case ATH10K_SCAN_IDLE:
3247 reinit_completion(&ar->scan.started);
3248 reinit_completion(&ar->scan.completed);
3249 ar->scan.state = ATH10K_SCAN_STARTING;
3250 ar->scan.is_roc = false;
3251 ar->scan.vdev_id = arvif->vdev_id;
3254 case ATH10K_SCAN_STARTING:
3255 case ATH10K_SCAN_RUNNING:
3256 case ATH10K_SCAN_ABORTING:
3260 spin_unlock_bh(&ar->data_lock);
3265 memset(&arg, 0, sizeof(arg));
3266 ath10k_wmi_start_scan_init(ar, &arg);
3267 arg.vdev_id = arvif->vdev_id;
3268 arg.scan_id = ATH10K_SCAN_ID;
3271 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3274 arg.ie_len = req->ie_len;
3275 memcpy(arg.ie, req->ie, arg.ie_len);
3279 arg.n_ssids = req->n_ssids;
3280 for (i = 0; i < arg.n_ssids; i++) {
3281 arg.ssids[i].len = req->ssids[i].ssid_len;
3282 arg.ssids[i].ssid = req->ssids[i].ssid;
3285 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3288 if (req->n_channels) {
3289 arg.n_channels = req->n_channels;
3290 for (i = 0; i < arg.n_channels; i++)
3291 arg.channels[i] = req->channels[i]->center_freq;
3294 ret = ath10k_start_scan(ar, &arg);
3296 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3297 spin_lock_bh(&ar->data_lock);
3298 ar->scan.state = ATH10K_SCAN_IDLE;
3299 spin_unlock_bh(&ar->data_lock);
3303 mutex_unlock(&ar->conf_mutex);
3307 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3308 struct ieee80211_vif *vif)
3310 struct ath10k *ar = hw->priv;
3312 mutex_lock(&ar->conf_mutex);
3313 cancel_delayed_work_sync(&ar->scan.timeout);
3314 ath10k_scan_abort(ar);
3315 mutex_unlock(&ar->conf_mutex);
3318 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3319 struct ath10k_vif *arvif,
3320 enum set_key_cmd cmd,
3321 struct ieee80211_key_conf *key)
3323 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3326 /* 10.1 firmware branch requires default key index to be set to group
3327 * key index after installing it. Otherwise FW/HW Txes corrupted
3328 * frames with multi-vif APs. This is not required for main firmware
3329 * branch (e.g. 636).
3331 * FIXME: This has been tested only in AP. It remains unknown if this
3332 * is required for multi-vif STA interfaces on 10.1 */
3334 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3337 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3340 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3343 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3349 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3352 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3353 arvif->vdev_id, ret);
3356 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3357 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3358 struct ieee80211_key_conf *key)
3360 struct ath10k *ar = hw->priv;
3361 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3362 struct ath10k_peer *peer;
3363 const u8 *peer_addr;
3364 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3365 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3368 if (key->keyidx > WMI_MAX_KEY_INDEX)
3371 mutex_lock(&ar->conf_mutex);
3374 peer_addr = sta->addr;
3375 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3376 peer_addr = vif->bss_conf.bssid;
3378 peer_addr = vif->addr;
3380 key->hw_key_idx = key->keyidx;
3382 /* the peer should not disappear in mid-way (unless FW goes awry) since
3383 * we already hold conf_mutex. we just make sure its there now. */
3384 spin_lock_bh(&ar->data_lock);
3385 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3386 spin_unlock_bh(&ar->data_lock);
3389 if (cmd == SET_KEY) {
3390 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3395 /* if the peer doesn't exist there is no key to disable
3403 arvif->wep_keys[key->keyidx] = key;
3405 arvif->wep_keys[key->keyidx] = NULL;
3407 if (cmd == DISABLE_KEY)
3408 ath10k_clear_vdev_key(arvif, key);
3411 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3413 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3414 arvif->vdev_id, peer_addr, ret);
3418 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3420 spin_lock_bh(&ar->data_lock);
3421 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3422 if (peer && cmd == SET_KEY)
3423 peer->keys[key->keyidx] = key;
3424 else if (peer && cmd == DISABLE_KEY)
3425 peer->keys[key->keyidx] = NULL;
3426 else if (peer == NULL)
3427 /* impossible unless FW goes crazy */
3428 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3429 spin_unlock_bh(&ar->data_lock);
3432 mutex_unlock(&ar->conf_mutex);
3436 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3439 struct ath10k_vif *arvif;
3440 struct ath10k_sta *arsta;
3441 struct ieee80211_sta *sta;
3442 u32 changed, bw, nss, smps;
3445 arsta = container_of(wk, struct ath10k_sta, update_wk);
3446 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3447 arvif = arsta->arvif;
3450 spin_lock_bh(&ar->data_lock);
3452 changed = arsta->changed;
3459 spin_unlock_bh(&ar->data_lock);
3461 mutex_lock(&ar->conf_mutex);
3463 if (changed & IEEE80211_RC_BW_CHANGED) {
3464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3467 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3468 WMI_PEER_CHAN_WIDTH, bw);
3470 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3471 sta->addr, bw, err);
3474 if (changed & IEEE80211_RC_NSS_CHANGED) {
3475 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3478 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3481 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3482 sta->addr, nss, err);
3485 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3486 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3489 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3490 WMI_PEER_SMPS_STATE, smps);
3492 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3493 sta->addr, smps, err);
3496 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3497 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3500 err = ath10k_station_assoc(ar, arvif, sta, true);
3502 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3506 mutex_unlock(&ar->conf_mutex);
3509 static int ath10k_sta_state(struct ieee80211_hw *hw,
3510 struct ieee80211_vif *vif,
3511 struct ieee80211_sta *sta,
3512 enum ieee80211_sta_state old_state,
3513 enum ieee80211_sta_state new_state)
3515 struct ath10k *ar = hw->priv;
3516 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3517 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3521 if (old_state == IEEE80211_STA_NOTEXIST &&
3522 new_state == IEEE80211_STA_NONE) {
3523 memset(arsta, 0, sizeof(*arsta));
3524 arsta->arvif = arvif;
3525 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3528 /* cancel must be done outside the mutex to avoid deadlock */
3529 if ((old_state == IEEE80211_STA_NONE &&
3530 new_state == IEEE80211_STA_NOTEXIST))
3531 cancel_work_sync(&arsta->update_wk);
3533 mutex_lock(&ar->conf_mutex);
3535 if (old_state == IEEE80211_STA_NOTEXIST &&
3536 new_state == IEEE80211_STA_NONE &&
3537 vif->type != NL80211_IFTYPE_STATION) {
3539 * New station addition.
3541 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3542 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3544 max_num_peers = TARGET_NUM_PEERS;
3546 if (ar->num_peers >= max_num_peers) {
3547 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
3548 ar->num_peers, max_num_peers);
3553 ath10k_dbg(ar, ATH10K_DBG_MAC,
3554 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3555 arvif->vdev_id, sta->addr, ar->num_peers);
3557 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3559 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3560 sta->addr, arvif->vdev_id, ret);
3561 } else if ((old_state == IEEE80211_STA_NONE &&
3562 new_state == IEEE80211_STA_NOTEXIST)) {
3564 * Existing station deletion.
3566 ath10k_dbg(ar, ATH10K_DBG_MAC,
3567 "mac vdev %d peer delete %pM (sta gone)\n",
3568 arvif->vdev_id, sta->addr);
3569 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3571 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3572 sta->addr, arvif->vdev_id, ret);
3574 if (vif->type == NL80211_IFTYPE_STATION)
3575 ath10k_bss_disassoc(hw, vif);
3576 } else if (old_state == IEEE80211_STA_AUTH &&
3577 new_state == IEEE80211_STA_ASSOC &&
3578 (vif->type == NL80211_IFTYPE_AP ||
3579 vif->type == NL80211_IFTYPE_ADHOC)) {
3583 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3586 ret = ath10k_station_assoc(ar, arvif, sta, false);
3588 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3589 sta->addr, arvif->vdev_id, ret);
3590 } else if (old_state == IEEE80211_STA_ASSOC &&
3591 new_state == IEEE80211_STA_AUTH &&
3592 (vif->type == NL80211_IFTYPE_AP ||
3593 vif->type == NL80211_IFTYPE_ADHOC)) {
3597 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3600 ret = ath10k_station_disassoc(ar, arvif, sta);
3602 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3603 sta->addr, arvif->vdev_id, ret);
3606 mutex_unlock(&ar->conf_mutex);
3610 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3611 u16 ac, bool enable)
3613 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3617 lockdep_assert_held(&ar->conf_mutex);
3619 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3623 case IEEE80211_AC_VO:
3624 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3625 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3627 case IEEE80211_AC_VI:
3628 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3629 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3631 case IEEE80211_AC_BE:
3632 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3633 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3635 case IEEE80211_AC_BK:
3636 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3637 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3642 arvif->u.sta.uapsd |= value;
3644 arvif->u.sta.uapsd &= ~value;
3646 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3647 WMI_STA_PS_PARAM_UAPSD,
3648 arvif->u.sta.uapsd);
3650 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3654 if (arvif->u.sta.uapsd)
3655 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3657 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3659 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3660 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3663 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3669 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3670 struct ieee80211_vif *vif, u16 ac,
3671 const struct ieee80211_tx_queue_params *params)
3673 struct ath10k *ar = hw->priv;
3674 struct wmi_wmm_params_arg *p = NULL;
3677 mutex_lock(&ar->conf_mutex);
3680 case IEEE80211_AC_VO:
3681 p = &ar->wmm_params.ac_vo;
3683 case IEEE80211_AC_VI:
3684 p = &ar->wmm_params.ac_vi;
3686 case IEEE80211_AC_BE:
3687 p = &ar->wmm_params.ac_be;
3689 case IEEE80211_AC_BK:
3690 p = &ar->wmm_params.ac_bk;
3699 p->cwmin = params->cw_min;
3700 p->cwmax = params->cw_max;
3701 p->aifs = params->aifs;
3704 * The channel time duration programmed in the HW is in absolute
3705 * microseconds, while mac80211 gives the txop in units of
3708 p->txop = params->txop * 32;
3710 /* FIXME: FW accepts wmm params per hw, not per vif */
3711 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3713 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3717 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3719 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3722 mutex_unlock(&ar->conf_mutex);
3726 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3728 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3729 struct ieee80211_vif *vif,
3730 struct ieee80211_channel *chan,
3732 enum ieee80211_roc_type type)
3734 struct ath10k *ar = hw->priv;
3735 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3736 struct wmi_start_scan_arg arg;
3739 mutex_lock(&ar->conf_mutex);
3741 spin_lock_bh(&ar->data_lock);
3742 switch (ar->scan.state) {
3743 case ATH10K_SCAN_IDLE:
3744 reinit_completion(&ar->scan.started);
3745 reinit_completion(&ar->scan.completed);
3746 reinit_completion(&ar->scan.on_channel);
3747 ar->scan.state = ATH10K_SCAN_STARTING;
3748 ar->scan.is_roc = true;
3749 ar->scan.vdev_id = arvif->vdev_id;
3750 ar->scan.roc_freq = chan->center_freq;
3753 case ATH10K_SCAN_STARTING:
3754 case ATH10K_SCAN_RUNNING:
3755 case ATH10K_SCAN_ABORTING:
3759 spin_unlock_bh(&ar->data_lock);
3764 memset(&arg, 0, sizeof(arg));
3765 ath10k_wmi_start_scan_init(ar, &arg);
3766 arg.vdev_id = arvif->vdev_id;
3767 arg.scan_id = ATH10K_SCAN_ID;
3769 arg.channels[0] = chan->center_freq;
3770 arg.dwell_time_active = duration;
3771 arg.dwell_time_passive = duration;
3772 arg.max_scan_time = 2 * duration;
3773 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3774 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3776 ret = ath10k_start_scan(ar, &arg);
3778 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
3779 spin_lock_bh(&ar->data_lock);
3780 ar->scan.state = ATH10K_SCAN_IDLE;
3781 spin_unlock_bh(&ar->data_lock);
3785 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3787 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
3789 ret = ath10k_scan_stop(ar);
3791 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3799 mutex_unlock(&ar->conf_mutex);
3803 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3805 struct ath10k *ar = hw->priv;
3807 mutex_lock(&ar->conf_mutex);
3808 cancel_delayed_work_sync(&ar->scan.timeout);
3809 ath10k_scan_abort(ar);
3810 mutex_unlock(&ar->conf_mutex);
3816 * Both RTS and Fragmentation threshold are interface-specific
3817 * in ath10k, but device-specific in mac80211.
3820 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3822 struct ath10k *ar = hw->priv;
3823 struct ath10k_vif *arvif;
3826 mutex_lock(&ar->conf_mutex);
3827 list_for_each_entry(arvif, &ar->arvifs, list) {
3828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3829 arvif->vdev_id, value);
3831 ret = ath10k_mac_set_rts(arvif, value);
3833 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3834 arvif->vdev_id, ret);
3838 mutex_unlock(&ar->conf_mutex);
3843 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3845 struct ath10k *ar = hw->priv;
3846 struct ath10k_vif *arvif;
3849 mutex_lock(&ar->conf_mutex);
3850 list_for_each_entry(arvif, &ar->arvifs, list) {
3851 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3852 arvif->vdev_id, value);
3854 ret = ath10k_mac_set_rts(arvif, value);
3856 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
3857 arvif->vdev_id, ret);
3861 mutex_unlock(&ar->conf_mutex);
3866 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3867 u32 queues, bool drop)
3869 struct ath10k *ar = hw->priv;
3873 /* mac80211 doesn't care if we really xmit queued frames or not
3874 * we'll collect those frames either way if we stop/delete vdevs */
3878 mutex_lock(&ar->conf_mutex);
3880 if (ar->state == ATH10K_STATE_WEDGED)
3883 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3886 spin_lock_bh(&ar->htt.tx_lock);
3887 empty = (ar->htt.num_pending_tx == 0);
3888 spin_unlock_bh(&ar->htt.tx_lock);
3890 skip = (ar->state == ATH10K_STATE_WEDGED);
3893 }), ATH10K_FLUSH_TIMEOUT_HZ);
3895 if (ret <= 0 || skip)
3896 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
3897 skip, ar->state, ret);
3900 mutex_unlock(&ar->conf_mutex);
3903 /* TODO: Implement this function properly
3904 * For now it is needed to reply to Probe Requests in IBSS mode.
3905 * Propably we need this information from FW.
3907 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3913 static int ath10k_suspend(struct ieee80211_hw *hw,
3914 struct cfg80211_wowlan *wowlan)
3916 struct ath10k *ar = hw->priv;
3919 mutex_lock(&ar->conf_mutex);
3921 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
3923 if (ret == -ETIMEDOUT)
3929 ret = ath10k_hif_suspend(ar);
3931 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
3938 ret = ath10k_wmi_pdev_resume_target(ar);
3940 ath10k_warn(ar, "failed to resume target: %d\n", ret);
3944 mutex_unlock(&ar->conf_mutex);
3948 static int ath10k_resume(struct ieee80211_hw *hw)
3950 struct ath10k *ar = hw->priv;
3953 mutex_lock(&ar->conf_mutex);
3955 ret = ath10k_hif_resume(ar);
3957 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
3962 ret = ath10k_wmi_pdev_resume_target(ar);
3964 ath10k_warn(ar, "failed to resume target: %d\n", ret);
3971 mutex_unlock(&ar->conf_mutex);
3976 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3978 struct ath10k *ar = hw->priv;
3980 mutex_lock(&ar->conf_mutex);
3982 /* If device failed to restart it will be in a different state, e.g.
3983 * ATH10K_STATE_WEDGED */
3984 if (ar->state == ATH10K_STATE_RESTARTED) {
3985 ath10k_info(ar, "device successfully recovered\n");
3986 ar->state = ATH10K_STATE_ON;
3989 mutex_unlock(&ar->conf_mutex);
3992 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3993 struct survey_info *survey)
3995 struct ath10k *ar = hw->priv;
3996 struct ieee80211_supported_band *sband;
3997 struct survey_info *ar_survey = &ar->survey[idx];
4000 mutex_lock(&ar->conf_mutex);
4002 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4003 if (sband && idx >= sband->n_channels) {
4004 idx -= sband->n_channels;
4009 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4011 if (!sband || idx >= sband->n_channels) {
4016 spin_lock_bh(&ar->data_lock);
4017 memcpy(survey, ar_survey, sizeof(*survey));
4018 spin_unlock_bh(&ar->data_lock);
4020 survey->channel = &sband->channels[idx];
4023 mutex_unlock(&ar->conf_mutex);
4027 /* Helper table for legacy fixed_rate/bitrate_mask */
4028 static const u8 cck_ofdm_rate[] = {
4045 /* Check if only one bit set */
4046 static int ath10k_check_single_mask(u32 mask)
4054 mask &= ~BIT(bit - 1);
4062 ath10k_default_bitrate_mask(struct ath10k *ar,
4063 enum ieee80211_band band,
4064 const struct cfg80211_bitrate_mask *mask)
4066 u32 legacy = 0x00ff;
4071 case IEEE80211_BAND_2GHZ:
4075 case IEEE80211_BAND_5GHZ:
4081 if (mask->control[band].legacy != legacy)
4084 for (i = 0; i < ar->num_rf_chains; i++)
4085 if (mask->control[band].ht_mcs[i] != ht)
4088 for (i = 0; i < ar->num_rf_chains; i++)
4089 if (mask->control[band].vht_mcs[i] != vht)
4096 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4097 enum ieee80211_band band,
4100 int ht_nss = 0, vht_nss = 0, i;
4103 if (ath10k_check_single_mask(mask->control[band].legacy))
4107 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4108 if (mask->control[band].ht_mcs[i] == 0xff)
4110 else if (mask->control[band].ht_mcs[i] == 0x00)
4119 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4120 if (mask->control[band].vht_mcs[i] == 0x03ff)
4122 else if (mask->control[band].vht_mcs[i] == 0x0000)
4130 if (ht_nss > 0 && vht_nss > 0)
4134 *fixed_nss = ht_nss;
4136 *fixed_nss = vht_nss;
4144 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4145 enum ieee80211_band band,
4146 enum wmi_rate_preamble *preamble)
4148 int legacy = 0, ht = 0, vht = 0, i;
4150 *preamble = WMI_RATE_PREAMBLE_OFDM;
4153 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4158 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4159 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4164 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4165 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4169 /* Currently we support only one fixed_rate */
4170 if ((legacy + ht + vht) != 1)
4174 *preamble = WMI_RATE_PREAMBLE_HT;
4176 *preamble = WMI_RATE_PREAMBLE_VHT;
4182 ath10k_bitrate_mask_rate(struct ath10k *ar,
4183 const struct cfg80211_bitrate_mask *mask,
4184 enum ieee80211_band band,
4188 u8 rate = 0, pream = 0, nss = 0, i;
4189 enum wmi_rate_preamble preamble;
4191 /* Check if single rate correct */
4192 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4198 case WMI_RATE_PREAMBLE_CCK:
4199 case WMI_RATE_PREAMBLE_OFDM:
4200 i = ffs(mask->control[band].legacy) - 1;
4202 if (band == IEEE80211_BAND_2GHZ && i < 4)
4203 pream = WMI_RATE_PREAMBLE_CCK;
4205 if (band == IEEE80211_BAND_5GHZ)
4208 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4211 rate = cck_ofdm_rate[i];
4213 case WMI_RATE_PREAMBLE_HT:
4214 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4215 if (mask->control[band].ht_mcs[i])
4218 if (i == IEEE80211_HT_MCS_MASK_LEN)
4221 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4224 case WMI_RATE_PREAMBLE_VHT:
4225 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4226 if (mask->control[band].vht_mcs[i])
4229 if (i == NL80211_VHT_NSS_MAX)
4232 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4237 *fixed_nss = nss + 1;
4241 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4244 *fixed_rate = pream | nss | rate;
4249 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4250 const struct cfg80211_bitrate_mask *mask,
4251 enum ieee80211_band band,
4255 /* First check full NSS mask, if we can simply limit NSS */
4256 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4259 /* Next Check single rate is set */
4260 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4263 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4268 struct ath10k *ar = arvif->ar;
4272 mutex_lock(&ar->conf_mutex);
4274 if (arvif->fixed_rate == fixed_rate &&
4275 arvif->fixed_nss == fixed_nss &&
4276 arvif->force_sgi == force_sgi)
4279 if (fixed_rate == WMI_FIXED_RATE_NONE)
4280 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4283 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4285 vdev_param = ar->wmi.vdev_param->fixed_rate;
4286 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4287 vdev_param, fixed_rate);
4289 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4295 arvif->fixed_rate = fixed_rate;
4297 vdev_param = ar->wmi.vdev_param->nss;
4298 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4299 vdev_param, fixed_nss);
4302 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4308 arvif->fixed_nss = fixed_nss;
4310 vdev_param = ar->wmi.vdev_param->sgi;
4311 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4315 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4321 arvif->force_sgi = force_sgi;
4324 mutex_unlock(&ar->conf_mutex);
4328 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4329 struct ieee80211_vif *vif,
4330 const struct cfg80211_bitrate_mask *mask)
4332 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4333 struct ath10k *ar = arvif->ar;
4334 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4335 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4336 u8 fixed_nss = ar->num_rf_chains;
4339 force_sgi = mask->control[band].gi;
4340 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4343 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4344 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4350 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4351 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4355 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4356 fixed_nss, force_sgi);
4359 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4360 struct ieee80211_vif *vif,
4361 struct ieee80211_sta *sta,
4364 struct ath10k *ar = hw->priv;
4365 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4368 spin_lock_bh(&ar->data_lock);
4370 ath10k_dbg(ar, ATH10K_DBG_MAC,
4371 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4372 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4375 if (changed & IEEE80211_RC_BW_CHANGED) {
4376 bw = WMI_PEER_CHWIDTH_20MHZ;
4378 switch (sta->bandwidth) {
4379 case IEEE80211_STA_RX_BW_20:
4380 bw = WMI_PEER_CHWIDTH_20MHZ;
4382 case IEEE80211_STA_RX_BW_40:
4383 bw = WMI_PEER_CHWIDTH_40MHZ;
4385 case IEEE80211_STA_RX_BW_80:
4386 bw = WMI_PEER_CHWIDTH_80MHZ;
4388 case IEEE80211_STA_RX_BW_160:
4389 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4390 sta->bandwidth, sta->addr);
4391 bw = WMI_PEER_CHWIDTH_20MHZ;
4398 if (changed & IEEE80211_RC_NSS_CHANGED)
4399 arsta->nss = sta->rx_nss;
4401 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4402 smps = WMI_PEER_SMPS_PS_NONE;
4404 switch (sta->smps_mode) {
4405 case IEEE80211_SMPS_AUTOMATIC:
4406 case IEEE80211_SMPS_OFF:
4407 smps = WMI_PEER_SMPS_PS_NONE;
4409 case IEEE80211_SMPS_STATIC:
4410 smps = WMI_PEER_SMPS_STATIC;
4412 case IEEE80211_SMPS_DYNAMIC:
4413 smps = WMI_PEER_SMPS_DYNAMIC;
4415 case IEEE80211_SMPS_NUM_MODES:
4416 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4417 sta->smps_mode, sta->addr);
4418 smps = WMI_PEER_SMPS_PS_NONE;
4425 arsta->changed |= changed;
4427 spin_unlock_bh(&ar->data_lock);
4429 ieee80211_queue_work(hw, &arsta->update_wk);
4432 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4435 * FIXME: Return 0 for time being. Need to figure out whether FW
4436 * has the API to fetch 64-bit local TSF
4442 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4443 struct ieee80211_vif *vif,
4444 enum ieee80211_ampdu_mlme_action action,
4445 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4448 struct ath10k *ar = hw->priv;
4449 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4451 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4452 arvif->vdev_id, sta->addr, tid, action);
4455 case IEEE80211_AMPDU_RX_START:
4456 case IEEE80211_AMPDU_RX_STOP:
4457 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4458 * creation/removal. Do we need to verify this?
4461 case IEEE80211_AMPDU_TX_START:
4462 case IEEE80211_AMPDU_TX_STOP_CONT:
4463 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4464 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4465 case IEEE80211_AMPDU_TX_OPERATIONAL:
4466 /* Firmware offloads Tx aggregation entirely so deny mac80211
4467 * Tx aggregation requests.
4475 static const struct ieee80211_ops ath10k_ops = {
4477 .start = ath10k_start,
4478 .stop = ath10k_stop,
4479 .config = ath10k_config,
4480 .add_interface = ath10k_add_interface,
4481 .remove_interface = ath10k_remove_interface,
4482 .configure_filter = ath10k_configure_filter,
4483 .bss_info_changed = ath10k_bss_info_changed,
4484 .hw_scan = ath10k_hw_scan,
4485 .cancel_hw_scan = ath10k_cancel_hw_scan,
4486 .set_key = ath10k_set_key,
4487 .sta_state = ath10k_sta_state,
4488 .conf_tx = ath10k_conf_tx,
4489 .remain_on_channel = ath10k_remain_on_channel,
4490 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4491 .set_rts_threshold = ath10k_set_rts_threshold,
4492 .set_frag_threshold = ath10k_set_frag_threshold,
4493 .flush = ath10k_flush,
4494 .tx_last_beacon = ath10k_tx_last_beacon,
4495 .set_antenna = ath10k_set_antenna,
4496 .get_antenna = ath10k_get_antenna,
4497 .restart_complete = ath10k_restart_complete,
4498 .get_survey = ath10k_get_survey,
4499 .set_bitrate_mask = ath10k_set_bitrate_mask,
4500 .sta_rc_update = ath10k_sta_rc_update,
4501 .get_tsf = ath10k_get_tsf,
4502 .ampdu_action = ath10k_ampdu_action,
4503 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4504 .get_et_stats = ath10k_debug_get_et_stats,
4505 .get_et_strings = ath10k_debug_get_et_strings,
4507 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4510 .suspend = ath10k_suspend,
4511 .resume = ath10k_resume,
4515 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4516 .bitrate = (_rate), \
4517 .flags = (_flags), \
4518 .hw_value = (_rateid), \
4521 #define CHAN2G(_channel, _freq, _flags) { \
4522 .band = IEEE80211_BAND_2GHZ, \
4523 .hw_value = (_channel), \
4524 .center_freq = (_freq), \
4525 .flags = (_flags), \
4526 .max_antenna_gain = 0, \
4530 #define CHAN5G(_channel, _freq, _flags) { \
4531 .band = IEEE80211_BAND_5GHZ, \
4532 .hw_value = (_channel), \
4533 .center_freq = (_freq), \
4534 .flags = (_flags), \
4535 .max_antenna_gain = 0, \
4539 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4549 CHAN2G(10, 2457, 0),
4550 CHAN2G(11, 2462, 0),
4551 CHAN2G(12, 2467, 0),
4552 CHAN2G(13, 2472, 0),
4553 CHAN2G(14, 2484, 0),
4556 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4557 CHAN5G(36, 5180, 0),
4558 CHAN5G(40, 5200, 0),
4559 CHAN5G(44, 5220, 0),
4560 CHAN5G(48, 5240, 0),
4561 CHAN5G(52, 5260, 0),
4562 CHAN5G(56, 5280, 0),
4563 CHAN5G(60, 5300, 0),
4564 CHAN5G(64, 5320, 0),
4565 CHAN5G(100, 5500, 0),
4566 CHAN5G(104, 5520, 0),
4567 CHAN5G(108, 5540, 0),
4568 CHAN5G(112, 5560, 0),
4569 CHAN5G(116, 5580, 0),
4570 CHAN5G(120, 5600, 0),
4571 CHAN5G(124, 5620, 0),
4572 CHAN5G(128, 5640, 0),
4573 CHAN5G(132, 5660, 0),
4574 CHAN5G(136, 5680, 0),
4575 CHAN5G(140, 5700, 0),
4576 CHAN5G(149, 5745, 0),
4577 CHAN5G(153, 5765, 0),
4578 CHAN5G(157, 5785, 0),
4579 CHAN5G(161, 5805, 0),
4580 CHAN5G(165, 5825, 0),
4583 static struct ieee80211_rate ath10k_rates[] = {
4585 RATETAB_ENT(10, 0x82, 0),
4586 RATETAB_ENT(20, 0x84, 0),
4587 RATETAB_ENT(55, 0x8b, 0),
4588 RATETAB_ENT(110, 0x96, 0),
4590 RATETAB_ENT(60, 0x0c, 0),
4591 RATETAB_ENT(90, 0x12, 0),
4592 RATETAB_ENT(120, 0x18, 0),
4593 RATETAB_ENT(180, 0x24, 0),
4594 RATETAB_ENT(240, 0x30, 0),
4595 RATETAB_ENT(360, 0x48, 0),
4596 RATETAB_ENT(480, 0x60, 0),
4597 RATETAB_ENT(540, 0x6c, 0),
4600 #define ath10k_a_rates (ath10k_rates + 4)
4601 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4602 #define ath10k_g_rates (ath10k_rates + 0)
4603 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4605 struct ath10k *ath10k_mac_create(size_t priv_size)
4607 struct ieee80211_hw *hw;
4610 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4620 void ath10k_mac_destroy(struct ath10k *ar)
4622 ieee80211_free_hw(ar->hw);
4625 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4628 .types = BIT(NL80211_IFTYPE_STATION)
4629 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4633 .types = BIT(NL80211_IFTYPE_P2P_GO)
4637 .types = BIT(NL80211_IFTYPE_AP)
4641 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4644 .types = BIT(NL80211_IFTYPE_AP)
4648 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4650 .limits = ath10k_if_limits,
4651 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4652 .max_interfaces = 8,
4653 .num_different_channels = 1,
4654 .beacon_int_infra_match = true,
4658 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4660 .limits = ath10k_10x_if_limits,
4661 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4662 .max_interfaces = 8,
4663 .num_different_channels = 1,
4664 .beacon_int_infra_match = true,
4665 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4666 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4667 BIT(NL80211_CHAN_WIDTH_20) |
4668 BIT(NL80211_CHAN_WIDTH_40) |
4669 BIT(NL80211_CHAN_WIDTH_80),
4674 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4676 struct ieee80211_sta_vht_cap vht_cap = {0};
4680 vht_cap.vht_supported = 1;
4681 vht_cap.cap = ar->vht_cap_info;
4684 for (i = 0; i < 8; i++) {
4685 if (i < ar->num_rf_chains)
4686 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4688 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4691 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4692 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4697 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4700 struct ieee80211_sta_ht_cap ht_cap = {0};
4702 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4705 ht_cap.ht_supported = 1;
4706 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4707 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4708 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4709 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4710 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4712 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4713 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4715 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4716 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4718 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4721 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4722 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4727 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4728 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4730 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4733 stbc = ar->ht_cap_info;
4734 stbc &= WMI_HT_CAP_RX_STBC;
4735 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4736 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4737 stbc &= IEEE80211_HT_CAP_RX_STBC;
4742 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4743 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4745 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4746 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4748 /* max AMSDU is implicitly taken from vht_cap_info */
4749 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4750 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4752 for (i = 0; i < ar->num_rf_chains; i++)
4753 ht_cap.mcs.rx_mask[i] = 0xFF;
4755 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4760 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4761 struct ieee80211_vif *vif)
4763 struct ath10k_vif_iter *arvif_iter = data;
4764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4766 if (arvif->vdev_id == arvif_iter->vdev_id)
4767 arvif_iter->arvif = arvif;
4770 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4772 struct ath10k_vif_iter arvif_iter;
4775 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4776 arvif_iter.vdev_id = vdev_id;
4778 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4779 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4781 ath10k_get_arvif_iter,
4783 if (!arvif_iter.arvif) {
4784 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
4788 return arvif_iter.arvif;
4791 int ath10k_mac_register(struct ath10k *ar)
4793 struct ieee80211_supported_band *band;
4794 struct ieee80211_sta_vht_cap vht_cap;
4795 struct ieee80211_sta_ht_cap ht_cap;
4799 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4801 SET_IEEE80211_DEV(ar->hw, ar->dev);
4803 ht_cap = ath10k_get_ht_cap(ar);
4804 vht_cap = ath10k_create_vht_cap(ar);
4806 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4807 channels = kmemdup(ath10k_2ghz_channels,
4808 sizeof(ath10k_2ghz_channels),
4815 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4816 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4817 band->channels = channels;
4818 band->n_bitrates = ath10k_g_rates_size;
4819 band->bitrates = ath10k_g_rates;
4820 band->ht_cap = ht_cap;
4822 /* vht is not supported in 2.4 GHz */
4824 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4827 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4828 channels = kmemdup(ath10k_5ghz_channels,
4829 sizeof(ath10k_5ghz_channels),
4836 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4837 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4838 band->channels = channels;
4839 band->n_bitrates = ath10k_a_rates_size;
4840 band->bitrates = ath10k_a_rates;
4841 band->ht_cap = ht_cap;
4842 band->vht_cap = vht_cap;
4843 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4846 ar->hw->wiphy->interface_modes =
4847 BIT(NL80211_IFTYPE_STATION) |
4848 BIT(NL80211_IFTYPE_AP);
4850 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4851 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4853 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4854 ar->hw->wiphy->interface_modes |=
4855 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4856 BIT(NL80211_IFTYPE_P2P_GO);
4858 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4859 IEEE80211_HW_SUPPORTS_PS |
4860 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4861 IEEE80211_HW_SUPPORTS_UAPSD |
4862 IEEE80211_HW_MFP_CAPABLE |
4863 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4864 IEEE80211_HW_HAS_RATE_CONTROL |
4865 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4866 IEEE80211_HW_AP_LINK_PS |
4867 IEEE80211_HW_SPECTRUM_MGMT;
4869 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4870 * bytes is used for padding/alignment if necessary. */
4871 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4873 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4874 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4876 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4877 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4878 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4881 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4882 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4884 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4885 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
4887 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4889 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4890 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4891 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4893 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4895 * on LL hardware queues are managed entirely by the FW
4896 * so we only advertise to mac we can do the queues thing
4900 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4901 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4902 ar->hw->wiphy->n_iface_combinations =
4903 ARRAY_SIZE(ath10k_10x_if_comb);
4905 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4906 ar->hw->wiphy->n_iface_combinations =
4907 ARRAY_SIZE(ath10k_if_comb);
4909 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4912 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4914 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4915 /* Init ath dfs pattern detector */
4916 ar->ath_common.debug_mask = ATH_DBG_DFS;
4917 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4920 if (!ar->dfs_detector)
4921 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
4924 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4925 ath10k_reg_notifier);
4927 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
4931 ret = ieee80211_register_hw(ar->hw);
4933 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
4937 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4938 ret = regulatory_hint(ar->hw->wiphy,
4939 ar->ath_common.regulatory.alpha2);
4941 goto err_unregister;
4947 ieee80211_unregister_hw(ar->hw);
4949 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4950 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4955 void ath10k_mac_unregister(struct ath10k *ar)
4957 ieee80211_unregister_hw(ar->hw);
4959 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4960 ar->dfs_detector->exit(ar->dfs_detector);
4962 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4963 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4965 SET_IEEE80211_DEV(ar->hw, NULL);