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>
38 static struct ieee80211_rate ath10k_rates
[] = {
56 #define ath10k_a_rates (ath10k_rates + 4)
57 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
58 #define ath10k_g_rates (ath10k_rates + 0)
59 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
61 static bool ath10k_mac_bitrate_is_cck(int bitrate
)
74 static u8
ath10k_mac_bitrate_to_rate(int bitrate
)
76 return DIV_ROUND_UP(bitrate
, 5) |
77 (ath10k_mac_bitrate_is_cck(bitrate
) ? BIT(7) : 0);
84 static int ath10k_send_key(struct ath10k_vif
*arvif
,
85 struct ieee80211_key_conf
*key
,
87 const u8
*macaddr
, u32 flags
)
89 struct ath10k
*ar
= arvif
->ar
;
90 struct wmi_vdev_install_key_arg arg
= {
91 .vdev_id
= arvif
->vdev_id
,
92 .key_idx
= key
->keyidx
,
93 .key_len
= key
->keylen
,
99 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
101 switch (key
->cipher
) {
102 case WLAN_CIPHER_SUITE_CCMP
:
103 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
104 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
106 case WLAN_CIPHER_SUITE_TKIP
:
107 arg
.key_cipher
= WMI_CIPHER_TKIP
;
108 arg
.key_txmic_len
= 8;
109 arg
.key_rxmic_len
= 8;
111 case WLAN_CIPHER_SUITE_WEP40
:
112 case WLAN_CIPHER_SUITE_WEP104
:
113 arg
.key_cipher
= WMI_CIPHER_WEP
;
115 case WLAN_CIPHER_SUITE_AES_CMAC
:
119 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
123 if (cmd
== DISABLE_KEY
) {
124 arg
.key_cipher
= WMI_CIPHER_NONE
;
128 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
131 static int ath10k_install_key(struct ath10k_vif
*arvif
,
132 struct ieee80211_key_conf
*key
,
133 enum set_key_cmd cmd
,
134 const u8
*macaddr
, u32 flags
)
136 struct ath10k
*ar
= arvif
->ar
;
139 lockdep_assert_held(&ar
->conf_mutex
);
141 reinit_completion(&ar
->install_key_done
);
143 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
147 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
154 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
157 struct ath10k
*ar
= arvif
->ar
;
158 struct ath10k_peer
*peer
;
163 lockdep_assert_held(&ar
->conf_mutex
);
165 spin_lock_bh(&ar
->data_lock
);
166 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
167 spin_unlock_bh(&ar
->data_lock
);
172 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
173 if (arvif
->wep_keys
[i
] == NULL
)
177 flags
|= WMI_KEY_PAIRWISE
;
179 /* set TX_USAGE flag for default key id */
180 if (arvif
->def_wep_key_idx
== i
)
181 flags
|= WMI_KEY_TX_USAGE
;
183 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
188 spin_lock_bh(&ar
->data_lock
);
189 peer
->keys
[i
] = arvif
->wep_keys
[i
];
190 spin_unlock_bh(&ar
->data_lock
);
196 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
199 struct ath10k
*ar
= arvif
->ar
;
200 struct ath10k_peer
*peer
;
206 lockdep_assert_held(&ar
->conf_mutex
);
208 spin_lock_bh(&ar
->data_lock
);
209 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
210 spin_unlock_bh(&ar
->data_lock
);
215 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
216 if (peer
->keys
[i
] == NULL
)
219 /* key flags are not required to delete the key */
220 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
221 DISABLE_KEY
, addr
, flags
);
222 if (ret
&& first_errno
== 0)
226 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
229 spin_lock_bh(&ar
->data_lock
);
230 peer
->keys
[i
] = NULL
;
231 spin_unlock_bh(&ar
->data_lock
);
237 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
240 struct ath10k_peer
*peer
;
243 lockdep_assert_held(&ar
->data_lock
);
245 /* We don't know which vdev this peer belongs to,
246 * since WMI doesn't give us that information.
248 * FIXME: multi-bss needs to be handled.
250 peer
= ath10k_peer_find(ar
, 0, addr
);
254 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
255 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
262 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
263 struct ieee80211_key_conf
*key
)
265 struct ath10k
*ar
= arvif
->ar
;
266 struct ath10k_peer
*peer
;
273 lockdep_assert_held(&ar
->conf_mutex
);
276 /* since ath10k_install_key we can't hold data_lock all the
277 * time, so we try to remove the keys incrementally */
278 spin_lock_bh(&ar
->data_lock
);
280 list_for_each_entry(peer
, &ar
->peers
, list
) {
281 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
282 if (peer
->keys
[i
] == key
) {
283 ether_addr_copy(addr
, peer
->addr
);
284 peer
->keys
[i
] = NULL
;
289 if (i
< ARRAY_SIZE(peer
->keys
))
292 spin_unlock_bh(&ar
->data_lock
);
294 if (i
== ARRAY_SIZE(peer
->keys
))
296 /* key flags are not required to delete the key */
297 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
298 if (ret
&& first_errno
== 0)
302 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
309 static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif
*arvif
)
311 struct ath10k
*ar
= arvif
->ar
;
312 enum nl80211_iftype iftype
= arvif
->vif
->type
;
313 struct ieee80211_key_conf
*key
;
319 lockdep_assert_held(&ar
->conf_mutex
);
321 if (iftype
!= NL80211_IFTYPE_STATION
)
324 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
325 if (arvif
->wep_keys
[i
]) {
326 key
= arvif
->wep_keys
[i
];
334 flags
|= WMI_KEY_PAIRWISE
;
335 flags
|= WMI_KEY_TX_USAGE
;
337 ret
= ath10k_install_key(arvif
, key
, SET_KEY
, arvif
->bssid
, flags
);
339 ath10k_warn(ar
, "failed to install key %i on vdev %i: %d\n",
340 key
->keyidx
, arvif
->vdev_id
, ret
);
347 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
348 struct ieee80211_key_conf
*key
)
350 struct ath10k
*ar
= arvif
->ar
;
351 struct ath10k_peer
*peer
;
354 lockdep_assert_held(&ar
->conf_mutex
);
356 list_for_each_entry(peer
, &ar
->peers
, list
) {
357 if (!memcmp(peer
->addr
, arvif
->vif
->addr
, ETH_ALEN
))
360 if (!memcmp(peer
->addr
, arvif
->bssid
, ETH_ALEN
))
363 if (peer
->keys
[key
->keyidx
] == key
)
366 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
367 arvif
->vdev_id
, key
->keyidx
);
369 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
371 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
372 arvif
->vdev_id
, peer
->addr
, ret
);
380 /*********************/
381 /* General utilities */
382 /*********************/
384 static inline enum wmi_phy_mode
385 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
387 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
389 switch (chandef
->chan
->band
) {
390 case IEEE80211_BAND_2GHZ
:
391 switch (chandef
->width
) {
392 case NL80211_CHAN_WIDTH_20_NOHT
:
393 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
398 case NL80211_CHAN_WIDTH_20
:
399 phymode
= MODE_11NG_HT20
;
401 case NL80211_CHAN_WIDTH_40
:
402 phymode
= MODE_11NG_HT40
;
404 case NL80211_CHAN_WIDTH_5
:
405 case NL80211_CHAN_WIDTH_10
:
406 case NL80211_CHAN_WIDTH_80
:
407 case NL80211_CHAN_WIDTH_80P80
:
408 case NL80211_CHAN_WIDTH_160
:
409 phymode
= MODE_UNKNOWN
;
413 case IEEE80211_BAND_5GHZ
:
414 switch (chandef
->width
) {
415 case NL80211_CHAN_WIDTH_20_NOHT
:
418 case NL80211_CHAN_WIDTH_20
:
419 phymode
= MODE_11NA_HT20
;
421 case NL80211_CHAN_WIDTH_40
:
422 phymode
= MODE_11NA_HT40
;
424 case NL80211_CHAN_WIDTH_80
:
425 phymode
= MODE_11AC_VHT80
;
427 case NL80211_CHAN_WIDTH_5
:
428 case NL80211_CHAN_WIDTH_10
:
429 case NL80211_CHAN_WIDTH_80P80
:
430 case NL80211_CHAN_WIDTH_160
:
431 phymode
= MODE_UNKNOWN
;
439 WARN_ON(phymode
== MODE_UNKNOWN
);
443 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
446 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
447 * 0 for no restriction
456 switch (mpdudensity
) {
462 /* Our lower layer calculations limit our precision to
478 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
,
479 enum wmi_peer_type peer_type
)
483 lockdep_assert_held(&ar
->conf_mutex
);
485 if (ar
->num_peers
>= ar
->max_num_peers
)
488 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
490 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
495 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
497 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
507 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
509 struct ath10k
*ar
= arvif
->ar
;
513 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
514 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
515 ATH10K_KICKOUT_THRESHOLD
);
517 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
518 arvif
->vdev_id
, ret
);
522 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
523 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
524 ATH10K_KEEPALIVE_MIN_IDLE
);
526 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
527 arvif
->vdev_id
, ret
);
531 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
532 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
533 ATH10K_KEEPALIVE_MAX_IDLE
);
535 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
536 arvif
->vdev_id
, ret
);
540 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
541 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
542 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
544 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
545 arvif
->vdev_id
, ret
);
552 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
554 struct ath10k
*ar
= arvif
->ar
;
557 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
558 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
561 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
563 struct ath10k
*ar
= arvif
->ar
;
566 if (value
!= 0xFFFFFFFF)
567 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
568 ATH10K_FRAGMT_THRESHOLD_MIN
,
569 ATH10K_FRAGMT_THRESHOLD_MAX
);
571 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
572 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
575 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
579 lockdep_assert_held(&ar
->conf_mutex
);
581 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
585 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
594 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
596 struct ath10k_peer
*peer
, *tmp
;
598 lockdep_assert_held(&ar
->conf_mutex
);
600 spin_lock_bh(&ar
->data_lock
);
601 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
602 if (peer
->vdev_id
!= vdev_id
)
605 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
606 peer
->addr
, vdev_id
);
608 list_del(&peer
->list
);
612 spin_unlock_bh(&ar
->data_lock
);
615 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
617 struct ath10k_peer
*peer
, *tmp
;
619 lockdep_assert_held(&ar
->conf_mutex
);
621 spin_lock_bh(&ar
->data_lock
);
622 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
623 list_del(&peer
->list
);
626 spin_unlock_bh(&ar
->data_lock
);
629 ar
->num_stations
= 0;
632 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
633 struct ieee80211_sta
*sta
,
634 enum wmi_tdls_peer_state state
)
637 struct wmi_tdls_peer_update_cmd_arg arg
= {};
638 struct wmi_tdls_peer_capab_arg cap
= {};
639 struct wmi_channel_arg chan_arg
= {};
641 lockdep_assert_held(&ar
->conf_mutex
);
643 arg
.vdev_id
= vdev_id
;
644 arg
.peer_state
= state
;
645 ether_addr_copy(arg
.addr
, sta
->addr
);
647 cap
.peer_max_sp
= sta
->max_sp
;
648 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
650 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
651 !sta
->tdls_initiator
)
652 cap
.is_peer_responder
= 1;
654 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
656 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
657 arg
.addr
, vdev_id
, ret
);
664 /************************/
665 /* Interface management */
666 /************************/
668 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
670 struct ath10k
*ar
= arvif
->ar
;
672 lockdep_assert_held(&ar
->data_lock
);
677 if (!arvif
->beacon_buf
)
678 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
679 arvif
->beacon
->len
, DMA_TO_DEVICE
);
681 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
682 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
685 dev_kfree_skb_any(arvif
->beacon
);
687 arvif
->beacon
= NULL
;
688 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
691 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
693 struct ath10k
*ar
= arvif
->ar
;
695 lockdep_assert_held(&ar
->data_lock
);
697 ath10k_mac_vif_beacon_free(arvif
);
699 if (arvif
->beacon_buf
) {
700 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
701 arvif
->beacon_buf
, arvif
->beacon_paddr
);
702 arvif
->beacon_buf
= NULL
;
706 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
710 lockdep_assert_held(&ar
->conf_mutex
);
712 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
715 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
716 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
723 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
725 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
726 struct ieee80211_channel
*channel
= chandef
->chan
;
727 struct wmi_vdev_start_request_arg arg
= {};
730 lockdep_assert_held(&ar
->conf_mutex
);
732 arg
.vdev_id
= vdev_id
;
733 arg
.channel
.freq
= channel
->center_freq
;
734 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
736 /* TODO setup this dynamically, what in case we
737 don't have any vifs? */
738 arg
.channel
.mode
= chan_to_phymode(chandef
);
739 arg
.channel
.chan_radar
=
740 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
742 arg
.channel
.min_power
= 0;
743 arg
.channel
.max_power
= channel
->max_power
* 2;
744 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
745 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
747 reinit_completion(&ar
->vdev_setup_done
);
749 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
751 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
756 ret
= ath10k_vdev_setup_sync(ar
);
758 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
763 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
765 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
770 ar
->monitor_vdev_id
= vdev_id
;
772 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
773 ar
->monitor_vdev_id
);
777 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
779 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
780 ar
->monitor_vdev_id
, ret
);
785 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
789 lockdep_assert_held(&ar
->conf_mutex
);
791 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
793 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
794 ar
->monitor_vdev_id
, ret
);
796 reinit_completion(&ar
->vdev_setup_done
);
798 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
800 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
801 ar
->monitor_vdev_id
, ret
);
803 ret
= ath10k_vdev_setup_sync(ar
);
805 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
806 ar
->monitor_vdev_id
, ret
);
808 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
809 ar
->monitor_vdev_id
);
813 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
817 lockdep_assert_held(&ar
->conf_mutex
);
819 if (ar
->free_vdev_map
== 0) {
820 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
824 bit
= __ffs64(ar
->free_vdev_map
);
826 ar
->monitor_vdev_id
= bit
;
828 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
829 WMI_VDEV_TYPE_MONITOR
,
832 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
833 ar
->monitor_vdev_id
, ret
);
837 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
838 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
839 ar
->monitor_vdev_id
);
844 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
848 lockdep_assert_held(&ar
->conf_mutex
);
850 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
852 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
853 ar
->monitor_vdev_id
, ret
);
857 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
859 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
860 ar
->monitor_vdev_id
);
864 static int ath10k_monitor_start(struct ath10k
*ar
)
868 lockdep_assert_held(&ar
->conf_mutex
);
870 ret
= ath10k_monitor_vdev_create(ar
);
872 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
876 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
878 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
879 ath10k_monitor_vdev_delete(ar
);
883 ar
->monitor_started
= true;
884 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
889 static int ath10k_monitor_stop(struct ath10k
*ar
)
893 lockdep_assert_held(&ar
->conf_mutex
);
895 ret
= ath10k_monitor_vdev_stop(ar
);
897 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
901 ret
= ath10k_monitor_vdev_delete(ar
);
903 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
907 ar
->monitor_started
= false;
908 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
913 static bool ath10k_mac_should_disable_promisc(struct ath10k
*ar
)
915 struct ath10k_vif
*arvif
;
917 if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
))
920 if (!ar
->num_started_vdevs
)
923 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
924 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
927 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
928 "mac disabling promiscuous mode because vdev is started\n");
932 static int ath10k_monitor_recalc(struct ath10k
*ar
)
936 lockdep_assert_held(&ar
->conf_mutex
);
938 should_start
= ar
->monitor
||
939 !ath10k_mac_should_disable_promisc(ar
) ||
940 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
942 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
943 "mac monitor recalc started? %d should? %d\n",
944 ar
->monitor_started
, should_start
);
946 if (should_start
== ar
->monitor_started
)
950 return ath10k_monitor_start(ar
);
952 return ath10k_monitor_stop(ar
);
955 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
957 struct ath10k
*ar
= arvif
->ar
;
958 u32 vdev_param
, rts_cts
= 0;
960 lockdep_assert_held(&ar
->conf_mutex
);
962 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
964 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
966 if (arvif
->num_legacy_stations
> 0)
967 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
970 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
973 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
977 static int ath10k_start_cac(struct ath10k
*ar
)
981 lockdep_assert_held(&ar
->conf_mutex
);
983 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
985 ret
= ath10k_monitor_recalc(ar
);
987 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
988 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
992 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
993 ar
->monitor_vdev_id
);
998 static int ath10k_stop_cac(struct ath10k
*ar
)
1000 lockdep_assert_held(&ar
->conf_mutex
);
1002 /* CAC is not running - do nothing */
1003 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1006 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1007 ath10k_monitor_stop(ar
);
1009 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1014 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1018 lockdep_assert_held(&ar
->conf_mutex
);
1020 ath10k_stop_cac(ar
);
1022 if (!ar
->radar_enabled
)
1025 if (ar
->num_started_vdevs
> 0)
1028 ret
= ath10k_start_cac(ar
);
1031 * Not possible to start CAC on current channel so starting
1032 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1033 * by indicating that radar was detected.
1035 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1036 ieee80211_radar_detected(ar
->hw
);
1040 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1042 struct ath10k
*ar
= arvif
->ar
;
1045 lockdep_assert_held(&ar
->conf_mutex
);
1047 reinit_completion(&ar
->vdev_setup_done
);
1049 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1051 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1052 arvif
->vdev_id
, ret
);
1056 ret
= ath10k_vdev_setup_sync(ar
);
1058 ath10k_warn(ar
, "failed to syncronise setup for vdev %i: %d\n",
1059 arvif
->vdev_id
, ret
);
1063 WARN_ON(ar
->num_started_vdevs
== 0);
1065 if (ar
->num_started_vdevs
!= 0) {
1066 ar
->num_started_vdevs
--;
1067 ath10k_recalc_radar_detection(ar
);
1073 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
, bool restart
)
1075 struct ath10k
*ar
= arvif
->ar
;
1076 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
1077 struct wmi_vdev_start_request_arg arg
= {};
1080 lockdep_assert_held(&ar
->conf_mutex
);
1082 reinit_completion(&ar
->vdev_setup_done
);
1084 arg
.vdev_id
= arvif
->vdev_id
;
1085 arg
.dtim_period
= arvif
->dtim_period
;
1086 arg
.bcn_intval
= arvif
->beacon_interval
;
1088 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1089 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1090 arg
.channel
.mode
= chan_to_phymode(chandef
);
1092 arg
.channel
.min_power
= 0;
1093 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1094 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1095 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1097 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1098 arg
.ssid
= arvif
->u
.ap
.ssid
;
1099 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1100 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1102 /* For now allow DFS for AP mode */
1103 arg
.channel
.chan_radar
=
1104 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1105 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1106 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1107 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1110 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1111 "mac vdev %d start center_freq %d phymode %s\n",
1112 arg
.vdev_id
, arg
.channel
.freq
,
1113 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1116 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1118 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1121 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1126 ret
= ath10k_vdev_setup_sync(ar
);
1129 "failed to synchronize setup for vdev %i restart %d: %d\n",
1130 arg
.vdev_id
, restart
, ret
);
1134 ar
->num_started_vdevs
++;
1135 ath10k_recalc_radar_detection(ar
);
1137 ret
= ath10k_monitor_recalc(ar
);
1139 ath10k_warn(ar
, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1140 arg
.vdev_id
, restart
, ret
);
1141 ret2
= ath10k_vdev_stop(arvif
);
1143 ath10k_warn(ar
, "mac failed to stop vdev %i restart %d: %d\n",
1144 arg
.vdev_id
, restart
, ret2
);
1150 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
1152 return ath10k_vdev_start_restart(arvif
, false);
1155 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
)
1157 return ath10k_vdev_start_restart(arvif
, true);
1160 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1161 struct sk_buff
*bcn
)
1163 struct ath10k
*ar
= arvif
->ar
;
1164 struct ieee80211_mgmt
*mgmt
;
1168 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1171 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1174 mgmt
= (void *)bcn
->data
;
1175 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1176 mgmt
->u
.beacon
.variable
,
1177 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1182 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1184 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1185 arvif
->vdev_id
, ret
);
1192 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1193 u8 oui_type
, size_t ie_offset
)
1200 if (WARN_ON(skb
->len
< ie_offset
))
1203 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1204 skb
->data
+ ie_offset
,
1205 skb
->len
- ie_offset
);
1210 end
= skb
->data
+ skb
->len
;
1213 if (WARN_ON(next
> end
))
1216 memmove(ie
, next
, end
- next
);
1217 skb_trim(skb
, skb
->len
- len
);
1222 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1224 struct ath10k
*ar
= arvif
->ar
;
1225 struct ieee80211_hw
*hw
= ar
->hw
;
1226 struct ieee80211_vif
*vif
= arvif
->vif
;
1227 struct ieee80211_mutable_offsets offs
= {};
1228 struct sk_buff
*bcn
;
1231 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1234 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1235 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1238 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1240 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1244 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1246 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1251 /* P2P IE is inserted by firmware automatically (as configured above)
1252 * so remove it from the base beacon template to avoid duplicate P2P
1253 * IEs in beacon frames.
1255 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1256 offsetof(struct ieee80211_mgmt
,
1257 u
.beacon
.variable
));
1259 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1264 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1272 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1274 struct ath10k
*ar
= arvif
->ar
;
1275 struct ieee80211_hw
*hw
= ar
->hw
;
1276 struct ieee80211_vif
*vif
= arvif
->vif
;
1277 struct sk_buff
*prb
;
1280 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1283 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1286 prb
= ieee80211_proberesp_get(hw
, vif
);
1288 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1292 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1296 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1304 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1305 struct ieee80211_bss_conf
*info
)
1307 struct ath10k
*ar
= arvif
->ar
;
1310 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1312 if (!info
->enable_beacon
) {
1313 ath10k_vdev_stop(arvif
);
1315 arvif
->is_started
= false;
1316 arvif
->is_up
= false;
1318 spin_lock_bh(&arvif
->ar
->data_lock
);
1319 ath10k_mac_vif_beacon_free(arvif
);
1320 spin_unlock_bh(&arvif
->ar
->data_lock
);
1325 arvif
->tx_seq_no
= 0x1000;
1327 ret
= ath10k_vdev_start(arvif
);
1332 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1334 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1337 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1338 arvif
->vdev_id
, ret
);
1339 ath10k_vdev_stop(arvif
);
1343 arvif
->is_started
= true;
1344 arvif
->is_up
= true;
1346 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1349 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1350 struct ieee80211_bss_conf
*info
,
1351 const u8 self_peer
[ETH_ALEN
])
1353 struct ath10k
*ar
= arvif
->ar
;
1357 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1359 if (!info
->ibss_joined
) {
1360 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
1362 ath10k_warn(ar
, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1363 self_peer
, arvif
->vdev_id
, ret
);
1365 if (is_zero_ether_addr(arvif
->bssid
))
1368 memset(arvif
->bssid
, 0, ETH_ALEN
);
1373 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
,
1374 WMI_PEER_TYPE_DEFAULT
);
1376 ath10k_warn(ar
, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1377 self_peer
, arvif
->vdev_id
, ret
);
1381 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1382 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1383 ATH10K_DEFAULT_ATIM
);
1385 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1386 arvif
->vdev_id
, ret
);
1389 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1391 struct ath10k
*ar
= arvif
->ar
;
1396 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1398 if (arvif
->u
.sta
.uapsd
)
1399 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1401 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1403 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1404 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1406 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1407 value
, arvif
->vdev_id
, ret
);
1414 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1416 struct ath10k
*ar
= arvif
->ar
;
1421 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1423 if (arvif
->u
.sta
.uapsd
)
1424 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1426 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1428 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1429 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1432 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1433 value
, arvif
->vdev_id
, ret
);
1440 static int ath10k_mac_ps_vif_count(struct ath10k
*ar
)
1442 struct ath10k_vif
*arvif
;
1445 lockdep_assert_held(&ar
->conf_mutex
);
1447 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1454 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1456 struct ath10k
*ar
= arvif
->ar
;
1457 struct ieee80211_vif
*vif
= arvif
->vif
;
1458 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1459 enum wmi_sta_powersave_param param
;
1460 enum wmi_sta_ps_mode psmode
;
1465 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1467 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1470 enable_ps
= arvif
->ps
;
1472 if (enable_ps
&& ath10k_mac_ps_vif_count(ar
) > 1 &&
1473 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1475 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1481 psmode
= WMI_STA_PS_MODE_ENABLED
;
1482 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1484 ps_timeout
= conf
->dynamic_ps_timeout
;
1485 if (ps_timeout
== 0) {
1486 /* Firmware doesn't like 0 */
1487 ps_timeout
= ieee80211_tu_to_usec(
1488 vif
->bss_conf
.beacon_int
) / 1000;
1491 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1494 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1495 arvif
->vdev_id
, ret
);
1499 psmode
= WMI_STA_PS_MODE_DISABLED
;
1502 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1503 arvif
->vdev_id
, psmode
? "enable" : "disable");
1505 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1507 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1508 psmode
, arvif
->vdev_id
, ret
);
1515 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1517 struct ath10k
*ar
= arvif
->ar
;
1518 struct wmi_sta_keepalive_arg arg
= {};
1521 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1523 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1526 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1529 /* Some firmware revisions have a bug and ignore the `enabled` field.
1530 * Instead use the interval to disable the keepalive.
1532 arg
.vdev_id
= arvif
->vdev_id
;
1534 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1535 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1537 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1539 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1540 arvif
->vdev_id
, ret
);
1547 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
1549 struct ath10k
*ar
= arvif
->ar
;
1550 struct ieee80211_vif
*vif
= arvif
->vif
;
1553 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1555 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
1558 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1561 if (!vif
->csa_active
)
1567 if (!ieee80211_csa_is_complete(vif
)) {
1568 ieee80211_csa_update_counter(vif
);
1570 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1572 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
1575 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1577 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
1580 ieee80211_csa_finish(vif
);
1584 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
1586 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1588 struct ath10k
*ar
= arvif
->ar
;
1590 mutex_lock(&ar
->conf_mutex
);
1591 ath10k_mac_vif_ap_csa_count_down(arvif
);
1592 mutex_unlock(&ar
->conf_mutex
);
1595 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
1596 struct ieee80211_vif
*vif
)
1598 struct sk_buff
*skb
= data
;
1599 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1600 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1602 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1605 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
1608 cancel_delayed_work(&arvif
->connection_loss_work
);
1611 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
1613 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1614 IEEE80211_IFACE_ITER_NORMAL
,
1615 ath10k_mac_handle_beacon_iter
,
1619 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
1620 struct ieee80211_vif
*vif
)
1622 u32
*vdev_id
= data
;
1623 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1624 struct ath10k
*ar
= arvif
->ar
;
1625 struct ieee80211_hw
*hw
= ar
->hw
;
1627 if (arvif
->vdev_id
!= *vdev_id
)
1633 ieee80211_beacon_loss(vif
);
1635 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1636 * (done by mac80211) succeeds but beacons do not resume then it
1637 * doesn't make sense to continue operation. Queue connection loss work
1638 * which can be cancelled when beacon is received.
1640 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
1641 ATH10K_CONNECTION_LOSS_HZ
);
1644 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
1646 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1647 IEEE80211_IFACE_ITER_NORMAL
,
1648 ath10k_mac_handle_beacon_miss_iter
,
1652 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
1654 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1655 connection_loss_work
.work
);
1656 struct ieee80211_vif
*vif
= arvif
->vif
;
1661 ieee80211_connection_loss(vif
);
1664 /**********************/
1665 /* Station management */
1666 /**********************/
1668 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1669 struct ieee80211_vif
*vif
)
1671 /* Some firmware revisions have unstable STA powersave when listen
1672 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1673 * generate NullFunc frames properly even if buffered frames have been
1674 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1675 * buffered frames. Often pinging the device from AP would simply fail.
1677 * As a workaround set it to 1.
1679 if (vif
->type
== NL80211_IFTYPE_STATION
)
1682 return ar
->hw
->conf
.listen_interval
;
1685 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1686 struct ieee80211_vif
*vif
,
1687 struct ieee80211_sta
*sta
,
1688 struct wmi_peer_assoc_complete_arg
*arg
)
1690 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1692 lockdep_assert_held(&ar
->conf_mutex
);
1694 ether_addr_copy(arg
->addr
, sta
->addr
);
1695 arg
->vdev_id
= arvif
->vdev_id
;
1696 arg
->peer_aid
= sta
->aid
;
1697 arg
->peer_flags
|= WMI_PEER_AUTH
;
1698 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1699 arg
->peer_num_spatial_streams
= 1;
1700 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1703 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1704 struct ieee80211_vif
*vif
,
1705 struct wmi_peer_assoc_complete_arg
*arg
)
1707 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1708 struct cfg80211_bss
*bss
;
1709 const u8
*rsnie
= NULL
;
1710 const u8
*wpaie
= NULL
;
1712 lockdep_assert_held(&ar
->conf_mutex
);
1714 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
1715 info
->bssid
, NULL
, 0, IEEE80211_BSS_TYPE_ANY
,
1716 IEEE80211_PRIVACY_ANY
);
1718 const struct cfg80211_bss_ies
*ies
;
1721 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1723 ies
= rcu_dereference(bss
->ies
);
1725 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1726 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1730 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1733 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1734 if (rsnie
|| wpaie
) {
1735 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1736 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1740 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1741 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1745 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1746 struct ieee80211_sta
*sta
,
1747 struct wmi_peer_assoc_complete_arg
*arg
)
1749 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
1750 const struct ieee80211_supported_band
*sband
;
1751 const struct ieee80211_rate
*rates
;
1756 lockdep_assert_held(&ar
->conf_mutex
);
1758 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
1759 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
1760 rates
= sband
->bitrates
;
1762 rateset
->num_rates
= 0;
1764 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
1765 if (!(ratemask
& 1))
1768 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
1769 rateset
->rates
[rateset
->num_rates
] = rate
;
1770 rateset
->num_rates
++;
1774 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
1775 struct ieee80211_sta
*sta
,
1776 struct wmi_peer_assoc_complete_arg
*arg
)
1778 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1782 lockdep_assert_held(&ar
->conf_mutex
);
1784 if (!ht_cap
->ht_supported
)
1787 arg
->peer_flags
|= WMI_PEER_HT
;
1788 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1789 ht_cap
->ampdu_factor
)) - 1;
1791 arg
->peer_mpdu_density
=
1792 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
1794 arg
->peer_ht_caps
= ht_cap
->cap
;
1795 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
1797 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
1798 arg
->peer_flags
|= WMI_PEER_LDPC
;
1800 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
1801 arg
->peer_flags
|= WMI_PEER_40MHZ
;
1802 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
1805 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
1806 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1808 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
1809 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1811 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
1812 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
1813 arg
->peer_flags
|= WMI_PEER_STBC
;
1816 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
1817 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
1818 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
1819 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
1820 arg
->peer_rate_caps
|= stbc
;
1821 arg
->peer_flags
|= WMI_PEER_STBC
;
1824 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
1825 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
1826 else if (ht_cap
->mcs
.rx_mask
[1])
1827 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
1829 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
1830 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
1831 arg
->peer_ht_rates
.rates
[n
++] = i
;
1834 * This is a workaround for HT-enabled STAs which break the spec
1835 * and have no HT capabilities RX mask (no HT RX MCS map).
1837 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1838 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1840 * Firmware asserts if such situation occurs.
1843 arg
->peer_ht_rates
.num_rates
= 8;
1844 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
1845 arg
->peer_ht_rates
.rates
[i
] = i
;
1847 arg
->peer_ht_rates
.num_rates
= n
;
1848 arg
->peer_num_spatial_streams
= sta
->rx_nss
;
1851 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
1853 arg
->peer_ht_rates
.num_rates
,
1854 arg
->peer_num_spatial_streams
);
1857 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
1858 struct ath10k_vif
*arvif
,
1859 struct ieee80211_sta
*sta
)
1865 lockdep_assert_held(&ar
->conf_mutex
);
1867 if (sta
->wme
&& sta
->uapsd_queues
) {
1868 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
1869 sta
->uapsd_queues
, sta
->max_sp
);
1871 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1872 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
1873 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
1874 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1875 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
1876 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
1877 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1878 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
1879 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
1880 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1881 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
1882 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
1884 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
1885 max_sp
= sta
->max_sp
;
1887 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1889 WMI_AP_PS_PEER_PARAM_UAPSD
,
1892 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1893 arvif
->vdev_id
, ret
);
1897 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1899 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1902 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1903 arvif
->vdev_id
, ret
);
1907 /* TODO setup this based on STA listen interval and
1908 beacon interval. Currently we don't know
1909 sta->listen_interval - mac80211 patch required.
1910 Currently use 10 seconds */
1911 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
1912 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
1915 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1916 arvif
->vdev_id
, ret
);
1924 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1925 struct ieee80211_sta
*sta
,
1926 struct wmi_peer_assoc_complete_arg
*arg
)
1928 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1931 if (!vht_cap
->vht_supported
)
1934 arg
->peer_flags
|= WMI_PEER_VHT
;
1936 if (ar
->hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
1937 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
1939 arg
->peer_vht_caps
= vht_cap
->cap
;
1941 ampdu_factor
= (vht_cap
->cap
&
1942 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1943 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1945 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1946 * zero in VHT IE. Using it would result in degraded throughput.
1947 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1948 * it if VHT max_mpdu is smaller. */
1949 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1950 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1951 ampdu_factor
)) - 1);
1953 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1954 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1956 arg
->peer_vht_rates
.rx_max_rate
=
1957 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1958 arg
->peer_vht_rates
.rx_mcs_set
=
1959 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1960 arg
->peer_vht_rates
.tx_max_rate
=
1961 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1962 arg
->peer_vht_rates
.tx_mcs_set
=
1963 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1965 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1966 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1969 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1970 struct ieee80211_vif
*vif
,
1971 struct ieee80211_sta
*sta
,
1972 struct wmi_peer_assoc_complete_arg
*arg
)
1974 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1976 switch (arvif
->vdev_type
) {
1977 case WMI_VDEV_TYPE_AP
:
1979 arg
->peer_flags
|= WMI_PEER_QOS
;
1981 if (sta
->wme
&& sta
->uapsd_queues
) {
1982 arg
->peer_flags
|= WMI_PEER_APSD
;
1983 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
1986 case WMI_VDEV_TYPE_STA
:
1987 if (vif
->bss_conf
.qos
)
1988 arg
->peer_flags
|= WMI_PEER_QOS
;
1990 case WMI_VDEV_TYPE_IBSS
:
1992 arg
->peer_flags
|= WMI_PEER_QOS
;
1998 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
1999 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
2002 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta
*sta
)
2004 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
2005 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >> 4;
2008 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2009 struct ieee80211_vif
*vif
,
2010 struct ieee80211_sta
*sta
,
2011 struct wmi_peer_assoc_complete_arg
*arg
)
2013 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2015 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
2016 case IEEE80211_BAND_2GHZ
:
2017 if (sta
->vht_cap
.vht_supported
) {
2018 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2019 phymode
= MODE_11AC_VHT40
;
2021 phymode
= MODE_11AC_VHT20
;
2022 } else if (sta
->ht_cap
.ht_supported
) {
2023 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2024 phymode
= MODE_11NG_HT40
;
2026 phymode
= MODE_11NG_HT20
;
2027 } else if (ath10k_mac_sta_has_11g_rates(sta
)) {
2034 case IEEE80211_BAND_5GHZ
:
2038 if (sta
->vht_cap
.vht_supported
) {
2039 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2040 phymode
= MODE_11AC_VHT80
;
2041 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2042 phymode
= MODE_11AC_VHT40
;
2043 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2044 phymode
= MODE_11AC_VHT20
;
2045 } else if (sta
->ht_cap
.ht_supported
) {
2046 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2047 phymode
= MODE_11NA_HT40
;
2049 phymode
= MODE_11NA_HT20
;
2059 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2060 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2062 arg
->peer_phymode
= phymode
;
2063 WARN_ON(phymode
== MODE_UNKNOWN
);
2066 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2067 struct ieee80211_vif
*vif
,
2068 struct ieee80211_sta
*sta
,
2069 struct wmi_peer_assoc_complete_arg
*arg
)
2071 lockdep_assert_held(&ar
->conf_mutex
);
2073 memset(arg
, 0, sizeof(*arg
));
2075 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2076 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
2077 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
2078 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
2079 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
2080 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2081 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2086 static const u32 ath10k_smps_map
[] = {
2087 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2088 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2089 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2090 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2093 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2095 const struct ieee80211_sta_ht_cap
*ht_cap
)
2099 if (!ht_cap
->ht_supported
)
2102 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2103 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2105 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2108 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2109 WMI_PEER_SMPS_STATE
,
2110 ath10k_smps_map
[smps
]);
2113 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2114 struct ieee80211_vif
*vif
,
2115 struct ieee80211_sta_vht_cap vht_cap
)
2117 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2122 if (!(ar
->vht_cap_info
&
2123 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2124 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2125 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2126 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2129 param
= ar
->wmi
.vdev_param
->txbf
;
2132 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2135 /* The following logic is correct. If a remote STA advertises support
2136 * for being a beamformer then we should enable us being a beamformee.
2139 if (ar
->vht_cap_info
&
2140 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2141 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2142 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2143 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2145 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2146 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2149 if (ar
->vht_cap_info
&
2150 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2151 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2152 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2153 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2155 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2156 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2159 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2160 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2162 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2163 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2165 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2167 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2175 /* can be called only in mac80211 callbacks due to `key_count` usage */
2176 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2177 struct ieee80211_vif
*vif
,
2178 struct ieee80211_bss_conf
*bss_conf
)
2180 struct ath10k
*ar
= hw
->priv
;
2181 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2182 struct ieee80211_sta_ht_cap ht_cap
;
2183 struct ieee80211_sta_vht_cap vht_cap
;
2184 struct wmi_peer_assoc_complete_arg peer_arg
;
2185 struct ieee80211_sta
*ap_sta
;
2188 lockdep_assert_held(&ar
->conf_mutex
);
2190 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2191 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2195 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2197 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2198 bss_conf
->bssid
, arvif
->vdev_id
);
2203 /* ap_sta must be accessed only within rcu section which must be left
2204 * before calling ath10k_setup_peer_smps() which might sleep. */
2205 ht_cap
= ap_sta
->ht_cap
;
2206 vht_cap
= ap_sta
->vht_cap
;
2208 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2210 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2211 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2218 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2220 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2221 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2225 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2227 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2228 arvif
->vdev_id
, ret
);
2232 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2234 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2235 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2239 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2240 "mac vdev %d up (associated) bssid %pM aid %d\n",
2241 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2243 WARN_ON(arvif
->is_up
);
2245 arvif
->aid
= bss_conf
->aid
;
2246 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2248 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2250 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2251 arvif
->vdev_id
, ret
);
2255 arvif
->is_up
= true;
2257 /* Workaround: Some firmware revisions (tested with qca6174
2258 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2259 * poked with peer param command.
2261 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2262 WMI_PEER_DUMMY_VAR
, 1);
2264 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2265 arvif
->bssid
, arvif
->vdev_id
, ret
);
2270 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2271 struct ieee80211_vif
*vif
)
2273 struct ath10k
*ar
= hw
->priv
;
2274 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2275 struct ieee80211_sta_vht_cap vht_cap
= {};
2278 lockdep_assert_held(&ar
->conf_mutex
);
2280 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2281 arvif
->vdev_id
, arvif
->bssid
);
2283 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2285 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
2286 arvif
->vdev_id
, ret
);
2288 arvif
->def_wep_key_idx
= -1;
2290 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2292 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2293 arvif
->vdev_id
, ret
);
2297 arvif
->is_up
= false;
2299 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
2302 static int ath10k_station_assoc(struct ath10k
*ar
,
2303 struct ieee80211_vif
*vif
,
2304 struct ieee80211_sta
*sta
,
2307 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2308 struct wmi_peer_assoc_complete_arg peer_arg
;
2311 lockdep_assert_held(&ar
->conf_mutex
);
2313 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2315 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2316 sta
->addr
, arvif
->vdev_id
, ret
);
2320 peer_arg
.peer_reassoc
= reassoc
;
2321 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2323 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2324 sta
->addr
, arvif
->vdev_id
, ret
);
2328 /* Re-assoc is run only to update supported rates for given station. It
2329 * doesn't make much sense to reconfigure the peer completely.
2332 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2335 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2336 arvif
->vdev_id
, ret
);
2340 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2342 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2343 sta
->addr
, arvif
->vdev_id
, ret
);
2348 arvif
->num_legacy_stations
++;
2349 ret
= ath10k_recalc_rtscts_prot(arvif
);
2351 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2352 arvif
->vdev_id
, ret
);
2357 /* Plumb cached keys only for static WEP */
2358 if (arvif
->def_wep_key_idx
!= -1) {
2359 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2361 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2362 arvif
->vdev_id
, ret
);
2371 static int ath10k_station_disassoc(struct ath10k
*ar
,
2372 struct ieee80211_vif
*vif
,
2373 struct ieee80211_sta
*sta
)
2375 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2378 lockdep_assert_held(&ar
->conf_mutex
);
2381 arvif
->num_legacy_stations
--;
2382 ret
= ath10k_recalc_rtscts_prot(arvif
);
2384 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2385 arvif
->vdev_id
, ret
);
2390 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2392 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2393 arvif
->vdev_id
, ret
);
2404 static int ath10k_update_channel_list(struct ath10k
*ar
)
2406 struct ieee80211_hw
*hw
= ar
->hw
;
2407 struct ieee80211_supported_band
**bands
;
2408 enum ieee80211_band band
;
2409 struct ieee80211_channel
*channel
;
2410 struct wmi_scan_chan_list_arg arg
= {0};
2411 struct wmi_channel_arg
*ch
;
2417 lockdep_assert_held(&ar
->conf_mutex
);
2419 bands
= hw
->wiphy
->bands
;
2420 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2424 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2425 if (bands
[band
]->channels
[i
].flags
&
2426 IEEE80211_CHAN_DISABLED
)
2433 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2434 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2439 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2443 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2444 channel
= &bands
[band
]->channels
[i
];
2446 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2449 ch
->allow_ht
= true;
2451 /* FIXME: when should we really allow VHT? */
2452 ch
->allow_vht
= true;
2455 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2458 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2461 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2463 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2464 ch
->passive
= passive
;
2466 ch
->freq
= channel
->center_freq
;
2467 ch
->band_center_freq1
= channel
->center_freq
;
2469 ch
->max_power
= channel
->max_power
* 2;
2470 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2471 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2472 ch
->reg_class_id
= 0; /* FIXME */
2474 /* FIXME: why use only legacy modes, why not any
2475 * HT/VHT modes? Would that even make any
2477 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2478 ch
->mode
= MODE_11G
;
2480 ch
->mode
= MODE_11A
;
2482 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2485 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2486 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2487 ch
- arg
.channels
, arg
.n_channels
,
2488 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2489 ch
->max_antenna_gain
, ch
->mode
);
2495 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2496 kfree(arg
.channels
);
2501 static enum wmi_dfs_region
2502 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2504 switch (dfs_region
) {
2505 case NL80211_DFS_UNSET
:
2506 return WMI_UNINIT_DFS_DOMAIN
;
2507 case NL80211_DFS_FCC
:
2508 return WMI_FCC_DFS_DOMAIN
;
2509 case NL80211_DFS_ETSI
:
2510 return WMI_ETSI_DFS_DOMAIN
;
2511 case NL80211_DFS_JP
:
2512 return WMI_MKK4_DFS_DOMAIN
;
2514 return WMI_UNINIT_DFS_DOMAIN
;
2517 static void ath10k_regd_update(struct ath10k
*ar
)
2519 struct reg_dmn_pair_mapping
*regpair
;
2521 enum wmi_dfs_region wmi_dfs_reg
;
2522 enum nl80211_dfs_regions nl_dfs_reg
;
2524 lockdep_assert_held(&ar
->conf_mutex
);
2526 ret
= ath10k_update_channel_list(ar
);
2528 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2530 regpair
= ar
->ath_common
.regulatory
.regpair
;
2532 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2533 nl_dfs_reg
= ar
->dfs_detector
->region
;
2534 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2536 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2539 /* Target allows setting up per-band regdomain but ath_common provides
2540 * a combined one only */
2541 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2542 regpair
->reg_domain
,
2543 regpair
->reg_domain
, /* 2ghz */
2544 regpair
->reg_domain
, /* 5ghz */
2545 regpair
->reg_2ghz_ctl
,
2546 regpair
->reg_5ghz_ctl
,
2549 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2552 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2553 struct regulatory_request
*request
)
2555 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2556 struct ath10k
*ar
= hw
->priv
;
2559 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2561 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2562 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
2563 request
->dfs_region
);
2564 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
2565 request
->dfs_region
);
2567 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2568 request
->dfs_region
);
2571 mutex_lock(&ar
->conf_mutex
);
2572 if (ar
->state
== ATH10K_STATE_ON
)
2573 ath10k_regd_update(ar
);
2574 mutex_unlock(&ar
->conf_mutex
);
2581 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
2583 if (ieee80211_is_mgmt(hdr
->frame_control
))
2584 return HTT_DATA_TX_EXT_TID_MGMT
;
2586 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2587 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2589 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
2590 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2592 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
2595 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
2598 return ath10k_vif_to_arvif(vif
)->vdev_id
;
2600 if (ar
->monitor_started
)
2601 return ar
->monitor_vdev_id
;
2603 ath10k_warn(ar
, "failed to resolve vdev id\n");
2607 static enum ath10k_hw_txrx_mode
2608 ath10k_tx_h_get_txmode(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
2609 struct ieee80211_sta
*sta
, struct sk_buff
*skb
)
2611 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
2612 __le16 fc
= hdr
->frame_control
;
2614 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
2615 return ATH10K_HW_TXRX_RAW
;
2617 if (ieee80211_is_mgmt(fc
))
2618 return ATH10K_HW_TXRX_MGMT
;
2622 * NullFunc frames are mostly used to ping if a client or AP are still
2623 * reachable and responsive. This implies tx status reports must be
2624 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2625 * come to a conclusion that the other end disappeared and tear down
2626 * BSS connection or it can never disconnect from BSS/client (which is
2629 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2630 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2631 * which seems to deliver correct tx reports for NullFunc frames. The
2632 * downside of using it is it ignores client powersave state so it can
2633 * end up disconnecting sleeping clients in AP mode. It should fix STA
2634 * mode though because AP don't sleep.
2636 if (ar
->htt
.target_version_major
< 3 &&
2637 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
2638 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
, ar
->fw_features
))
2639 return ATH10K_HW_TXRX_MGMT
;
2643 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2644 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2645 * to work with Ethernet txmode so use it.
2647 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
2648 return ATH10K_HW_TXRX_ETHERNET
;
2650 return ATH10K_HW_TXRX_NATIVE_WIFI
;
2653 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2654 * Control in the header.
2656 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2658 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
2659 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
2662 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2665 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
2666 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
2667 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
2668 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
2670 /* Some firmware revisions don't handle sending QoS NullFunc well.
2671 * These frames are mainly used for CQM purposes so it doesn't really
2672 * matter whether QoS NullFunc or NullFunc are sent.
2674 hdr
= (void *)skb
->data
;
2675 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
2676 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2678 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2681 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
2683 struct ieee80211_hdr
*hdr
;
2684 struct rfc1042_hdr
*rfc1042
;
2691 hdr
= (void *)skb
->data
;
2692 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
2693 rfc1042
= (void *)skb
->data
+ hdrlen
;
2695 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
2696 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
2697 type
= rfc1042
->snap_type
;
2699 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
2700 skb_push(skb
, sizeof(*eth
));
2702 eth
= (void *)skb
->data
;
2703 ether_addr_copy(eth
->h_dest
, da
);
2704 ether_addr_copy(eth
->h_source
, sa
);
2705 eth
->h_proto
= type
;
2708 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
2709 struct ieee80211_vif
*vif
,
2710 struct sk_buff
*skb
)
2712 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2713 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2715 /* This is case only for P2P_GO */
2716 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
2717 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
2720 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
2721 spin_lock_bh(&ar
->data_lock
);
2722 if (arvif
->u
.ap
.noa_data
)
2723 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
2725 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
2726 arvif
->u
.ap
.noa_data
,
2727 arvif
->u
.ap
.noa_len
);
2728 spin_unlock_bh(&ar
->data_lock
);
2732 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
2734 /* FIXME: Not really sure since when the behaviour changed. At some
2735 * point new firmware stopped requiring creation of peer entries for
2736 * offchannel tx (and actually creating them causes issues with wmi-htc
2737 * tx credit replenishment and reliability). Assuming it's at least 3.4
2738 * because that's when the `freq` was introduced to TX_FRM HTT command.
2740 return !(ar
->htt
.target_version_major
>= 3 &&
2741 ar
->htt
.target_version_minor
>= 4);
2744 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
2746 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
2749 spin_lock_bh(&ar
->data_lock
);
2751 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
2752 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
2757 __skb_queue_tail(q
, skb
);
2758 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
2761 spin_unlock_bh(&ar
->data_lock
);
2766 static void ath10k_mac_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
2768 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
2769 struct ath10k_htt
*htt
= &ar
->htt
;
2772 switch (cb
->txmode
) {
2773 case ATH10K_HW_TXRX_RAW
:
2774 case ATH10K_HW_TXRX_NATIVE_WIFI
:
2775 case ATH10K_HW_TXRX_ETHERNET
:
2776 ret
= ath10k_htt_tx(htt
, skb
);
2778 case ATH10K_HW_TXRX_MGMT
:
2779 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2781 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
2782 else if (ar
->htt
.target_version_major
>= 3)
2783 ret
= ath10k_htt_tx(htt
, skb
);
2785 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
2790 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
2792 ieee80211_free_txskb(ar
->hw
, skb
);
2796 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
2798 struct sk_buff
*skb
;
2801 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2805 ieee80211_free_txskb(ar
->hw
, skb
);
2809 void ath10k_offchan_tx_work(struct work_struct
*work
)
2811 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
2812 struct ath10k_peer
*peer
;
2813 struct ieee80211_hdr
*hdr
;
2814 struct sk_buff
*skb
;
2815 const u8
*peer_addr
;
2819 /* FW requirement: We must create a peer before FW will send out
2820 * an offchannel frame. Otherwise the frame will be stuck and
2821 * never transmitted. We delete the peer upon tx completion.
2822 * It is unlikely that a peer for offchannel tx will already be
2823 * present. However it may be in some rare cases so account for that.
2824 * Otherwise we might remove a legitimate peer and break stuff. */
2827 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2831 mutex_lock(&ar
->conf_mutex
);
2833 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
2836 hdr
= (struct ieee80211_hdr
*)skb
->data
;
2837 peer_addr
= ieee80211_get_DA(hdr
);
2838 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
2840 spin_lock_bh(&ar
->data_lock
);
2841 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
2842 spin_unlock_bh(&ar
->data_lock
);
2845 /* FIXME: should this use ath10k_warn()? */
2846 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
2847 peer_addr
, vdev_id
);
2850 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
,
2851 WMI_PEER_TYPE_DEFAULT
);
2853 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
2854 peer_addr
, vdev_id
, ret
);
2857 spin_lock_bh(&ar
->data_lock
);
2858 reinit_completion(&ar
->offchan_tx_completed
);
2859 ar
->offchan_tx_skb
= skb
;
2860 spin_unlock_bh(&ar
->data_lock
);
2862 ath10k_mac_tx(ar
, skb
);
2864 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
2867 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
2871 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
2873 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
2874 peer_addr
, vdev_id
, ret
);
2877 mutex_unlock(&ar
->conf_mutex
);
2881 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
2883 struct sk_buff
*skb
;
2886 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2890 ieee80211_free_txskb(ar
->hw
, skb
);
2894 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
2896 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
2897 struct sk_buff
*skb
;
2901 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2905 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
2907 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
2909 ieee80211_free_txskb(ar
->hw
, skb
);
2918 void __ath10k_scan_finish(struct ath10k
*ar
)
2920 lockdep_assert_held(&ar
->data_lock
);
2922 switch (ar
->scan
.state
) {
2923 case ATH10K_SCAN_IDLE
:
2925 case ATH10K_SCAN_RUNNING
:
2926 if (ar
->scan
.is_roc
)
2927 ieee80211_remain_on_channel_expired(ar
->hw
);
2929 case ATH10K_SCAN_ABORTING
:
2930 if (!ar
->scan
.is_roc
)
2931 ieee80211_scan_completed(ar
->hw
,
2933 ATH10K_SCAN_ABORTING
));
2935 case ATH10K_SCAN_STARTING
:
2936 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
2937 ar
->scan_channel
= NULL
;
2938 ath10k_offchan_tx_purge(ar
);
2939 cancel_delayed_work(&ar
->scan
.timeout
);
2940 complete_all(&ar
->scan
.completed
);
2945 void ath10k_scan_finish(struct ath10k
*ar
)
2947 spin_lock_bh(&ar
->data_lock
);
2948 __ath10k_scan_finish(ar
);
2949 spin_unlock_bh(&ar
->data_lock
);
2952 static int ath10k_scan_stop(struct ath10k
*ar
)
2954 struct wmi_stop_scan_arg arg
= {
2955 .req_id
= 1, /* FIXME */
2956 .req_type
= WMI_SCAN_STOP_ONE
,
2957 .u
.scan_id
= ATH10K_SCAN_ID
,
2961 lockdep_assert_held(&ar
->conf_mutex
);
2963 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
2965 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
2969 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
2971 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
2973 } else if (ret
> 0) {
2978 /* Scan state should be updated upon scan completion but in case
2979 * firmware fails to deliver the event (for whatever reason) it is
2980 * desired to clean up scan state anyway. Firmware may have just
2981 * dropped the scan completion event delivery due to transport pipe
2982 * being overflown with data and/or it can recover on its own before
2983 * next scan request is submitted.
2985 spin_lock_bh(&ar
->data_lock
);
2986 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
2987 __ath10k_scan_finish(ar
);
2988 spin_unlock_bh(&ar
->data_lock
);
2993 static void ath10k_scan_abort(struct ath10k
*ar
)
2997 lockdep_assert_held(&ar
->conf_mutex
);
2999 spin_lock_bh(&ar
->data_lock
);
3001 switch (ar
->scan
.state
) {
3002 case ATH10K_SCAN_IDLE
:
3003 /* This can happen if timeout worker kicked in and called
3004 * abortion while scan completion was being processed.
3007 case ATH10K_SCAN_STARTING
:
3008 case ATH10K_SCAN_ABORTING
:
3009 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3010 ath10k_scan_state_str(ar
->scan
.state
),
3013 case ATH10K_SCAN_RUNNING
:
3014 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
3015 spin_unlock_bh(&ar
->data_lock
);
3017 ret
= ath10k_scan_stop(ar
);
3019 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
3021 spin_lock_bh(&ar
->data_lock
);
3025 spin_unlock_bh(&ar
->data_lock
);
3028 void ath10k_scan_timeout_work(struct work_struct
*work
)
3030 struct ath10k
*ar
= container_of(work
, struct ath10k
,
3033 mutex_lock(&ar
->conf_mutex
);
3034 ath10k_scan_abort(ar
);
3035 mutex_unlock(&ar
->conf_mutex
);
3038 static int ath10k_start_scan(struct ath10k
*ar
,
3039 const struct wmi_start_scan_arg
*arg
)
3043 lockdep_assert_held(&ar
->conf_mutex
);
3045 ret
= ath10k_wmi_start_scan(ar
, arg
);
3049 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
3051 ret
= ath10k_scan_stop(ar
);
3053 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
3058 /* If we failed to start the scan, return error code at
3059 * this point. This is probably due to some issue in the
3060 * firmware, but no need to wedge the driver due to that...
3062 spin_lock_bh(&ar
->data_lock
);
3063 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
3064 spin_unlock_bh(&ar
->data_lock
);
3067 spin_unlock_bh(&ar
->data_lock
);
3069 /* Add a 200ms margin to account for event/command processing */
3070 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
3071 msecs_to_jiffies(arg
->max_scan_time
+200));
3075 /**********************/
3076 /* mac80211 callbacks */
3077 /**********************/
3079 static void ath10k_tx(struct ieee80211_hw
*hw
,
3080 struct ieee80211_tx_control
*control
,
3081 struct sk_buff
*skb
)
3083 struct ath10k
*ar
= hw
->priv
;
3084 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3085 struct ieee80211_vif
*vif
= info
->control
.vif
;
3086 struct ieee80211_sta
*sta
= control
->sta
;
3087 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3088 __le16 fc
= hdr
->frame_control
;
3090 /* We should disable CCK RATE due to P2P */
3091 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3092 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3094 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
3095 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3096 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
3097 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
3098 ATH10K_SKB_CB(skb
)->txmode
= ath10k_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3099 ATH10K_SKB_CB(skb
)->is_protected
= ieee80211_has_protected(fc
);
3101 switch (ATH10K_SKB_CB(skb
)->txmode
) {
3102 case ATH10K_HW_TXRX_MGMT
:
3103 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3104 ath10k_tx_h_nwifi(hw
, skb
);
3105 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3106 ath10k_tx_h_seq_no(vif
, skb
);
3108 case ATH10K_HW_TXRX_ETHERNET
:
3109 ath10k_tx_h_8023(skb
);
3111 case ATH10K_HW_TXRX_RAW
:
3112 /* FIXME: Packet injection isn't implemented. It should be
3113 * doable with firmware 10.2 on qca988x.
3116 ieee80211_free_txskb(hw
, skb
);
3120 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3121 spin_lock_bh(&ar
->data_lock
);
3122 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
3123 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
3124 spin_unlock_bh(&ar
->data_lock
);
3126 if (ath10k_mac_need_offchan_tx_work(ar
)) {
3127 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3128 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
3130 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
3133 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3134 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3139 ath10k_mac_tx(ar
, skb
);
3142 /* Must not be called with conf_mutex held as workers can use that also. */
3143 void ath10k_drain_tx(struct ath10k
*ar
)
3145 /* make sure rcu-protected mac80211 tx path itself is drained */
3148 ath10k_offchan_tx_purge(ar
);
3149 ath10k_mgmt_over_wmi_tx_purge(ar
);
3151 cancel_work_sync(&ar
->offchan_tx_work
);
3152 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
3155 void ath10k_halt(struct ath10k
*ar
)
3157 struct ath10k_vif
*arvif
;
3159 lockdep_assert_held(&ar
->conf_mutex
);
3161 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
3162 ar
->filter_flags
= 0;
3163 ar
->monitor
= false;
3165 if (ar
->monitor_started
)
3166 ath10k_monitor_stop(ar
);
3168 ar
->monitor_started
= false;
3170 ath10k_scan_finish(ar
);
3171 ath10k_peer_cleanup_all(ar
);
3172 ath10k_core_stop(ar
);
3173 ath10k_hif_power_down(ar
);
3175 spin_lock_bh(&ar
->data_lock
);
3176 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
3177 ath10k_mac_vif_beacon_cleanup(arvif
);
3178 spin_unlock_bh(&ar
->data_lock
);
3181 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
3183 struct ath10k
*ar
= hw
->priv
;
3185 mutex_lock(&ar
->conf_mutex
);
3187 if (ar
->cfg_tx_chainmask
) {
3188 *tx_ant
= ar
->cfg_tx_chainmask
;
3189 *rx_ant
= ar
->cfg_rx_chainmask
;
3191 *tx_ant
= ar
->supp_tx_chainmask
;
3192 *rx_ant
= ar
->supp_rx_chainmask
;
3195 mutex_unlock(&ar
->conf_mutex
);
3200 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
3202 /* It is not clear that allowing gaps in chainmask
3203 * is helpful. Probably it will not do what user
3204 * is hoping for, so warn in that case.
3206 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
3209 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3213 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
3217 lockdep_assert_held(&ar
->conf_mutex
);
3219 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
3220 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
3222 ar
->cfg_tx_chainmask
= tx_ant
;
3223 ar
->cfg_rx_chainmask
= rx_ant
;
3225 if ((ar
->state
!= ATH10K_STATE_ON
) &&
3226 (ar
->state
!= ATH10K_STATE_RESTARTED
))
3229 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
3232 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
3237 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
3240 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
3248 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
3250 struct ath10k
*ar
= hw
->priv
;
3253 mutex_lock(&ar
->conf_mutex
);
3254 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
3255 mutex_unlock(&ar
->conf_mutex
);
3259 static int ath10k_start(struct ieee80211_hw
*hw
)
3261 struct ath10k
*ar
= hw
->priv
;
3265 * This makes sense only when restarting hw. It is harmless to call
3266 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3267 * commands will be submitted while restarting.
3269 ath10k_drain_tx(ar
);
3271 mutex_lock(&ar
->conf_mutex
);
3273 switch (ar
->state
) {
3274 case ATH10K_STATE_OFF
:
3275 ar
->state
= ATH10K_STATE_ON
;
3277 case ATH10K_STATE_RESTARTING
:
3279 ar
->state
= ATH10K_STATE_RESTARTED
;
3281 case ATH10K_STATE_ON
:
3282 case ATH10K_STATE_RESTARTED
:
3283 case ATH10K_STATE_WEDGED
:
3287 case ATH10K_STATE_UTF
:
3292 ret
= ath10k_hif_power_up(ar
);
3294 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
3298 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
3300 ath10k_err(ar
, "Could not init core: %d\n", ret
);
3301 goto err_power_down
;
3304 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
3306 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
3310 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
3312 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
3316 if (ar
->cfg_tx_chainmask
)
3317 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
3318 ar
->cfg_rx_chainmask
);
3321 * By default FW set ARP frames ac to voice (6). In that case ARP
3322 * exchange is not working properly for UAPSD enabled AP. ARP requests
3323 * which arrives with access category 0 are processed by network stack
3324 * and send back with access category 0, but FW changes access category
3325 * to 6. Set ARP frames access category to best effort (0) solves
3329 ret
= ath10k_wmi_pdev_set_param(ar
,
3330 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
3332 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
3337 ret
= ath10k_wmi_pdev_set_param(ar
,
3338 ar
->wmi
.pdev_param
->ani_enable
, 1);
3340 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
3345 ar
->ani_enabled
= true;
3347 ar
->num_started_vdevs
= 0;
3348 ath10k_regd_update(ar
);
3350 ath10k_spectral_start(ar
);
3351 ath10k_thermal_set_throttling(ar
);
3353 mutex_unlock(&ar
->conf_mutex
);
3357 ath10k_core_stop(ar
);
3360 ath10k_hif_power_down(ar
);
3363 ar
->state
= ATH10K_STATE_OFF
;
3366 mutex_unlock(&ar
->conf_mutex
);
3370 static void ath10k_stop(struct ieee80211_hw
*hw
)
3372 struct ath10k
*ar
= hw
->priv
;
3374 ath10k_drain_tx(ar
);
3376 mutex_lock(&ar
->conf_mutex
);
3377 if (ar
->state
!= ATH10K_STATE_OFF
) {
3379 ar
->state
= ATH10K_STATE_OFF
;
3381 mutex_unlock(&ar
->conf_mutex
);
3383 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3384 cancel_work_sync(&ar
->restart_work
);
3387 static int ath10k_config_ps(struct ath10k
*ar
)
3389 struct ath10k_vif
*arvif
;
3392 lockdep_assert_held(&ar
->conf_mutex
);
3394 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3395 ret
= ath10k_mac_vif_setup_ps(arvif
);
3397 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
3405 static const char *chandef_get_width(enum nl80211_chan_width width
)
3408 case NL80211_CHAN_WIDTH_20_NOHT
:
3410 case NL80211_CHAN_WIDTH_20
:
3412 case NL80211_CHAN_WIDTH_40
:
3414 case NL80211_CHAN_WIDTH_80
:
3416 case NL80211_CHAN_WIDTH_80P80
:
3418 case NL80211_CHAN_WIDTH_160
:
3420 case NL80211_CHAN_WIDTH_5
:
3422 case NL80211_CHAN_WIDTH_10
:
3428 static void ath10k_config_chan(struct ath10k
*ar
)
3430 struct ath10k_vif
*arvif
;
3433 lockdep_assert_held(&ar
->conf_mutex
);
3435 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3436 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3437 ar
->chandef
.chan
->center_freq
,
3438 ar
->chandef
.center_freq1
,
3439 ar
->chandef
.center_freq2
,
3440 chandef_get_width(ar
->chandef
.width
));
3442 /* First stop monitor interface. Some FW versions crash if there's a
3443 * lone monitor interface. */
3444 if (ar
->monitor_started
)
3445 ath10k_monitor_stop(ar
);
3447 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3448 if (!arvif
->is_started
)
3454 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3457 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
3459 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
3460 arvif
->vdev_id
, ret
);
3465 /* all vdevs are downed now - attempt to restart and re-up them */
3467 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3468 if (!arvif
->is_started
)
3471 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3474 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3476 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
3479 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
3481 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
3484 ret
= ath10k_vdev_restart(arvif
);
3486 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
3487 arvif
->vdev_id
, ret
);
3494 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
3497 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
3498 arvif
->vdev_id
, ret
);
3503 ath10k_monitor_recalc(ar
);
3506 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
3511 lockdep_assert_held(&ar
->conf_mutex
);
3513 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
3515 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
3516 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3518 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
3523 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
3524 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3526 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
3534 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
3536 struct ath10k_vif
*arvif
;
3537 int ret
, txpower
= -1;
3539 lockdep_assert_held(&ar
->conf_mutex
);
3541 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3542 WARN_ON(arvif
->txpower
< 0);
3545 txpower
= arvif
->txpower
;
3547 txpower
= min(txpower
, arvif
->txpower
);
3550 if (WARN_ON(txpower
== -1))
3553 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
3555 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
3563 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
3565 struct ath10k
*ar
= hw
->priv
;
3566 struct ieee80211_conf
*conf
= &hw
->conf
;
3569 mutex_lock(&ar
->conf_mutex
);
3571 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
3572 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3573 "mac config channel %dMHz flags 0x%x radar %d\n",
3574 conf
->chandef
.chan
->center_freq
,
3575 conf
->chandef
.chan
->flags
,
3576 conf
->radar_enabled
);
3578 spin_lock_bh(&ar
->data_lock
);
3579 ar
->rx_channel
= conf
->chandef
.chan
;
3580 spin_unlock_bh(&ar
->data_lock
);
3582 ar
->radar_enabled
= conf
->radar_enabled
;
3583 ath10k_recalc_radar_detection(ar
);
3585 if (!cfg80211_chandef_identical(&ar
->chandef
, &conf
->chandef
)) {
3586 ar
->chandef
= conf
->chandef
;
3587 ath10k_config_chan(ar
);
3591 if (changed
& IEEE80211_CONF_CHANGE_PS
)
3592 ath10k_config_ps(ar
);
3594 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
3595 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
3596 ret
= ath10k_monitor_recalc(ar
);
3598 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
3601 mutex_unlock(&ar
->conf_mutex
);
3605 static u32
get_nss_from_chainmask(u16 chain_mask
)
3607 if ((chain_mask
& 0x15) == 0x15)
3609 else if ((chain_mask
& 0x7) == 0x7)
3611 else if ((chain_mask
& 0x3) == 0x3)
3618 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3619 * because we will send mgmt frames without CCK. This requirement
3620 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3623 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
3624 struct ieee80211_vif
*vif
)
3626 struct ath10k
*ar
= hw
->priv
;
3627 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3628 enum wmi_sta_powersave_param param
;
3634 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
3636 mutex_lock(&ar
->conf_mutex
);
3638 memset(arvif
, 0, sizeof(*arvif
));
3643 INIT_LIST_HEAD(&arvif
->list
);
3644 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
3645 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
3646 ath10k_mac_vif_sta_connection_loss_work
);
3648 if (ar
->free_vdev_map
== 0) {
3649 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
3653 bit
= __ffs64(ar
->free_vdev_map
);
3655 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
3656 bit
, ar
->free_vdev_map
);
3658 arvif
->vdev_id
= bit
;
3659 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
3661 switch (vif
->type
) {
3662 case NL80211_IFTYPE_P2P_DEVICE
:
3663 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
3664 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
3666 case NL80211_IFTYPE_UNSPECIFIED
:
3667 case NL80211_IFTYPE_STATION
:
3668 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
3670 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
3672 case NL80211_IFTYPE_ADHOC
:
3673 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
3675 case NL80211_IFTYPE_AP
:
3676 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
3679 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
3681 case NL80211_IFTYPE_MONITOR
:
3682 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
3689 /* Some firmware revisions don't wait for beacon tx completion before
3690 * sending another SWBA event. This could lead to hardware using old
3691 * (freed) beacon data in some cases, e.g. tx credit starvation
3692 * combined with missed TBTT. This is very very rare.
3694 * On non-IOMMU-enabled hosts this could be a possible security issue
3695 * because hw could beacon some random data on the air. On
3696 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3697 * device would crash.
3699 * Since there are no beacon tx completions (implicit nor explicit)
3700 * propagated to host the only workaround for this is to allocate a
3701 * DMA-coherent buffer for a lifetime of a vif and use it for all
3702 * beacon tx commands. Worst case for this approach is some beacons may
3703 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3705 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
3706 vif
->type
== NL80211_IFTYPE_AP
) {
3707 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
3708 IEEE80211_MAX_FRAME_LEN
,
3709 &arvif
->beacon_paddr
,
3711 if (!arvif
->beacon_buf
) {
3713 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
3719 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3720 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
3721 arvif
->beacon_buf
? "single-buf" : "per-skb");
3723 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
3724 arvif
->vdev_subtype
, vif
->addr
);
3726 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
3727 arvif
->vdev_id
, ret
);
3731 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
3732 list_add(&arvif
->list
, &ar
->arvifs
);
3734 /* It makes no sense to have firmware do keepalives. mac80211 already
3735 * takes care of this with idle connection polling.
3737 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
3739 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
3740 arvif
->vdev_id
, ret
);
3741 goto err_vdev_delete
;
3744 arvif
->def_wep_key_idx
= -1;
3746 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
3747 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3748 ATH10K_HW_TXRX_NATIVE_WIFI
);
3749 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3750 if (ret
&& ret
!= -EOPNOTSUPP
) {
3751 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
3752 arvif
->vdev_id
, ret
);
3753 goto err_vdev_delete
;
3756 if (ar
->cfg_tx_chainmask
) {
3757 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
3759 vdev_param
= ar
->wmi
.vdev_param
->nss
;
3760 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3763 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3764 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
3766 goto err_vdev_delete
;
3770 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3771 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
,
3772 WMI_PEER_TYPE_DEFAULT
);
3774 ath10k_warn(ar
, "failed to create vdev %i peer for AP: %d\n",
3775 arvif
->vdev_id
, ret
);
3776 goto err_vdev_delete
;
3779 ret
= ath10k_mac_set_kickout(arvif
);
3781 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
3782 arvif
->vdev_id
, ret
);
3783 goto err_peer_delete
;
3787 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
3788 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
3789 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
3790 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3793 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
3794 arvif
->vdev_id
, ret
);
3795 goto err_peer_delete
;
3798 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
3800 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
3801 arvif
->vdev_id
, ret
);
3802 goto err_peer_delete
;
3805 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
3807 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
3808 arvif
->vdev_id
, ret
);
3809 goto err_peer_delete
;
3813 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
3815 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
3816 arvif
->vdev_id
, ret
);
3817 goto err_peer_delete
;
3820 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
3822 ath10k_warn(ar
, "failed to set frag threshold for vdev %d: %d\n",
3823 arvif
->vdev_id
, ret
);
3824 goto err_peer_delete
;
3827 arvif
->txpower
= vif
->bss_conf
.txpower
;
3828 ret
= ath10k_mac_txpower_recalc(ar
);
3830 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
3831 goto err_peer_delete
;
3834 mutex_unlock(&ar
->conf_mutex
);
3838 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
3839 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
3842 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
3843 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
3844 list_del(&arvif
->list
);
3847 if (arvif
->beacon_buf
) {
3848 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
3849 arvif
->beacon_buf
, arvif
->beacon_paddr
);
3850 arvif
->beacon_buf
= NULL
;
3853 mutex_unlock(&ar
->conf_mutex
);
3858 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
3859 struct ieee80211_vif
*vif
)
3861 struct ath10k
*ar
= hw
->priv
;
3862 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3865 cancel_work_sync(&arvif
->ap_csa_work
);
3866 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
3868 mutex_lock(&ar
->conf_mutex
);
3870 spin_lock_bh(&ar
->data_lock
);
3871 ath10k_mac_vif_beacon_cleanup(arvif
);
3872 spin_unlock_bh(&ar
->data_lock
);
3874 ret
= ath10k_spectral_vif_stop(arvif
);
3876 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
3877 arvif
->vdev_id
, ret
);
3879 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
3880 list_del(&arvif
->list
);
3882 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3883 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
3886 ath10k_warn(ar
, "failed to submit AP self-peer removal on vdev %i: %d\n",
3887 arvif
->vdev_id
, ret
);
3889 kfree(arvif
->u
.ap
.noa_data
);
3892 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
3895 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
3897 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
3898 arvif
->vdev_id
, ret
);
3900 /* Some firmware revisions don't notify host about self-peer removal
3901 * until after associated vdev is deleted.
3903 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3904 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
3907 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
3908 arvif
->vdev_id
, ret
);
3910 spin_lock_bh(&ar
->data_lock
);
3912 spin_unlock_bh(&ar
->data_lock
);
3915 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
3917 mutex_unlock(&ar
->conf_mutex
);
3921 * FIXME: Has to be verified.
3923 #define SUPPORTED_FILTERS \
3924 (FIF_PROMISC_IN_BSS | \
3929 FIF_BCN_PRBRESP_PROMISC | \
3933 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
3934 unsigned int changed_flags
,
3935 unsigned int *total_flags
,
3938 struct ath10k
*ar
= hw
->priv
;
3941 mutex_lock(&ar
->conf_mutex
);
3943 changed_flags
&= SUPPORTED_FILTERS
;
3944 *total_flags
&= SUPPORTED_FILTERS
;
3945 ar
->filter_flags
= *total_flags
;
3947 ret
= ath10k_monitor_recalc(ar
);
3949 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
3951 mutex_unlock(&ar
->conf_mutex
);
3954 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
3955 struct ieee80211_vif
*vif
,
3956 struct ieee80211_bss_conf
*info
,
3959 struct ath10k
*ar
= hw
->priv
;
3960 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3962 u32 vdev_param
, pdev_param
, slottime
, preamble
;
3964 mutex_lock(&ar
->conf_mutex
);
3966 if (changed
& BSS_CHANGED_IBSS
)
3967 ath10k_control_ibss(arvif
, info
, vif
->addr
);
3969 if (changed
& BSS_CHANGED_BEACON_INT
) {
3970 arvif
->beacon_interval
= info
->beacon_int
;
3971 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
3972 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3973 arvif
->beacon_interval
);
3974 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3975 "mac vdev %d beacon_interval %d\n",
3976 arvif
->vdev_id
, arvif
->beacon_interval
);
3979 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
3980 arvif
->vdev_id
, ret
);
3983 if (changed
& BSS_CHANGED_BEACON
) {
3984 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3985 "vdev %d set beacon tx mode to staggered\n",
3988 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
3989 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
3990 WMI_BEACON_STAGGERED_MODE
);
3992 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
3993 arvif
->vdev_id
, ret
);
3995 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3997 ath10k_warn(ar
, "failed to update beacon template: %d\n",
4001 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
4002 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
4004 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
4005 arvif
->vdev_id
, ret
);
4008 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
4009 arvif
->dtim_period
= info
->dtim_period
;
4011 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4012 "mac vdev %d dtim_period %d\n",
4013 arvif
->vdev_id
, arvif
->dtim_period
);
4015 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
4016 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4017 arvif
->dtim_period
);
4019 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
4020 arvif
->vdev_id
, ret
);
4023 if (changed
& BSS_CHANGED_SSID
&&
4024 vif
->type
== NL80211_IFTYPE_AP
) {
4025 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
4027 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
4028 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
4031 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
4032 ether_addr_copy(arvif
->bssid
, info
->bssid
);
4034 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4035 ath10k_control_beaconing(arvif
, info
);
4037 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
4038 arvif
->use_cts_prot
= info
->use_cts_prot
;
4039 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
4040 arvif
->vdev_id
, info
->use_cts_prot
);
4042 ret
= ath10k_recalc_rtscts_prot(arvif
);
4044 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4045 arvif
->vdev_id
, ret
);
4047 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
4048 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4049 info
->use_cts_prot
? 1 : 0);
4051 ath10k_warn(ar
, "failed to set protection mode %d on vdev %i: %d\n",
4052 info
->use_cts_prot
, arvif
->vdev_id
, ret
);
4055 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4056 if (info
->use_short_slot
)
4057 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
4060 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
4062 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
4063 arvif
->vdev_id
, slottime
);
4065 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
4066 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4069 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
4070 arvif
->vdev_id
, ret
);
4073 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4074 if (info
->use_short_preamble
)
4075 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
4077 preamble
= WMI_VDEV_PREAMBLE_LONG
;
4079 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4080 "mac vdev %d preamble %dn",
4081 arvif
->vdev_id
, preamble
);
4083 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
4084 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4087 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
4088 arvif
->vdev_id
, ret
);
4091 if (changed
& BSS_CHANGED_ASSOC
) {
4093 /* Workaround: Make sure monitor vdev is not running
4094 * when associating to prevent some firmware revisions
4095 * (e.g. 10.1 and 10.2) from crashing.
4097 if (ar
->monitor_started
)
4098 ath10k_monitor_stop(ar
);
4099 ath10k_bss_assoc(hw
, vif
, info
);
4100 ath10k_monitor_recalc(ar
);
4102 ath10k_bss_disassoc(hw
, vif
);
4106 if (changed
& BSS_CHANGED_TXPOWER
) {
4107 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
4108 arvif
->vdev_id
, info
->txpower
);
4110 arvif
->txpower
= info
->txpower
;
4111 ret
= ath10k_mac_txpower_recalc(ar
);
4113 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4116 if (changed
& BSS_CHANGED_PS
) {
4117 arvif
->ps
= vif
->bss_conf
.ps
;
4119 ret
= ath10k_config_ps(ar
);
4121 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
4122 arvif
->vdev_id
, ret
);
4125 mutex_unlock(&ar
->conf_mutex
);
4128 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
4129 struct ieee80211_vif
*vif
,
4130 struct ieee80211_scan_request
*hw_req
)
4132 struct ath10k
*ar
= hw
->priv
;
4133 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4134 struct cfg80211_scan_request
*req
= &hw_req
->req
;
4135 struct wmi_start_scan_arg arg
;
4139 mutex_lock(&ar
->conf_mutex
);
4141 spin_lock_bh(&ar
->data_lock
);
4142 switch (ar
->scan
.state
) {
4143 case ATH10K_SCAN_IDLE
:
4144 reinit_completion(&ar
->scan
.started
);
4145 reinit_completion(&ar
->scan
.completed
);
4146 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4147 ar
->scan
.is_roc
= false;
4148 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4151 case ATH10K_SCAN_STARTING
:
4152 case ATH10K_SCAN_RUNNING
:
4153 case ATH10K_SCAN_ABORTING
:
4157 spin_unlock_bh(&ar
->data_lock
);
4162 memset(&arg
, 0, sizeof(arg
));
4163 ath10k_wmi_start_scan_init(ar
, &arg
);
4164 arg
.vdev_id
= arvif
->vdev_id
;
4165 arg
.scan_id
= ATH10K_SCAN_ID
;
4168 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
4171 arg
.ie_len
= req
->ie_len
;
4172 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
4176 arg
.n_ssids
= req
->n_ssids
;
4177 for (i
= 0; i
< arg
.n_ssids
; i
++) {
4178 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
4179 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
4182 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4185 if (req
->n_channels
) {
4186 arg
.n_channels
= req
->n_channels
;
4187 for (i
= 0; i
< arg
.n_channels
; i
++)
4188 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
4191 ret
= ath10k_start_scan(ar
, &arg
);
4193 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
4194 spin_lock_bh(&ar
->data_lock
);
4195 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4196 spin_unlock_bh(&ar
->data_lock
);
4200 mutex_unlock(&ar
->conf_mutex
);
4204 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
4205 struct ieee80211_vif
*vif
)
4207 struct ath10k
*ar
= hw
->priv
;
4209 mutex_lock(&ar
->conf_mutex
);
4210 ath10k_scan_abort(ar
);
4211 mutex_unlock(&ar
->conf_mutex
);
4213 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4216 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
4217 struct ath10k_vif
*arvif
,
4218 enum set_key_cmd cmd
,
4219 struct ieee80211_key_conf
*key
)
4221 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
4224 /* 10.1 firmware branch requires default key index to be set to group
4225 * key index after installing it. Otherwise FW/HW Txes corrupted
4226 * frames with multi-vif APs. This is not required for main firmware
4227 * branch (e.g. 636).
4229 * FIXME: This has been tested only in AP. It remains unknown if this
4230 * is required for multi-vif STA interfaces on 10.1 */
4232 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
4235 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
4238 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
4241 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4247 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4250 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
4251 arvif
->vdev_id
, ret
);
4254 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
4255 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
4256 struct ieee80211_key_conf
*key
)
4258 struct ath10k
*ar
= hw
->priv
;
4259 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4260 struct ath10k_peer
*peer
;
4261 const u8
*peer_addr
;
4262 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
4263 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
4267 /* this one needs to be done in software */
4268 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
4271 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
4274 mutex_lock(&ar
->conf_mutex
);
4277 peer_addr
= sta
->addr
;
4278 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
4279 peer_addr
= vif
->bss_conf
.bssid
;
4281 peer_addr
= vif
->addr
;
4283 key
->hw_key_idx
= key
->keyidx
;
4285 /* the peer should not disappear in mid-way (unless FW goes awry) since
4286 * we already hold conf_mutex. we just make sure its there now. */
4287 spin_lock_bh(&ar
->data_lock
);
4288 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4289 spin_unlock_bh(&ar
->data_lock
);
4292 if (cmd
== SET_KEY
) {
4293 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
4298 /* if the peer doesn't exist there is no key to disable
4304 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4305 flags
|= WMI_KEY_PAIRWISE
;
4307 flags
|= WMI_KEY_GROUP
;
4311 arvif
->wep_keys
[key
->keyidx
] = key
;
4313 arvif
->wep_keys
[key
->keyidx
] = NULL
;
4315 if (cmd
== DISABLE_KEY
)
4316 ath10k_clear_vdev_key(arvif
, key
);
4318 /* When WEP keys are uploaded it's possible that there are
4319 * stations associated already (e.g. when merging) without any
4320 * keys. Static WEP needs an explicit per-peer key upload.
4322 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
4324 ath10k_mac_vif_update_wep_key(arvif
, key
);
4326 /* 802.1x never sets the def_wep_key_idx so each set_key()
4327 * call changes default tx key.
4329 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4330 * after first set_key().
4332 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
4333 flags
|= WMI_KEY_TX_USAGE
;
4335 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4336 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4337 * mode and associated stations in AP/IBSS.
4339 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4340 * work fine when mapped directly from mac80211.
4342 * Note: When installing first static WEP groupwise key (which
4343 * should be pairwise) def_wep_key_idx isn't known yet (it's
4344 * equal to -1). Since .set_default_unicast_key is called only
4345 * for static WEP it's used to re-upload the key as pairwise.
4347 if (arvif
->def_wep_key_idx
>= 0 &&
4348 memcmp(peer_addr
, arvif
->vif
->addr
, ETH_ALEN
)) {
4349 flags
&= ~WMI_KEY_GROUP
;
4350 flags
|= WMI_KEY_PAIRWISE
;
4354 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
4356 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
4357 arvif
->vdev_id
, peer_addr
, ret
);
4361 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
4363 spin_lock_bh(&ar
->data_lock
);
4364 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4365 if (peer
&& cmd
== SET_KEY
)
4366 peer
->keys
[key
->keyidx
] = key
;
4367 else if (peer
&& cmd
== DISABLE_KEY
)
4368 peer
->keys
[key
->keyidx
] = NULL
;
4369 else if (peer
== NULL
)
4370 /* impossible unless FW goes crazy */
4371 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
4372 spin_unlock_bh(&ar
->data_lock
);
4375 mutex_unlock(&ar
->conf_mutex
);
4379 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
4380 struct ieee80211_vif
*vif
,
4383 struct ath10k
*ar
= hw
->priv
;
4384 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4387 mutex_lock(&arvif
->ar
->conf_mutex
);
4389 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
4392 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
4393 arvif
->vdev_id
, keyidx
);
4395 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
4397 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
4401 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
4407 arvif
->def_wep_key_idx
= keyidx
;
4409 ret
= ath10k_mac_vif_sta_fix_wep_key(arvif
);
4411 ath10k_warn(ar
, "failed to fix sta wep key on vdev %i: %d\n",
4412 arvif
->vdev_id
, ret
);
4417 mutex_unlock(&arvif
->ar
->conf_mutex
);
4420 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
4423 struct ath10k_vif
*arvif
;
4424 struct ath10k_sta
*arsta
;
4425 struct ieee80211_sta
*sta
;
4426 u32 changed
, bw
, nss
, smps
;
4429 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
4430 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
4431 arvif
= arsta
->arvif
;
4434 spin_lock_bh(&ar
->data_lock
);
4436 changed
= arsta
->changed
;
4443 spin_unlock_bh(&ar
->data_lock
);
4445 mutex_lock(&ar
->conf_mutex
);
4447 if (changed
& IEEE80211_RC_BW_CHANGED
) {
4448 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
4451 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4452 WMI_PEER_CHAN_WIDTH
, bw
);
4454 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
4455 sta
->addr
, bw
, err
);
4458 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
4459 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
4462 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4465 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
4466 sta
->addr
, nss
, err
);
4469 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
4470 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
4473 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4474 WMI_PEER_SMPS_STATE
, smps
);
4476 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
4477 sta
->addr
, smps
, err
);
4480 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
||
4481 changed
& IEEE80211_RC_NSS_CHANGED
) {
4482 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates/nss\n",
4485 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
4487 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
4491 mutex_unlock(&ar
->conf_mutex
);
4494 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
4495 struct ieee80211_sta
*sta
)
4497 struct ath10k
*ar
= arvif
->ar
;
4499 lockdep_assert_held(&ar
->conf_mutex
);
4501 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
4504 if (ar
->num_stations
>= ar
->max_num_stations
)
4512 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
4513 struct ieee80211_sta
*sta
)
4515 struct ath10k
*ar
= arvif
->ar
;
4517 lockdep_assert_held(&ar
->conf_mutex
);
4519 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
4525 struct ath10k_mac_tdls_iter_data
{
4526 u32 num_tdls_stations
;
4527 struct ieee80211_vif
*curr_vif
;
4530 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
4531 struct ieee80211_sta
*sta
)
4533 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
4534 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4535 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
4537 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
4538 iter_data
->num_tdls_stations
++;
4541 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
4542 struct ieee80211_vif
*vif
)
4544 struct ath10k_mac_tdls_iter_data data
= {};
4546 data
.curr_vif
= vif
;
4548 ieee80211_iterate_stations_atomic(hw
,
4549 ath10k_mac_tdls_vif_stations_count_iter
,
4551 return data
.num_tdls_stations
;
4554 static void ath10k_mac_tdls_vifs_count_iter(void *data
, u8
*mac
,
4555 struct ieee80211_vif
*vif
)
4557 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4558 int *num_tdls_vifs
= data
;
4560 if (vif
->type
!= NL80211_IFTYPE_STATION
)
4563 if (ath10k_mac_tdls_vif_stations_count(arvif
->ar
->hw
, vif
) > 0)
4567 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw
*hw
)
4569 int num_tdls_vifs
= 0;
4571 ieee80211_iterate_active_interfaces_atomic(hw
,
4572 IEEE80211_IFACE_ITER_NORMAL
,
4573 ath10k_mac_tdls_vifs_count_iter
,
4575 return num_tdls_vifs
;
4578 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
4579 struct ieee80211_vif
*vif
,
4580 struct ieee80211_sta
*sta
,
4581 enum ieee80211_sta_state old_state
,
4582 enum ieee80211_sta_state new_state
)
4584 struct ath10k
*ar
= hw
->priv
;
4585 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4586 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4589 if (old_state
== IEEE80211_STA_NOTEXIST
&&
4590 new_state
== IEEE80211_STA_NONE
) {
4591 memset(arsta
, 0, sizeof(*arsta
));
4592 arsta
->arvif
= arvif
;
4593 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
4596 /* cancel must be done outside the mutex to avoid deadlock */
4597 if ((old_state
== IEEE80211_STA_NONE
&&
4598 new_state
== IEEE80211_STA_NOTEXIST
))
4599 cancel_work_sync(&arsta
->update_wk
);
4601 mutex_lock(&ar
->conf_mutex
);
4603 if (old_state
== IEEE80211_STA_NOTEXIST
&&
4604 new_state
== IEEE80211_STA_NONE
) {
4606 * New station addition.
4608 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
4609 u32 num_tdls_stations
;
4612 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4613 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4614 arvif
->vdev_id
, sta
->addr
,
4615 ar
->num_stations
+ 1, ar
->max_num_stations
,
4616 ar
->num_peers
+ 1, ar
->max_num_peers
);
4618 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
4620 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
4621 ar
->max_num_stations
);
4626 peer_type
= WMI_PEER_TYPE_TDLS
;
4628 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
,
4631 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
4632 sta
->addr
, arvif
->vdev_id
, ret
);
4633 ath10k_mac_dec_num_stations(arvif
, sta
);
4637 if (vif
->type
== NL80211_IFTYPE_STATION
&&
4639 WARN_ON(arvif
->is_started
);
4641 ret
= ath10k_vdev_start(arvif
);
4643 ath10k_warn(ar
, "failed to start vdev %i: %d\n",
4644 arvif
->vdev_id
, ret
);
4645 WARN_ON(ath10k_peer_delete(ar
, arvif
->vdev_id
,
4647 ath10k_mac_dec_num_stations(arvif
, sta
);
4651 arvif
->is_started
= true;
4657 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
4658 num_tdls_vifs
= ath10k_mac_tdls_vifs_count(hw
);
4660 if (num_tdls_vifs
>= ar
->max_num_tdls_vdevs
&&
4661 num_tdls_stations
== 0) {
4662 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4663 arvif
->vdev_id
, ar
->max_num_tdls_vdevs
);
4664 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
4665 ath10k_mac_dec_num_stations(arvif
, sta
);
4670 if (num_tdls_stations
== 0) {
4671 /* This is the first tdls peer in current vif */
4672 enum wmi_tdls_state state
= WMI_TDLS_ENABLE_ACTIVE
;
4674 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
4677 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
4678 arvif
->vdev_id
, ret
);
4679 ath10k_peer_delete(ar
, arvif
->vdev_id
,
4681 ath10k_mac_dec_num_stations(arvif
, sta
);
4686 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
4687 WMI_TDLS_PEER_STATE_PEERING
);
4690 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
4691 sta
->addr
, arvif
->vdev_id
, ret
);
4692 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
4693 ath10k_mac_dec_num_stations(arvif
, sta
);
4695 if (num_tdls_stations
!= 0)
4697 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
4700 } else if ((old_state
== IEEE80211_STA_NONE
&&
4701 new_state
== IEEE80211_STA_NOTEXIST
)) {
4703 * Existing station deletion.
4705 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4706 "mac vdev %d peer delete %pM (sta gone)\n",
4707 arvif
->vdev_id
, sta
->addr
);
4709 if (vif
->type
== NL80211_IFTYPE_STATION
&&
4711 WARN_ON(!arvif
->is_started
);
4713 ret
= ath10k_vdev_stop(arvif
);
4715 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
4716 arvif
->vdev_id
, ret
);
4718 arvif
->is_started
= false;
4721 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
4723 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
4724 sta
->addr
, arvif
->vdev_id
, ret
);
4726 ath10k_mac_dec_num_stations(arvif
, sta
);
4731 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
4734 /* This was the last tdls peer in current vif */
4735 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
4738 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
4739 arvif
->vdev_id
, ret
);
4741 } else if (old_state
== IEEE80211_STA_AUTH
&&
4742 new_state
== IEEE80211_STA_ASSOC
&&
4743 (vif
->type
== NL80211_IFTYPE_AP
||
4744 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
4748 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
4751 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
4753 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
4754 sta
->addr
, arvif
->vdev_id
, ret
);
4755 } else if (old_state
== IEEE80211_STA_ASSOC
&&
4756 new_state
== IEEE80211_STA_AUTHORIZED
&&
4759 * Tdls station authorized.
4761 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
4764 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
4766 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
4767 sta
->addr
, arvif
->vdev_id
, ret
);
4771 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
4772 WMI_TDLS_PEER_STATE_CONNECTED
);
4774 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
4775 sta
->addr
, arvif
->vdev_id
, ret
);
4776 } else if (old_state
== IEEE80211_STA_ASSOC
&&
4777 new_state
== IEEE80211_STA_AUTH
&&
4778 (vif
->type
== NL80211_IFTYPE_AP
||
4779 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
4783 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
4786 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
4788 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
4789 sta
->addr
, arvif
->vdev_id
, ret
);
4792 mutex_unlock(&ar
->conf_mutex
);
4796 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
4797 u16 ac
, bool enable
)
4799 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4800 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
4801 u32 prio
= 0, acc
= 0;
4805 lockdep_assert_held(&ar
->conf_mutex
);
4807 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
4811 case IEEE80211_AC_VO
:
4812 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
4813 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
4817 case IEEE80211_AC_VI
:
4818 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
4819 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
4823 case IEEE80211_AC_BE
:
4824 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
4825 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
4829 case IEEE80211_AC_BK
:
4830 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
4831 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
4838 arvif
->u
.sta
.uapsd
|= value
;
4840 arvif
->u
.sta
.uapsd
&= ~value
;
4842 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4843 WMI_STA_PS_PARAM_UAPSD
,
4844 arvif
->u
.sta
.uapsd
);
4846 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
4850 if (arvif
->u
.sta
.uapsd
)
4851 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
4853 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4855 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4856 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
4859 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
4861 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4863 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4864 arvif
->vdev_id
, ret
);
4868 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4870 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4871 arvif
->vdev_id
, ret
);
4875 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
4876 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
4877 /* Only userspace can make an educated decision when to send
4878 * trigger frame. The following effectively disables u-UAPSD
4879 * autotrigger in firmware (which is enabled by default
4880 * provided the autotrigger service is available).
4884 arg
.user_priority
= prio
;
4885 arg
.service_interval
= 0;
4886 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
4887 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
4889 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
4890 arvif
->bssid
, &arg
, 1);
4892 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
4902 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
4903 struct ieee80211_vif
*vif
, u16 ac
,
4904 const struct ieee80211_tx_queue_params
*params
)
4906 struct ath10k
*ar
= hw
->priv
;
4907 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4908 struct wmi_wmm_params_arg
*p
= NULL
;
4911 mutex_lock(&ar
->conf_mutex
);
4914 case IEEE80211_AC_VO
:
4915 p
= &arvif
->wmm_params
.ac_vo
;
4917 case IEEE80211_AC_VI
:
4918 p
= &arvif
->wmm_params
.ac_vi
;
4920 case IEEE80211_AC_BE
:
4921 p
= &arvif
->wmm_params
.ac_be
;
4923 case IEEE80211_AC_BK
:
4924 p
= &arvif
->wmm_params
.ac_bk
;
4933 p
->cwmin
= params
->cw_min
;
4934 p
->cwmax
= params
->cw_max
;
4935 p
->aifs
= params
->aifs
;
4938 * The channel time duration programmed in the HW is in absolute
4939 * microseconds, while mac80211 gives the txop in units of
4942 p
->txop
= params
->txop
* 32;
4944 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
4945 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
4946 &arvif
->wmm_params
);
4948 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
4949 arvif
->vdev_id
, ret
);
4953 /* This won't work well with multi-interface cases but it's
4954 * better than nothing.
4956 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
4958 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
4963 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
4965 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
4968 mutex_unlock(&ar
->conf_mutex
);
4972 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4974 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
4975 struct ieee80211_vif
*vif
,
4976 struct ieee80211_channel
*chan
,
4978 enum ieee80211_roc_type type
)
4980 struct ath10k
*ar
= hw
->priv
;
4981 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4982 struct wmi_start_scan_arg arg
;
4985 mutex_lock(&ar
->conf_mutex
);
4987 spin_lock_bh(&ar
->data_lock
);
4988 switch (ar
->scan
.state
) {
4989 case ATH10K_SCAN_IDLE
:
4990 reinit_completion(&ar
->scan
.started
);
4991 reinit_completion(&ar
->scan
.completed
);
4992 reinit_completion(&ar
->scan
.on_channel
);
4993 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4994 ar
->scan
.is_roc
= true;
4995 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4996 ar
->scan
.roc_freq
= chan
->center_freq
;
4999 case ATH10K_SCAN_STARTING
:
5000 case ATH10K_SCAN_RUNNING
:
5001 case ATH10K_SCAN_ABORTING
:
5005 spin_unlock_bh(&ar
->data_lock
);
5010 duration
= max(duration
, WMI_SCAN_CHAN_MIN_TIME_MSEC
);
5012 memset(&arg
, 0, sizeof(arg
));
5013 ath10k_wmi_start_scan_init(ar
, &arg
);
5014 arg
.vdev_id
= arvif
->vdev_id
;
5015 arg
.scan_id
= ATH10K_SCAN_ID
;
5017 arg
.channels
[0] = chan
->center_freq
;
5018 arg
.dwell_time_active
= duration
;
5019 arg
.dwell_time_passive
= duration
;
5020 arg
.max_scan_time
= 2 * duration
;
5021 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
5022 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
5024 ret
= ath10k_start_scan(ar
, &arg
);
5026 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
5027 spin_lock_bh(&ar
->data_lock
);
5028 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
5029 spin_unlock_bh(&ar
->data_lock
);
5033 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
5035 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
5037 ret
= ath10k_scan_stop(ar
);
5039 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
5047 mutex_unlock(&ar
->conf_mutex
);
5051 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
5053 struct ath10k
*ar
= hw
->priv
;
5055 mutex_lock(&ar
->conf_mutex
);
5056 ath10k_scan_abort(ar
);
5057 mutex_unlock(&ar
->conf_mutex
);
5059 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5065 * Both RTS and Fragmentation threshold are interface-specific
5066 * in ath10k, but device-specific in mac80211.
5069 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5071 struct ath10k
*ar
= hw
->priv
;
5072 struct ath10k_vif
*arvif
;
5075 mutex_lock(&ar
->conf_mutex
);
5076 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5077 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
5078 arvif
->vdev_id
, value
);
5080 ret
= ath10k_mac_set_rts(arvif
, value
);
5082 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5083 arvif
->vdev_id
, ret
);
5087 mutex_unlock(&ar
->conf_mutex
);
5092 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5093 u32 queues
, bool drop
)
5095 struct ath10k
*ar
= hw
->priv
;
5099 /* mac80211 doesn't care if we really xmit queued frames or not
5100 * we'll collect those frames either way if we stop/delete vdevs */
5104 mutex_lock(&ar
->conf_mutex
);
5106 if (ar
->state
== ATH10K_STATE_WEDGED
)
5109 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
5112 spin_lock_bh(&ar
->htt
.tx_lock
);
5113 empty
= (ar
->htt
.num_pending_tx
== 0);
5114 spin_unlock_bh(&ar
->htt
.tx_lock
);
5116 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
5117 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
5121 }), ATH10K_FLUSH_TIMEOUT_HZ
);
5123 if (ret
<= 0 || skip
)
5124 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
5125 skip
, ar
->state
, ret
);
5128 mutex_unlock(&ar
->conf_mutex
);
5131 /* TODO: Implement this function properly
5132 * For now it is needed to reply to Probe Requests in IBSS mode.
5133 * Propably we need this information from FW.
5135 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
5140 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
5141 enum ieee80211_reconfig_type reconfig_type
)
5143 struct ath10k
*ar
= hw
->priv
;
5145 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
5148 mutex_lock(&ar
->conf_mutex
);
5150 /* If device failed to restart it will be in a different state, e.g.
5151 * ATH10K_STATE_WEDGED */
5152 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
5153 ath10k_info(ar
, "device successfully recovered\n");
5154 ar
->state
= ATH10K_STATE_ON
;
5155 ieee80211_wake_queues(ar
->hw
);
5158 mutex_unlock(&ar
->conf_mutex
);
5161 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5162 struct survey_info
*survey
)
5164 struct ath10k
*ar
= hw
->priv
;
5165 struct ieee80211_supported_band
*sband
;
5166 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
5169 mutex_lock(&ar
->conf_mutex
);
5171 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5172 if (sband
&& idx
>= sband
->n_channels
) {
5173 idx
-= sband
->n_channels
;
5178 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5180 if (!sband
|| idx
>= sband
->n_channels
) {
5185 spin_lock_bh(&ar
->data_lock
);
5186 memcpy(survey
, ar_survey
, sizeof(*survey
));
5187 spin_unlock_bh(&ar
->data_lock
);
5189 survey
->channel
= &sband
->channels
[idx
];
5191 if (ar
->rx_channel
== survey
->channel
)
5192 survey
->filled
|= SURVEY_INFO_IN_USE
;
5195 mutex_unlock(&ar
->conf_mutex
);
5199 /* Helper table for legacy fixed_rate/bitrate_mask */
5200 static const u8 cck_ofdm_rate
[] = {
5201 ATH10K_HW_RATE_CCK_LP_1M
,
5202 ATH10K_HW_RATE_CCK_LP_2M
,
5203 ATH10K_HW_RATE_CCK_LP_5_5M
,
5204 ATH10K_HW_RATE_CCK_LP_11M
,
5205 ATH10K_HW_RATE_OFDM_6M
,
5206 ATH10K_HW_RATE_OFDM_9M
,
5207 ATH10K_HW_RATE_OFDM_12M
,
5208 ATH10K_HW_RATE_OFDM_18M
,
5209 ATH10K_HW_RATE_OFDM_24M
,
5210 ATH10K_HW_RATE_OFDM_36M
,
5211 ATH10K_HW_RATE_OFDM_48M
,
5212 ATH10K_HW_RATE_OFDM_54M
,
5215 /* Check if only one bit set */
5216 static int ath10k_check_single_mask(u32 mask
)
5224 mask
&= ~BIT(bit
- 1);
5232 ath10k_default_bitrate_mask(struct ath10k
*ar
,
5233 enum ieee80211_band band
,
5234 const struct cfg80211_bitrate_mask
*mask
)
5236 u32 legacy
= 0x00ff;
5239 u16 nrf
= ar
->num_rf_chains
;
5241 if (ar
->cfg_tx_chainmask
)
5242 nrf
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
5245 case IEEE80211_BAND_2GHZ
:
5249 case IEEE80211_BAND_5GHZ
:
5255 if (mask
->control
[band
].legacy
!= legacy
)
5258 for (i
= 0; i
< nrf
; i
++)
5259 if (mask
->control
[band
].ht_mcs
[i
] != ht
)
5262 for (i
= 0; i
< nrf
; i
++)
5263 if (mask
->control
[band
].vht_mcs
[i
] != vht
)
5270 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask
*mask
,
5271 enum ieee80211_band band
,
5274 int ht_nss
= 0, vht_nss
= 0, i
;
5277 if (ath10k_check_single_mask(mask
->control
[band
].legacy
))
5281 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
5282 if (mask
->control
[band
].ht_mcs
[i
] == 0xff)
5284 else if (mask
->control
[band
].ht_mcs
[i
] == 0x00)
5293 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
5294 if (mask
->control
[band
].vht_mcs
[i
] == 0x03ff)
5296 else if (mask
->control
[band
].vht_mcs
[i
] == 0x0000)
5304 if (ht_nss
> 0 && vht_nss
> 0)
5308 *fixed_nss
= ht_nss
;
5310 *fixed_nss
= vht_nss
;
5318 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask
*mask
,
5319 enum ieee80211_band band
,
5320 enum wmi_rate_preamble
*preamble
)
5322 int legacy
= 0, ht
= 0, vht
= 0, i
;
5324 *preamble
= WMI_RATE_PREAMBLE_OFDM
;
5327 legacy
= ath10k_check_single_mask(mask
->control
[band
].legacy
);
5332 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
5333 ht
+= ath10k_check_single_mask(mask
->control
[band
].ht_mcs
[i
]);
5338 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
5339 vht
+= ath10k_check_single_mask(mask
->control
[band
].vht_mcs
[i
]);
5343 /* Currently we support only one fixed_rate */
5344 if ((legacy
+ ht
+ vht
) != 1)
5348 *preamble
= WMI_RATE_PREAMBLE_HT
;
5350 *preamble
= WMI_RATE_PREAMBLE_VHT
;
5356 ath10k_bitrate_mask_rate(struct ath10k
*ar
,
5357 const struct cfg80211_bitrate_mask
*mask
,
5358 enum ieee80211_band band
,
5362 u8 rate
= 0, pream
= 0, nss
= 0, i
;
5363 enum wmi_rate_preamble preamble
;
5365 /* Check if single rate correct */
5366 if (!ath10k_bitrate_mask_correct(mask
, band
, &preamble
))
5372 case WMI_RATE_PREAMBLE_CCK
:
5373 case WMI_RATE_PREAMBLE_OFDM
:
5374 i
= ffs(mask
->control
[band
].legacy
) - 1;
5376 if (band
== IEEE80211_BAND_2GHZ
&& i
< 4)
5377 pream
= WMI_RATE_PREAMBLE_CCK
;
5379 if (band
== IEEE80211_BAND_5GHZ
)
5382 if (i
>= ARRAY_SIZE(cck_ofdm_rate
))
5385 rate
= cck_ofdm_rate
[i
];
5387 case WMI_RATE_PREAMBLE_HT
:
5388 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
5389 if (mask
->control
[band
].ht_mcs
[i
])
5392 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
5395 rate
= ffs(mask
->control
[band
].ht_mcs
[i
]) - 1;
5398 case WMI_RATE_PREAMBLE_VHT
:
5399 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
5400 if (mask
->control
[band
].vht_mcs
[i
])
5403 if (i
== NL80211_VHT_NSS_MAX
)
5406 rate
= ffs(mask
->control
[band
].vht_mcs
[i
]) - 1;
5411 *fixed_nss
= nss
+ 1;
5415 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
5418 *fixed_rate
= pream
| nss
| rate
;
5423 static bool ath10k_get_fixed_rate_nss(struct ath10k
*ar
,
5424 const struct cfg80211_bitrate_mask
*mask
,
5425 enum ieee80211_band band
,
5429 /* First check full NSS mask, if we can simply limit NSS */
5430 if (ath10k_bitrate_mask_nss(mask
, band
, fixed_nss
))
5433 /* Next Check single rate is set */
5434 return ath10k_bitrate_mask_rate(ar
, mask
, band
, fixed_rate
, fixed_nss
);
5437 static int ath10k_set_fixed_rate_param(struct ath10k_vif
*arvif
,
5442 struct ath10k
*ar
= arvif
->ar
;
5446 mutex_lock(&ar
->conf_mutex
);
5448 if (arvif
->fixed_rate
== fixed_rate
&&
5449 arvif
->fixed_nss
== fixed_nss
&&
5450 arvif
->force_sgi
== force_sgi
)
5453 if (fixed_rate
== WMI_FIXED_RATE_NONE
)
5454 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac disable fixed bitrate mask\n");
5457 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac force sgi\n");
5459 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
5460 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5461 vdev_param
, fixed_rate
);
5463 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
5469 arvif
->fixed_rate
= fixed_rate
;
5471 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5472 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5473 vdev_param
, fixed_nss
);
5476 ath10k_warn(ar
, "failed to set fixed nss param %d: %d\n",
5482 arvif
->fixed_nss
= fixed_nss
;
5484 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
5485 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5489 ath10k_warn(ar
, "failed to set sgi param %d: %d\n",
5495 arvif
->force_sgi
= force_sgi
;
5498 mutex_unlock(&ar
->conf_mutex
);
5502 static int ath10k_set_bitrate_mask(struct ieee80211_hw
*hw
,
5503 struct ieee80211_vif
*vif
,
5504 const struct cfg80211_bitrate_mask
*mask
)
5506 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5507 struct ath10k
*ar
= arvif
->ar
;
5508 enum ieee80211_band band
= ar
->hw
->conf
.chandef
.chan
->band
;
5509 u8 fixed_rate
= WMI_FIXED_RATE_NONE
;
5510 u8 fixed_nss
= ar
->num_rf_chains
;
5513 if (ar
->cfg_tx_chainmask
)
5514 fixed_nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
5516 force_sgi
= mask
->control
[band
].gi
;
5517 if (force_sgi
== NL80211_TXRATE_FORCE_LGI
)
5520 if (!ath10k_default_bitrate_mask(ar
, band
, mask
)) {
5521 if (!ath10k_get_fixed_rate_nss(ar
, mask
, band
,
5527 if (fixed_rate
== WMI_FIXED_RATE_NONE
&& force_sgi
) {
5528 ath10k_warn(ar
, "failed to force SGI usage for default rate settings\n");
5532 return ath10k_set_fixed_rate_param(arvif
, fixed_rate
,
5533 fixed_nss
, force_sgi
);
5536 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
5537 struct ieee80211_vif
*vif
,
5538 struct ieee80211_sta
*sta
,
5541 struct ath10k
*ar
= hw
->priv
;
5542 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5545 spin_lock_bh(&ar
->data_lock
);
5547 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5548 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5549 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
5552 if (changed
& IEEE80211_RC_BW_CHANGED
) {
5553 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5555 switch (sta
->bandwidth
) {
5556 case IEEE80211_STA_RX_BW_20
:
5557 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5559 case IEEE80211_STA_RX_BW_40
:
5560 bw
= WMI_PEER_CHWIDTH_40MHZ
;
5562 case IEEE80211_STA_RX_BW_80
:
5563 bw
= WMI_PEER_CHWIDTH_80MHZ
;
5565 case IEEE80211_STA_RX_BW_160
:
5566 ath10k_warn(ar
, "Invalid bandwith %d in rc update for %pM\n",
5567 sta
->bandwidth
, sta
->addr
);
5568 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5575 if (changed
& IEEE80211_RC_NSS_CHANGED
)
5576 arsta
->nss
= sta
->rx_nss
;
5578 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5579 smps
= WMI_PEER_SMPS_PS_NONE
;
5581 switch (sta
->smps_mode
) {
5582 case IEEE80211_SMPS_AUTOMATIC
:
5583 case IEEE80211_SMPS_OFF
:
5584 smps
= WMI_PEER_SMPS_PS_NONE
;
5586 case IEEE80211_SMPS_STATIC
:
5587 smps
= WMI_PEER_SMPS_STATIC
;
5589 case IEEE80211_SMPS_DYNAMIC
:
5590 smps
= WMI_PEER_SMPS_DYNAMIC
;
5592 case IEEE80211_SMPS_NUM_MODES
:
5593 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
5594 sta
->smps_mode
, sta
->addr
);
5595 smps
= WMI_PEER_SMPS_PS_NONE
;
5602 arsta
->changed
|= changed
;
5604 spin_unlock_bh(&ar
->data_lock
);
5606 ieee80211_queue_work(hw
, &arsta
->update_wk
);
5609 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
5612 * FIXME: Return 0 for time being. Need to figure out whether FW
5613 * has the API to fetch 64-bit local TSF
5619 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
5620 struct ieee80211_vif
*vif
,
5621 enum ieee80211_ampdu_mlme_action action
,
5622 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
5625 struct ath10k
*ar
= hw
->priv
;
5626 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5628 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
5629 arvif
->vdev_id
, sta
->addr
, tid
, action
);
5632 case IEEE80211_AMPDU_RX_START
:
5633 case IEEE80211_AMPDU_RX_STOP
:
5634 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5635 * creation/removal. Do we need to verify this?
5638 case IEEE80211_AMPDU_TX_START
:
5639 case IEEE80211_AMPDU_TX_STOP_CONT
:
5640 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
5641 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
5642 case IEEE80211_AMPDU_TX_OPERATIONAL
:
5643 /* Firmware offloads Tx aggregation entirely so deny mac80211
5644 * Tx aggregation requests.
5652 static const struct ieee80211_ops ath10k_ops
= {
5654 .start
= ath10k_start
,
5655 .stop
= ath10k_stop
,
5656 .config
= ath10k_config
,
5657 .add_interface
= ath10k_add_interface
,
5658 .remove_interface
= ath10k_remove_interface
,
5659 .configure_filter
= ath10k_configure_filter
,
5660 .bss_info_changed
= ath10k_bss_info_changed
,
5661 .hw_scan
= ath10k_hw_scan
,
5662 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
5663 .set_key
= ath10k_set_key
,
5664 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
5665 .sta_state
= ath10k_sta_state
,
5666 .conf_tx
= ath10k_conf_tx
,
5667 .remain_on_channel
= ath10k_remain_on_channel
,
5668 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
5669 .set_rts_threshold
= ath10k_set_rts_threshold
,
5670 .flush
= ath10k_flush
,
5671 .tx_last_beacon
= ath10k_tx_last_beacon
,
5672 .set_antenna
= ath10k_set_antenna
,
5673 .get_antenna
= ath10k_get_antenna
,
5674 .reconfig_complete
= ath10k_reconfig_complete
,
5675 .get_survey
= ath10k_get_survey
,
5676 .set_bitrate_mask
= ath10k_set_bitrate_mask
,
5677 .sta_rc_update
= ath10k_sta_rc_update
,
5678 .get_tsf
= ath10k_get_tsf
,
5679 .ampdu_action
= ath10k_ampdu_action
,
5680 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
5681 .get_et_stats
= ath10k_debug_get_et_stats
,
5682 .get_et_strings
= ath10k_debug_get_et_strings
,
5684 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
5687 .suspend
= ath10k_wow_op_suspend
,
5688 .resume
= ath10k_wow_op_resume
,
5690 #ifdef CONFIG_MAC80211_DEBUGFS
5691 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
5695 #define CHAN2G(_channel, _freq, _flags) { \
5696 .band = IEEE80211_BAND_2GHZ, \
5697 .hw_value = (_channel), \
5698 .center_freq = (_freq), \
5699 .flags = (_flags), \
5700 .max_antenna_gain = 0, \
5704 #define CHAN5G(_channel, _freq, _flags) { \
5705 .band = IEEE80211_BAND_5GHZ, \
5706 .hw_value = (_channel), \
5707 .center_freq = (_freq), \
5708 .flags = (_flags), \
5709 .max_antenna_gain = 0, \
5713 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
5723 CHAN2G(10, 2457, 0),
5724 CHAN2G(11, 2462, 0),
5725 CHAN2G(12, 2467, 0),
5726 CHAN2G(13, 2472, 0),
5727 CHAN2G(14, 2484, 0),
5730 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
5731 CHAN5G(36, 5180, 0),
5732 CHAN5G(40, 5200, 0),
5733 CHAN5G(44, 5220, 0),
5734 CHAN5G(48, 5240, 0),
5735 CHAN5G(52, 5260, 0),
5736 CHAN5G(56, 5280, 0),
5737 CHAN5G(60, 5300, 0),
5738 CHAN5G(64, 5320, 0),
5739 CHAN5G(100, 5500, 0),
5740 CHAN5G(104, 5520, 0),
5741 CHAN5G(108, 5540, 0),
5742 CHAN5G(112, 5560, 0),
5743 CHAN5G(116, 5580, 0),
5744 CHAN5G(120, 5600, 0),
5745 CHAN5G(124, 5620, 0),
5746 CHAN5G(128, 5640, 0),
5747 CHAN5G(132, 5660, 0),
5748 CHAN5G(136, 5680, 0),
5749 CHAN5G(140, 5700, 0),
5750 CHAN5G(144, 5720, 0),
5751 CHAN5G(149, 5745, 0),
5752 CHAN5G(153, 5765, 0),
5753 CHAN5G(157, 5785, 0),
5754 CHAN5G(161, 5805, 0),
5755 CHAN5G(165, 5825, 0),
5758 struct ath10k
*ath10k_mac_create(size_t priv_size
)
5760 struct ieee80211_hw
*hw
;
5763 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
5773 void ath10k_mac_destroy(struct ath10k
*ar
)
5775 ieee80211_free_hw(ar
->hw
);
5778 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
5781 .types
= BIT(NL80211_IFTYPE_STATION
)
5782 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
5786 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
5790 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5794 .types
= BIT(NL80211_IFTYPE_AP
)
5798 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
5801 .types
= BIT(NL80211_IFTYPE_AP
)
5805 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
5807 .limits
= ath10k_if_limits
,
5808 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
5809 .max_interfaces
= 8,
5810 .num_different_channels
= 1,
5811 .beacon_int_infra_match
= true,
5815 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
5817 .limits
= ath10k_10x_if_limits
,
5818 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
5819 .max_interfaces
= 8,
5820 .num_different_channels
= 1,
5821 .beacon_int_infra_match
= true,
5822 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
5823 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
5824 BIT(NL80211_CHAN_WIDTH_20
) |
5825 BIT(NL80211_CHAN_WIDTH_40
) |
5826 BIT(NL80211_CHAN_WIDTH_80
),
5831 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
5833 struct ieee80211_sta_vht_cap vht_cap
= {0};
5838 vht_cap
.vht_supported
= 1;
5839 vht_cap
.cap
= ar
->vht_cap_info
;
5841 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
5842 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
5843 val
= ar
->num_rf_chains
- 1;
5844 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
5845 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
5850 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
5851 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
5852 val
= ar
->num_rf_chains
- 1;
5853 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
5854 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
5860 for (i
= 0; i
< 8; i
++) {
5861 if (i
< ar
->num_rf_chains
)
5862 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
5864 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
5867 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
5868 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
5873 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
5876 struct ieee80211_sta_ht_cap ht_cap
= {0};
5878 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
5881 ht_cap
.ht_supported
= 1;
5882 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
5883 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
5884 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5885 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
5886 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
5888 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
5889 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
5891 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
5892 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
5894 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
5897 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
5898 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
5903 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
5904 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
5906 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
5909 stbc
= ar
->ht_cap_info
;
5910 stbc
&= WMI_HT_CAP_RX_STBC
;
5911 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
5912 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
5913 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
5918 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
5919 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
5921 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
5922 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
5924 /* max AMSDU is implicitly taken from vht_cap_info */
5925 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
5926 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
5928 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
5929 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
5931 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
5936 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
5937 struct ieee80211_vif
*vif
)
5939 struct ath10k_vif_iter
*arvif_iter
= data
;
5940 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5942 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
5943 arvif_iter
->arvif
= arvif
;
5946 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
5948 struct ath10k_vif_iter arvif_iter
;
5951 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
5952 arvif_iter
.vdev_id
= vdev_id
;
5954 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
5955 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
5957 ath10k_get_arvif_iter
,
5959 if (!arvif_iter
.arvif
) {
5960 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
5964 return arvif_iter
.arvif
;
5967 int ath10k_mac_register(struct ath10k
*ar
)
5969 static const u32 cipher_suites
[] = {
5970 WLAN_CIPHER_SUITE_WEP40
,
5971 WLAN_CIPHER_SUITE_WEP104
,
5972 WLAN_CIPHER_SUITE_TKIP
,
5973 WLAN_CIPHER_SUITE_CCMP
,
5974 WLAN_CIPHER_SUITE_AES_CMAC
,
5976 struct ieee80211_supported_band
*band
;
5977 struct ieee80211_sta_vht_cap vht_cap
;
5978 struct ieee80211_sta_ht_cap ht_cap
;
5982 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
5984 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
5986 ht_cap
= ath10k_get_ht_cap(ar
);
5987 vht_cap
= ath10k_create_vht_cap(ar
);
5989 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
5990 channels
= kmemdup(ath10k_2ghz_channels
,
5991 sizeof(ath10k_2ghz_channels
),
5998 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
5999 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
6000 band
->channels
= channels
;
6001 band
->n_bitrates
= ath10k_g_rates_size
;
6002 band
->bitrates
= ath10k_g_rates
;
6003 band
->ht_cap
= ht_cap
;
6005 /* Enable the VHT support at 2.4 GHz */
6006 band
->vht_cap
= vht_cap
;
6008 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
6011 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
6012 channels
= kmemdup(ath10k_5ghz_channels
,
6013 sizeof(ath10k_5ghz_channels
),
6020 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
6021 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
6022 band
->channels
= channels
;
6023 band
->n_bitrates
= ath10k_a_rates_size
;
6024 band
->bitrates
= ath10k_a_rates
;
6025 band
->ht_cap
= ht_cap
;
6026 band
->vht_cap
= vht_cap
;
6027 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
6030 ar
->hw
->wiphy
->interface_modes
=
6031 BIT(NL80211_IFTYPE_STATION
) |
6032 BIT(NL80211_IFTYPE_AP
);
6034 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
6035 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
6037 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
6038 ar
->hw
->wiphy
->interface_modes
|=
6039 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
6040 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6041 BIT(NL80211_IFTYPE_P2P_GO
);
6043 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
6044 IEEE80211_HW_SUPPORTS_PS
|
6045 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
6046 IEEE80211_HW_MFP_CAPABLE
|
6047 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
6048 IEEE80211_HW_HAS_RATE_CONTROL
|
6049 IEEE80211_HW_AP_LINK_PS
|
6050 IEEE80211_HW_SPECTRUM_MGMT
|
6051 IEEE80211_HW_SW_CRYPTO_CONTROL
|
6052 IEEE80211_HW_CONNECTION_MONITOR
;
6054 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
6056 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
6057 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
6059 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
6060 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
6061 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
6064 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
6065 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
6067 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
6068 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
6070 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
6072 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
6073 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
6075 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6076 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6077 * correct Probe Responses. This is more of a hack advert..
6079 ar
->hw
->wiphy
->probe_resp_offload
|=
6080 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
6081 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
6082 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
6085 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
))
6086 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
6088 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
6089 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
6090 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
6092 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
6093 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
6095 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
6097 ret
= ath10k_wow_init(ar
);
6099 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
6104 * on LL hardware queues are managed entirely by the FW
6105 * so we only advertise to mac we can do the queues thing
6109 switch (ar
->wmi
.op_version
) {
6110 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
6111 case ATH10K_FW_WMI_OP_VERSION_TLV
:
6112 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
6113 ar
->hw
->wiphy
->n_iface_combinations
=
6114 ARRAY_SIZE(ath10k_if_comb
);
6115 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
6117 case ATH10K_FW_WMI_OP_VERSION_10_1
:
6118 case ATH10K_FW_WMI_OP_VERSION_10_2
:
6119 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
6120 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
6121 ar
->hw
->wiphy
->n_iface_combinations
=
6122 ARRAY_SIZE(ath10k_10x_if_comb
);
6124 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
6125 case ATH10K_FW_WMI_OP_VERSION_MAX
:
6131 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
6133 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
6134 /* Init ath dfs pattern detector */
6135 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
6136 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
6139 if (!ar
->dfs_detector
)
6140 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
6143 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
6144 ath10k_reg_notifier
);
6146 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
6150 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
6151 ar
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
6153 ret
= ieee80211_register_hw(ar
->hw
);
6155 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
6159 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
6160 ret
= regulatory_hint(ar
->hw
->wiphy
,
6161 ar
->ath_common
.regulatory
.alpha2
);
6163 goto err_unregister
;
6169 ieee80211_unregister_hw(ar
->hw
);
6171 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
6172 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
6177 void ath10k_mac_unregister(struct ath10k
*ar
)
6179 ieee80211_unregister_hw(ar
->hw
);
6181 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
6182 ar
->dfs_detector
->exit(ar
->dfs_detector
);
6184 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
6185 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
6187 SET_IEEE80211_DEV(ar
->hw
, NULL
);