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 ath10k *ar = arvif->ar;
40 struct wmi_vdev_install_key_arg arg = {
41 .vdev_id = arvif->vdev_id,
42 .key_idx = key->keyidx,
43 .key_len = key->keylen,
48 lockdep_assert_held(&arvif->ar->conf_mutex);
50 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
51 arg.key_flags = WMI_KEY_PAIRWISE;
53 arg.key_flags = WMI_KEY_GROUP;
55 switch (key->cipher) {
56 case WLAN_CIPHER_SUITE_CCMP:
57 arg.key_cipher = WMI_CIPHER_AES_CCM;
58 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
59 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
61 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
63 case WLAN_CIPHER_SUITE_TKIP:
64 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
77 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
81 if (cmd == DISABLE_KEY) {
82 arg.key_cipher = WMI_CIPHER_NONE;
86 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
89 static int ath10k_install_key(struct ath10k_vif *arvif,
90 struct ieee80211_key_conf *key,
94 struct ath10k *ar = arvif->ar;
97 lockdep_assert_held(&ar->conf_mutex);
99 reinit_completion(&ar->install_key_done);
101 ret = ath10k_send_key(arvif, key, cmd, macaddr);
105 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
112 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
115 struct ath10k *ar = arvif->ar;
116 struct ath10k_peer *peer;
120 lockdep_assert_held(&ar->conf_mutex);
122 spin_lock_bh(&ar->data_lock);
123 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
124 spin_unlock_bh(&ar->data_lock);
129 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
130 if (arvif->wep_keys[i] == NULL)
133 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
138 peer->keys[i] = arvif->wep_keys[i];
144 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
147 struct ath10k *ar = arvif->ar;
148 struct ath10k_peer *peer;
153 lockdep_assert_held(&ar->conf_mutex);
155 spin_lock_bh(&ar->data_lock);
156 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
157 spin_unlock_bh(&ar->data_lock);
162 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
163 if (peer->keys[i] == NULL)
166 ret = ath10k_install_key(arvif, peer->keys[i],
168 if (ret && first_errno == 0)
172 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
175 peer->keys[i] = NULL;
181 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
182 struct ieee80211_key_conf *key)
184 struct ath10k *ar = arvif->ar;
185 struct ath10k_peer *peer;
191 lockdep_assert_held(&ar->conf_mutex);
194 /* since ath10k_install_key we can't hold data_lock all the
195 * time, so we try to remove the keys incrementally */
196 spin_lock_bh(&ar->data_lock);
198 list_for_each_entry(peer, &ar->peers, list) {
199 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
200 if (peer->keys[i] == key) {
201 memcpy(addr, peer->addr, ETH_ALEN);
202 peer->keys[i] = NULL;
207 if (i < ARRAY_SIZE(peer->keys))
210 spin_unlock_bh(&ar->data_lock);
212 if (i == ARRAY_SIZE(peer->keys))
215 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
216 if (ret && first_errno == 0)
220 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
228 /*********************/
229 /* General utilities */
230 /*********************/
232 static inline enum wmi_phy_mode
233 chan_to_phymode(const struct cfg80211_chan_def *chandef)
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
284 WARN_ON(phymode == MODE_UNKNOWN);
288 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
301 switch (mpdudensity) {
307 /* Our lower layer calculations limit our precision to
323 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
327 lockdep_assert_held(&ar->conf_mutex);
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
342 spin_lock_bh(&ar->data_lock);
344 spin_unlock_bh(&ar->data_lock);
349 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
351 struct ath10k *ar = arvif->ar;
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
360 arvif->vdev_id, ret);
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
369 arvif->vdev_id, ret);
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
378 arvif->vdev_id, ret);
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
387 arvif->vdev_id, ret);
394 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
396 struct ath10k *ar = arvif->ar;
399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
407 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
409 struct ath10k *ar = arvif->ar;
412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
421 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
425 lockdep_assert_held(&ar->conf_mutex);
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
435 spin_lock_bh(&ar->data_lock);
437 spin_unlock_bh(&ar->data_lock);
442 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
444 struct ath10k_peer *peer, *tmp;
446 lockdep_assert_held(&ar->conf_mutex);
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
454 peer->addr, vdev_id);
456 list_del(&peer->list);
460 spin_unlock_bh(&ar->data_lock);
463 static void ath10k_peer_cleanup_all(struct ath10k *ar)
465 struct ath10k_peer *peer, *tmp;
467 lockdep_assert_held(&ar->conf_mutex);
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
475 spin_unlock_bh(&ar->data_lock);
478 /************************/
479 /* Interface management */
480 /************************/
482 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
486 lockdep_assert_held(&ar->conf_mutex);
488 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
489 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
496 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
498 struct cfg80211_chan_def *chandef = &ar->chandef;
499 struct ieee80211_channel *channel = chandef->chan;
500 struct wmi_vdev_start_request_arg arg = {};
503 lockdep_assert_held(&ar->conf_mutex);
505 arg.vdev_id = vdev_id;
506 arg.channel.freq = channel->center_freq;
507 arg.channel.band_center_freq1 = chandef->center_freq1;
509 /* TODO setup this dynamically, what in case we
510 don't have any vifs? */
511 arg.channel.mode = chan_to_phymode(chandef);
512 arg.channel.chan_radar =
513 !!(channel->flags & IEEE80211_CHAN_RADAR);
515 arg.channel.min_power = 0;
516 arg.channel.max_power = channel->max_power * 2;
517 arg.channel.max_reg_power = channel->max_reg_power * 2;
518 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
520 ret = ath10k_wmi_vdev_start(ar, &arg);
522 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
527 ret = ath10k_vdev_setup_sync(ar);
529 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
534 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
536 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
541 ar->monitor_vdev_id = vdev_id;
543 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
544 ar->monitor_vdev_id);
548 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
550 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
551 ar->monitor_vdev_id, ret);
556 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
560 lockdep_assert_held(&ar->conf_mutex);
562 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
564 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
565 ar->monitor_vdev_id, ret);
567 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
569 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
570 ar->monitor_vdev_id, ret);
572 ret = ath10k_vdev_setup_sync(ar);
574 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
575 ar->monitor_vdev_id, ret);
577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
578 ar->monitor_vdev_id);
582 static int ath10k_monitor_vdev_create(struct ath10k *ar)
586 lockdep_assert_held(&ar->conf_mutex);
588 if (ar->free_vdev_map == 0) {
589 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
593 bit = ffs(ar->free_vdev_map);
595 ar->monitor_vdev_id = bit - 1;
597 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
598 WMI_VDEV_TYPE_MONITOR,
601 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
602 ar->monitor_vdev_id, ret);
606 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
608 ar->monitor_vdev_id);
613 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
617 lockdep_assert_held(&ar->conf_mutex);
619 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
621 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
622 ar->monitor_vdev_id, ret);
626 ar->free_vdev_map |= 1 << ar->monitor_vdev_id;
628 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
629 ar->monitor_vdev_id);
633 static int ath10k_monitor_start(struct ath10k *ar)
637 lockdep_assert_held(&ar->conf_mutex);
639 ret = ath10k_monitor_vdev_create(ar);
641 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
645 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
647 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
648 ath10k_monitor_vdev_delete(ar);
652 ar->monitor_started = true;
653 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
658 static int ath10k_monitor_stop(struct ath10k *ar)
662 lockdep_assert_held(&ar->conf_mutex);
664 ret = ath10k_monitor_vdev_stop(ar);
666 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
670 ret = ath10k_monitor_vdev_delete(ar);
672 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
676 ar->monitor_started = false;
677 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
682 static int ath10k_monitor_recalc(struct ath10k *ar)
686 lockdep_assert_held(&ar->conf_mutex);
688 should_start = ar->monitor ||
689 ar->filter_flags & FIF_PROMISC_IN_BSS ||
690 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
692 ath10k_dbg(ar, ATH10K_DBG_MAC,
693 "mac monitor recalc started? %d should? %d\n",
694 ar->monitor_started, should_start);
696 if (should_start == ar->monitor_started)
700 return ath10k_monitor_start(ar);
702 return ath10k_monitor_stop(ar);
705 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
707 struct ath10k *ar = arvif->ar;
708 u32 vdev_param, rts_cts = 0;
710 lockdep_assert_held(&ar->conf_mutex);
712 vdev_param = ar->wmi.vdev_param->enable_rtscts;
714 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
715 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
717 if (arvif->num_legacy_stations > 0)
718 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
721 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
725 static int ath10k_start_cac(struct ath10k *ar)
729 lockdep_assert_held(&ar->conf_mutex);
731 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
733 ret = ath10k_monitor_recalc(ar);
735 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
736 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
741 ar->monitor_vdev_id);
746 static int ath10k_stop_cac(struct ath10k *ar)
748 lockdep_assert_held(&ar->conf_mutex);
750 /* CAC is not running - do nothing */
751 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
754 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
755 ath10k_monitor_stop(ar);
757 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
762 static void ath10k_recalc_radar_detection(struct ath10k *ar)
766 lockdep_assert_held(&ar->conf_mutex);
770 if (!ar->radar_enabled)
773 if (ar->num_started_vdevs > 0)
776 ret = ath10k_start_cac(ar);
779 * Not possible to start CAC on current channel so starting
780 * radiation is not allowed, make this channel DFS_UNAVAILABLE
781 * by indicating that radar was detected.
783 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
784 ieee80211_radar_detected(ar->hw);
788 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
790 struct ath10k *ar = arvif->ar;
791 struct cfg80211_chan_def *chandef = &ar->chandef;
792 struct wmi_vdev_start_request_arg arg = {};
795 lockdep_assert_held(&ar->conf_mutex);
797 reinit_completion(&ar->vdev_setup_done);
799 arg.vdev_id = arvif->vdev_id;
800 arg.dtim_period = arvif->dtim_period;
801 arg.bcn_intval = arvif->beacon_interval;
803 arg.channel.freq = chandef->chan->center_freq;
804 arg.channel.band_center_freq1 = chandef->center_freq1;
805 arg.channel.mode = chan_to_phymode(chandef);
807 arg.channel.min_power = 0;
808 arg.channel.max_power = chandef->chan->max_power * 2;
809 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
810 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
812 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
813 arg.ssid = arvif->u.ap.ssid;
814 arg.ssid_len = arvif->u.ap.ssid_len;
815 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
817 /* For now allow DFS for AP mode */
818 arg.channel.chan_radar =
819 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
820 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
821 arg.ssid = arvif->vif->bss_conf.ssid;
822 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
825 ath10k_dbg(ar, ATH10K_DBG_MAC,
826 "mac vdev %d start center_freq %d phymode %s\n",
827 arg.vdev_id, arg.channel.freq,
828 ath10k_wmi_phymode_str(arg.channel.mode));
831 ret = ath10k_wmi_vdev_restart(ar, &arg);
833 ret = ath10k_wmi_vdev_start(ar, &arg);
836 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
841 ret = ath10k_vdev_setup_sync(ar);
843 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
848 ar->num_started_vdevs++;
849 ath10k_recalc_radar_detection(ar);
854 static int ath10k_vdev_start(struct ath10k_vif *arvif)
856 return ath10k_vdev_start_restart(arvif, false);
859 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
861 return ath10k_vdev_start_restart(arvif, true);
864 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
866 struct ath10k *ar = arvif->ar;
869 lockdep_assert_held(&ar->conf_mutex);
871 reinit_completion(&ar->vdev_setup_done);
873 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
875 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
876 arvif->vdev_id, ret);
880 ret = ath10k_vdev_setup_sync(ar);
882 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
883 arvif->vdev_id, ret);
887 WARN_ON(ar->num_started_vdevs == 0);
889 if (ar->num_started_vdevs != 0) {
890 ar->num_started_vdevs--;
891 ath10k_recalc_radar_detection(ar);
897 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
898 struct ieee80211_bss_conf *info)
900 struct ath10k *ar = arvif->ar;
903 lockdep_assert_held(&arvif->ar->conf_mutex);
905 if (!info->enable_beacon) {
906 ath10k_vdev_stop(arvif);
908 arvif->is_started = false;
909 arvif->is_up = false;
911 spin_lock_bh(&arvif->ar->data_lock);
913 dma_unmap_single(arvif->ar->dev,
914 ATH10K_SKB_CB(arvif->beacon)->paddr,
915 arvif->beacon->len, DMA_TO_DEVICE);
916 dev_kfree_skb_any(arvif->beacon);
918 arvif->beacon = NULL;
919 arvif->beacon_sent = false;
921 spin_unlock_bh(&arvif->ar->data_lock);
926 arvif->tx_seq_no = 0x1000;
928 ret = ath10k_vdev_start(arvif);
933 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
935 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
938 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
939 arvif->vdev_id, ret);
940 ath10k_vdev_stop(arvif);
944 arvif->is_started = true;
947 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
950 static void ath10k_control_ibss(struct ath10k_vif *arvif,
951 struct ieee80211_bss_conf *info,
952 const u8 self_peer[ETH_ALEN])
954 struct ath10k *ar = arvif->ar;
958 lockdep_assert_held(&arvif->ar->conf_mutex);
960 if (!info->ibss_joined) {
961 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
963 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
964 self_peer, arvif->vdev_id, ret);
966 if (is_zero_ether_addr(arvif->bssid))
969 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
972 ath10k_warn(ar, "failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
973 arvif->bssid, arvif->vdev_id, ret);
977 memset(arvif->bssid, 0, ETH_ALEN);
982 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
984 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
985 self_peer, arvif->vdev_id, ret);
989 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
990 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
991 ATH10K_DEFAULT_ATIM);
993 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
994 arvif->vdev_id, ret);
998 * Review this when mac80211 gains per-interface powersave support.
1000 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1002 struct ath10k *ar = arvif->ar;
1003 struct ieee80211_conf *conf = &ar->hw->conf;
1004 enum wmi_sta_powersave_param param;
1005 enum wmi_sta_ps_mode psmode;
1008 lockdep_assert_held(&arvif->ar->conf_mutex);
1010 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1013 if (conf->flags & IEEE80211_CONF_PS) {
1014 psmode = WMI_STA_PS_MODE_ENABLED;
1015 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1017 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1018 conf->dynamic_ps_timeout);
1020 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1021 arvif->vdev_id, ret);
1025 psmode = WMI_STA_PS_MODE_DISABLED;
1028 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1029 arvif->vdev_id, psmode ? "enable" : "disable");
1031 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1033 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1034 psmode, arvif->vdev_id, ret);
1041 /**********************/
1042 /* Station management */
1043 /**********************/
1045 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1046 struct ath10k_vif *arvif,
1047 struct ieee80211_sta *sta,
1048 struct ieee80211_bss_conf *bss_conf,
1049 struct wmi_peer_assoc_complete_arg *arg)
1051 lockdep_assert_held(&ar->conf_mutex);
1053 memcpy(arg->addr, sta->addr, ETH_ALEN);
1054 arg->vdev_id = arvif->vdev_id;
1055 arg->peer_aid = sta->aid;
1056 arg->peer_flags |= WMI_PEER_AUTH;
1058 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1060 * Seems FW have problems with Power Save in STA
1061 * mode when we setup this parameter to high (eg. 5).
1062 * Often we see that FW don't send NULL (with clean P flags)
1063 * frame even there is info about buffered frames in beacons.
1064 * Sometimes we have to wait more than 10 seconds before FW
1065 * will wakeup. Often sending one ping from AP to our device
1066 * just fail (more than 50%).
1068 * Seems setting this FW parameter to 1 couse FW
1069 * will check every beacon and will wakup immediately
1070 * after detection buffered data.
1072 arg->peer_listen_intval = 1;
1074 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1076 arg->peer_num_spatial_streams = 1;
1079 * The assoc capabilities are available only in managed mode.
1081 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1082 arg->peer_caps = bss_conf->assoc_capability;
1085 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1086 struct ath10k_vif *arvif,
1087 struct wmi_peer_assoc_complete_arg *arg)
1089 struct ieee80211_vif *vif = arvif->vif;
1090 struct ieee80211_bss_conf *info = &vif->bss_conf;
1091 struct cfg80211_bss *bss;
1092 const u8 *rsnie = NULL;
1093 const u8 *wpaie = NULL;
1095 lockdep_assert_held(&ar->conf_mutex);
1097 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1098 info->bssid, NULL, 0, 0, 0);
1100 const struct cfg80211_bss_ies *ies;
1103 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1105 ies = rcu_dereference(bss->ies);
1107 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1108 WLAN_OUI_TYPE_MICROSOFT_WPA,
1112 cfg80211_put_bss(ar->hw->wiphy, bss);
1115 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1116 if (rsnie || wpaie) {
1117 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1118 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1122 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1123 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1127 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1128 struct ieee80211_sta *sta,
1129 struct wmi_peer_assoc_complete_arg *arg)
1131 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1132 const struct ieee80211_supported_band *sband;
1133 const struct ieee80211_rate *rates;
1137 lockdep_assert_held(&ar->conf_mutex);
1139 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1140 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1141 rates = sband->bitrates;
1143 rateset->num_rates = 0;
1145 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1146 if (!(ratemask & 1))
1149 rateset->rates[rateset->num_rates] = rates->hw_value;
1150 rateset->num_rates++;
1154 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1155 struct ieee80211_sta *sta,
1156 struct wmi_peer_assoc_complete_arg *arg)
1158 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1161 lockdep_assert_held(&ar->conf_mutex);
1163 if (!ht_cap->ht_supported)
1166 arg->peer_flags |= WMI_PEER_HT;
1167 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1168 ht_cap->ampdu_factor)) - 1;
1170 arg->peer_mpdu_density =
1171 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1173 arg->peer_ht_caps = ht_cap->cap;
1174 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1176 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1177 arg->peer_flags |= WMI_PEER_LDPC;
1179 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1180 arg->peer_flags |= WMI_PEER_40MHZ;
1181 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1184 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1185 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1187 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1188 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1190 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1191 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1192 arg->peer_flags |= WMI_PEER_STBC;
1195 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1197 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1198 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1199 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1200 arg->peer_rate_caps |= stbc;
1201 arg->peer_flags |= WMI_PEER_STBC;
1204 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1205 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1206 else if (ht_cap->mcs.rx_mask[1])
1207 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1209 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1210 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1211 arg->peer_ht_rates.rates[n++] = i;
1214 * This is a workaround for HT-enabled STAs which break the spec
1215 * and have no HT capabilities RX mask (no HT RX MCS map).
1217 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1218 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1220 * Firmware asserts if such situation occurs.
1223 arg->peer_ht_rates.num_rates = 8;
1224 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1225 arg->peer_ht_rates.rates[i] = i;
1227 arg->peer_ht_rates.num_rates = n;
1228 arg->peer_num_spatial_streams = sta->rx_nss;
1231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1233 arg->peer_ht_rates.num_rates,
1234 arg->peer_num_spatial_streams);
1237 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1238 struct ath10k_vif *arvif,
1239 struct ieee80211_sta *sta)
1245 lockdep_assert_held(&ar->conf_mutex);
1247 if (sta->wme && sta->uapsd_queues) {
1248 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1249 sta->uapsd_queues, sta->max_sp);
1251 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1252 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1253 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1254 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1255 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1256 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1257 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1258 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1259 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1260 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1261 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1262 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1265 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1266 max_sp = sta->max_sp;
1268 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1270 WMI_AP_PS_PEER_PARAM_UAPSD,
1273 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1274 arvif->vdev_id, ret);
1278 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1280 WMI_AP_PS_PEER_PARAM_MAX_SP,
1283 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1284 arvif->vdev_id, ret);
1288 /* TODO setup this based on STA listen interval and
1289 beacon interval. Currently we don't know
1290 sta->listen_interval - mac80211 patch required.
1291 Currently use 10 seconds */
1292 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1293 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1295 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1296 arvif->vdev_id, ret);
1304 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1305 struct ieee80211_sta *sta,
1306 struct wmi_peer_assoc_complete_arg *arg)
1308 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1311 if (!vht_cap->vht_supported)
1314 arg->peer_flags |= WMI_PEER_VHT;
1315 arg->peer_vht_caps = vht_cap->cap;
1318 ampdu_factor = (vht_cap->cap &
1319 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1320 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1322 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1323 * zero in VHT IE. Using it would result in degraded throughput.
1324 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1325 * it if VHT max_mpdu is smaller. */
1326 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1327 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1328 ampdu_factor)) - 1);
1330 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1331 arg->peer_flags |= WMI_PEER_80MHZ;
1333 arg->peer_vht_rates.rx_max_rate =
1334 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1335 arg->peer_vht_rates.rx_mcs_set =
1336 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1337 arg->peer_vht_rates.tx_max_rate =
1338 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1339 arg->peer_vht_rates.tx_mcs_set =
1340 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1342 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1343 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1346 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1347 struct ath10k_vif *arvif,
1348 struct ieee80211_sta *sta,
1349 struct ieee80211_bss_conf *bss_conf,
1350 struct wmi_peer_assoc_complete_arg *arg)
1352 switch (arvif->vdev_type) {
1353 case WMI_VDEV_TYPE_AP:
1355 arg->peer_flags |= WMI_PEER_QOS;
1357 if (sta->wme && sta->uapsd_queues) {
1358 arg->peer_flags |= WMI_PEER_APSD;
1359 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1362 case WMI_VDEV_TYPE_STA:
1364 arg->peer_flags |= WMI_PEER_QOS;
1371 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1372 struct ath10k_vif *arvif,
1373 struct ieee80211_sta *sta,
1374 struct wmi_peer_assoc_complete_arg *arg)
1376 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1378 switch (ar->hw->conf.chandef.chan->band) {
1379 case IEEE80211_BAND_2GHZ:
1380 if (sta->ht_cap.ht_supported) {
1381 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1382 phymode = MODE_11NG_HT40;
1384 phymode = MODE_11NG_HT20;
1390 case IEEE80211_BAND_5GHZ:
1394 if (sta->vht_cap.vht_supported) {
1395 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1396 phymode = MODE_11AC_VHT80;
1397 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1398 phymode = MODE_11AC_VHT40;
1399 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1400 phymode = MODE_11AC_VHT20;
1401 } else if (sta->ht_cap.ht_supported) {
1402 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1403 phymode = MODE_11NA_HT40;
1405 phymode = MODE_11NA_HT20;
1415 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1416 sta->addr, ath10k_wmi_phymode_str(phymode));
1418 arg->peer_phymode = phymode;
1419 WARN_ON(phymode == MODE_UNKNOWN);
1422 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1423 struct ath10k_vif *arvif,
1424 struct ieee80211_sta *sta,
1425 struct ieee80211_bss_conf *bss_conf,
1426 struct wmi_peer_assoc_complete_arg *arg)
1428 lockdep_assert_held(&ar->conf_mutex);
1430 memset(arg, 0, sizeof(*arg));
1432 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1433 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1434 ath10k_peer_assoc_h_rates(ar, sta, arg);
1435 ath10k_peer_assoc_h_ht(ar, sta, arg);
1436 ath10k_peer_assoc_h_vht(ar, sta, arg);
1437 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1438 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
1443 static const u32 ath10k_smps_map[] = {
1444 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1445 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1446 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1447 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1450 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1452 const struct ieee80211_sta_ht_cap *ht_cap)
1456 if (!ht_cap->ht_supported)
1459 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1460 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1462 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1465 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1466 WMI_PEER_SMPS_STATE,
1467 ath10k_smps_map[smps]);
1470 /* can be called only in mac80211 callbacks due to `key_count` usage */
1471 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1472 struct ieee80211_vif *vif,
1473 struct ieee80211_bss_conf *bss_conf)
1475 struct ath10k *ar = hw->priv;
1476 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1477 struct ieee80211_sta_ht_cap ht_cap;
1478 struct wmi_peer_assoc_complete_arg peer_arg;
1479 struct ieee80211_sta *ap_sta;
1482 lockdep_assert_held(&ar->conf_mutex);
1486 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1488 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1489 bss_conf->bssid, arvif->vdev_id);
1494 /* ap_sta must be accessed only within rcu section which must be left
1495 * before calling ath10k_setup_peer_smps() which might sleep. */
1496 ht_cap = ap_sta->ht_cap;
1498 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1499 bss_conf, &peer_arg);
1501 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1502 bss_conf->bssid, arvif->vdev_id, ret);
1509 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1511 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1512 bss_conf->bssid, arvif->vdev_id, ret);
1516 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1518 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1519 arvif->vdev_id, ret);
1523 ath10k_dbg(ar, ATH10K_DBG_MAC,
1524 "mac vdev %d up (associated) bssid %pM aid %d\n",
1525 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1527 arvif->aid = bss_conf->aid;
1528 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1530 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1532 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1533 arvif->vdev_id, ret);
1537 arvif->is_up = true;
1543 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1544 struct ieee80211_vif *vif)
1546 struct ath10k *ar = hw->priv;
1547 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1550 lockdep_assert_held(&ar->conf_mutex);
1553 * For some reason, calling VDEV-DOWN before VDEV-STOP
1554 * makes the FW to send frames via HTT after disassociation.
1555 * No idea why this happens, even though VDEV-DOWN is supposed
1556 * to be analogous to link down, so just stop the VDEV.
1558 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1561 /* FIXME: check return value */
1562 ret = ath10k_vdev_stop(arvif);
1565 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1566 * report beacons from previously associated network through HTT.
1567 * This in turn would spam mac80211 WARN_ON if we bring down all
1568 * interfaces as it expects there is no rx when no interface is
1571 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1573 /* FIXME: why don't we print error if wmi call fails? */
1574 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1576 arvif->def_wep_key_idx = 0;
1578 arvif->is_started = false;
1579 arvif->is_up = false;
1582 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1583 struct ieee80211_sta *sta, bool reassoc)
1585 struct wmi_peer_assoc_complete_arg peer_arg;
1588 lockdep_assert_held(&ar->conf_mutex);
1590 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1592 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1593 sta->addr, arvif->vdev_id, ret);
1597 peer_arg.peer_reassoc = reassoc;
1598 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1600 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1601 sta->addr, arvif->vdev_id, ret);
1605 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1607 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1608 arvif->vdev_id, ret);
1612 if (!sta->wme && !reassoc) {
1613 arvif->num_legacy_stations++;
1614 ret = ath10k_recalc_rtscts_prot(arvif);
1616 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1617 arvif->vdev_id, ret);
1622 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1624 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1625 arvif->vdev_id, ret);
1629 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1631 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1632 sta->addr, arvif->vdev_id, ret);
1639 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1640 struct ieee80211_sta *sta)
1644 lockdep_assert_held(&ar->conf_mutex);
1647 arvif->num_legacy_stations--;
1648 ret = ath10k_recalc_rtscts_prot(arvif);
1650 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1651 arvif->vdev_id, ret);
1656 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1658 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1659 arvif->vdev_id, ret);
1670 static int ath10k_update_channel_list(struct ath10k *ar)
1672 struct ieee80211_hw *hw = ar->hw;
1673 struct ieee80211_supported_band **bands;
1674 enum ieee80211_band band;
1675 struct ieee80211_channel *channel;
1676 struct wmi_scan_chan_list_arg arg = {0};
1677 struct wmi_channel_arg *ch;
1683 lockdep_assert_held(&ar->conf_mutex);
1685 bands = hw->wiphy->bands;
1686 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1690 for (i = 0; i < bands[band]->n_channels; i++) {
1691 if (bands[band]->channels[i].flags &
1692 IEEE80211_CHAN_DISABLED)
1699 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1700 arg.channels = kzalloc(len, GFP_KERNEL);
1705 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1709 for (i = 0; i < bands[band]->n_channels; i++) {
1710 channel = &bands[band]->channels[i];
1712 if (channel->flags & IEEE80211_CHAN_DISABLED)
1715 ch->allow_ht = true;
1717 /* FIXME: when should we really allow VHT? */
1718 ch->allow_vht = true;
1721 !(channel->flags & IEEE80211_CHAN_NO_IR);
1724 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1727 !!(channel->flags & IEEE80211_CHAN_RADAR);
1729 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1730 ch->passive = passive;
1732 ch->freq = channel->center_freq;
1734 ch->max_power = channel->max_power * 2;
1735 ch->max_reg_power = channel->max_reg_power * 2;
1736 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1737 ch->reg_class_id = 0; /* FIXME */
1739 /* FIXME: why use only legacy modes, why not any
1740 * HT/VHT modes? Would that even make any
1742 if (channel->band == IEEE80211_BAND_2GHZ)
1743 ch->mode = MODE_11G;
1745 ch->mode = MODE_11A;
1747 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1750 ath10k_dbg(ar, ATH10K_DBG_WMI,
1751 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1752 ch - arg.channels, arg.n_channels,
1753 ch->freq, ch->max_power, ch->max_reg_power,
1754 ch->max_antenna_gain, ch->mode);
1760 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1761 kfree(arg.channels);
1766 static enum wmi_dfs_region
1767 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1769 switch (dfs_region) {
1770 case NL80211_DFS_UNSET:
1771 return WMI_UNINIT_DFS_DOMAIN;
1772 case NL80211_DFS_FCC:
1773 return WMI_FCC_DFS_DOMAIN;
1774 case NL80211_DFS_ETSI:
1775 return WMI_ETSI_DFS_DOMAIN;
1776 case NL80211_DFS_JP:
1777 return WMI_MKK4_DFS_DOMAIN;
1779 return WMI_UNINIT_DFS_DOMAIN;
1782 static void ath10k_regd_update(struct ath10k *ar)
1784 struct reg_dmn_pair_mapping *regpair;
1786 enum wmi_dfs_region wmi_dfs_reg;
1787 enum nl80211_dfs_regions nl_dfs_reg;
1789 lockdep_assert_held(&ar->conf_mutex);
1791 ret = ath10k_update_channel_list(ar);
1793 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1795 regpair = ar->ath_common.regulatory.regpair;
1797 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1798 nl_dfs_reg = ar->dfs_detector->region;
1799 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1801 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1804 /* Target allows setting up per-band regdomain but ath_common provides
1805 * a combined one only */
1806 ret = ath10k_wmi_pdev_set_regdomain(ar,
1807 regpair->reg_domain,
1808 regpair->reg_domain, /* 2ghz */
1809 regpair->reg_domain, /* 5ghz */
1810 regpair->reg_2ghz_ctl,
1811 regpair->reg_5ghz_ctl,
1814 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1817 static void ath10k_reg_notifier(struct wiphy *wiphy,
1818 struct regulatory_request *request)
1820 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1821 struct ath10k *ar = hw->priv;
1824 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1826 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1827 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1828 request->dfs_region);
1829 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1830 request->dfs_region);
1832 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1833 request->dfs_region);
1836 mutex_lock(&ar->conf_mutex);
1837 if (ar->state == ATH10K_STATE_ON)
1838 ath10k_regd_update(ar);
1839 mutex_unlock(&ar->conf_mutex);
1846 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1848 if (ieee80211_is_mgmt(hdr->frame_control))
1849 return HTT_DATA_TX_EXT_TID_MGMT;
1851 if (!ieee80211_is_data_qos(hdr->frame_control))
1852 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1854 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1855 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1857 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1860 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1861 struct ieee80211_tx_info *info)
1863 if (info->control.vif)
1864 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1866 if (ar->monitor_started)
1867 return ar->monitor_vdev_id;
1869 ath10k_warn(ar, "failed to resolve vdev id\n");
1873 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1874 * Control in the header.
1876 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1878 struct ieee80211_hdr *hdr = (void *)skb->data;
1879 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1882 if (!ieee80211_is_data_qos(hdr->frame_control))
1885 qos_ctl = ieee80211_get_qos_ctl(hdr);
1886 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1887 skb->data, (void *)qos_ctl - (void *)skb->data);
1888 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1890 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1891 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1892 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1893 * it is safe to downgrade to NullFunc.
1895 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1896 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1897 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1901 static void ath10k_tx_wep_key_work(struct work_struct *work)
1903 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1905 struct ath10k *ar = arvif->ar;
1906 int ret, keyidx = arvif->def_wep_key_newidx;
1908 mutex_lock(&arvif->ar->conf_mutex);
1910 if (arvif->ar->state != ATH10K_STATE_ON)
1913 if (arvif->def_wep_key_idx == keyidx)
1916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1917 arvif->vdev_id, keyidx);
1919 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1921 arvif->ar->wmi.vdev_param->def_keyid,
1924 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
1930 arvif->def_wep_key_idx = keyidx;
1933 mutex_unlock(&arvif->ar->conf_mutex);
1936 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1937 struct ieee80211_key_conf *key,
1938 struct sk_buff *skb)
1940 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1941 struct ath10k *ar = arvif->ar;
1942 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1944 if (!ieee80211_has_protected(hdr->frame_control))
1950 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1951 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1954 if (key->keyidx == arvif->def_wep_key_idx)
1957 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1958 * queueing frames until key index is updated is not an option because
1959 * sk_buff may need more processing to be done, e.g. offchannel */
1960 arvif->def_wep_key_newidx = key->keyidx;
1961 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1964 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1965 struct ieee80211_vif *vif,
1966 struct sk_buff *skb)
1968 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1969 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1971 /* This is case only for P2P_GO */
1972 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1973 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1976 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1977 spin_lock_bh(&ar->data_lock);
1978 if (arvif->u.ap.noa_data)
1979 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1981 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1982 arvif->u.ap.noa_data,
1983 arvif->u.ap.noa_len);
1984 spin_unlock_bh(&ar->data_lock);
1988 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1990 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1993 if (ar->htt.target_version_major >= 3) {
1994 /* Since HTT 3.0 there is no separate mgmt tx command */
1995 ret = ath10k_htt_tx(&ar->htt, skb);
1999 if (ieee80211_is_mgmt(hdr->frame_control)) {
2000 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2002 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2003 ATH10K_MAX_NUM_MGMT_PENDING) {
2004 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2009 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2010 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2012 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2014 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2016 ieee80211_is_nullfunc(hdr->frame_control)) {
2017 /* FW does not report tx status properly for NullFunc frames
2018 * unless they are sent through mgmt tx path. mac80211 sends
2019 * those frames when it detects link/beacon loss and depends
2020 * on the tx status to be correct. */
2021 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2023 ret = ath10k_htt_tx(&ar->htt, skb);
2028 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2030 ieee80211_free_txskb(ar->hw, skb);
2034 void ath10k_offchan_tx_purge(struct ath10k *ar)
2036 struct sk_buff *skb;
2039 skb = skb_dequeue(&ar->offchan_tx_queue);
2043 ieee80211_free_txskb(ar->hw, skb);
2047 void ath10k_offchan_tx_work(struct work_struct *work)
2049 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2050 struct ath10k_peer *peer;
2051 struct ieee80211_hdr *hdr;
2052 struct sk_buff *skb;
2053 const u8 *peer_addr;
2057 /* FW requirement: We must create a peer before FW will send out
2058 * an offchannel frame. Otherwise the frame will be stuck and
2059 * never transmitted. We delete the peer upon tx completion.
2060 * It is unlikely that a peer for offchannel tx will already be
2061 * present. However it may be in some rare cases so account for that.
2062 * Otherwise we might remove a legitimate peer and break stuff. */
2065 skb = skb_dequeue(&ar->offchan_tx_queue);
2069 mutex_lock(&ar->conf_mutex);
2071 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2074 hdr = (struct ieee80211_hdr *)skb->data;
2075 peer_addr = ieee80211_get_DA(hdr);
2076 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2078 spin_lock_bh(&ar->data_lock);
2079 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2080 spin_unlock_bh(&ar->data_lock);
2083 /* FIXME: should this use ath10k_warn()? */
2084 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2085 peer_addr, vdev_id);
2088 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2090 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2091 peer_addr, vdev_id, ret);
2094 spin_lock_bh(&ar->data_lock);
2095 reinit_completion(&ar->offchan_tx_completed);
2096 ar->offchan_tx_skb = skb;
2097 spin_unlock_bh(&ar->data_lock);
2099 ath10k_tx_htt(ar, skb);
2101 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2104 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2108 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2110 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2111 peer_addr, vdev_id, ret);
2114 mutex_unlock(&ar->conf_mutex);
2118 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2120 struct sk_buff *skb;
2123 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2127 ieee80211_free_txskb(ar->hw, skb);
2131 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2133 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2134 struct sk_buff *skb;
2138 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2142 ret = ath10k_wmi_mgmt_tx(ar, skb);
2144 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2146 ieee80211_free_txskb(ar->hw, skb);
2155 void __ath10k_scan_finish(struct ath10k *ar)
2157 lockdep_assert_held(&ar->data_lock);
2159 switch (ar->scan.state) {
2160 case ATH10K_SCAN_IDLE:
2162 case ATH10K_SCAN_RUNNING:
2163 case ATH10K_SCAN_ABORTING:
2164 if (ar->scan.is_roc)
2165 ieee80211_remain_on_channel_expired(ar->hw);
2167 ieee80211_scan_completed(ar->hw,
2169 ATH10K_SCAN_ABORTING));
2171 case ATH10K_SCAN_STARTING:
2172 ar->scan.state = ATH10K_SCAN_IDLE;
2173 ar->scan_channel = NULL;
2174 ath10k_offchan_tx_purge(ar);
2175 cancel_delayed_work(&ar->scan.timeout);
2176 complete_all(&ar->scan.completed);
2181 void ath10k_scan_finish(struct ath10k *ar)
2183 spin_lock_bh(&ar->data_lock);
2184 __ath10k_scan_finish(ar);
2185 spin_unlock_bh(&ar->data_lock);
2188 static int ath10k_scan_stop(struct ath10k *ar)
2190 struct wmi_stop_scan_arg arg = {
2191 .req_id = 1, /* FIXME */
2192 .req_type = WMI_SCAN_STOP_ONE,
2193 .u.scan_id = ATH10K_SCAN_ID,
2197 lockdep_assert_held(&ar->conf_mutex);
2199 ret = ath10k_wmi_stop_scan(ar, &arg);
2201 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2205 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2207 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2209 } else if (ret > 0) {
2214 /* Scan state should be updated upon scan completion but in case
2215 * firmware fails to deliver the event (for whatever reason) it is
2216 * desired to clean up scan state anyway. Firmware may have just
2217 * dropped the scan completion event delivery due to transport pipe
2218 * being overflown with data and/or it can recover on its own before
2219 * next scan request is submitted.
2221 spin_lock_bh(&ar->data_lock);
2222 if (ar->scan.state != ATH10K_SCAN_IDLE)
2223 __ath10k_scan_finish(ar);
2224 spin_unlock_bh(&ar->data_lock);
2229 static void ath10k_scan_abort(struct ath10k *ar)
2233 lockdep_assert_held(&ar->conf_mutex);
2235 spin_lock_bh(&ar->data_lock);
2237 switch (ar->scan.state) {
2238 case ATH10K_SCAN_IDLE:
2239 /* This can happen if timeout worker kicked in and called
2240 * abortion while scan completion was being processed.
2243 case ATH10K_SCAN_STARTING:
2244 case ATH10K_SCAN_ABORTING:
2245 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2246 ath10k_scan_state_str(ar->scan.state),
2249 case ATH10K_SCAN_RUNNING:
2250 ar->scan.state = ATH10K_SCAN_ABORTING;
2251 spin_unlock_bh(&ar->data_lock);
2253 ret = ath10k_scan_stop(ar);
2255 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2257 spin_lock_bh(&ar->data_lock);
2261 spin_unlock_bh(&ar->data_lock);
2264 void ath10k_scan_timeout_work(struct work_struct *work)
2266 struct ath10k *ar = container_of(work, struct ath10k,
2269 mutex_lock(&ar->conf_mutex);
2270 ath10k_scan_abort(ar);
2271 mutex_unlock(&ar->conf_mutex);
2274 static int ath10k_start_scan(struct ath10k *ar,
2275 const struct wmi_start_scan_arg *arg)
2279 lockdep_assert_held(&ar->conf_mutex);
2281 ret = ath10k_wmi_start_scan(ar, arg);
2285 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2287 ret = ath10k_scan_stop(ar);
2289 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2294 /* Add a 200ms margin to account for event/command processing */
2295 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2296 msecs_to_jiffies(arg->max_scan_time+200));
2300 /**********************/
2301 /* mac80211 callbacks */
2302 /**********************/
2304 static void ath10k_tx(struct ieee80211_hw *hw,
2305 struct ieee80211_tx_control *control,
2306 struct sk_buff *skb)
2308 struct ath10k *ar = hw->priv;
2309 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2310 struct ieee80211_vif *vif = info->control.vif;
2311 struct ieee80211_key_conf *key = info->control.hw_key;
2312 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2314 /* We should disable CCK RATE due to P2P */
2315 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2316 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2318 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2319 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2320 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
2322 /* it makes no sense to process injected frames like that */
2323 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2324 ath10k_tx_h_nwifi(hw, skb);
2325 ath10k_tx_h_update_wep_key(vif, key, skb);
2326 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2327 ath10k_tx_h_seq_no(vif, skb);
2330 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2331 spin_lock_bh(&ar->data_lock);
2332 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2333 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2334 spin_unlock_bh(&ar->data_lock);
2336 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2339 skb_queue_tail(&ar->offchan_tx_queue, skb);
2340 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2344 ath10k_tx_htt(ar, skb);
2347 /* Must not be called with conf_mutex held as workers can use that also. */
2348 static void ath10k_drain_tx(struct ath10k *ar)
2350 /* make sure rcu-protected mac80211 tx path itself is drained */
2353 ath10k_offchan_tx_purge(ar);
2354 ath10k_mgmt_over_wmi_tx_purge(ar);
2356 cancel_work_sync(&ar->offchan_tx_work);
2357 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2360 void ath10k_halt(struct ath10k *ar)
2362 struct ath10k_vif *arvif;
2364 lockdep_assert_held(&ar->conf_mutex);
2366 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2367 ar->filter_flags = 0;
2368 ar->monitor = false;
2370 if (ar->monitor_started)
2371 ath10k_monitor_stop(ar);
2373 ar->monitor_started = false;
2375 ath10k_scan_finish(ar);
2376 ath10k_peer_cleanup_all(ar);
2377 ath10k_core_stop(ar);
2378 ath10k_hif_power_down(ar);
2380 spin_lock_bh(&ar->data_lock);
2381 list_for_each_entry(arvif, &ar->arvifs, list) {
2385 dma_unmap_single(arvif->ar->dev,
2386 ATH10K_SKB_CB(arvif->beacon)->paddr,
2387 arvif->beacon->len, DMA_TO_DEVICE);
2388 dev_kfree_skb_any(arvif->beacon);
2389 arvif->beacon = NULL;
2391 spin_unlock_bh(&ar->data_lock);
2394 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2396 struct ath10k *ar = hw->priv;
2398 mutex_lock(&ar->conf_mutex);
2400 if (ar->cfg_tx_chainmask) {
2401 *tx_ant = ar->cfg_tx_chainmask;
2402 *rx_ant = ar->cfg_rx_chainmask;
2404 *tx_ant = ar->supp_tx_chainmask;
2405 *rx_ant = ar->supp_rx_chainmask;
2408 mutex_unlock(&ar->conf_mutex);
2413 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2417 lockdep_assert_held(&ar->conf_mutex);
2419 ar->cfg_tx_chainmask = tx_ant;
2420 ar->cfg_rx_chainmask = rx_ant;
2422 if ((ar->state != ATH10K_STATE_ON) &&
2423 (ar->state != ATH10K_STATE_RESTARTED))
2426 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2429 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2434 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2437 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2445 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2447 struct ath10k *ar = hw->priv;
2450 mutex_lock(&ar->conf_mutex);
2451 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2452 mutex_unlock(&ar->conf_mutex);
2456 static int ath10k_start(struct ieee80211_hw *hw)
2458 struct ath10k *ar = hw->priv;
2462 * This makes sense only when restarting hw. It is harmless to call
2463 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2464 * commands will be submitted while restarting.
2466 ath10k_drain_tx(ar);
2468 mutex_lock(&ar->conf_mutex);
2470 switch (ar->state) {
2471 case ATH10K_STATE_OFF:
2472 ar->state = ATH10K_STATE_ON;
2474 case ATH10K_STATE_RESTARTING:
2476 ar->state = ATH10K_STATE_RESTARTED;
2478 case ATH10K_STATE_ON:
2479 case ATH10K_STATE_RESTARTED:
2480 case ATH10K_STATE_WEDGED:
2486 ret = ath10k_hif_power_up(ar);
2488 ath10k_err(ar, "Could not init hif: %d\n", ret);
2492 ret = ath10k_core_start(ar);
2494 ath10k_err(ar, "Could not init core: %d\n", ret);
2495 goto err_power_down;
2498 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2500 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2504 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2506 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2510 if (ar->cfg_tx_chainmask)
2511 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2512 ar->cfg_rx_chainmask);
2515 * By default FW set ARP frames ac to voice (6). In that case ARP
2516 * exchange is not working properly for UAPSD enabled AP. ARP requests
2517 * which arrives with access category 0 are processed by network stack
2518 * and send back with access category 0, but FW changes access category
2519 * to 6. Set ARP frames access category to best effort (0) solves
2523 ret = ath10k_wmi_pdev_set_param(ar,
2524 ar->wmi.pdev_param->arp_ac_override, 0);
2526 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2531 ar->num_started_vdevs = 0;
2532 ath10k_regd_update(ar);
2534 ath10k_spectral_start(ar);
2536 mutex_unlock(&ar->conf_mutex);
2540 ath10k_core_stop(ar);
2543 ath10k_hif_power_down(ar);
2546 ar->state = ATH10K_STATE_OFF;
2549 mutex_unlock(&ar->conf_mutex);
2553 static void ath10k_stop(struct ieee80211_hw *hw)
2555 struct ath10k *ar = hw->priv;
2557 ath10k_drain_tx(ar);
2559 mutex_lock(&ar->conf_mutex);
2560 if (ar->state != ATH10K_STATE_OFF) {
2562 ar->state = ATH10K_STATE_OFF;
2564 mutex_unlock(&ar->conf_mutex);
2566 cancel_delayed_work_sync(&ar->scan.timeout);
2567 cancel_work_sync(&ar->restart_work);
2570 static int ath10k_config_ps(struct ath10k *ar)
2572 struct ath10k_vif *arvif;
2575 lockdep_assert_held(&ar->conf_mutex);
2577 list_for_each_entry(arvif, &ar->arvifs, list) {
2578 ret = ath10k_mac_vif_setup_ps(arvif);
2580 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2588 static const char *chandef_get_width(enum nl80211_chan_width width)
2591 case NL80211_CHAN_WIDTH_20_NOHT:
2593 case NL80211_CHAN_WIDTH_20:
2595 case NL80211_CHAN_WIDTH_40:
2597 case NL80211_CHAN_WIDTH_80:
2599 case NL80211_CHAN_WIDTH_80P80:
2601 case NL80211_CHAN_WIDTH_160:
2603 case NL80211_CHAN_WIDTH_5:
2605 case NL80211_CHAN_WIDTH_10:
2611 static void ath10k_config_chan(struct ath10k *ar)
2613 struct ath10k_vif *arvif;
2616 lockdep_assert_held(&ar->conf_mutex);
2618 ath10k_dbg(ar, ATH10K_DBG_MAC,
2619 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2620 ar->chandef.chan->center_freq,
2621 ar->chandef.center_freq1,
2622 ar->chandef.center_freq2,
2623 chandef_get_width(ar->chandef.width));
2625 /* First stop monitor interface. Some FW versions crash if there's a
2626 * lone monitor interface. */
2627 if (ar->monitor_started)
2628 ath10k_monitor_stop(ar);
2630 list_for_each_entry(arvif, &ar->arvifs, list) {
2631 if (!arvif->is_started)
2637 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2640 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2642 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2643 arvif->vdev_id, ret);
2648 /* all vdevs are downed now - attempt to restart and re-up them */
2650 list_for_each_entry(arvif, &ar->arvifs, list) {
2651 if (!arvif->is_started)
2654 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2657 ret = ath10k_vdev_restart(arvif);
2659 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2660 arvif->vdev_id, ret);
2667 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2670 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2671 arvif->vdev_id, ret);
2676 ath10k_monitor_recalc(ar);
2679 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2681 struct ath10k *ar = hw->priv;
2682 struct ieee80211_conf *conf = &hw->conf;
2686 mutex_lock(&ar->conf_mutex);
2688 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2689 ath10k_dbg(ar, ATH10K_DBG_MAC,
2690 "mac config channel %dMHz flags 0x%x radar %d\n",
2691 conf->chandef.chan->center_freq,
2692 conf->chandef.chan->flags,
2693 conf->radar_enabled);
2695 spin_lock_bh(&ar->data_lock);
2696 ar->rx_channel = conf->chandef.chan;
2697 spin_unlock_bh(&ar->data_lock);
2699 ar->radar_enabled = conf->radar_enabled;
2700 ath10k_recalc_radar_detection(ar);
2702 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2703 ar->chandef = conf->chandef;
2704 ath10k_config_chan(ar);
2708 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2709 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
2710 hw->conf.power_level);
2712 param = ar->wmi.pdev_param->txpower_limit2g;
2713 ret = ath10k_wmi_pdev_set_param(ar, param,
2714 hw->conf.power_level * 2);
2716 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2717 hw->conf.power_level, ret);
2719 param = ar->wmi.pdev_param->txpower_limit5g;
2720 ret = ath10k_wmi_pdev_set_param(ar, param,
2721 hw->conf.power_level * 2);
2723 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2724 hw->conf.power_level, ret);
2727 if (changed & IEEE80211_CONF_CHANGE_PS)
2728 ath10k_config_ps(ar);
2730 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2731 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2732 ret = ath10k_monitor_recalc(ar);
2734 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2737 mutex_unlock(&ar->conf_mutex);
2743 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2744 * because we will send mgmt frames without CCK. This requirement
2745 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2748 static int ath10k_add_interface(struct ieee80211_hw *hw,
2749 struct ieee80211_vif *vif)
2751 struct ath10k *ar = hw->priv;
2752 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2753 enum wmi_sta_powersave_param param;
2759 mutex_lock(&ar->conf_mutex);
2761 memset(arvif, 0, sizeof(*arvif));
2766 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2767 INIT_LIST_HEAD(&arvif->list);
2769 if (ar->free_vdev_map == 0) {
2770 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2774 bit = ffs(ar->free_vdev_map);
2776 arvif->vdev_id = bit - 1;
2777 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2780 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2782 switch (vif->type) {
2783 case NL80211_IFTYPE_UNSPECIFIED:
2784 case NL80211_IFTYPE_STATION:
2785 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2787 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2789 case NL80211_IFTYPE_ADHOC:
2790 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2792 case NL80211_IFTYPE_AP:
2793 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2796 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2798 case NL80211_IFTYPE_MONITOR:
2799 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
2807 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2809 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2810 arvif->vdev_subtype, vif->addr);
2812 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
2813 arvif->vdev_id, ret);
2817 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
2818 list_add(&arvif->list, &ar->arvifs);
2820 vdev_param = ar->wmi.vdev_param->def_keyid;
2821 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2822 arvif->def_wep_key_idx);
2824 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
2825 arvif->vdev_id, ret);
2826 goto err_vdev_delete;
2829 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2830 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2831 ATH10K_HW_TXRX_NATIVE_WIFI);
2832 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2833 if (ret && ret != -EOPNOTSUPP) {
2834 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
2835 arvif->vdev_id, ret);
2836 goto err_vdev_delete;
2839 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2840 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2842 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
2843 arvif->vdev_id, ret);
2844 goto err_vdev_delete;
2847 ret = ath10k_mac_set_kickout(arvif);
2849 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
2850 arvif->vdev_id, ret);
2851 goto err_peer_delete;
2855 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2856 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2857 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2858 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2861 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
2862 arvif->vdev_id, ret);
2863 goto err_peer_delete;
2866 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2867 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2868 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2871 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
2872 arvif->vdev_id, ret);
2873 goto err_peer_delete;
2876 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2877 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2878 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2881 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
2882 arvif->vdev_id, ret);
2883 goto err_peer_delete;
2887 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2889 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
2890 arvif->vdev_id, ret);
2891 goto err_peer_delete;
2894 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2896 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
2897 arvif->vdev_id, ret);
2898 goto err_peer_delete;
2901 mutex_unlock(&ar->conf_mutex);
2905 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2906 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2909 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2910 ar->free_vdev_map |= 1 << arvif->vdev_id;
2911 list_del(&arvif->list);
2914 mutex_unlock(&ar->conf_mutex);
2919 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2920 struct ieee80211_vif *vif)
2922 struct ath10k *ar = hw->priv;
2923 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2926 mutex_lock(&ar->conf_mutex);
2928 cancel_work_sync(&arvif->wep_key_work);
2930 spin_lock_bh(&ar->data_lock);
2931 if (arvif->beacon) {
2932 dma_unmap_single(arvif->ar->dev,
2933 ATH10K_SKB_CB(arvif->beacon)->paddr,
2934 arvif->beacon->len, DMA_TO_DEVICE);
2935 dev_kfree_skb_any(arvif->beacon);
2936 arvif->beacon = NULL;
2939 spin_unlock_bh(&ar->data_lock);
2941 ret = ath10k_spectral_vif_stop(arvif);
2943 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
2944 arvif->vdev_id, ret);
2946 ar->free_vdev_map |= 1 << arvif->vdev_id;
2947 list_del(&arvif->list);
2949 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2950 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2952 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
2953 arvif->vdev_id, ret);
2955 kfree(arvif->u.ap.noa_data);
2958 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
2961 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2963 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
2964 arvif->vdev_id, ret);
2966 ath10k_peer_cleanup(ar, arvif->vdev_id);
2968 mutex_unlock(&ar->conf_mutex);
2972 * FIXME: Has to be verified.
2974 #define SUPPORTED_FILTERS \
2975 (FIF_PROMISC_IN_BSS | \
2980 FIF_BCN_PRBRESP_PROMISC | \
2984 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2985 unsigned int changed_flags,
2986 unsigned int *total_flags,
2989 struct ath10k *ar = hw->priv;
2992 mutex_lock(&ar->conf_mutex);
2994 changed_flags &= SUPPORTED_FILTERS;
2995 *total_flags &= SUPPORTED_FILTERS;
2996 ar->filter_flags = *total_flags;
2998 ret = ath10k_monitor_recalc(ar);
3000 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3002 mutex_unlock(&ar->conf_mutex);
3005 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3006 struct ieee80211_vif *vif,
3007 struct ieee80211_bss_conf *info,
3010 struct ath10k *ar = hw->priv;
3011 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3013 u32 vdev_param, pdev_param;
3015 mutex_lock(&ar->conf_mutex);
3017 if (changed & BSS_CHANGED_IBSS)
3018 ath10k_control_ibss(arvif, info, vif->addr);
3020 if (changed & BSS_CHANGED_BEACON_INT) {
3021 arvif->beacon_interval = info->beacon_int;
3022 vdev_param = ar->wmi.vdev_param->beacon_interval;
3023 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3024 arvif->beacon_interval);
3025 ath10k_dbg(ar, ATH10K_DBG_MAC,
3026 "mac vdev %d beacon_interval %d\n",
3027 arvif->vdev_id, arvif->beacon_interval);
3030 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3031 arvif->vdev_id, ret);
3034 if (changed & BSS_CHANGED_BEACON) {
3035 ath10k_dbg(ar, ATH10K_DBG_MAC,
3036 "vdev %d set beacon tx mode to staggered\n",
3039 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3040 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3041 WMI_BEACON_STAGGERED_MODE);
3043 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3044 arvif->vdev_id, ret);
3047 if (changed & BSS_CHANGED_BEACON_INFO) {
3048 arvif->dtim_period = info->dtim_period;
3050 ath10k_dbg(ar, ATH10K_DBG_MAC,
3051 "mac vdev %d dtim_period %d\n",
3052 arvif->vdev_id, arvif->dtim_period);
3054 vdev_param = ar->wmi.vdev_param->dtim_period;
3055 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3056 arvif->dtim_period);
3058 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3059 arvif->vdev_id, ret);
3062 if (changed & BSS_CHANGED_SSID &&
3063 vif->type == NL80211_IFTYPE_AP) {
3064 arvif->u.ap.ssid_len = info->ssid_len;
3066 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3067 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3071 * Firmware manages AP self-peer internally so make sure to not create
3072 * it in driver. Otherwise AP self-peer deletion may timeout later.
3074 if (changed & BSS_CHANGED_BSSID &&
3075 vif->type != NL80211_IFTYPE_AP) {
3076 if (!is_zero_ether_addr(info->bssid)) {
3077 ath10k_dbg(ar, ATH10K_DBG_MAC,
3078 "mac vdev %d create peer %pM\n",
3079 arvif->vdev_id, info->bssid);
3081 ret = ath10k_peer_create(ar, arvif->vdev_id,
3084 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
3085 info->bssid, arvif->vdev_id, ret);
3087 if (vif->type == NL80211_IFTYPE_STATION) {
3089 * this is never erased as we it for crypto key
3090 * clearing; this is FW requirement
3092 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
3094 ath10k_dbg(ar, ATH10K_DBG_MAC,
3095 "mac vdev %d start %pM\n",
3096 arvif->vdev_id, info->bssid);
3098 ret = ath10k_vdev_start(arvif);
3100 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3101 arvif->vdev_id, ret);
3105 arvif->is_started = true;
3109 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3110 * so driver need to store it. It is needed when leaving
3111 * IBSS in order to remove BSSID peer.
3113 if (vif->type == NL80211_IFTYPE_ADHOC)
3114 memcpy(arvif->bssid, info->bssid,
3119 if (changed & BSS_CHANGED_BEACON_ENABLED)
3120 ath10k_control_beaconing(arvif, info);
3122 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3123 arvif->use_cts_prot = info->use_cts_prot;
3124 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3125 arvif->vdev_id, info->use_cts_prot);
3127 ret = ath10k_recalc_rtscts_prot(arvif);
3129 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3130 arvif->vdev_id, ret);
3133 if (changed & BSS_CHANGED_ERP_SLOT) {
3135 if (info->use_short_slot)
3136 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3139 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3141 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3142 arvif->vdev_id, slottime);
3144 vdev_param = ar->wmi.vdev_param->slot_time;
3145 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3148 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3149 arvif->vdev_id, ret);
3152 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3154 if (info->use_short_preamble)
3155 preamble = WMI_VDEV_PREAMBLE_SHORT;
3157 preamble = WMI_VDEV_PREAMBLE_LONG;
3159 ath10k_dbg(ar, ATH10K_DBG_MAC,
3160 "mac vdev %d preamble %dn",
3161 arvif->vdev_id, preamble);
3163 vdev_param = ar->wmi.vdev_param->preamble;
3164 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3167 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3168 arvif->vdev_id, ret);
3171 if (changed & BSS_CHANGED_ASSOC) {
3173 ath10k_bss_assoc(hw, vif, info);
3177 mutex_unlock(&ar->conf_mutex);
3180 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3181 struct ieee80211_vif *vif,
3182 struct ieee80211_scan_request *hw_req)
3184 struct ath10k *ar = hw->priv;
3185 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3186 struct cfg80211_scan_request *req = &hw_req->req;
3187 struct wmi_start_scan_arg arg;
3191 mutex_lock(&ar->conf_mutex);
3193 spin_lock_bh(&ar->data_lock);
3194 switch (ar->scan.state) {
3195 case ATH10K_SCAN_IDLE:
3196 reinit_completion(&ar->scan.started);
3197 reinit_completion(&ar->scan.completed);
3198 ar->scan.state = ATH10K_SCAN_STARTING;
3199 ar->scan.is_roc = false;
3200 ar->scan.vdev_id = arvif->vdev_id;
3203 case ATH10K_SCAN_STARTING:
3204 case ATH10K_SCAN_RUNNING:
3205 case ATH10K_SCAN_ABORTING:
3209 spin_unlock_bh(&ar->data_lock);
3214 memset(&arg, 0, sizeof(arg));
3215 ath10k_wmi_start_scan_init(ar, &arg);
3216 arg.vdev_id = arvif->vdev_id;
3217 arg.scan_id = ATH10K_SCAN_ID;
3220 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3223 arg.ie_len = req->ie_len;
3224 memcpy(arg.ie, req->ie, arg.ie_len);
3228 arg.n_ssids = req->n_ssids;
3229 for (i = 0; i < arg.n_ssids; i++) {
3230 arg.ssids[i].len = req->ssids[i].ssid_len;
3231 arg.ssids[i].ssid = req->ssids[i].ssid;
3234 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3237 if (req->n_channels) {
3238 arg.n_channels = req->n_channels;
3239 for (i = 0; i < arg.n_channels; i++)
3240 arg.channels[i] = req->channels[i]->center_freq;
3243 ret = ath10k_start_scan(ar, &arg);
3245 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3246 spin_lock_bh(&ar->data_lock);
3247 ar->scan.state = ATH10K_SCAN_IDLE;
3248 spin_unlock_bh(&ar->data_lock);
3252 mutex_unlock(&ar->conf_mutex);
3256 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3257 struct ieee80211_vif *vif)
3259 struct ath10k *ar = hw->priv;
3261 mutex_lock(&ar->conf_mutex);
3262 cancel_delayed_work_sync(&ar->scan.timeout);
3263 ath10k_scan_abort(ar);
3264 mutex_unlock(&ar->conf_mutex);
3267 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3268 struct ath10k_vif *arvif,
3269 enum set_key_cmd cmd,
3270 struct ieee80211_key_conf *key)
3272 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3275 /* 10.1 firmware branch requires default key index to be set to group
3276 * key index after installing it. Otherwise FW/HW Txes corrupted
3277 * frames with multi-vif APs. This is not required for main firmware
3278 * branch (e.g. 636).
3280 * FIXME: This has been tested only in AP. It remains unknown if this
3281 * is required for multi-vif STA interfaces on 10.1 */
3283 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3286 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3289 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3292 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3298 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3301 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3302 arvif->vdev_id, ret);
3305 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3306 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3307 struct ieee80211_key_conf *key)
3309 struct ath10k *ar = hw->priv;
3310 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3311 struct ath10k_peer *peer;
3312 const u8 *peer_addr;
3313 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3314 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3317 if (key->keyidx > WMI_MAX_KEY_INDEX)
3320 mutex_lock(&ar->conf_mutex);
3323 peer_addr = sta->addr;
3324 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3325 peer_addr = vif->bss_conf.bssid;
3327 peer_addr = vif->addr;
3329 key->hw_key_idx = key->keyidx;
3331 /* the peer should not disappear in mid-way (unless FW goes awry) since
3332 * we already hold conf_mutex. we just make sure its there now. */
3333 spin_lock_bh(&ar->data_lock);
3334 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3335 spin_unlock_bh(&ar->data_lock);
3338 if (cmd == SET_KEY) {
3339 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3344 /* if the peer doesn't exist there is no key to disable
3352 arvif->wep_keys[key->keyidx] = key;
3354 arvif->wep_keys[key->keyidx] = NULL;
3356 if (cmd == DISABLE_KEY)
3357 ath10k_clear_vdev_key(arvif, key);
3360 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3362 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3363 arvif->vdev_id, peer_addr, ret);
3367 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3369 spin_lock_bh(&ar->data_lock);
3370 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3371 if (peer && cmd == SET_KEY)
3372 peer->keys[key->keyidx] = key;
3373 else if (peer && cmd == DISABLE_KEY)
3374 peer->keys[key->keyidx] = NULL;
3375 else if (peer == NULL)
3376 /* impossible unless FW goes crazy */
3377 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3378 spin_unlock_bh(&ar->data_lock);
3381 mutex_unlock(&ar->conf_mutex);
3385 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3388 struct ath10k_vif *arvif;
3389 struct ath10k_sta *arsta;
3390 struct ieee80211_sta *sta;
3391 u32 changed, bw, nss, smps;
3394 arsta = container_of(wk, struct ath10k_sta, update_wk);
3395 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3396 arvif = arsta->arvif;
3399 spin_lock_bh(&ar->data_lock);
3401 changed = arsta->changed;
3408 spin_unlock_bh(&ar->data_lock);
3410 mutex_lock(&ar->conf_mutex);
3412 if (changed & IEEE80211_RC_BW_CHANGED) {
3413 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3416 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3417 WMI_PEER_CHAN_WIDTH, bw);
3419 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3420 sta->addr, bw, err);
3423 if (changed & IEEE80211_RC_NSS_CHANGED) {
3424 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3427 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3430 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3431 sta->addr, nss, err);
3434 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3435 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3438 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3439 WMI_PEER_SMPS_STATE, smps);
3441 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3442 sta->addr, smps, err);
3445 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3446 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3449 err = ath10k_station_assoc(ar, arvif, sta, true);
3451 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3455 mutex_unlock(&ar->conf_mutex);
3458 static int ath10k_sta_state(struct ieee80211_hw *hw,
3459 struct ieee80211_vif *vif,
3460 struct ieee80211_sta *sta,
3461 enum ieee80211_sta_state old_state,
3462 enum ieee80211_sta_state new_state)
3464 struct ath10k *ar = hw->priv;
3465 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3466 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3470 if (old_state == IEEE80211_STA_NOTEXIST &&
3471 new_state == IEEE80211_STA_NONE) {
3472 memset(arsta, 0, sizeof(*arsta));
3473 arsta->arvif = arvif;
3474 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3477 /* cancel must be done outside the mutex to avoid deadlock */
3478 if ((old_state == IEEE80211_STA_NONE &&
3479 new_state == IEEE80211_STA_NOTEXIST))
3480 cancel_work_sync(&arsta->update_wk);
3482 mutex_lock(&ar->conf_mutex);
3484 if (old_state == IEEE80211_STA_NOTEXIST &&
3485 new_state == IEEE80211_STA_NONE &&
3486 vif->type != NL80211_IFTYPE_STATION) {
3488 * New station addition.
3490 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3491 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3493 max_num_peers = TARGET_NUM_PEERS;
3495 if (ar->num_peers >= max_num_peers) {
3496 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
3497 ar->num_peers, max_num_peers);
3502 ath10k_dbg(ar, ATH10K_DBG_MAC,
3503 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3504 arvif->vdev_id, sta->addr, ar->num_peers);
3506 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3508 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3509 sta->addr, arvif->vdev_id, ret);
3510 } else if ((old_state == IEEE80211_STA_NONE &&
3511 new_state == IEEE80211_STA_NOTEXIST)) {
3513 * Existing station deletion.
3515 ath10k_dbg(ar, ATH10K_DBG_MAC,
3516 "mac vdev %d peer delete %pM (sta gone)\n",
3517 arvif->vdev_id, sta->addr);
3518 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3520 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3521 sta->addr, arvif->vdev_id, ret);
3523 if (vif->type == NL80211_IFTYPE_STATION)
3524 ath10k_bss_disassoc(hw, vif);
3525 } else if (old_state == IEEE80211_STA_AUTH &&
3526 new_state == IEEE80211_STA_ASSOC &&
3527 (vif->type == NL80211_IFTYPE_AP ||
3528 vif->type == NL80211_IFTYPE_ADHOC)) {
3532 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3535 ret = ath10k_station_assoc(ar, arvif, sta, false);
3537 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3538 sta->addr, arvif->vdev_id, ret);
3539 } else if (old_state == IEEE80211_STA_ASSOC &&
3540 new_state == IEEE80211_STA_AUTH &&
3541 (vif->type == NL80211_IFTYPE_AP ||
3542 vif->type == NL80211_IFTYPE_ADHOC)) {
3546 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3549 ret = ath10k_station_disassoc(ar, arvif, sta);
3551 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3552 sta->addr, arvif->vdev_id, ret);
3555 mutex_unlock(&ar->conf_mutex);
3559 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3560 u16 ac, bool enable)
3562 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3566 lockdep_assert_held(&ar->conf_mutex);
3568 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3572 case IEEE80211_AC_VO:
3573 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3574 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3576 case IEEE80211_AC_VI:
3577 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3578 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3580 case IEEE80211_AC_BE:
3581 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3582 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3584 case IEEE80211_AC_BK:
3585 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3586 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3591 arvif->u.sta.uapsd |= value;
3593 arvif->u.sta.uapsd &= ~value;
3595 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3596 WMI_STA_PS_PARAM_UAPSD,
3597 arvif->u.sta.uapsd);
3599 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3603 if (arvif->u.sta.uapsd)
3604 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3606 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3608 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3609 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3612 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3618 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3619 struct ieee80211_vif *vif, u16 ac,
3620 const struct ieee80211_tx_queue_params *params)
3622 struct ath10k *ar = hw->priv;
3623 struct wmi_wmm_params_arg *p = NULL;
3626 mutex_lock(&ar->conf_mutex);
3629 case IEEE80211_AC_VO:
3630 p = &ar->wmm_params.ac_vo;
3632 case IEEE80211_AC_VI:
3633 p = &ar->wmm_params.ac_vi;
3635 case IEEE80211_AC_BE:
3636 p = &ar->wmm_params.ac_be;
3638 case IEEE80211_AC_BK:
3639 p = &ar->wmm_params.ac_bk;
3648 p->cwmin = params->cw_min;
3649 p->cwmax = params->cw_max;
3650 p->aifs = params->aifs;
3653 * The channel time duration programmed in the HW is in absolute
3654 * microseconds, while mac80211 gives the txop in units of
3657 p->txop = params->txop * 32;
3659 /* FIXME: FW accepts wmm params per hw, not per vif */
3660 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3662 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3666 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3668 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3671 mutex_unlock(&ar->conf_mutex);
3675 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3677 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3678 struct ieee80211_vif *vif,
3679 struct ieee80211_channel *chan,
3681 enum ieee80211_roc_type type)
3683 struct ath10k *ar = hw->priv;
3684 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3685 struct wmi_start_scan_arg arg;
3688 mutex_lock(&ar->conf_mutex);
3690 spin_lock_bh(&ar->data_lock);
3691 switch (ar->scan.state) {
3692 case ATH10K_SCAN_IDLE:
3693 reinit_completion(&ar->scan.started);
3694 reinit_completion(&ar->scan.completed);
3695 reinit_completion(&ar->scan.on_channel);
3696 ar->scan.state = ATH10K_SCAN_STARTING;
3697 ar->scan.is_roc = true;
3698 ar->scan.vdev_id = arvif->vdev_id;
3699 ar->scan.roc_freq = chan->center_freq;
3702 case ATH10K_SCAN_STARTING:
3703 case ATH10K_SCAN_RUNNING:
3704 case ATH10K_SCAN_ABORTING:
3708 spin_unlock_bh(&ar->data_lock);
3713 memset(&arg, 0, sizeof(arg));
3714 ath10k_wmi_start_scan_init(ar, &arg);
3715 arg.vdev_id = arvif->vdev_id;
3716 arg.scan_id = ATH10K_SCAN_ID;
3718 arg.channels[0] = chan->center_freq;
3719 arg.dwell_time_active = duration;
3720 arg.dwell_time_passive = duration;
3721 arg.max_scan_time = 2 * duration;
3722 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3723 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3725 ret = ath10k_start_scan(ar, &arg);
3727 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
3728 spin_lock_bh(&ar->data_lock);
3729 ar->scan.state = ATH10K_SCAN_IDLE;
3730 spin_unlock_bh(&ar->data_lock);
3734 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3736 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
3738 ret = ath10k_scan_stop(ar);
3740 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3748 mutex_unlock(&ar->conf_mutex);
3752 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3754 struct ath10k *ar = hw->priv;
3756 mutex_lock(&ar->conf_mutex);
3757 cancel_delayed_work_sync(&ar->scan.timeout);
3758 ath10k_scan_abort(ar);
3759 mutex_unlock(&ar->conf_mutex);
3765 * Both RTS and Fragmentation threshold are interface-specific
3766 * in ath10k, but device-specific in mac80211.
3769 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3771 struct ath10k *ar = hw->priv;
3772 struct ath10k_vif *arvif;
3775 mutex_lock(&ar->conf_mutex);
3776 list_for_each_entry(arvif, &ar->arvifs, list) {
3777 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3778 arvif->vdev_id, value);
3780 ret = ath10k_mac_set_rts(arvif, value);
3782 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3783 arvif->vdev_id, ret);
3787 mutex_unlock(&ar->conf_mutex);
3792 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3794 struct ath10k *ar = hw->priv;
3795 struct ath10k_vif *arvif;
3798 mutex_lock(&ar->conf_mutex);
3799 list_for_each_entry(arvif, &ar->arvifs, list) {
3800 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3801 arvif->vdev_id, value);
3803 ret = ath10k_mac_set_rts(arvif, value);
3805 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
3806 arvif->vdev_id, ret);
3810 mutex_unlock(&ar->conf_mutex);
3815 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3816 u32 queues, bool drop)
3818 struct ath10k *ar = hw->priv;
3822 /* mac80211 doesn't care if we really xmit queued frames or not
3823 * we'll collect those frames either way if we stop/delete vdevs */
3827 mutex_lock(&ar->conf_mutex);
3829 if (ar->state == ATH10K_STATE_WEDGED)
3832 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3835 spin_lock_bh(&ar->htt.tx_lock);
3836 empty = (ar->htt.num_pending_tx == 0);
3837 spin_unlock_bh(&ar->htt.tx_lock);
3839 skip = (ar->state == ATH10K_STATE_WEDGED);
3842 }), ATH10K_FLUSH_TIMEOUT_HZ);
3844 if (ret <= 0 || skip)
3845 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
3846 skip, ar->state, ret);
3849 mutex_unlock(&ar->conf_mutex);
3852 /* TODO: Implement this function properly
3853 * For now it is needed to reply to Probe Requests in IBSS mode.
3854 * Propably we need this information from FW.
3856 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3862 static int ath10k_suspend(struct ieee80211_hw *hw,
3863 struct cfg80211_wowlan *wowlan)
3865 struct ath10k *ar = hw->priv;
3868 mutex_lock(&ar->conf_mutex);
3870 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
3872 if (ret == -ETIMEDOUT)
3878 ret = ath10k_hif_suspend(ar);
3880 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
3887 ret = ath10k_wmi_pdev_resume_target(ar);
3889 ath10k_warn(ar, "failed to resume target: %d\n", ret);
3893 mutex_unlock(&ar->conf_mutex);
3897 static int ath10k_resume(struct ieee80211_hw *hw)
3899 struct ath10k *ar = hw->priv;
3902 mutex_lock(&ar->conf_mutex);
3904 ret = ath10k_hif_resume(ar);
3906 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
3911 ret = ath10k_wmi_pdev_resume_target(ar);
3913 ath10k_warn(ar, "failed to resume target: %d\n", ret);
3920 mutex_unlock(&ar->conf_mutex);
3925 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3927 struct ath10k *ar = hw->priv;
3929 mutex_lock(&ar->conf_mutex);
3931 /* If device failed to restart it will be in a different state, e.g.
3932 * ATH10K_STATE_WEDGED */
3933 if (ar->state == ATH10K_STATE_RESTARTED) {
3934 ath10k_info(ar, "device successfully recovered\n");
3935 ar->state = ATH10K_STATE_ON;
3938 mutex_unlock(&ar->conf_mutex);
3941 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3942 struct survey_info *survey)
3944 struct ath10k *ar = hw->priv;
3945 struct ieee80211_supported_band *sband;
3946 struct survey_info *ar_survey = &ar->survey[idx];
3949 mutex_lock(&ar->conf_mutex);
3951 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3952 if (sband && idx >= sband->n_channels) {
3953 idx -= sband->n_channels;
3958 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3960 if (!sband || idx >= sband->n_channels) {
3965 spin_lock_bh(&ar->data_lock);
3966 memcpy(survey, ar_survey, sizeof(*survey));
3967 spin_unlock_bh(&ar->data_lock);
3969 survey->channel = &sband->channels[idx];
3972 mutex_unlock(&ar->conf_mutex);
3976 /* Helper table for legacy fixed_rate/bitrate_mask */
3977 static const u8 cck_ofdm_rate[] = {
3994 /* Check if only one bit set */
3995 static int ath10k_check_single_mask(u32 mask)
4003 mask &= ~BIT(bit - 1);
4011 ath10k_default_bitrate_mask(struct ath10k *ar,
4012 enum ieee80211_band band,
4013 const struct cfg80211_bitrate_mask *mask)
4015 u32 legacy = 0x00ff;
4020 case IEEE80211_BAND_2GHZ:
4024 case IEEE80211_BAND_5GHZ:
4030 if (mask->control[band].legacy != legacy)
4033 for (i = 0; i < ar->num_rf_chains; i++)
4034 if (mask->control[band].ht_mcs[i] != ht)
4037 for (i = 0; i < ar->num_rf_chains; i++)
4038 if (mask->control[band].vht_mcs[i] != vht)
4045 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4046 enum ieee80211_band band,
4049 int ht_nss = 0, vht_nss = 0, i;
4052 if (ath10k_check_single_mask(mask->control[band].legacy))
4056 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4057 if (mask->control[band].ht_mcs[i] == 0xff)
4059 else if (mask->control[band].ht_mcs[i] == 0x00)
4068 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4069 if (mask->control[band].vht_mcs[i] == 0x03ff)
4071 else if (mask->control[band].vht_mcs[i] == 0x0000)
4079 if (ht_nss > 0 && vht_nss > 0)
4083 *fixed_nss = ht_nss;
4085 *fixed_nss = vht_nss;
4093 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4094 enum ieee80211_band band,
4095 enum wmi_rate_preamble *preamble)
4097 int legacy = 0, ht = 0, vht = 0, i;
4099 *preamble = WMI_RATE_PREAMBLE_OFDM;
4102 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4107 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4108 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4113 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4114 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4118 /* Currently we support only one fixed_rate */
4119 if ((legacy + ht + vht) != 1)
4123 *preamble = WMI_RATE_PREAMBLE_HT;
4125 *preamble = WMI_RATE_PREAMBLE_VHT;
4131 ath10k_bitrate_mask_rate(struct ath10k *ar,
4132 const struct cfg80211_bitrate_mask *mask,
4133 enum ieee80211_band band,
4137 u8 rate = 0, pream = 0, nss = 0, i;
4138 enum wmi_rate_preamble preamble;
4140 /* Check if single rate correct */
4141 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4147 case WMI_RATE_PREAMBLE_CCK:
4148 case WMI_RATE_PREAMBLE_OFDM:
4149 i = ffs(mask->control[band].legacy) - 1;
4151 if (band == IEEE80211_BAND_2GHZ && i < 4)
4152 pream = WMI_RATE_PREAMBLE_CCK;
4154 if (band == IEEE80211_BAND_5GHZ)
4157 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4160 rate = cck_ofdm_rate[i];
4162 case WMI_RATE_PREAMBLE_HT:
4163 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4164 if (mask->control[band].ht_mcs[i])
4167 if (i == IEEE80211_HT_MCS_MASK_LEN)
4170 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4173 case WMI_RATE_PREAMBLE_VHT:
4174 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4175 if (mask->control[band].vht_mcs[i])
4178 if (i == NL80211_VHT_NSS_MAX)
4181 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4186 *fixed_nss = nss + 1;
4190 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4193 *fixed_rate = pream | nss | rate;
4198 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4199 const struct cfg80211_bitrate_mask *mask,
4200 enum ieee80211_band band,
4204 /* First check full NSS mask, if we can simply limit NSS */
4205 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4208 /* Next Check single rate is set */
4209 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4212 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4217 struct ath10k *ar = arvif->ar;
4221 mutex_lock(&ar->conf_mutex);
4223 if (arvif->fixed_rate == fixed_rate &&
4224 arvif->fixed_nss == fixed_nss &&
4225 arvif->force_sgi == force_sgi)
4228 if (fixed_rate == WMI_FIXED_RATE_NONE)
4229 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4232 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4234 vdev_param = ar->wmi.vdev_param->fixed_rate;
4235 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4236 vdev_param, fixed_rate);
4238 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4244 arvif->fixed_rate = fixed_rate;
4246 vdev_param = ar->wmi.vdev_param->nss;
4247 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4248 vdev_param, fixed_nss);
4251 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4257 arvif->fixed_nss = fixed_nss;
4259 vdev_param = ar->wmi.vdev_param->sgi;
4260 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4264 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4270 arvif->force_sgi = force_sgi;
4273 mutex_unlock(&ar->conf_mutex);
4277 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4278 struct ieee80211_vif *vif,
4279 const struct cfg80211_bitrate_mask *mask)
4281 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4282 struct ath10k *ar = arvif->ar;
4283 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4284 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4285 u8 fixed_nss = ar->num_rf_chains;
4288 force_sgi = mask->control[band].gi;
4289 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4292 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4293 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4299 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4300 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4304 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4305 fixed_nss, force_sgi);
4308 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4309 struct ieee80211_vif *vif,
4310 struct ieee80211_sta *sta,
4313 struct ath10k *ar = hw->priv;
4314 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4317 spin_lock_bh(&ar->data_lock);
4319 ath10k_dbg(ar, ATH10K_DBG_MAC,
4320 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4321 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4324 if (changed & IEEE80211_RC_BW_CHANGED) {
4325 bw = WMI_PEER_CHWIDTH_20MHZ;
4327 switch (sta->bandwidth) {
4328 case IEEE80211_STA_RX_BW_20:
4329 bw = WMI_PEER_CHWIDTH_20MHZ;
4331 case IEEE80211_STA_RX_BW_40:
4332 bw = WMI_PEER_CHWIDTH_40MHZ;
4334 case IEEE80211_STA_RX_BW_80:
4335 bw = WMI_PEER_CHWIDTH_80MHZ;
4337 case IEEE80211_STA_RX_BW_160:
4338 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4339 sta->bandwidth, sta->addr);
4340 bw = WMI_PEER_CHWIDTH_20MHZ;
4347 if (changed & IEEE80211_RC_NSS_CHANGED)
4348 arsta->nss = sta->rx_nss;
4350 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4351 smps = WMI_PEER_SMPS_PS_NONE;
4353 switch (sta->smps_mode) {
4354 case IEEE80211_SMPS_AUTOMATIC:
4355 case IEEE80211_SMPS_OFF:
4356 smps = WMI_PEER_SMPS_PS_NONE;
4358 case IEEE80211_SMPS_STATIC:
4359 smps = WMI_PEER_SMPS_STATIC;
4361 case IEEE80211_SMPS_DYNAMIC:
4362 smps = WMI_PEER_SMPS_DYNAMIC;
4364 case IEEE80211_SMPS_NUM_MODES:
4365 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4366 sta->smps_mode, sta->addr);
4367 smps = WMI_PEER_SMPS_PS_NONE;
4374 arsta->changed |= changed;
4376 spin_unlock_bh(&ar->data_lock);
4378 ieee80211_queue_work(hw, &arsta->update_wk);
4381 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4384 * FIXME: Return 0 for time being. Need to figure out whether FW
4385 * has the API to fetch 64-bit local TSF
4391 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4392 struct ieee80211_vif *vif,
4393 enum ieee80211_ampdu_mlme_action action,
4394 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4397 struct ath10k *ar = hw->priv;
4398 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4400 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4401 arvif->vdev_id, sta->addr, tid, action);
4404 case IEEE80211_AMPDU_RX_START:
4405 case IEEE80211_AMPDU_RX_STOP:
4406 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4407 * creation/removal. Do we need to verify this?
4410 case IEEE80211_AMPDU_TX_START:
4411 case IEEE80211_AMPDU_TX_STOP_CONT:
4412 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4413 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4414 case IEEE80211_AMPDU_TX_OPERATIONAL:
4415 /* Firmware offloads Tx aggregation entirely so deny mac80211
4416 * Tx aggregation requests.
4424 static const struct ieee80211_ops ath10k_ops = {
4426 .start = ath10k_start,
4427 .stop = ath10k_stop,
4428 .config = ath10k_config,
4429 .add_interface = ath10k_add_interface,
4430 .remove_interface = ath10k_remove_interface,
4431 .configure_filter = ath10k_configure_filter,
4432 .bss_info_changed = ath10k_bss_info_changed,
4433 .hw_scan = ath10k_hw_scan,
4434 .cancel_hw_scan = ath10k_cancel_hw_scan,
4435 .set_key = ath10k_set_key,
4436 .sta_state = ath10k_sta_state,
4437 .conf_tx = ath10k_conf_tx,
4438 .remain_on_channel = ath10k_remain_on_channel,
4439 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4440 .set_rts_threshold = ath10k_set_rts_threshold,
4441 .set_frag_threshold = ath10k_set_frag_threshold,
4442 .flush = ath10k_flush,
4443 .tx_last_beacon = ath10k_tx_last_beacon,
4444 .set_antenna = ath10k_set_antenna,
4445 .get_antenna = ath10k_get_antenna,
4446 .restart_complete = ath10k_restart_complete,
4447 .get_survey = ath10k_get_survey,
4448 .set_bitrate_mask = ath10k_set_bitrate_mask,
4449 .sta_rc_update = ath10k_sta_rc_update,
4450 .get_tsf = ath10k_get_tsf,
4451 .ampdu_action = ath10k_ampdu_action,
4453 .suspend = ath10k_suspend,
4454 .resume = ath10k_resume,
4458 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4459 .bitrate = (_rate), \
4460 .flags = (_flags), \
4461 .hw_value = (_rateid), \
4464 #define CHAN2G(_channel, _freq, _flags) { \
4465 .band = IEEE80211_BAND_2GHZ, \
4466 .hw_value = (_channel), \
4467 .center_freq = (_freq), \
4468 .flags = (_flags), \
4469 .max_antenna_gain = 0, \
4473 #define CHAN5G(_channel, _freq, _flags) { \
4474 .band = IEEE80211_BAND_5GHZ, \
4475 .hw_value = (_channel), \
4476 .center_freq = (_freq), \
4477 .flags = (_flags), \
4478 .max_antenna_gain = 0, \
4482 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4492 CHAN2G(10, 2457, 0),
4493 CHAN2G(11, 2462, 0),
4494 CHAN2G(12, 2467, 0),
4495 CHAN2G(13, 2472, 0),
4496 CHAN2G(14, 2484, 0),
4499 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4500 CHAN5G(36, 5180, 0),
4501 CHAN5G(40, 5200, 0),
4502 CHAN5G(44, 5220, 0),
4503 CHAN5G(48, 5240, 0),
4504 CHAN5G(52, 5260, 0),
4505 CHAN5G(56, 5280, 0),
4506 CHAN5G(60, 5300, 0),
4507 CHAN5G(64, 5320, 0),
4508 CHAN5G(100, 5500, 0),
4509 CHAN5G(104, 5520, 0),
4510 CHAN5G(108, 5540, 0),
4511 CHAN5G(112, 5560, 0),
4512 CHAN5G(116, 5580, 0),
4513 CHAN5G(120, 5600, 0),
4514 CHAN5G(124, 5620, 0),
4515 CHAN5G(128, 5640, 0),
4516 CHAN5G(132, 5660, 0),
4517 CHAN5G(136, 5680, 0),
4518 CHAN5G(140, 5700, 0),
4519 CHAN5G(149, 5745, 0),
4520 CHAN5G(153, 5765, 0),
4521 CHAN5G(157, 5785, 0),
4522 CHAN5G(161, 5805, 0),
4523 CHAN5G(165, 5825, 0),
4526 static struct ieee80211_rate ath10k_rates[] = {
4528 RATETAB_ENT(10, 0x82, 0),
4529 RATETAB_ENT(20, 0x84, 0),
4530 RATETAB_ENT(55, 0x8b, 0),
4531 RATETAB_ENT(110, 0x96, 0),
4533 RATETAB_ENT(60, 0x0c, 0),
4534 RATETAB_ENT(90, 0x12, 0),
4535 RATETAB_ENT(120, 0x18, 0),
4536 RATETAB_ENT(180, 0x24, 0),
4537 RATETAB_ENT(240, 0x30, 0),
4538 RATETAB_ENT(360, 0x48, 0),
4539 RATETAB_ENT(480, 0x60, 0),
4540 RATETAB_ENT(540, 0x6c, 0),
4543 #define ath10k_a_rates (ath10k_rates + 4)
4544 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4545 #define ath10k_g_rates (ath10k_rates + 0)
4546 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4548 struct ath10k *ath10k_mac_create(size_t priv_size)
4550 struct ieee80211_hw *hw;
4553 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4563 void ath10k_mac_destroy(struct ath10k *ar)
4565 ieee80211_free_hw(ar->hw);
4568 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4571 .types = BIT(NL80211_IFTYPE_STATION)
4572 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4576 .types = BIT(NL80211_IFTYPE_P2P_GO)
4580 .types = BIT(NL80211_IFTYPE_AP)
4584 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4587 .types = BIT(NL80211_IFTYPE_AP)
4591 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4593 .limits = ath10k_if_limits,
4594 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4595 .max_interfaces = 8,
4596 .num_different_channels = 1,
4597 .beacon_int_infra_match = true,
4601 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4603 .limits = ath10k_10x_if_limits,
4604 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4605 .max_interfaces = 8,
4606 .num_different_channels = 1,
4607 .beacon_int_infra_match = true,
4608 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4609 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4610 BIT(NL80211_CHAN_WIDTH_20) |
4611 BIT(NL80211_CHAN_WIDTH_40) |
4612 BIT(NL80211_CHAN_WIDTH_80),
4617 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4619 struct ieee80211_sta_vht_cap vht_cap = {0};
4623 vht_cap.vht_supported = 1;
4624 vht_cap.cap = ar->vht_cap_info;
4627 for (i = 0; i < 8; i++) {
4628 if (i < ar->num_rf_chains)
4629 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4631 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4634 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4635 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4640 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4643 struct ieee80211_sta_ht_cap ht_cap = {0};
4645 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4648 ht_cap.ht_supported = 1;
4649 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4650 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4651 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4652 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4653 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4655 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4656 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4658 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4659 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4661 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4664 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4665 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4670 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4671 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4673 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4676 stbc = ar->ht_cap_info;
4677 stbc &= WMI_HT_CAP_RX_STBC;
4678 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4679 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4680 stbc &= IEEE80211_HT_CAP_RX_STBC;
4685 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4686 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4688 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4689 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4691 /* max AMSDU is implicitly taken from vht_cap_info */
4692 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4693 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4695 for (i = 0; i < ar->num_rf_chains; i++)
4696 ht_cap.mcs.rx_mask[i] = 0xFF;
4698 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4704 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4705 struct ieee80211_vif *vif)
4707 struct ath10k_vif_iter *arvif_iter = data;
4708 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4710 if (arvif->vdev_id == arvif_iter->vdev_id)
4711 arvif_iter->arvif = arvif;
4714 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4716 struct ath10k_vif_iter arvif_iter;
4719 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4720 arvif_iter.vdev_id = vdev_id;
4722 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4723 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4725 ath10k_get_arvif_iter,
4727 if (!arvif_iter.arvif) {
4728 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
4732 return arvif_iter.arvif;
4735 int ath10k_mac_register(struct ath10k *ar)
4737 struct ieee80211_supported_band *band;
4738 struct ieee80211_sta_vht_cap vht_cap;
4739 struct ieee80211_sta_ht_cap ht_cap;
4743 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4745 SET_IEEE80211_DEV(ar->hw, ar->dev);
4747 ht_cap = ath10k_get_ht_cap(ar);
4748 vht_cap = ath10k_create_vht_cap(ar);
4750 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4751 channels = kmemdup(ath10k_2ghz_channels,
4752 sizeof(ath10k_2ghz_channels),
4759 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4760 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4761 band->channels = channels;
4762 band->n_bitrates = ath10k_g_rates_size;
4763 band->bitrates = ath10k_g_rates;
4764 band->ht_cap = ht_cap;
4766 /* vht is not supported in 2.4 GHz */
4768 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4771 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4772 channels = kmemdup(ath10k_5ghz_channels,
4773 sizeof(ath10k_5ghz_channels),
4780 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4781 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4782 band->channels = channels;
4783 band->n_bitrates = ath10k_a_rates_size;
4784 band->bitrates = ath10k_a_rates;
4785 band->ht_cap = ht_cap;
4786 band->vht_cap = vht_cap;
4787 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4790 ar->hw->wiphy->interface_modes =
4791 BIT(NL80211_IFTYPE_STATION) |
4792 BIT(NL80211_IFTYPE_AP);
4794 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4795 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4796 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4797 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4799 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4800 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4803 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4804 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4806 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4807 ar->hw->wiphy->interface_modes |=
4808 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4809 BIT(NL80211_IFTYPE_P2P_GO);
4811 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4812 IEEE80211_HW_SUPPORTS_PS |
4813 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4814 IEEE80211_HW_SUPPORTS_UAPSD |
4815 IEEE80211_HW_MFP_CAPABLE |
4816 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4817 IEEE80211_HW_HAS_RATE_CONTROL |
4818 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4819 IEEE80211_HW_AP_LINK_PS |
4820 IEEE80211_HW_SPECTRUM_MGMT;
4822 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4823 * bytes is used for padding/alignment if necessary. */
4824 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4826 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4827 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4829 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4830 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4831 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4834 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4835 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4837 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4838 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
4840 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4842 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4843 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4844 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4846 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4848 * on LL hardware queues are managed entirely by the FW
4849 * so we only advertise to mac we can do the queues thing
4853 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4854 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4855 ar->hw->wiphy->n_iface_combinations =
4856 ARRAY_SIZE(ath10k_10x_if_comb);
4858 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4859 ar->hw->wiphy->n_iface_combinations =
4860 ARRAY_SIZE(ath10k_if_comb);
4862 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4865 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4867 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4868 /* Init ath dfs pattern detector */
4869 ar->ath_common.debug_mask = ATH_DBG_DFS;
4870 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4873 if (!ar->dfs_detector)
4874 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
4877 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4878 ath10k_reg_notifier);
4880 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
4884 ret = ieee80211_register_hw(ar->hw);
4886 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
4890 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4891 ret = regulatory_hint(ar->hw->wiphy,
4892 ar->ath_common.regulatory.alpha2);
4894 goto err_unregister;
4900 ieee80211_unregister_hw(ar->hw);
4902 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4903 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4908 void ath10k_mac_unregister(struct ath10k *ar)
4910 ieee80211_unregister_hw(ar->hw);
4912 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4913 ar->dfs_detector->exit(ar->dfs_detector);
4915 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4916 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4918 SET_IEEE80211_DEV(ar->hw, NULL);