2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
34 static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
47 lockdep_assert_held(&arvif->ar->conf_mutex);
49 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
52 arg.key_flags = WMI_KEY_GROUP;
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
58 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
60 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
62 case WLAN_CIPHER_SUITE_TKIP:
63 arg.key_cipher = WMI_CIPHER_TKIP;
64 arg.key_txmic_len = 8;
65 arg.key_rxmic_len = 8;
67 case WLAN_CIPHER_SUITE_WEP40:
68 case WLAN_CIPHER_SUITE_WEP104:
69 arg.key_cipher = WMI_CIPHER_WEP;
70 /* AP/IBSS mode requires self-key to be groupwise
71 * Otherwise pairwise key must be set */
72 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
73 arg.key_flags = WMI_KEY_PAIRWISE;
76 ath10k_warn("cipher %d is not supported\n", key->cipher);
80 if (cmd == DISABLE_KEY) {
81 arg.key_cipher = WMI_CIPHER_NONE;
85 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
88 static int ath10k_install_key(struct ath10k_vif *arvif,
89 struct ieee80211_key_conf *key,
93 struct ath10k *ar = arvif->ar;
96 lockdep_assert_held(&ar->conf_mutex);
98 reinit_completion(&ar->install_key_done);
100 ret = ath10k_send_key(arvif, key, cmd, macaddr);
104 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
111 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
114 struct ath10k *ar = arvif->ar;
115 struct ath10k_peer *peer;
119 lockdep_assert_held(&ar->conf_mutex);
121 spin_lock_bh(&ar->data_lock);
122 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
123 spin_unlock_bh(&ar->data_lock);
128 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
129 if (arvif->wep_keys[i] == NULL)
132 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
137 peer->keys[i] = arvif->wep_keys[i];
143 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
146 struct ath10k *ar = arvif->ar;
147 struct ath10k_peer *peer;
152 lockdep_assert_held(&ar->conf_mutex);
154 spin_lock_bh(&ar->data_lock);
155 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
156 spin_unlock_bh(&ar->data_lock);
161 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
162 if (peer->keys[i] == NULL)
165 ret = ath10k_install_key(arvif, peer->keys[i],
167 if (ret && first_errno == 0)
171 ath10k_warn("failed to remove peer wep key %d: %d\n",
174 peer->keys[i] = NULL;
180 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
181 struct ieee80211_key_conf *key)
183 struct ath10k *ar = arvif->ar;
184 struct ath10k_peer *peer;
190 lockdep_assert_held(&ar->conf_mutex);
193 /* since ath10k_install_key we can't hold data_lock all the
194 * time, so we try to remove the keys incrementally */
195 spin_lock_bh(&ar->data_lock);
197 list_for_each_entry(peer, &ar->peers, list) {
198 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
199 if (peer->keys[i] == key) {
200 memcpy(addr, peer->addr, ETH_ALEN);
201 peer->keys[i] = NULL;
206 if (i < ARRAY_SIZE(peer->keys))
209 spin_unlock_bh(&ar->data_lock);
211 if (i == ARRAY_SIZE(peer->keys))
214 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
215 if (ret && first_errno == 0)
219 ath10k_warn("failed to remove key for %pM: %d\n",
227 /*********************/
228 /* General utilities */
229 /*********************/
231 static inline enum wmi_phy_mode
232 chan_to_phymode(const struct cfg80211_chan_def *chandef)
234 enum wmi_phy_mode phymode = MODE_UNKNOWN;
236 switch (chandef->chan->band) {
237 case IEEE80211_BAND_2GHZ:
238 switch (chandef->width) {
239 case NL80211_CHAN_WIDTH_20_NOHT:
242 case NL80211_CHAN_WIDTH_20:
243 phymode = MODE_11NG_HT20;
245 case NL80211_CHAN_WIDTH_40:
246 phymode = MODE_11NG_HT40;
248 case NL80211_CHAN_WIDTH_5:
249 case NL80211_CHAN_WIDTH_10:
250 case NL80211_CHAN_WIDTH_80:
251 case NL80211_CHAN_WIDTH_80P80:
252 case NL80211_CHAN_WIDTH_160:
253 phymode = MODE_UNKNOWN;
257 case IEEE80211_BAND_5GHZ:
258 switch (chandef->width) {
259 case NL80211_CHAN_WIDTH_20_NOHT:
262 case NL80211_CHAN_WIDTH_20:
263 phymode = MODE_11NA_HT20;
265 case NL80211_CHAN_WIDTH_40:
266 phymode = MODE_11NA_HT40;
268 case NL80211_CHAN_WIDTH_80:
269 phymode = MODE_11AC_VHT80;
271 case NL80211_CHAN_WIDTH_5:
272 case NL80211_CHAN_WIDTH_10:
273 case NL80211_CHAN_WIDTH_80P80:
274 case NL80211_CHAN_WIDTH_160:
275 phymode = MODE_UNKNOWN;
283 WARN_ON(phymode == MODE_UNKNOWN);
287 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
290 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
291 * 0 for no restriction
300 switch (mpdudensity) {
306 /* Our lower layer calculations limit our precision to
322 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
326 lockdep_assert_held(&ar->conf_mutex);
328 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
330 ath10k_warn("failed to create wmi peer %pM on vdev %i: %i\n",
335 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
337 ath10k_warn("failed to wait for created wmi peer %pM on vdev %i: %i\n",
341 spin_lock_bh(&ar->data_lock);
343 spin_unlock_bh(&ar->data_lock);
348 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
350 struct ath10k *ar = arvif->ar;
354 param = ar->wmi.pdev_param->sta_kickout_th;
355 ret = ath10k_wmi_pdev_set_param(ar, param,
356 ATH10K_KICKOUT_THRESHOLD);
358 ath10k_warn("failed to set kickout threshold on vdev %i: %d\n",
359 arvif->vdev_id, ret);
363 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
364 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
365 ATH10K_KEEPALIVE_MIN_IDLE);
367 ath10k_warn("failed to set keepalive minimum idle time on vdev %i: %d\n",
368 arvif->vdev_id, ret);
372 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
373 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
374 ATH10K_KEEPALIVE_MAX_IDLE);
376 ath10k_warn("failed to set keepalive maximum idle time on vdev %i: %d\n",
377 arvif->vdev_id, ret);
381 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
382 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
383 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
385 ath10k_warn("failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
386 arvif->vdev_id, ret);
393 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
395 struct ath10k *ar = arvif->ar;
398 if (value != 0xFFFFFFFF)
399 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
402 vdev_param = ar->wmi.vdev_param->rts_threshold;
403 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
406 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
408 struct ath10k *ar = arvif->ar;
411 if (value != 0xFFFFFFFF)
412 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
413 ATH10K_FRAGMT_THRESHOLD_MIN,
414 ATH10K_FRAGMT_THRESHOLD_MAX);
416 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
417 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
420 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
424 lockdep_assert_held(&ar->conf_mutex);
426 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
430 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
434 spin_lock_bh(&ar->data_lock);
436 spin_unlock_bh(&ar->data_lock);
441 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
443 struct ath10k_peer *peer, *tmp;
445 lockdep_assert_held(&ar->conf_mutex);
447 spin_lock_bh(&ar->data_lock);
448 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
449 if (peer->vdev_id != vdev_id)
452 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
453 peer->addr, vdev_id);
455 list_del(&peer->list);
459 spin_unlock_bh(&ar->data_lock);
462 static void ath10k_peer_cleanup_all(struct ath10k *ar)
464 struct ath10k_peer *peer, *tmp;
466 lockdep_assert_held(&ar->conf_mutex);
468 spin_lock_bh(&ar->data_lock);
469 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
470 list_del(&peer->list);
474 spin_unlock_bh(&ar->data_lock);
477 /************************/
478 /* Interface management */
479 /************************/
481 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
485 lockdep_assert_held(&ar->conf_mutex);
487 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
488 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
495 static bool ath10k_monitor_is_enabled(struct ath10k *ar)
497 lockdep_assert_held(&ar->conf_mutex);
499 ath10k_dbg(ATH10K_DBG_MAC,
500 "mac monitor refs: promisc %d monitor %d cac %d\n",
501 ar->promisc, ar->monitor,
502 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags));
504 return ar->promisc || ar->monitor ||
505 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
508 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
510 struct cfg80211_chan_def *chandef = &ar->chandef;
511 struct ieee80211_channel *channel = chandef->chan;
512 struct wmi_vdev_start_request_arg arg = {};
515 lockdep_assert_held(&ar->conf_mutex);
517 arg.vdev_id = vdev_id;
518 arg.channel.freq = channel->center_freq;
519 arg.channel.band_center_freq1 = chandef->center_freq1;
521 /* TODO setup this dynamically, what in case we
522 don't have any vifs? */
523 arg.channel.mode = chan_to_phymode(chandef);
524 arg.channel.chan_radar =
525 !!(channel->flags & IEEE80211_CHAN_RADAR);
527 arg.channel.min_power = 0;
528 arg.channel.max_power = channel->max_power * 2;
529 arg.channel.max_reg_power = channel->max_reg_power * 2;
530 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
532 ret = ath10k_wmi_vdev_start(ar, &arg);
534 ath10k_warn("failed to request monitor vdev %i start: %d\n",
539 ret = ath10k_vdev_setup_sync(ar);
541 ath10k_warn("failed to synchronize setup for monitor vdev %i: %d\n",
546 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
548 ath10k_warn("failed to put up monitor vdev %i: %d\n",
553 ar->monitor_vdev_id = vdev_id;
555 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
556 ar->monitor_vdev_id);
560 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
562 ath10k_warn("failed to stop monitor vdev %i after start failure: %d\n",
563 ar->monitor_vdev_id, ret);
568 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
572 lockdep_assert_held(&ar->conf_mutex);
574 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
576 ath10k_warn("failed to put down monitor vdev %i: %d\n",
577 ar->monitor_vdev_id, ret);
579 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
581 ath10k_warn("failed to to request monitor vdev %i stop: %d\n",
582 ar->monitor_vdev_id, ret);
584 ret = ath10k_vdev_setup_sync(ar);
586 ath10k_warn("failed to synchronise monitor vdev %i: %d\n",
587 ar->monitor_vdev_id, ret);
589 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
590 ar->monitor_vdev_id);
594 static int ath10k_monitor_vdev_create(struct ath10k *ar)
598 lockdep_assert_held(&ar->conf_mutex);
600 bit = ffs(ar->free_vdev_map);
602 ath10k_warn("failed to find free vdev id for monitor vdev\n");
606 ar->monitor_vdev_id = bit - 1;
607 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
609 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
610 WMI_VDEV_TYPE_MONITOR,
613 ath10k_warn("failed to request monitor vdev %i creation: %d\n",
614 ar->monitor_vdev_id, ret);
618 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
619 ar->monitor_vdev_id);
625 * Restore the ID to the global map.
627 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
631 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
635 lockdep_assert_held(&ar->conf_mutex);
637 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
639 ath10k_warn("failed to request wmi monitor vdev %i removal: %d\n",
640 ar->monitor_vdev_id, ret);
644 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
646 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
647 ar->monitor_vdev_id);
651 static int ath10k_monitor_start(struct ath10k *ar)
655 lockdep_assert_held(&ar->conf_mutex);
657 if (!ath10k_monitor_is_enabled(ar)) {
658 ath10k_warn("trying to start monitor with no references\n");
662 if (ar->monitor_started) {
663 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor already started\n");
667 ret = ath10k_monitor_vdev_create(ar);
669 ath10k_warn("failed to create monitor vdev: %d\n", ret);
673 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
675 ath10k_warn("failed to start monitor vdev: %d\n", ret);
676 ath10k_monitor_vdev_delete(ar);
680 ar->monitor_started = true;
681 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor started\n");
686 static void ath10k_monitor_stop(struct ath10k *ar)
690 lockdep_assert_held(&ar->conf_mutex);
692 if (ath10k_monitor_is_enabled(ar)) {
693 ath10k_dbg(ATH10K_DBG_MAC,
694 "mac monitor will be stopped later\n");
698 if (!ar->monitor_started) {
699 ath10k_dbg(ATH10K_DBG_MAC,
700 "mac monitor probably failed to start earlier\n");
704 ret = ath10k_monitor_vdev_stop(ar);
706 ath10k_warn("failed to stop monitor vdev: %d\n", ret);
708 ret = ath10k_monitor_vdev_delete(ar);
710 ath10k_warn("failed to delete monitor vdev: %d\n", ret);
712 ar->monitor_started = false;
713 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor stopped\n");
716 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
718 struct ath10k *ar = arvif->ar;
719 u32 vdev_param, rts_cts = 0;
721 lockdep_assert_held(&ar->conf_mutex);
723 vdev_param = ar->wmi.vdev_param->enable_rtscts;
725 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
726 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
728 if (arvif->num_legacy_stations > 0)
729 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
732 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
736 static int ath10k_start_cac(struct ath10k *ar)
740 lockdep_assert_held(&ar->conf_mutex);
742 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
744 ret = ath10k_monitor_start(ar);
746 ath10k_warn("failed to start monitor (cac): %d\n", ret);
747 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
751 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
752 ar->monitor_vdev_id);
757 static int ath10k_stop_cac(struct ath10k *ar)
759 lockdep_assert_held(&ar->conf_mutex);
761 /* CAC is not running - do nothing */
762 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
765 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
766 ath10k_monitor_stop(ar);
768 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
773 static void ath10k_recalc_radar_detection(struct ath10k *ar)
777 lockdep_assert_held(&ar->conf_mutex);
781 if (!ar->radar_enabled)
784 if (ar->num_started_vdevs > 0)
787 ret = ath10k_start_cac(ar);
790 * Not possible to start CAC on current channel so starting
791 * radiation is not allowed, make this channel DFS_UNAVAILABLE
792 * by indicating that radar was detected.
794 ath10k_warn("failed to start CAC: %d\n", ret);
795 ieee80211_radar_detected(ar->hw);
799 static int ath10k_vdev_start(struct ath10k_vif *arvif)
801 struct ath10k *ar = arvif->ar;
802 struct cfg80211_chan_def *chandef = &ar->chandef;
803 struct wmi_vdev_start_request_arg arg = {};
806 lockdep_assert_held(&ar->conf_mutex);
808 reinit_completion(&ar->vdev_setup_done);
810 arg.vdev_id = arvif->vdev_id;
811 arg.dtim_period = arvif->dtim_period;
812 arg.bcn_intval = arvif->beacon_interval;
814 arg.channel.freq = chandef->chan->center_freq;
815 arg.channel.band_center_freq1 = chandef->center_freq1;
816 arg.channel.mode = chan_to_phymode(chandef);
818 arg.channel.min_power = 0;
819 arg.channel.max_power = chandef->chan->max_power * 2;
820 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
821 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
823 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
824 arg.ssid = arvif->u.ap.ssid;
825 arg.ssid_len = arvif->u.ap.ssid_len;
826 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
828 /* For now allow DFS for AP mode */
829 arg.channel.chan_radar =
830 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
831 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
832 arg.ssid = arvif->vif->bss_conf.ssid;
833 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
836 ath10k_dbg(ATH10K_DBG_MAC,
837 "mac vdev %d start center_freq %d phymode %s\n",
838 arg.vdev_id, arg.channel.freq,
839 ath10k_wmi_phymode_str(arg.channel.mode));
841 ret = ath10k_wmi_vdev_start(ar, &arg);
843 ath10k_warn("failed to start WMI vdev %i: %d\n",
848 ret = ath10k_vdev_setup_sync(ar);
850 ath10k_warn("failed to synchronise setup for vdev %i: %d\n",
855 ar->num_started_vdevs++;
856 ath10k_recalc_radar_detection(ar);
861 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
863 struct ath10k *ar = arvif->ar;
866 lockdep_assert_held(&ar->conf_mutex);
868 reinit_completion(&ar->vdev_setup_done);
870 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
872 ath10k_warn("failed to stop WMI vdev %i: %d\n",
873 arvif->vdev_id, ret);
877 ret = ath10k_vdev_setup_sync(ar);
879 ath10k_warn("failed to syncronise setup for vdev %i: %d\n",
880 arvif->vdev_id, ret);
884 WARN_ON(ar->num_started_vdevs == 0);
886 if (ar->num_started_vdevs != 0) {
887 ar->num_started_vdevs--;
888 ath10k_recalc_radar_detection(ar);
894 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
895 struct ieee80211_bss_conf *info)
899 lockdep_assert_held(&arvif->ar->conf_mutex);
901 if (!info->enable_beacon) {
902 ath10k_vdev_stop(arvif);
904 arvif->is_started = false;
905 arvif->is_up = false;
907 spin_lock_bh(&arvif->ar->data_lock);
909 dma_unmap_single(arvif->ar->dev,
910 ATH10K_SKB_CB(arvif->beacon)->paddr,
911 arvif->beacon->len, DMA_TO_DEVICE);
912 dev_kfree_skb_any(arvif->beacon);
914 arvif->beacon = NULL;
915 arvif->beacon_sent = false;
917 spin_unlock_bh(&arvif->ar->data_lock);
922 arvif->tx_seq_no = 0x1000;
924 ret = ath10k_vdev_start(arvif);
929 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
931 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
934 ath10k_warn("failed to bring up vdev %d: %i\n",
935 arvif->vdev_id, ret);
936 ath10k_vdev_stop(arvif);
940 arvif->is_started = true;
943 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
946 static void ath10k_control_ibss(struct ath10k_vif *arvif,
947 struct ieee80211_bss_conf *info,
948 const u8 self_peer[ETH_ALEN])
953 lockdep_assert_held(&arvif->ar->conf_mutex);
955 if (!info->ibss_joined) {
956 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
958 ath10k_warn("failed to delete IBSS self peer %pM for vdev %d: %d\n",
959 self_peer, arvif->vdev_id, ret);
961 if (is_zero_ether_addr(arvif->bssid))
964 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
967 ath10k_warn("failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
968 arvif->bssid, arvif->vdev_id, ret);
972 memset(arvif->bssid, 0, ETH_ALEN);
977 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
979 ath10k_warn("failed to create IBSS self peer %pM for vdev %d: %d\n",
980 self_peer, arvif->vdev_id, ret);
984 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
985 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
986 ATH10K_DEFAULT_ATIM);
988 ath10k_warn("failed to set IBSS ATIM for vdev %d: %d\n",
989 arvif->vdev_id, ret);
993 * Review this when mac80211 gains per-interface powersave support.
995 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
997 struct ath10k *ar = arvif->ar;
998 struct ieee80211_conf *conf = &ar->hw->conf;
999 enum wmi_sta_powersave_param param;
1000 enum wmi_sta_ps_mode psmode;
1003 lockdep_assert_held(&arvif->ar->conf_mutex);
1005 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1008 if (conf->flags & IEEE80211_CONF_PS) {
1009 psmode = WMI_STA_PS_MODE_ENABLED;
1010 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1012 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1013 conf->dynamic_ps_timeout);
1015 ath10k_warn("failed to set inactivity time for vdev %d: %i\n",
1016 arvif->vdev_id, ret);
1020 psmode = WMI_STA_PS_MODE_DISABLED;
1023 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1024 arvif->vdev_id, psmode ? "enable" : "disable");
1026 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1028 ath10k_warn("failed to set PS Mode %d for vdev %d: %d\n",
1029 psmode, arvif->vdev_id, ret);
1036 /**********************/
1037 /* Station management */
1038 /**********************/
1040 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1041 struct ath10k_vif *arvif,
1042 struct ieee80211_sta *sta,
1043 struct ieee80211_bss_conf *bss_conf,
1044 struct wmi_peer_assoc_complete_arg *arg)
1046 lockdep_assert_held(&ar->conf_mutex);
1048 memcpy(arg->addr, sta->addr, ETH_ALEN);
1049 arg->vdev_id = arvif->vdev_id;
1050 arg->peer_aid = sta->aid;
1051 arg->peer_flags |= WMI_PEER_AUTH;
1053 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1055 * Seems FW have problems with Power Save in STA
1056 * mode when we setup this parameter to high (eg. 5).
1057 * Often we see that FW don't send NULL (with clean P flags)
1058 * frame even there is info about buffered frames in beacons.
1059 * Sometimes we have to wait more than 10 seconds before FW
1060 * will wakeup. Often sending one ping from AP to our device
1061 * just fail (more than 50%).
1063 * Seems setting this FW parameter to 1 couse FW
1064 * will check every beacon and will wakup immediately
1065 * after detection buffered data.
1067 arg->peer_listen_intval = 1;
1069 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1071 arg->peer_num_spatial_streams = 1;
1074 * The assoc capabilities are available only in managed mode.
1076 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1077 arg->peer_caps = bss_conf->assoc_capability;
1080 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1081 struct ath10k_vif *arvif,
1082 struct wmi_peer_assoc_complete_arg *arg)
1084 struct ieee80211_vif *vif = arvif->vif;
1085 struct ieee80211_bss_conf *info = &vif->bss_conf;
1086 struct cfg80211_bss *bss;
1087 const u8 *rsnie = NULL;
1088 const u8 *wpaie = NULL;
1090 lockdep_assert_held(&ar->conf_mutex);
1092 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1093 info->bssid, NULL, 0, 0, 0);
1095 const struct cfg80211_bss_ies *ies;
1098 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1100 ies = rcu_dereference(bss->ies);
1102 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1103 WLAN_OUI_TYPE_MICROSOFT_WPA,
1107 cfg80211_put_bss(ar->hw->wiphy, bss);
1110 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1111 if (rsnie || wpaie) {
1112 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1113 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1117 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1118 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1122 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1123 struct ieee80211_sta *sta,
1124 struct wmi_peer_assoc_complete_arg *arg)
1126 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1127 const struct ieee80211_supported_band *sband;
1128 const struct ieee80211_rate *rates;
1132 lockdep_assert_held(&ar->conf_mutex);
1134 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1135 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1136 rates = sband->bitrates;
1138 rateset->num_rates = 0;
1140 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1141 if (!(ratemask & 1))
1144 rateset->rates[rateset->num_rates] = rates->hw_value;
1145 rateset->num_rates++;
1149 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1150 struct ieee80211_sta *sta,
1151 struct wmi_peer_assoc_complete_arg *arg)
1153 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1156 lockdep_assert_held(&ar->conf_mutex);
1158 if (!ht_cap->ht_supported)
1161 arg->peer_flags |= WMI_PEER_HT;
1162 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1163 ht_cap->ampdu_factor)) - 1;
1165 arg->peer_mpdu_density =
1166 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1168 arg->peer_ht_caps = ht_cap->cap;
1169 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1171 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1172 arg->peer_flags |= WMI_PEER_LDPC;
1174 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1175 arg->peer_flags |= WMI_PEER_40MHZ;
1176 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1179 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1180 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1182 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1183 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1185 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1186 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1187 arg->peer_flags |= WMI_PEER_STBC;
1190 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1192 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1193 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1194 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1195 arg->peer_rate_caps |= stbc;
1196 arg->peer_flags |= WMI_PEER_STBC;
1199 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1200 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1201 else if (ht_cap->mcs.rx_mask[1])
1202 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1204 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1205 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1206 arg->peer_ht_rates.rates[n++] = i;
1209 * This is a workaround for HT-enabled STAs which break the spec
1210 * and have no HT capabilities RX mask (no HT RX MCS map).
1212 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1213 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1215 * Firmware asserts if such situation occurs.
1218 arg->peer_ht_rates.num_rates = 8;
1219 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1220 arg->peer_ht_rates.rates[i] = i;
1222 arg->peer_ht_rates.num_rates = n;
1223 arg->peer_num_spatial_streams = sta->rx_nss;
1226 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1228 arg->peer_ht_rates.num_rates,
1229 arg->peer_num_spatial_streams);
1232 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1233 struct ath10k_vif *arvif,
1234 struct ieee80211_sta *sta)
1240 lockdep_assert_held(&ar->conf_mutex);
1242 if (sta->wme && sta->uapsd_queues) {
1243 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1244 sta->uapsd_queues, sta->max_sp);
1246 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1247 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1248 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1249 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1250 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1251 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1252 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1253 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1254 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1255 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1256 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1257 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1260 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1261 max_sp = sta->max_sp;
1263 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1265 WMI_AP_PS_PEER_PARAM_UAPSD,
1268 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1269 arvif->vdev_id, ret);
1273 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1275 WMI_AP_PS_PEER_PARAM_MAX_SP,
1278 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1279 arvif->vdev_id, ret);
1283 /* TODO setup this based on STA listen interval and
1284 beacon interval. Currently we don't know
1285 sta->listen_interval - mac80211 patch required.
1286 Currently use 10 seconds */
1287 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1288 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1290 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1291 arvif->vdev_id, ret);
1299 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1300 struct ieee80211_sta *sta,
1301 struct wmi_peer_assoc_complete_arg *arg)
1303 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1306 if (!vht_cap->vht_supported)
1309 arg->peer_flags |= WMI_PEER_VHT;
1310 arg->peer_vht_caps = vht_cap->cap;
1313 ampdu_factor = (vht_cap->cap &
1314 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1315 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1317 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1318 * zero in VHT IE. Using it would result in degraded throughput.
1319 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1320 * it if VHT max_mpdu is smaller. */
1321 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1322 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1323 ampdu_factor)) - 1);
1325 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1326 arg->peer_flags |= WMI_PEER_80MHZ;
1328 arg->peer_vht_rates.rx_max_rate =
1329 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1330 arg->peer_vht_rates.rx_mcs_set =
1331 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1332 arg->peer_vht_rates.tx_max_rate =
1333 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1334 arg->peer_vht_rates.tx_mcs_set =
1335 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1337 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1338 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1341 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1342 struct ath10k_vif *arvif,
1343 struct ieee80211_sta *sta,
1344 struct ieee80211_bss_conf *bss_conf,
1345 struct wmi_peer_assoc_complete_arg *arg)
1347 switch (arvif->vdev_type) {
1348 case WMI_VDEV_TYPE_AP:
1350 arg->peer_flags |= WMI_PEER_QOS;
1352 if (sta->wme && sta->uapsd_queues) {
1353 arg->peer_flags |= WMI_PEER_APSD;
1354 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1357 case WMI_VDEV_TYPE_STA:
1359 arg->peer_flags |= WMI_PEER_QOS;
1366 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1367 struct ath10k_vif *arvif,
1368 struct ieee80211_sta *sta,
1369 struct wmi_peer_assoc_complete_arg *arg)
1371 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1373 switch (ar->hw->conf.chandef.chan->band) {
1374 case IEEE80211_BAND_2GHZ:
1375 if (sta->ht_cap.ht_supported) {
1376 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1377 phymode = MODE_11NG_HT40;
1379 phymode = MODE_11NG_HT20;
1385 case IEEE80211_BAND_5GHZ:
1389 if (sta->vht_cap.vht_supported) {
1390 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1391 phymode = MODE_11AC_VHT80;
1392 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1393 phymode = MODE_11AC_VHT40;
1394 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1395 phymode = MODE_11AC_VHT20;
1396 } else if (sta->ht_cap.ht_supported) {
1397 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1398 phymode = MODE_11NA_HT40;
1400 phymode = MODE_11NA_HT20;
1410 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1411 sta->addr, ath10k_wmi_phymode_str(phymode));
1413 arg->peer_phymode = phymode;
1414 WARN_ON(phymode == MODE_UNKNOWN);
1417 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1418 struct ath10k_vif *arvif,
1419 struct ieee80211_sta *sta,
1420 struct ieee80211_bss_conf *bss_conf,
1421 struct wmi_peer_assoc_complete_arg *arg)
1423 lockdep_assert_held(&ar->conf_mutex);
1425 memset(arg, 0, sizeof(*arg));
1427 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1428 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1429 ath10k_peer_assoc_h_rates(ar, sta, arg);
1430 ath10k_peer_assoc_h_ht(ar, sta, arg);
1431 ath10k_peer_assoc_h_vht(ar, sta, arg);
1432 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1433 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
1438 static const u32 ath10k_smps_map[] = {
1439 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1440 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1441 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1442 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1445 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1447 const struct ieee80211_sta_ht_cap *ht_cap)
1451 if (!ht_cap->ht_supported)
1454 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1455 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1457 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1460 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1461 WMI_PEER_SMPS_STATE,
1462 ath10k_smps_map[smps]);
1465 /* can be called only in mac80211 callbacks due to `key_count` usage */
1466 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1467 struct ieee80211_vif *vif,
1468 struct ieee80211_bss_conf *bss_conf)
1470 struct ath10k *ar = hw->priv;
1471 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1472 struct ieee80211_sta_ht_cap ht_cap;
1473 struct wmi_peer_assoc_complete_arg peer_arg;
1474 struct ieee80211_sta *ap_sta;
1477 lockdep_assert_held(&ar->conf_mutex);
1481 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1483 ath10k_warn("failed to find station entry for bss %pM vdev %i\n",
1484 bss_conf->bssid, arvif->vdev_id);
1489 /* ap_sta must be accessed only within rcu section which must be left
1490 * before calling ath10k_setup_peer_smps() which might sleep. */
1491 ht_cap = ap_sta->ht_cap;
1493 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1494 bss_conf, &peer_arg);
1496 ath10k_warn("failed to prepare peer assoc for %pM vdev %i: %d\n",
1497 bss_conf->bssid, arvif->vdev_id, ret);
1504 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1506 ath10k_warn("failed to run peer assoc for %pM vdev %i: %d\n",
1507 bss_conf->bssid, arvif->vdev_id, ret);
1511 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1513 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1514 arvif->vdev_id, ret);
1518 ath10k_dbg(ATH10K_DBG_MAC,
1519 "mac vdev %d up (associated) bssid %pM aid %d\n",
1520 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1522 arvif->aid = bss_conf->aid;
1523 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1525 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1527 ath10k_warn("failed to set vdev %d up: %d\n",
1528 arvif->vdev_id, ret);
1532 arvif->is_up = true;
1538 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1539 struct ieee80211_vif *vif)
1541 struct ath10k *ar = hw->priv;
1542 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1545 lockdep_assert_held(&ar->conf_mutex);
1548 * For some reason, calling VDEV-DOWN before VDEV-STOP
1549 * makes the FW to send frames via HTT after disassociation.
1550 * No idea why this happens, even though VDEV-DOWN is supposed
1551 * to be analogous to link down, so just stop the VDEV.
1553 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1556 /* FIXME: check return value */
1557 ret = ath10k_vdev_stop(arvif);
1560 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1561 * report beacons from previously associated network through HTT.
1562 * This in turn would spam mac80211 WARN_ON if we bring down all
1563 * interfaces as it expects there is no rx when no interface is
1566 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1568 /* FIXME: why don't we print error if wmi call fails? */
1569 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1571 arvif->def_wep_key_idx = 0;
1573 arvif->is_started = false;
1574 arvif->is_up = false;
1577 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1578 struct ieee80211_sta *sta, bool reassoc)
1580 struct wmi_peer_assoc_complete_arg peer_arg;
1583 lockdep_assert_held(&ar->conf_mutex);
1585 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1587 ath10k_warn("failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1588 sta->addr, arvif->vdev_id, ret);
1592 peer_arg.peer_reassoc = reassoc;
1593 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1595 ath10k_warn("failed to run peer assoc for STA %pM vdev %i: %d\n",
1596 sta->addr, arvif->vdev_id, ret);
1600 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1602 ath10k_warn("failed to setup peer SMPS for vdev %d: %d\n",
1603 arvif->vdev_id, ret);
1608 arvif->num_legacy_stations++;
1609 ret = ath10k_recalc_rtscts_prot(arvif);
1611 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1612 arvif->vdev_id, ret);
1617 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1619 ath10k_warn("failed to install peer wep keys for vdev %i: %d\n",
1620 arvif->vdev_id, ret);
1624 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1626 ath10k_warn("failed to set qos params for STA %pM for vdev %i: %d\n",
1627 sta->addr, arvif->vdev_id, ret);
1634 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1635 struct ieee80211_sta *sta)
1639 lockdep_assert_held(&ar->conf_mutex);
1642 arvif->num_legacy_stations--;
1643 ret = ath10k_recalc_rtscts_prot(arvif);
1645 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1646 arvif->vdev_id, ret);
1651 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1653 ath10k_warn("failed to clear all peer wep keys for vdev %i: %d\n",
1654 arvif->vdev_id, ret);
1665 static int ath10k_update_channel_list(struct ath10k *ar)
1667 struct ieee80211_hw *hw = ar->hw;
1668 struct ieee80211_supported_band **bands;
1669 enum ieee80211_band band;
1670 struct ieee80211_channel *channel;
1671 struct wmi_scan_chan_list_arg arg = {0};
1672 struct wmi_channel_arg *ch;
1678 lockdep_assert_held(&ar->conf_mutex);
1680 bands = hw->wiphy->bands;
1681 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1685 for (i = 0; i < bands[band]->n_channels; i++) {
1686 if (bands[band]->channels[i].flags &
1687 IEEE80211_CHAN_DISABLED)
1694 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1695 arg.channels = kzalloc(len, GFP_KERNEL);
1700 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1704 for (i = 0; i < bands[band]->n_channels; i++) {
1705 channel = &bands[band]->channels[i];
1707 if (channel->flags & IEEE80211_CHAN_DISABLED)
1710 ch->allow_ht = true;
1712 /* FIXME: when should we really allow VHT? */
1713 ch->allow_vht = true;
1716 !(channel->flags & IEEE80211_CHAN_NO_IR);
1719 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1722 !!(channel->flags & IEEE80211_CHAN_RADAR);
1724 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1725 ch->passive = passive;
1727 ch->freq = channel->center_freq;
1729 ch->max_power = channel->max_power * 2;
1730 ch->max_reg_power = channel->max_reg_power * 2;
1731 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1732 ch->reg_class_id = 0; /* FIXME */
1734 /* FIXME: why use only legacy modes, why not any
1735 * HT/VHT modes? Would that even make any
1737 if (channel->band == IEEE80211_BAND_2GHZ)
1738 ch->mode = MODE_11G;
1740 ch->mode = MODE_11A;
1742 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1745 ath10k_dbg(ATH10K_DBG_WMI,
1746 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1747 ch - arg.channels, arg.n_channels,
1748 ch->freq, ch->max_power, ch->max_reg_power,
1749 ch->max_antenna_gain, ch->mode);
1755 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1756 kfree(arg.channels);
1761 static enum wmi_dfs_region
1762 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1764 switch (dfs_region) {
1765 case NL80211_DFS_UNSET:
1766 return WMI_UNINIT_DFS_DOMAIN;
1767 case NL80211_DFS_FCC:
1768 return WMI_FCC_DFS_DOMAIN;
1769 case NL80211_DFS_ETSI:
1770 return WMI_ETSI_DFS_DOMAIN;
1771 case NL80211_DFS_JP:
1772 return WMI_MKK4_DFS_DOMAIN;
1774 return WMI_UNINIT_DFS_DOMAIN;
1777 static void ath10k_regd_update(struct ath10k *ar)
1779 struct reg_dmn_pair_mapping *regpair;
1781 enum wmi_dfs_region wmi_dfs_reg;
1782 enum nl80211_dfs_regions nl_dfs_reg;
1784 lockdep_assert_held(&ar->conf_mutex);
1786 ret = ath10k_update_channel_list(ar);
1788 ath10k_warn("failed to update channel list: %d\n", ret);
1790 regpair = ar->ath_common.regulatory.regpair;
1792 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1793 nl_dfs_reg = ar->dfs_detector->region;
1794 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1796 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1799 /* Target allows setting up per-band regdomain but ath_common provides
1800 * a combined one only */
1801 ret = ath10k_wmi_pdev_set_regdomain(ar,
1802 regpair->reg_domain,
1803 regpair->reg_domain, /* 2ghz */
1804 regpair->reg_domain, /* 5ghz */
1805 regpair->reg_2ghz_ctl,
1806 regpair->reg_5ghz_ctl,
1809 ath10k_warn("failed to set pdev regdomain: %d\n", ret);
1812 static void ath10k_reg_notifier(struct wiphy *wiphy,
1813 struct regulatory_request *request)
1815 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1816 struct ath10k *ar = hw->priv;
1819 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1821 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1822 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1823 request->dfs_region);
1824 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1825 request->dfs_region);
1827 ath10k_warn("DFS region 0x%X not supported, will trigger radar for every pulse\n",
1828 request->dfs_region);
1831 mutex_lock(&ar->conf_mutex);
1832 if (ar->state == ATH10K_STATE_ON)
1833 ath10k_regd_update(ar);
1834 mutex_unlock(&ar->conf_mutex);
1841 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1843 if (ieee80211_is_mgmt(hdr->frame_control))
1844 return HTT_DATA_TX_EXT_TID_MGMT;
1846 if (!ieee80211_is_data_qos(hdr->frame_control))
1847 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1849 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1850 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1852 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1855 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1856 struct ieee80211_tx_info *info)
1858 if (info->control.vif)
1859 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1861 if (ar->monitor_started)
1862 return ar->monitor_vdev_id;
1864 ath10k_warn("failed to resolve vdev id\n");
1869 * Frames sent to the FW have to be in "Native Wifi" format.
1870 * Strip the QoS field from the 802.11 header.
1872 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1873 struct ieee80211_tx_control *control,
1874 struct sk_buff *skb)
1876 struct ieee80211_hdr *hdr = (void *)skb->data;
1879 if (!ieee80211_is_data_qos(hdr->frame_control))
1882 qos_ctl = ieee80211_get_qos_ctl(hdr);
1883 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1884 skb->data, (void *)qos_ctl - (void *)skb->data);
1885 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1888 static void ath10k_tx_wep_key_work(struct work_struct *work)
1890 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1892 int ret, keyidx = arvif->def_wep_key_newidx;
1894 if (arvif->def_wep_key_idx == keyidx)
1897 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1898 arvif->vdev_id, keyidx);
1900 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1902 arvif->ar->wmi.vdev_param->def_keyid,
1905 ath10k_warn("failed to update wep key index for vdev %d: %d\n",
1911 arvif->def_wep_key_idx = keyidx;
1914 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1916 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1917 struct ieee80211_vif *vif = info->control.vif;
1918 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1919 struct ath10k *ar = arvif->ar;
1920 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1921 struct ieee80211_key_conf *key = info->control.hw_key;
1923 if (!ieee80211_has_protected(hdr->frame_control))
1929 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1930 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1933 if (key->keyidx == arvif->def_wep_key_idx)
1936 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1937 * queueing frames until key index is updated is not an option because
1938 * sk_buff may need more processing to be done, e.g. offchannel */
1939 arvif->def_wep_key_newidx = key->keyidx;
1940 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1943 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1945 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1946 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1947 struct ieee80211_vif *vif = info->control.vif;
1948 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1950 /* This is case only for P2P_GO */
1951 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1952 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1955 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1956 spin_lock_bh(&ar->data_lock);
1957 if (arvif->u.ap.noa_data)
1958 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1960 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1961 arvif->u.ap.noa_data,
1962 arvif->u.ap.noa_len);
1963 spin_unlock_bh(&ar->data_lock);
1967 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1969 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1972 if (ar->htt.target_version_major >= 3) {
1973 /* Since HTT 3.0 there is no separate mgmt tx command */
1974 ret = ath10k_htt_tx(&ar->htt, skb);
1978 if (ieee80211_is_mgmt(hdr->frame_control)) {
1979 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1981 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1982 ATH10K_MAX_NUM_MGMT_PENDING) {
1983 ath10k_warn("reached WMI management tranmist queue limit\n");
1988 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1989 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1991 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1993 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1995 ieee80211_is_nullfunc(hdr->frame_control)) {
1996 /* FW does not report tx status properly for NullFunc frames
1997 * unless they are sent through mgmt tx path. mac80211 sends
1998 * those frames when it detects link/beacon loss and depends
1999 * on the tx status to be correct. */
2000 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2002 ret = ath10k_htt_tx(&ar->htt, skb);
2007 ath10k_warn("failed to transmit packet, dropping: %d\n", ret);
2008 ieee80211_free_txskb(ar->hw, skb);
2012 void ath10k_offchan_tx_purge(struct ath10k *ar)
2014 struct sk_buff *skb;
2017 skb = skb_dequeue(&ar->offchan_tx_queue);
2021 ieee80211_free_txskb(ar->hw, skb);
2025 void ath10k_offchan_tx_work(struct work_struct *work)
2027 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2028 struct ath10k_peer *peer;
2029 struct ieee80211_hdr *hdr;
2030 struct sk_buff *skb;
2031 const u8 *peer_addr;
2035 /* FW requirement: We must create a peer before FW will send out
2036 * an offchannel frame. Otherwise the frame will be stuck and
2037 * never transmitted. We delete the peer upon tx completion.
2038 * It is unlikely that a peer for offchannel tx will already be
2039 * present. However it may be in some rare cases so account for that.
2040 * Otherwise we might remove a legitimate peer and break stuff. */
2043 skb = skb_dequeue(&ar->offchan_tx_queue);
2047 mutex_lock(&ar->conf_mutex);
2049 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2052 hdr = (struct ieee80211_hdr *)skb->data;
2053 peer_addr = ieee80211_get_DA(hdr);
2054 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2056 spin_lock_bh(&ar->data_lock);
2057 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2058 spin_unlock_bh(&ar->data_lock);
2061 /* FIXME: should this use ath10k_warn()? */
2062 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2063 peer_addr, vdev_id);
2066 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2068 ath10k_warn("failed to create peer %pM on vdev %d: %d\n",
2069 peer_addr, vdev_id, ret);
2072 spin_lock_bh(&ar->data_lock);
2073 reinit_completion(&ar->offchan_tx_completed);
2074 ar->offchan_tx_skb = skb;
2075 spin_unlock_bh(&ar->data_lock);
2077 ath10k_tx_htt(ar, skb);
2079 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2082 ath10k_warn("timed out waiting for offchannel skb %p\n",
2086 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2088 ath10k_warn("failed to delete peer %pM on vdev %d: %d\n",
2089 peer_addr, vdev_id, ret);
2092 mutex_unlock(&ar->conf_mutex);
2096 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2098 struct sk_buff *skb;
2101 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2105 ieee80211_free_txskb(ar->hw, skb);
2109 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2111 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2112 struct sk_buff *skb;
2116 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2120 ret = ath10k_wmi_mgmt_tx(ar, skb);
2122 ath10k_warn("failed to transmit management frame via WMI: %d\n",
2124 ieee80211_free_txskb(ar->hw, skb);
2134 * This gets called if we dont get a heart-beat during scan.
2135 * This may indicate the FW has hung and we need to abort the
2136 * scan manually to prevent cancel_hw_scan() from deadlocking
2138 void ath10k_reset_scan(unsigned long ptr)
2140 struct ath10k *ar = (struct ath10k *)ptr;
2142 spin_lock_bh(&ar->data_lock);
2143 if (!ar->scan.in_progress) {
2144 spin_unlock_bh(&ar->data_lock);
2148 ath10k_warn("scan timed out, firmware problem?\n");
2150 if (ar->scan.is_roc)
2151 ieee80211_remain_on_channel_expired(ar->hw);
2153 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2155 ar->scan.in_progress = false;
2156 complete_all(&ar->scan.completed);
2157 spin_unlock_bh(&ar->data_lock);
2160 static int ath10k_abort_scan(struct ath10k *ar)
2162 struct wmi_stop_scan_arg arg = {
2163 .req_id = 1, /* FIXME */
2164 .req_type = WMI_SCAN_STOP_ONE,
2165 .u.scan_id = ATH10K_SCAN_ID,
2169 lockdep_assert_held(&ar->conf_mutex);
2171 del_timer_sync(&ar->scan.timeout);
2173 spin_lock_bh(&ar->data_lock);
2174 if (!ar->scan.in_progress) {
2175 spin_unlock_bh(&ar->data_lock);
2179 ar->scan.aborting = true;
2180 spin_unlock_bh(&ar->data_lock);
2182 ret = ath10k_wmi_stop_scan(ar, &arg);
2184 ath10k_warn("failed to stop wmi scan: %d\n", ret);
2185 spin_lock_bh(&ar->data_lock);
2186 ar->scan.in_progress = false;
2187 ath10k_offchan_tx_purge(ar);
2188 spin_unlock_bh(&ar->data_lock);
2192 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2194 ath10k_warn("timed out while waiting for scan to stop\n");
2196 /* scan completion may be done right after we timeout here, so let's
2197 * check the in_progress and tell mac80211 scan is completed. if we
2198 * don't do that and FW fails to send us scan completion indication
2199 * then userspace won't be able to scan anymore */
2202 spin_lock_bh(&ar->data_lock);
2203 if (ar->scan.in_progress) {
2204 ath10k_warn("failed to stop scan, it's still in progress\n");
2205 ar->scan.in_progress = false;
2206 ath10k_offchan_tx_purge(ar);
2209 spin_unlock_bh(&ar->data_lock);
2214 static int ath10k_start_scan(struct ath10k *ar,
2215 const struct wmi_start_scan_arg *arg)
2219 lockdep_assert_held(&ar->conf_mutex);
2221 ret = ath10k_wmi_start_scan(ar, arg);
2225 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2227 ath10k_abort_scan(ar);
2231 /* the scan can complete earlier, before we even
2232 * start the timer. in that case the timer handler
2233 * checks ar->scan.in_progress and bails out if its
2234 * false. Add a 200ms margin to account event/command
2236 mod_timer(&ar->scan.timeout, jiffies +
2237 msecs_to_jiffies(arg->max_scan_time+200));
2241 /**********************/
2242 /* mac80211 callbacks */
2243 /**********************/
2245 static void ath10k_tx(struct ieee80211_hw *hw,
2246 struct ieee80211_tx_control *control,
2247 struct sk_buff *skb)
2249 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2250 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2251 struct ath10k *ar = hw->priv;
2254 /* We should disable CCK RATE due to P2P */
2255 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2256 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2258 /* we must calculate tid before we apply qos workaround
2259 * as we'd lose the qos control field */
2260 tid = ath10k_tx_h_get_tid(hdr);
2261 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
2263 /* it makes no sense to process injected frames like that */
2264 if (info->control.vif &&
2265 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2266 ath10k_tx_h_qos_workaround(hw, control, skb);
2267 ath10k_tx_h_update_wep_key(skb);
2268 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2269 ath10k_tx_h_seq_no(skb);
2272 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
2273 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2274 ATH10K_SKB_CB(skb)->htt.tid = tid;
2276 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2277 spin_lock_bh(&ar->data_lock);
2278 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2279 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2280 spin_unlock_bh(&ar->data_lock);
2282 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2284 skb_queue_tail(&ar->offchan_tx_queue, skb);
2285 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2289 ath10k_tx_htt(ar, skb);
2293 * Initialize various parameters with default vaules.
2295 void ath10k_halt(struct ath10k *ar)
2297 struct ath10k_vif *arvif;
2299 lockdep_assert_held(&ar->conf_mutex);
2301 if (ath10k_monitor_is_enabled(ar)) {
2302 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2303 ar->promisc = false;
2304 ar->monitor = false;
2305 ath10k_monitor_stop(ar);
2308 del_timer_sync(&ar->scan.timeout);
2309 ath10k_reset_scan((unsigned long)ar);
2310 ath10k_offchan_tx_purge(ar);
2311 ath10k_mgmt_over_wmi_tx_purge(ar);
2312 ath10k_peer_cleanup_all(ar);
2313 ath10k_core_stop(ar);
2314 ath10k_hif_power_down(ar);
2316 spin_lock_bh(&ar->data_lock);
2317 list_for_each_entry(arvif, &ar->arvifs, list) {
2321 dma_unmap_single(arvif->ar->dev,
2322 ATH10K_SKB_CB(arvif->beacon)->paddr,
2323 arvif->beacon->len, DMA_TO_DEVICE);
2324 dev_kfree_skb_any(arvif->beacon);
2325 arvif->beacon = NULL;
2327 spin_unlock_bh(&ar->data_lock);
2330 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2332 struct ath10k *ar = hw->priv;
2334 mutex_lock(&ar->conf_mutex);
2336 if (ar->cfg_tx_chainmask) {
2337 *tx_ant = ar->cfg_tx_chainmask;
2338 *rx_ant = ar->cfg_rx_chainmask;
2340 *tx_ant = ar->supp_tx_chainmask;
2341 *rx_ant = ar->supp_rx_chainmask;
2344 mutex_unlock(&ar->conf_mutex);
2349 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2353 lockdep_assert_held(&ar->conf_mutex);
2355 ar->cfg_tx_chainmask = tx_ant;
2356 ar->cfg_rx_chainmask = rx_ant;
2358 if ((ar->state != ATH10K_STATE_ON) &&
2359 (ar->state != ATH10K_STATE_RESTARTED))
2362 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2365 ath10k_warn("failed to set tx-chainmask: %d, req 0x%x\n",
2370 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2373 ath10k_warn("failed to set rx-chainmask: %d, req 0x%x\n",
2381 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2383 struct ath10k *ar = hw->priv;
2386 mutex_lock(&ar->conf_mutex);
2387 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2388 mutex_unlock(&ar->conf_mutex);
2392 static int ath10k_start(struct ieee80211_hw *hw)
2394 struct ath10k *ar = hw->priv;
2397 mutex_lock(&ar->conf_mutex);
2399 switch (ar->state) {
2400 case ATH10K_STATE_OFF:
2401 ar->state = ATH10K_STATE_ON;
2403 case ATH10K_STATE_RESTARTING:
2405 ar->state = ATH10K_STATE_RESTARTED;
2407 case ATH10K_STATE_ON:
2408 case ATH10K_STATE_RESTARTED:
2409 case ATH10K_STATE_WEDGED:
2415 ret = ath10k_hif_power_up(ar);
2417 ath10k_err("Could not init hif: %d\n", ret);
2421 ret = ath10k_core_start(ar);
2423 ath10k_err("Could not init core: %d\n", ret);
2424 goto err_power_down;
2427 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2429 ath10k_warn("failed to enable PMF QOS: %d\n", ret);
2433 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2435 ath10k_warn("failed to enable dynamic BW: %d\n", ret);
2439 if (ar->cfg_tx_chainmask)
2440 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2441 ar->cfg_rx_chainmask);
2444 * By default FW set ARP frames ac to voice (6). In that case ARP
2445 * exchange is not working properly for UAPSD enabled AP. ARP requests
2446 * which arrives with access category 0 are processed by network stack
2447 * and send back with access category 0, but FW changes access category
2448 * to 6. Set ARP frames access category to best effort (0) solves
2452 ret = ath10k_wmi_pdev_set_param(ar,
2453 ar->wmi.pdev_param->arp_ac_override, 0);
2455 ath10k_warn("failed to set arp ac override parameter: %d\n",
2460 ar->num_started_vdevs = 0;
2461 ath10k_regd_update(ar);
2463 mutex_unlock(&ar->conf_mutex);
2467 ath10k_core_stop(ar);
2470 ath10k_hif_power_down(ar);
2473 ar->state = ATH10K_STATE_OFF;
2476 mutex_unlock(&ar->conf_mutex);
2480 static void ath10k_stop(struct ieee80211_hw *hw)
2482 struct ath10k *ar = hw->priv;
2484 mutex_lock(&ar->conf_mutex);
2485 if (ar->state != ATH10K_STATE_OFF) {
2487 ar->state = ATH10K_STATE_OFF;
2489 mutex_unlock(&ar->conf_mutex);
2491 ath10k_mgmt_over_wmi_tx_purge(ar);
2493 cancel_work_sync(&ar->offchan_tx_work);
2494 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2495 cancel_work_sync(&ar->restart_work);
2498 static int ath10k_config_ps(struct ath10k *ar)
2500 struct ath10k_vif *arvif;
2503 lockdep_assert_held(&ar->conf_mutex);
2505 list_for_each_entry(arvif, &ar->arvifs, list) {
2506 ret = ath10k_mac_vif_setup_ps(arvif);
2508 ath10k_warn("failed to setup powersave: %d\n", ret);
2516 static const char *chandef_get_width(enum nl80211_chan_width width)
2519 case NL80211_CHAN_WIDTH_20_NOHT:
2521 case NL80211_CHAN_WIDTH_20:
2523 case NL80211_CHAN_WIDTH_40:
2525 case NL80211_CHAN_WIDTH_80:
2527 case NL80211_CHAN_WIDTH_80P80:
2529 case NL80211_CHAN_WIDTH_160:
2531 case NL80211_CHAN_WIDTH_5:
2533 case NL80211_CHAN_WIDTH_10:
2539 static void ath10k_config_chan(struct ath10k *ar)
2541 struct ath10k_vif *arvif;
2544 lockdep_assert_held(&ar->conf_mutex);
2546 ath10k_dbg(ATH10K_DBG_MAC,
2547 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2548 ar->chandef.chan->center_freq,
2549 ar->chandef.center_freq1,
2550 ar->chandef.center_freq2,
2551 chandef_get_width(ar->chandef.width));
2553 /* First stop monitor interface. Some FW versions crash if there's a
2554 * lone monitor interface. */
2555 if (ar->monitor_started)
2556 ath10k_monitor_vdev_stop(ar);
2558 list_for_each_entry(arvif, &ar->arvifs, list) {
2559 if (!arvif->is_started)
2562 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2565 ret = ath10k_vdev_stop(arvif);
2567 ath10k_warn("failed to stop vdev %d: %d\n",
2568 arvif->vdev_id, ret);
2573 /* all vdevs are now stopped - now attempt to restart them */
2575 list_for_each_entry(arvif, &ar->arvifs, list) {
2576 if (!arvif->is_started)
2579 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2582 ret = ath10k_vdev_start(arvif);
2584 ath10k_warn("failed to start vdev %d: %d\n",
2585 arvif->vdev_id, ret);
2592 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2595 ath10k_warn("failed to bring vdev up %d: %d\n",
2596 arvif->vdev_id, ret);
2601 if (ath10k_monitor_is_enabled(ar))
2602 ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
2605 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2607 struct ath10k *ar = hw->priv;
2608 struct ieee80211_conf *conf = &hw->conf;
2612 mutex_lock(&ar->conf_mutex);
2614 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2615 ath10k_dbg(ATH10K_DBG_MAC,
2616 "mac config channel %dMHz flags 0x%x radar %d\n",
2617 conf->chandef.chan->center_freq,
2618 conf->chandef.chan->flags,
2619 conf->radar_enabled);
2621 spin_lock_bh(&ar->data_lock);
2622 ar->rx_channel = conf->chandef.chan;
2623 spin_unlock_bh(&ar->data_lock);
2625 ar->radar_enabled = conf->radar_enabled;
2626 ath10k_recalc_radar_detection(ar);
2628 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2629 ar->chandef = conf->chandef;
2630 ath10k_config_chan(ar);
2634 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2635 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2636 hw->conf.power_level);
2638 param = ar->wmi.pdev_param->txpower_limit2g;
2639 ret = ath10k_wmi_pdev_set_param(ar, param,
2640 hw->conf.power_level * 2);
2642 ath10k_warn("failed to set 2g txpower %d: %d\n",
2643 hw->conf.power_level, ret);
2645 param = ar->wmi.pdev_param->txpower_limit5g;
2646 ret = ath10k_wmi_pdev_set_param(ar, param,
2647 hw->conf.power_level * 2);
2649 ath10k_warn("failed to set 5g txpower %d: %d\n",
2650 hw->conf.power_level, ret);
2653 if (changed & IEEE80211_CONF_CHANGE_PS)
2654 ath10k_config_ps(ar);
2656 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2657 if (conf->flags & IEEE80211_CONF_MONITOR && !ar->monitor) {
2659 ret = ath10k_monitor_start(ar);
2661 ath10k_warn("failed to start monitor (config): %d\n",
2663 ar->monitor = false;
2665 } else if (!(conf->flags & IEEE80211_CONF_MONITOR) &&
2667 ar->monitor = false;
2668 ath10k_monitor_stop(ar);
2672 mutex_unlock(&ar->conf_mutex);
2678 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2679 * because we will send mgmt frames without CCK. This requirement
2680 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2683 static int ath10k_add_interface(struct ieee80211_hw *hw,
2684 struct ieee80211_vif *vif)
2686 struct ath10k *ar = hw->priv;
2687 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2688 enum wmi_sta_powersave_param param;
2694 mutex_lock(&ar->conf_mutex);
2696 memset(arvif, 0, sizeof(*arvif));
2701 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2702 INIT_LIST_HEAD(&arvif->list);
2704 bit = ffs(ar->free_vdev_map);
2710 arvif->vdev_id = bit - 1;
2711 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2714 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2716 switch (vif->type) {
2717 case NL80211_IFTYPE_UNSPECIFIED:
2718 case NL80211_IFTYPE_STATION:
2719 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2721 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2723 case NL80211_IFTYPE_ADHOC:
2724 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2726 case NL80211_IFTYPE_AP:
2727 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2730 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2732 case NL80211_IFTYPE_MONITOR:
2733 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2740 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
2741 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2743 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2744 arvif->vdev_subtype, vif->addr);
2746 ath10k_warn("failed to create WMI vdev %i: %d\n",
2747 arvif->vdev_id, ret);
2751 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2752 list_add(&arvif->list, &ar->arvifs);
2754 vdev_param = ar->wmi.vdev_param->def_keyid;
2755 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2756 arvif->def_wep_key_idx);
2758 ath10k_warn("failed to set vdev %i default key id: %d\n",
2759 arvif->vdev_id, ret);
2760 goto err_vdev_delete;
2763 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2764 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2765 ATH10K_HW_TXRX_NATIVE_WIFI);
2766 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2767 if (ret && ret != -EOPNOTSUPP) {
2768 ath10k_warn("failed to set vdev %i TX encapsulation: %d\n",
2769 arvif->vdev_id, ret);
2770 goto err_vdev_delete;
2773 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2774 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2776 ath10k_warn("failed to create vdev %i peer for AP: %d\n",
2777 arvif->vdev_id, ret);
2778 goto err_vdev_delete;
2781 ret = ath10k_mac_set_kickout(arvif);
2783 ath10k_warn("failed to set vdev %i kickout parameters: %d\n",
2784 arvif->vdev_id, ret);
2785 goto err_peer_delete;
2789 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2790 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2791 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2792 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2795 ath10k_warn("failed to set vdev %i RX wake policy: %d\n",
2796 arvif->vdev_id, ret);
2797 goto err_peer_delete;
2800 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2801 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2802 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2805 ath10k_warn("failed to set vdev %i TX wake thresh: %d\n",
2806 arvif->vdev_id, ret);
2807 goto err_peer_delete;
2810 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2811 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2812 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2815 ath10k_warn("failed to set vdev %i PSPOLL count: %d\n",
2816 arvif->vdev_id, ret);
2817 goto err_peer_delete;
2821 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2823 ath10k_warn("failed to set rts threshold for vdev %d: %d\n",
2824 arvif->vdev_id, ret);
2825 goto err_peer_delete;
2828 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2830 ath10k_warn("failed to set frag threshold for vdev %d: %d\n",
2831 arvif->vdev_id, ret);
2832 goto err_peer_delete;
2835 mutex_unlock(&ar->conf_mutex);
2839 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2840 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2843 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2844 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2845 list_del(&arvif->list);
2848 mutex_unlock(&ar->conf_mutex);
2853 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2854 struct ieee80211_vif *vif)
2856 struct ath10k *ar = hw->priv;
2857 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2860 mutex_lock(&ar->conf_mutex);
2862 cancel_work_sync(&arvif->wep_key_work);
2864 spin_lock_bh(&ar->data_lock);
2865 if (arvif->beacon) {
2866 dma_unmap_single(arvif->ar->dev,
2867 ATH10K_SKB_CB(arvif->beacon)->paddr,
2868 arvif->beacon->len, DMA_TO_DEVICE);
2869 dev_kfree_skb_any(arvif->beacon);
2870 arvif->beacon = NULL;
2872 spin_unlock_bh(&ar->data_lock);
2874 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2875 list_del(&arvif->list);
2877 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2878 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2880 ath10k_warn("failed to remove peer for AP vdev %i: %d\n",
2881 arvif->vdev_id, ret);
2883 kfree(arvif->u.ap.noa_data);
2886 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
2889 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2891 ath10k_warn("failed to delete WMI vdev %i: %d\n",
2892 arvif->vdev_id, ret);
2894 ath10k_peer_cleanup(ar, arvif->vdev_id);
2896 mutex_unlock(&ar->conf_mutex);
2900 * FIXME: Has to be verified.
2902 #define SUPPORTED_FILTERS \
2903 (FIF_PROMISC_IN_BSS | \
2908 FIF_BCN_PRBRESP_PROMISC | \
2912 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2913 unsigned int changed_flags,
2914 unsigned int *total_flags,
2917 struct ath10k *ar = hw->priv;
2920 mutex_lock(&ar->conf_mutex);
2922 changed_flags &= SUPPORTED_FILTERS;
2923 *total_flags &= SUPPORTED_FILTERS;
2924 ar->filter_flags = *total_flags;
2926 if (ar->filter_flags & FIF_PROMISC_IN_BSS && !ar->promisc) {
2928 ret = ath10k_monitor_start(ar);
2930 ath10k_warn("failed to start monitor (promisc): %d\n",
2932 ar->promisc = false;
2934 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) && ar->promisc) {
2935 ar->promisc = false;
2936 ath10k_monitor_stop(ar);
2939 mutex_unlock(&ar->conf_mutex);
2942 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2943 struct ieee80211_vif *vif,
2944 struct ieee80211_bss_conf *info,
2947 struct ath10k *ar = hw->priv;
2948 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2950 u32 vdev_param, pdev_param;
2952 mutex_lock(&ar->conf_mutex);
2954 if (changed & BSS_CHANGED_IBSS)
2955 ath10k_control_ibss(arvif, info, vif->addr);
2957 if (changed & BSS_CHANGED_BEACON_INT) {
2958 arvif->beacon_interval = info->beacon_int;
2959 vdev_param = ar->wmi.vdev_param->beacon_interval;
2960 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2961 arvif->beacon_interval);
2962 ath10k_dbg(ATH10K_DBG_MAC,
2963 "mac vdev %d beacon_interval %d\n",
2964 arvif->vdev_id, arvif->beacon_interval);
2967 ath10k_warn("failed to set beacon interval for vdev %d: %i\n",
2968 arvif->vdev_id, ret);
2971 if (changed & BSS_CHANGED_BEACON) {
2972 ath10k_dbg(ATH10K_DBG_MAC,
2973 "vdev %d set beacon tx mode to staggered\n",
2976 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2977 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
2978 WMI_BEACON_STAGGERED_MODE);
2980 ath10k_warn("failed to set beacon mode for vdev %d: %i\n",
2981 arvif->vdev_id, ret);
2984 if (changed & BSS_CHANGED_BEACON_INFO) {
2985 arvif->dtim_period = info->dtim_period;
2987 ath10k_dbg(ATH10K_DBG_MAC,
2988 "mac vdev %d dtim_period %d\n",
2989 arvif->vdev_id, arvif->dtim_period);
2991 vdev_param = ar->wmi.vdev_param->dtim_period;
2992 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2993 arvif->dtim_period);
2995 ath10k_warn("failed to set dtim period for vdev %d: %i\n",
2996 arvif->vdev_id, ret);
2999 if (changed & BSS_CHANGED_SSID &&
3000 vif->type == NL80211_IFTYPE_AP) {
3001 arvif->u.ap.ssid_len = info->ssid_len;
3003 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3004 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3007 if (changed & BSS_CHANGED_BSSID) {
3008 if (!is_zero_ether_addr(info->bssid)) {
3009 ath10k_dbg(ATH10K_DBG_MAC,
3010 "mac vdev %d create peer %pM\n",
3011 arvif->vdev_id, info->bssid);
3013 ret = ath10k_peer_create(ar, arvif->vdev_id,
3016 ath10k_warn("failed to add peer %pM for vdev %d when changing bssid: %i\n",
3017 info->bssid, arvif->vdev_id, ret);
3019 if (vif->type == NL80211_IFTYPE_STATION) {
3021 * this is never erased as we it for crypto key
3022 * clearing; this is FW requirement
3024 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
3026 ath10k_dbg(ATH10K_DBG_MAC,
3027 "mac vdev %d start %pM\n",
3028 arvif->vdev_id, info->bssid);
3030 ret = ath10k_vdev_start(arvif);
3032 ath10k_warn("failed to start vdev %i: %d\n",
3033 arvif->vdev_id, ret);
3037 arvif->is_started = true;
3041 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3042 * so driver need to store it. It is needed when leaving
3043 * IBSS in order to remove BSSID peer.
3045 if (vif->type == NL80211_IFTYPE_ADHOC)
3046 memcpy(arvif->bssid, info->bssid,
3051 if (changed & BSS_CHANGED_BEACON_ENABLED)
3052 ath10k_control_beaconing(arvif, info);
3054 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3055 arvif->use_cts_prot = info->use_cts_prot;
3056 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3057 arvif->vdev_id, info->use_cts_prot);
3059 ret = ath10k_recalc_rtscts_prot(arvif);
3061 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
3062 arvif->vdev_id, ret);
3065 if (changed & BSS_CHANGED_ERP_SLOT) {
3067 if (info->use_short_slot)
3068 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3071 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3073 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3074 arvif->vdev_id, slottime);
3076 vdev_param = ar->wmi.vdev_param->slot_time;
3077 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3080 ath10k_warn("failed to set erp slot for vdev %d: %i\n",
3081 arvif->vdev_id, ret);
3084 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3086 if (info->use_short_preamble)
3087 preamble = WMI_VDEV_PREAMBLE_SHORT;
3089 preamble = WMI_VDEV_PREAMBLE_LONG;
3091 ath10k_dbg(ATH10K_DBG_MAC,
3092 "mac vdev %d preamble %dn",
3093 arvif->vdev_id, preamble);
3095 vdev_param = ar->wmi.vdev_param->preamble;
3096 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3099 ath10k_warn("failed to set preamble for vdev %d: %i\n",
3100 arvif->vdev_id, ret);
3103 if (changed & BSS_CHANGED_ASSOC) {
3105 ath10k_bss_assoc(hw, vif, info);
3109 mutex_unlock(&ar->conf_mutex);
3112 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3113 struct ieee80211_vif *vif,
3114 struct cfg80211_scan_request *req)
3116 struct ath10k *ar = hw->priv;
3117 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3118 struct wmi_start_scan_arg arg;
3122 mutex_lock(&ar->conf_mutex);
3124 spin_lock_bh(&ar->data_lock);
3125 if (ar->scan.in_progress) {
3126 spin_unlock_bh(&ar->data_lock);
3131 reinit_completion(&ar->scan.started);
3132 reinit_completion(&ar->scan.completed);
3133 ar->scan.in_progress = true;
3134 ar->scan.aborting = false;
3135 ar->scan.is_roc = false;
3136 ar->scan.vdev_id = arvif->vdev_id;
3137 spin_unlock_bh(&ar->data_lock);
3139 memset(&arg, 0, sizeof(arg));
3140 ath10k_wmi_start_scan_init(ar, &arg);
3141 arg.vdev_id = arvif->vdev_id;
3142 arg.scan_id = ATH10K_SCAN_ID;
3145 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3148 arg.ie_len = req->ie_len;
3149 memcpy(arg.ie, req->ie, arg.ie_len);
3153 arg.n_ssids = req->n_ssids;
3154 for (i = 0; i < arg.n_ssids; i++) {
3155 arg.ssids[i].len = req->ssids[i].ssid_len;
3156 arg.ssids[i].ssid = req->ssids[i].ssid;
3159 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3162 if (req->n_channels) {
3163 arg.n_channels = req->n_channels;
3164 for (i = 0; i < arg.n_channels; i++)
3165 arg.channels[i] = req->channels[i]->center_freq;
3168 ret = ath10k_start_scan(ar, &arg);
3170 ath10k_warn("failed to start hw scan: %d\n", ret);
3171 spin_lock_bh(&ar->data_lock);
3172 ar->scan.in_progress = false;
3173 spin_unlock_bh(&ar->data_lock);
3177 mutex_unlock(&ar->conf_mutex);
3181 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3182 struct ieee80211_vif *vif)
3184 struct ath10k *ar = hw->priv;
3187 mutex_lock(&ar->conf_mutex);
3188 ret = ath10k_abort_scan(ar);
3190 ath10k_warn("failed to abort scan: %d\n", ret);
3191 ieee80211_scan_completed(hw, 1 /* aborted */);
3193 mutex_unlock(&ar->conf_mutex);
3196 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3197 struct ath10k_vif *arvif,
3198 enum set_key_cmd cmd,
3199 struct ieee80211_key_conf *key)
3201 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3204 /* 10.1 firmware branch requires default key index to be set to group
3205 * key index after installing it. Otherwise FW/HW Txes corrupted
3206 * frames with multi-vif APs. This is not required for main firmware
3207 * branch (e.g. 636).
3209 * FIXME: This has been tested only in AP. It remains unknown if this
3210 * is required for multi-vif STA interfaces on 10.1 */
3212 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3215 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3218 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3221 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3227 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3230 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3231 arvif->vdev_id, ret);
3234 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3235 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3236 struct ieee80211_key_conf *key)
3238 struct ath10k *ar = hw->priv;
3239 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3240 struct ath10k_peer *peer;
3241 const u8 *peer_addr;
3242 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3243 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3246 if (key->keyidx > WMI_MAX_KEY_INDEX)
3249 mutex_lock(&ar->conf_mutex);
3252 peer_addr = sta->addr;
3253 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3254 peer_addr = vif->bss_conf.bssid;
3256 peer_addr = vif->addr;
3258 key->hw_key_idx = key->keyidx;
3260 /* the peer should not disappear in mid-way (unless FW goes awry) since
3261 * we already hold conf_mutex. we just make sure its there now. */
3262 spin_lock_bh(&ar->data_lock);
3263 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3264 spin_unlock_bh(&ar->data_lock);
3267 if (cmd == SET_KEY) {
3268 ath10k_warn("failed to install key for non-existent peer %pM\n",
3273 /* if the peer doesn't exist there is no key to disable
3281 arvif->wep_keys[key->keyidx] = key;
3283 arvif->wep_keys[key->keyidx] = NULL;
3285 if (cmd == DISABLE_KEY)
3286 ath10k_clear_vdev_key(arvif, key);
3289 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3291 ath10k_warn("failed to install key for vdev %i peer %pM: %d\n",
3292 arvif->vdev_id, peer_addr, ret);
3296 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3298 spin_lock_bh(&ar->data_lock);
3299 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3300 if (peer && cmd == SET_KEY)
3301 peer->keys[key->keyidx] = key;
3302 else if (peer && cmd == DISABLE_KEY)
3303 peer->keys[key->keyidx] = NULL;
3304 else if (peer == NULL)
3305 /* impossible unless FW goes crazy */
3306 ath10k_warn("Peer %pM disappeared!\n", peer_addr);
3307 spin_unlock_bh(&ar->data_lock);
3310 mutex_unlock(&ar->conf_mutex);
3314 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3317 struct ath10k_vif *arvif;
3318 struct ath10k_sta *arsta;
3319 struct ieee80211_sta *sta;
3320 u32 changed, bw, nss, smps;
3323 arsta = container_of(wk, struct ath10k_sta, update_wk);
3324 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3325 arvif = arsta->arvif;
3328 spin_lock_bh(&ar->data_lock);
3330 changed = arsta->changed;
3337 spin_unlock_bh(&ar->data_lock);
3339 mutex_lock(&ar->conf_mutex);
3341 if (changed & IEEE80211_RC_BW_CHANGED) {
3342 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3345 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3346 WMI_PEER_CHAN_WIDTH, bw);
3348 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3349 sta->addr, bw, err);
3352 if (changed & IEEE80211_RC_NSS_CHANGED) {
3353 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3356 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3359 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3360 sta->addr, nss, err);
3363 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3364 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3367 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3368 WMI_PEER_SMPS_STATE, smps);
3370 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3371 sta->addr, smps, err);
3374 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3375 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3378 err = ath10k_station_assoc(ar, arvif, sta, true);
3380 ath10k_warn("failed to reassociate station: %pM\n",
3384 mutex_unlock(&ar->conf_mutex);
3387 static int ath10k_sta_state(struct ieee80211_hw *hw,
3388 struct ieee80211_vif *vif,
3389 struct ieee80211_sta *sta,
3390 enum ieee80211_sta_state old_state,
3391 enum ieee80211_sta_state new_state)
3393 struct ath10k *ar = hw->priv;
3394 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3395 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3399 if (old_state == IEEE80211_STA_NOTEXIST &&
3400 new_state == IEEE80211_STA_NONE) {
3401 memset(arsta, 0, sizeof(*arsta));
3402 arsta->arvif = arvif;
3403 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3406 /* cancel must be done outside the mutex to avoid deadlock */
3407 if ((old_state == IEEE80211_STA_NONE &&
3408 new_state == IEEE80211_STA_NOTEXIST))
3409 cancel_work_sync(&arsta->update_wk);
3411 mutex_lock(&ar->conf_mutex);
3413 if (old_state == IEEE80211_STA_NOTEXIST &&
3414 new_state == IEEE80211_STA_NONE &&
3415 vif->type != NL80211_IFTYPE_STATION) {
3417 * New station addition.
3419 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3420 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3422 max_num_peers = TARGET_NUM_PEERS;
3424 if (ar->num_peers >= max_num_peers) {
3425 ath10k_warn("number of peers exceeded: peers number %d (max peers %d)\n",
3426 ar->num_peers, max_num_peers);
3431 ath10k_dbg(ATH10K_DBG_MAC,
3432 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3433 arvif->vdev_id, sta->addr, ar->num_peers);
3435 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3437 ath10k_warn("failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3438 sta->addr, arvif->vdev_id, ret);
3439 } else if ((old_state == IEEE80211_STA_NONE &&
3440 new_state == IEEE80211_STA_NOTEXIST)) {
3442 * Existing station deletion.
3444 ath10k_dbg(ATH10K_DBG_MAC,
3445 "mac vdev %d peer delete %pM (sta gone)\n",
3446 arvif->vdev_id, sta->addr);
3447 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3449 ath10k_warn("failed to delete peer %pM for vdev %d: %i\n",
3450 sta->addr, arvif->vdev_id, ret);
3452 if (vif->type == NL80211_IFTYPE_STATION)
3453 ath10k_bss_disassoc(hw, vif);
3454 } else if (old_state == IEEE80211_STA_AUTH &&
3455 new_state == IEEE80211_STA_ASSOC &&
3456 (vif->type == NL80211_IFTYPE_AP ||
3457 vif->type == NL80211_IFTYPE_ADHOC)) {
3461 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3464 ret = ath10k_station_assoc(ar, arvif, sta, false);
3466 ath10k_warn("failed to associate station %pM for vdev %i: %i\n",
3467 sta->addr, arvif->vdev_id, ret);
3468 } else if (old_state == IEEE80211_STA_ASSOC &&
3469 new_state == IEEE80211_STA_AUTH &&
3470 (vif->type == NL80211_IFTYPE_AP ||
3471 vif->type == NL80211_IFTYPE_ADHOC)) {
3475 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3478 ret = ath10k_station_disassoc(ar, arvif, sta);
3480 ath10k_warn("failed to disassociate station: %pM vdev %i: %i\n",
3481 sta->addr, arvif->vdev_id, ret);
3484 mutex_unlock(&ar->conf_mutex);
3488 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3489 u16 ac, bool enable)
3491 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3495 lockdep_assert_held(&ar->conf_mutex);
3497 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3501 case IEEE80211_AC_VO:
3502 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3503 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3505 case IEEE80211_AC_VI:
3506 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3507 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3509 case IEEE80211_AC_BE:
3510 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3511 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3513 case IEEE80211_AC_BK:
3514 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3515 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3520 arvif->u.sta.uapsd |= value;
3522 arvif->u.sta.uapsd &= ~value;
3524 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3525 WMI_STA_PS_PARAM_UAPSD,
3526 arvif->u.sta.uapsd);
3528 ath10k_warn("failed to set uapsd params: %d\n", ret);
3532 if (arvif->u.sta.uapsd)
3533 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3535 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3537 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3538 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3541 ath10k_warn("failed to set rx wake param: %d\n", ret);
3547 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3548 struct ieee80211_vif *vif, u16 ac,
3549 const struct ieee80211_tx_queue_params *params)
3551 struct ath10k *ar = hw->priv;
3552 struct wmi_wmm_params_arg *p = NULL;
3555 mutex_lock(&ar->conf_mutex);
3558 case IEEE80211_AC_VO:
3559 p = &ar->wmm_params.ac_vo;
3561 case IEEE80211_AC_VI:
3562 p = &ar->wmm_params.ac_vi;
3564 case IEEE80211_AC_BE:
3565 p = &ar->wmm_params.ac_be;
3567 case IEEE80211_AC_BK:
3568 p = &ar->wmm_params.ac_bk;
3577 p->cwmin = params->cw_min;
3578 p->cwmax = params->cw_max;
3579 p->aifs = params->aifs;
3582 * The channel time duration programmed in the HW is in absolute
3583 * microseconds, while mac80211 gives the txop in units of
3586 p->txop = params->txop * 32;
3588 /* FIXME: FW accepts wmm params per hw, not per vif */
3589 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3591 ath10k_warn("failed to set wmm params: %d\n", ret);
3595 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3597 ath10k_warn("failed to set sta uapsd: %d\n", ret);
3600 mutex_unlock(&ar->conf_mutex);
3604 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3606 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3607 struct ieee80211_vif *vif,
3608 struct ieee80211_channel *chan,
3610 enum ieee80211_roc_type type)
3612 struct ath10k *ar = hw->priv;
3613 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3614 struct wmi_start_scan_arg arg;
3617 mutex_lock(&ar->conf_mutex);
3619 spin_lock_bh(&ar->data_lock);
3620 if (ar->scan.in_progress) {
3621 spin_unlock_bh(&ar->data_lock);
3626 reinit_completion(&ar->scan.started);
3627 reinit_completion(&ar->scan.completed);
3628 reinit_completion(&ar->scan.on_channel);
3629 ar->scan.in_progress = true;
3630 ar->scan.aborting = false;
3631 ar->scan.is_roc = true;
3632 ar->scan.vdev_id = arvif->vdev_id;
3633 ar->scan.roc_freq = chan->center_freq;
3634 spin_unlock_bh(&ar->data_lock);
3636 memset(&arg, 0, sizeof(arg));
3637 ath10k_wmi_start_scan_init(ar, &arg);
3638 arg.vdev_id = arvif->vdev_id;
3639 arg.scan_id = ATH10K_SCAN_ID;
3641 arg.channels[0] = chan->center_freq;
3642 arg.dwell_time_active = duration;
3643 arg.dwell_time_passive = duration;
3644 arg.max_scan_time = 2 * duration;
3645 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3646 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3648 ret = ath10k_start_scan(ar, &arg);
3650 ath10k_warn("failed to start roc scan: %d\n", ret);
3651 spin_lock_bh(&ar->data_lock);
3652 ar->scan.in_progress = false;
3653 spin_unlock_bh(&ar->data_lock);
3657 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3659 ath10k_warn("failed to switch to channel for roc scan\n");
3660 ath10k_abort_scan(ar);
3667 mutex_unlock(&ar->conf_mutex);
3671 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3673 struct ath10k *ar = hw->priv;
3675 mutex_lock(&ar->conf_mutex);
3676 ath10k_abort_scan(ar);
3677 mutex_unlock(&ar->conf_mutex);
3683 * Both RTS and Fragmentation threshold are interface-specific
3684 * in ath10k, but device-specific in mac80211.
3687 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3689 struct ath10k *ar = hw->priv;
3690 struct ath10k_vif *arvif;
3693 mutex_lock(&ar->conf_mutex);
3694 list_for_each_entry(arvif, &ar->arvifs, list) {
3695 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3696 arvif->vdev_id, value);
3698 ret = ath10k_mac_set_rts(arvif, value);
3700 ath10k_warn("failed to set rts threshold for vdev %d: %d\n",
3701 arvif->vdev_id, ret);
3705 mutex_unlock(&ar->conf_mutex);
3710 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3712 struct ath10k *ar = hw->priv;
3713 struct ath10k_vif *arvif;
3716 mutex_lock(&ar->conf_mutex);
3717 list_for_each_entry(arvif, &ar->arvifs, list) {
3718 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3719 arvif->vdev_id, value);
3721 ret = ath10k_mac_set_rts(arvif, value);
3723 ath10k_warn("failed to set fragmentation threshold for vdev %d: %d\n",
3724 arvif->vdev_id, ret);
3728 mutex_unlock(&ar->conf_mutex);
3733 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3734 u32 queues, bool drop)
3736 struct ath10k *ar = hw->priv;
3740 /* mac80211 doesn't care if we really xmit queued frames or not
3741 * we'll collect those frames either way if we stop/delete vdevs */
3745 mutex_lock(&ar->conf_mutex);
3747 if (ar->state == ATH10K_STATE_WEDGED)
3750 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3753 spin_lock_bh(&ar->htt.tx_lock);
3754 empty = (ar->htt.num_pending_tx == 0);
3755 spin_unlock_bh(&ar->htt.tx_lock);
3757 skip = (ar->state == ATH10K_STATE_WEDGED);
3760 }), ATH10K_FLUSH_TIMEOUT_HZ);
3762 if (ret <= 0 || skip)
3763 ath10k_warn("failed to flush transmit queue (skip %i ar-state %i): %i\n",
3764 skip, ar->state, ret);
3767 mutex_unlock(&ar->conf_mutex);
3770 /* TODO: Implement this function properly
3771 * For now it is needed to reply to Probe Requests in IBSS mode.
3772 * Propably we need this information from FW.
3774 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3780 static int ath10k_suspend(struct ieee80211_hw *hw,
3781 struct cfg80211_wowlan *wowlan)
3783 struct ath10k *ar = hw->priv;
3786 mutex_lock(&ar->conf_mutex);
3788 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
3790 if (ret == -ETIMEDOUT)
3796 ret = ath10k_hif_suspend(ar);
3798 ath10k_warn("failed to suspend hif: %d\n", ret);
3805 ret = ath10k_wmi_pdev_resume_target(ar);
3807 ath10k_warn("failed to resume target: %d\n", ret);
3811 mutex_unlock(&ar->conf_mutex);
3815 static int ath10k_resume(struct ieee80211_hw *hw)
3817 struct ath10k *ar = hw->priv;
3820 mutex_lock(&ar->conf_mutex);
3822 ret = ath10k_hif_resume(ar);
3824 ath10k_warn("failed to resume hif: %d\n", ret);
3829 ret = ath10k_wmi_pdev_resume_target(ar);
3831 ath10k_warn("failed to resume target: %d\n", ret);
3838 mutex_unlock(&ar->conf_mutex);
3843 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3845 struct ath10k *ar = hw->priv;
3847 mutex_lock(&ar->conf_mutex);
3849 /* If device failed to restart it will be in a different state, e.g.
3850 * ATH10K_STATE_WEDGED */
3851 if (ar->state == ATH10K_STATE_RESTARTED) {
3852 ath10k_info("device successfully recovered\n");
3853 ar->state = ATH10K_STATE_ON;
3856 mutex_unlock(&ar->conf_mutex);
3859 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3860 struct survey_info *survey)
3862 struct ath10k *ar = hw->priv;
3863 struct ieee80211_supported_band *sband;
3864 struct survey_info *ar_survey = &ar->survey[idx];
3867 mutex_lock(&ar->conf_mutex);
3869 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3870 if (sband && idx >= sband->n_channels) {
3871 idx -= sband->n_channels;
3876 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3878 if (!sband || idx >= sband->n_channels) {
3883 spin_lock_bh(&ar->data_lock);
3884 memcpy(survey, ar_survey, sizeof(*survey));
3885 spin_unlock_bh(&ar->data_lock);
3887 survey->channel = &sband->channels[idx];
3890 mutex_unlock(&ar->conf_mutex);
3894 /* Helper table for legacy fixed_rate/bitrate_mask */
3895 static const u8 cck_ofdm_rate[] = {
3912 /* Check if only one bit set */
3913 static int ath10k_check_single_mask(u32 mask)
3921 mask &= ~BIT(bit - 1);
3929 ath10k_default_bitrate_mask(struct ath10k *ar,
3930 enum ieee80211_band band,
3931 const struct cfg80211_bitrate_mask *mask)
3933 u32 legacy = 0x00ff;
3938 case IEEE80211_BAND_2GHZ:
3942 case IEEE80211_BAND_5GHZ:
3948 if (mask->control[band].legacy != legacy)
3951 for (i = 0; i < ar->num_rf_chains; i++)
3952 if (mask->control[band].ht_mcs[i] != ht)
3955 for (i = 0; i < ar->num_rf_chains; i++)
3956 if (mask->control[band].vht_mcs[i] != vht)
3963 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3964 enum ieee80211_band band,
3967 int ht_nss = 0, vht_nss = 0, i;
3970 if (ath10k_check_single_mask(mask->control[band].legacy))
3974 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3975 if (mask->control[band].ht_mcs[i] == 0xff)
3977 else if (mask->control[band].ht_mcs[i] == 0x00)
3986 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3987 if (mask->control[band].vht_mcs[i] == 0x03ff)
3989 else if (mask->control[band].vht_mcs[i] == 0x0000)
3997 if (ht_nss > 0 && vht_nss > 0)
4001 *fixed_nss = ht_nss;
4003 *fixed_nss = vht_nss;
4011 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4012 enum ieee80211_band band,
4013 enum wmi_rate_preamble *preamble)
4015 int legacy = 0, ht = 0, vht = 0, i;
4017 *preamble = WMI_RATE_PREAMBLE_OFDM;
4020 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4025 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4026 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4031 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4032 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4036 /* Currently we support only one fixed_rate */
4037 if ((legacy + ht + vht) != 1)
4041 *preamble = WMI_RATE_PREAMBLE_HT;
4043 *preamble = WMI_RATE_PREAMBLE_VHT;
4049 ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
4050 enum ieee80211_band band,
4054 u8 rate = 0, pream = 0, nss = 0, i;
4055 enum wmi_rate_preamble preamble;
4057 /* Check if single rate correct */
4058 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4064 case WMI_RATE_PREAMBLE_CCK:
4065 case WMI_RATE_PREAMBLE_OFDM:
4066 i = ffs(mask->control[band].legacy) - 1;
4068 if (band == IEEE80211_BAND_2GHZ && i < 4)
4069 pream = WMI_RATE_PREAMBLE_CCK;
4071 if (band == IEEE80211_BAND_5GHZ)
4074 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4077 rate = cck_ofdm_rate[i];
4079 case WMI_RATE_PREAMBLE_HT:
4080 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4081 if (mask->control[band].ht_mcs[i])
4084 if (i == IEEE80211_HT_MCS_MASK_LEN)
4087 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4090 case WMI_RATE_PREAMBLE_VHT:
4091 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4092 if (mask->control[band].vht_mcs[i])
4095 if (i == NL80211_VHT_NSS_MAX)
4098 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4103 *fixed_nss = nss + 1;
4107 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4110 *fixed_rate = pream | nss | rate;
4115 static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
4116 enum ieee80211_band band,
4120 /* First check full NSS mask, if we can simply limit NSS */
4121 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4124 /* Next Check single rate is set */
4125 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
4128 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4133 struct ath10k *ar = arvif->ar;
4137 mutex_lock(&ar->conf_mutex);
4139 if (arvif->fixed_rate == fixed_rate &&
4140 arvif->fixed_nss == fixed_nss &&
4141 arvif->force_sgi == force_sgi)
4144 if (fixed_rate == WMI_FIXED_RATE_NONE)
4145 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4148 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
4150 vdev_param = ar->wmi.vdev_param->fixed_rate;
4151 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4152 vdev_param, fixed_rate);
4154 ath10k_warn("failed to set fixed rate param 0x%02x: %d\n",
4160 arvif->fixed_rate = fixed_rate;
4162 vdev_param = ar->wmi.vdev_param->nss;
4163 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4164 vdev_param, fixed_nss);
4167 ath10k_warn("failed to set fixed nss param %d: %d\n",
4173 arvif->fixed_nss = fixed_nss;
4175 vdev_param = ar->wmi.vdev_param->sgi;
4176 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4180 ath10k_warn("failed to set sgi param %d: %d\n",
4186 arvif->force_sgi = force_sgi;
4189 mutex_unlock(&ar->conf_mutex);
4193 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4194 struct ieee80211_vif *vif,
4195 const struct cfg80211_bitrate_mask *mask)
4197 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4198 struct ath10k *ar = arvif->ar;
4199 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4200 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4201 u8 fixed_nss = ar->num_rf_chains;
4204 force_sgi = mask->control[band].gi;
4205 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4208 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4209 if (!ath10k_get_fixed_rate_nss(mask, band,
4215 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4216 ath10k_warn("failed to force SGI usage for default rate settings\n");
4220 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4221 fixed_nss, force_sgi);
4224 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4225 struct ieee80211_vif *vif,
4226 struct ieee80211_sta *sta,
4229 struct ath10k *ar = hw->priv;
4230 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4233 spin_lock_bh(&ar->data_lock);
4235 ath10k_dbg(ATH10K_DBG_MAC,
4236 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4237 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4240 if (changed & IEEE80211_RC_BW_CHANGED) {
4241 bw = WMI_PEER_CHWIDTH_20MHZ;
4243 switch (sta->bandwidth) {
4244 case IEEE80211_STA_RX_BW_20:
4245 bw = WMI_PEER_CHWIDTH_20MHZ;
4247 case IEEE80211_STA_RX_BW_40:
4248 bw = WMI_PEER_CHWIDTH_40MHZ;
4250 case IEEE80211_STA_RX_BW_80:
4251 bw = WMI_PEER_CHWIDTH_80MHZ;
4253 case IEEE80211_STA_RX_BW_160:
4254 ath10k_warn("Invalid bandwith %d in rc update for %pM\n",
4255 sta->bandwidth, sta->addr);
4256 bw = WMI_PEER_CHWIDTH_20MHZ;
4263 if (changed & IEEE80211_RC_NSS_CHANGED)
4264 arsta->nss = sta->rx_nss;
4266 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4267 smps = WMI_PEER_SMPS_PS_NONE;
4269 switch (sta->smps_mode) {
4270 case IEEE80211_SMPS_AUTOMATIC:
4271 case IEEE80211_SMPS_OFF:
4272 smps = WMI_PEER_SMPS_PS_NONE;
4274 case IEEE80211_SMPS_STATIC:
4275 smps = WMI_PEER_SMPS_STATIC;
4277 case IEEE80211_SMPS_DYNAMIC:
4278 smps = WMI_PEER_SMPS_DYNAMIC;
4280 case IEEE80211_SMPS_NUM_MODES:
4281 ath10k_warn("Invalid smps %d in sta rc update for %pM\n",
4282 sta->smps_mode, sta->addr);
4283 smps = WMI_PEER_SMPS_PS_NONE;
4290 arsta->changed |= changed;
4292 spin_unlock_bh(&ar->data_lock);
4294 ieee80211_queue_work(hw, &arsta->update_wk);
4297 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4300 * FIXME: Return 0 for time being. Need to figure out whether FW
4301 * has the API to fetch 64-bit local TSF
4307 static const struct ieee80211_ops ath10k_ops = {
4309 .start = ath10k_start,
4310 .stop = ath10k_stop,
4311 .config = ath10k_config,
4312 .add_interface = ath10k_add_interface,
4313 .remove_interface = ath10k_remove_interface,
4314 .configure_filter = ath10k_configure_filter,
4315 .bss_info_changed = ath10k_bss_info_changed,
4316 .hw_scan = ath10k_hw_scan,
4317 .cancel_hw_scan = ath10k_cancel_hw_scan,
4318 .set_key = ath10k_set_key,
4319 .sta_state = ath10k_sta_state,
4320 .conf_tx = ath10k_conf_tx,
4321 .remain_on_channel = ath10k_remain_on_channel,
4322 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4323 .set_rts_threshold = ath10k_set_rts_threshold,
4324 .set_frag_threshold = ath10k_set_frag_threshold,
4325 .flush = ath10k_flush,
4326 .tx_last_beacon = ath10k_tx_last_beacon,
4327 .set_antenna = ath10k_set_antenna,
4328 .get_antenna = ath10k_get_antenna,
4329 .restart_complete = ath10k_restart_complete,
4330 .get_survey = ath10k_get_survey,
4331 .set_bitrate_mask = ath10k_set_bitrate_mask,
4332 .sta_rc_update = ath10k_sta_rc_update,
4333 .get_tsf = ath10k_get_tsf,
4335 .suspend = ath10k_suspend,
4336 .resume = ath10k_resume,
4340 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4341 .bitrate = (_rate), \
4342 .flags = (_flags), \
4343 .hw_value = (_rateid), \
4346 #define CHAN2G(_channel, _freq, _flags) { \
4347 .band = IEEE80211_BAND_2GHZ, \
4348 .hw_value = (_channel), \
4349 .center_freq = (_freq), \
4350 .flags = (_flags), \
4351 .max_antenna_gain = 0, \
4355 #define CHAN5G(_channel, _freq, _flags) { \
4356 .band = IEEE80211_BAND_5GHZ, \
4357 .hw_value = (_channel), \
4358 .center_freq = (_freq), \
4359 .flags = (_flags), \
4360 .max_antenna_gain = 0, \
4364 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4374 CHAN2G(10, 2457, 0),
4375 CHAN2G(11, 2462, 0),
4376 CHAN2G(12, 2467, 0),
4377 CHAN2G(13, 2472, 0),
4378 CHAN2G(14, 2484, 0),
4381 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4382 CHAN5G(36, 5180, 0),
4383 CHAN5G(40, 5200, 0),
4384 CHAN5G(44, 5220, 0),
4385 CHAN5G(48, 5240, 0),
4386 CHAN5G(52, 5260, 0),
4387 CHAN5G(56, 5280, 0),
4388 CHAN5G(60, 5300, 0),
4389 CHAN5G(64, 5320, 0),
4390 CHAN5G(100, 5500, 0),
4391 CHAN5G(104, 5520, 0),
4392 CHAN5G(108, 5540, 0),
4393 CHAN5G(112, 5560, 0),
4394 CHAN5G(116, 5580, 0),
4395 CHAN5G(120, 5600, 0),
4396 CHAN5G(124, 5620, 0),
4397 CHAN5G(128, 5640, 0),
4398 CHAN5G(132, 5660, 0),
4399 CHAN5G(136, 5680, 0),
4400 CHAN5G(140, 5700, 0),
4401 CHAN5G(149, 5745, 0),
4402 CHAN5G(153, 5765, 0),
4403 CHAN5G(157, 5785, 0),
4404 CHAN5G(161, 5805, 0),
4405 CHAN5G(165, 5825, 0),
4408 static struct ieee80211_rate ath10k_rates[] = {
4410 RATETAB_ENT(10, 0x82, 0),
4411 RATETAB_ENT(20, 0x84, 0),
4412 RATETAB_ENT(55, 0x8b, 0),
4413 RATETAB_ENT(110, 0x96, 0),
4415 RATETAB_ENT(60, 0x0c, 0),
4416 RATETAB_ENT(90, 0x12, 0),
4417 RATETAB_ENT(120, 0x18, 0),
4418 RATETAB_ENT(180, 0x24, 0),
4419 RATETAB_ENT(240, 0x30, 0),
4420 RATETAB_ENT(360, 0x48, 0),
4421 RATETAB_ENT(480, 0x60, 0),
4422 RATETAB_ENT(540, 0x6c, 0),
4425 #define ath10k_a_rates (ath10k_rates + 4)
4426 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4427 #define ath10k_g_rates (ath10k_rates + 0)
4428 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4430 struct ath10k *ath10k_mac_create(void)
4432 struct ieee80211_hw *hw;
4435 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4445 void ath10k_mac_destroy(struct ath10k *ar)
4447 ieee80211_free_hw(ar->hw);
4450 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4453 .types = BIT(NL80211_IFTYPE_STATION)
4454 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4458 .types = BIT(NL80211_IFTYPE_P2P_GO)
4462 .types = BIT(NL80211_IFTYPE_AP)
4466 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4469 .types = BIT(NL80211_IFTYPE_AP)
4473 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4475 .limits = ath10k_if_limits,
4476 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4477 .max_interfaces = 8,
4478 .num_different_channels = 1,
4479 .beacon_int_infra_match = true,
4483 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4485 .limits = ath10k_10x_if_limits,
4486 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4487 .max_interfaces = 8,
4488 .num_different_channels = 1,
4489 .beacon_int_infra_match = true,
4490 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4491 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4492 BIT(NL80211_CHAN_WIDTH_20) |
4493 BIT(NL80211_CHAN_WIDTH_40) |
4494 BIT(NL80211_CHAN_WIDTH_80),
4499 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4501 struct ieee80211_sta_vht_cap vht_cap = {0};
4505 vht_cap.vht_supported = 1;
4506 vht_cap.cap = ar->vht_cap_info;
4509 for (i = 0; i < 8; i++) {
4510 if (i < ar->num_rf_chains)
4511 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4513 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4516 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4517 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4522 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4525 struct ieee80211_sta_ht_cap ht_cap = {0};
4527 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4530 ht_cap.ht_supported = 1;
4531 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4532 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4533 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4534 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4535 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4537 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4538 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4540 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4541 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4543 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4546 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4547 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4552 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4553 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4555 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4558 stbc = ar->ht_cap_info;
4559 stbc &= WMI_HT_CAP_RX_STBC;
4560 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4561 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4562 stbc &= IEEE80211_HT_CAP_RX_STBC;
4567 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4568 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4570 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4571 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4573 /* max AMSDU is implicitly taken from vht_cap_info */
4574 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4575 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4577 for (i = 0; i < ar->num_rf_chains; i++)
4578 ht_cap.mcs.rx_mask[i] = 0xFF;
4580 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4586 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4587 struct ieee80211_vif *vif)
4589 struct ath10k_vif_iter *arvif_iter = data;
4590 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4592 if (arvif->vdev_id == arvif_iter->vdev_id)
4593 arvif_iter->arvif = arvif;
4596 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4598 struct ath10k_vif_iter arvif_iter;
4601 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4602 arvif_iter.vdev_id = vdev_id;
4604 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4605 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4607 ath10k_get_arvif_iter,
4609 if (!arvif_iter.arvif) {
4610 ath10k_warn("No VIF found for vdev %d\n", vdev_id);
4614 return arvif_iter.arvif;
4617 int ath10k_mac_register(struct ath10k *ar)
4619 struct ieee80211_supported_band *band;
4620 struct ieee80211_sta_vht_cap vht_cap;
4621 struct ieee80211_sta_ht_cap ht_cap;
4625 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4627 SET_IEEE80211_DEV(ar->hw, ar->dev);
4629 ht_cap = ath10k_get_ht_cap(ar);
4630 vht_cap = ath10k_create_vht_cap(ar);
4632 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4633 channels = kmemdup(ath10k_2ghz_channels,
4634 sizeof(ath10k_2ghz_channels),
4641 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4642 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4643 band->channels = channels;
4644 band->n_bitrates = ath10k_g_rates_size;
4645 band->bitrates = ath10k_g_rates;
4646 band->ht_cap = ht_cap;
4648 /* vht is not supported in 2.4 GHz */
4650 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4653 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4654 channels = kmemdup(ath10k_5ghz_channels,
4655 sizeof(ath10k_5ghz_channels),
4662 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4663 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4664 band->channels = channels;
4665 band->n_bitrates = ath10k_a_rates_size;
4666 band->bitrates = ath10k_a_rates;
4667 band->ht_cap = ht_cap;
4668 band->vht_cap = vht_cap;
4669 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4672 ar->hw->wiphy->interface_modes =
4673 BIT(NL80211_IFTYPE_STATION) |
4674 BIT(NL80211_IFTYPE_ADHOC) |
4675 BIT(NL80211_IFTYPE_AP);
4677 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4678 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4679 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4680 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4682 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4683 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4686 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4687 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4689 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4690 ar->hw->wiphy->interface_modes |=
4691 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4692 BIT(NL80211_IFTYPE_P2P_GO);
4694 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4695 IEEE80211_HW_SUPPORTS_PS |
4696 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4697 IEEE80211_HW_SUPPORTS_UAPSD |
4698 IEEE80211_HW_MFP_CAPABLE |
4699 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4700 IEEE80211_HW_HAS_RATE_CONTROL |
4701 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4702 IEEE80211_HW_AP_LINK_PS |
4703 IEEE80211_HW_SPECTRUM_MGMT;
4705 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4706 * bytes is used for padding/alignment if necessary. */
4707 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4709 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4710 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4712 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4713 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4714 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4717 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4718 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4720 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4721 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
4723 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4725 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4726 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4727 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4729 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4731 * on LL hardware queues are managed entirely by the FW
4732 * so we only advertise to mac we can do the queues thing
4736 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4737 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4738 ar->hw->wiphy->n_iface_combinations =
4739 ARRAY_SIZE(ath10k_10x_if_comb);
4741 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4742 ar->hw->wiphy->n_iface_combinations =
4743 ARRAY_SIZE(ath10k_if_comb);
4746 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4748 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4749 /* Init ath dfs pattern detector */
4750 ar->ath_common.debug_mask = ATH_DBG_DFS;
4751 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4754 if (!ar->dfs_detector)
4755 ath10k_warn("failed to initialise DFS pattern detector\n");
4758 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4759 ath10k_reg_notifier);
4761 ath10k_err("failed to initialise regulatory: %i\n", ret);
4765 ret = ieee80211_register_hw(ar->hw);
4767 ath10k_err("failed to register ieee80211: %d\n", ret);
4771 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4772 ret = regulatory_hint(ar->hw->wiphy,
4773 ar->ath_common.regulatory.alpha2);
4775 goto err_unregister;
4781 ieee80211_unregister_hw(ar->hw);
4783 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4784 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4789 void ath10k_mac_unregister(struct ath10k *ar)
4791 ieee80211_unregister_hw(ar->hw);
4793 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4794 ar->dfs_detector->exit(ar->dfs_detector);
4796 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4797 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4799 SET_IEEE80211_DEV(ar->hw, NULL);