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>
37 static int ath10k_send_key(struct ath10k_vif
*arvif
,
38 struct ieee80211_key_conf
*key
,
40 const u8
*macaddr
, u32 flags
)
42 struct ath10k
*ar
= arvif
->ar
;
43 struct wmi_vdev_install_key_arg arg
= {
44 .vdev_id
= arvif
->vdev_id
,
45 .key_idx
= key
->keyidx
,
46 .key_len
= key
->keylen
,
52 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
54 switch (key
->cipher
) {
55 case WLAN_CIPHER_SUITE_CCMP
:
56 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
57 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
59 case WLAN_CIPHER_SUITE_TKIP
:
60 arg
.key_cipher
= WMI_CIPHER_TKIP
;
61 arg
.key_txmic_len
= 8;
62 arg
.key_rxmic_len
= 8;
64 case WLAN_CIPHER_SUITE_WEP40
:
65 case WLAN_CIPHER_SUITE_WEP104
:
66 arg
.key_cipher
= WMI_CIPHER_WEP
;
68 case WLAN_CIPHER_SUITE_AES_CMAC
:
69 /* this one needs to be done in software */
72 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
76 if (cmd
== DISABLE_KEY
) {
77 arg
.key_cipher
= WMI_CIPHER_NONE
;
81 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
84 static int ath10k_install_key(struct ath10k_vif
*arvif
,
85 struct ieee80211_key_conf
*key
,
87 const u8
*macaddr
, u32 flags
)
89 struct ath10k
*ar
= arvif
->ar
;
92 lockdep_assert_held(&ar
->conf_mutex
);
94 reinit_completion(&ar
->install_key_done
);
96 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
100 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
107 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
110 struct ath10k
*ar
= arvif
->ar
;
111 struct ath10k_peer
*peer
;
116 lockdep_assert_held(&ar
->conf_mutex
);
118 spin_lock_bh(&ar
->data_lock
);
119 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
120 spin_unlock_bh(&ar
->data_lock
);
125 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
126 if (arvif
->wep_keys
[i
] == NULL
)
130 flags
|= WMI_KEY_PAIRWISE
;
132 /* set TX_USAGE flag for default key id */
133 if (arvif
->def_wep_key_idx
== i
)
134 flags
|= WMI_KEY_TX_USAGE
;
136 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
141 spin_lock_bh(&ar
->data_lock
);
142 peer
->keys
[i
] = arvif
->wep_keys
[i
];
143 spin_unlock_bh(&ar
->data_lock
);
149 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
152 struct ath10k
*ar
= arvif
->ar
;
153 struct ath10k_peer
*peer
;
159 lockdep_assert_held(&ar
->conf_mutex
);
161 spin_lock_bh(&ar
->data_lock
);
162 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
163 spin_unlock_bh(&ar
->data_lock
);
168 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
169 if (peer
->keys
[i
] == NULL
)
172 /* key flags are not required to delete the key */
173 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
174 DISABLE_KEY
, addr
, flags
);
175 if (ret
&& first_errno
== 0)
179 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
182 spin_lock_bh(&ar
->data_lock
);
183 peer
->keys
[i
] = NULL
;
184 spin_unlock_bh(&ar
->data_lock
);
190 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
193 struct ath10k_peer
*peer
;
196 lockdep_assert_held(&ar
->data_lock
);
198 /* We don't know which vdev this peer belongs to,
199 * since WMI doesn't give us that information.
201 * FIXME: multi-bss needs to be handled.
203 peer
= ath10k_peer_find(ar
, 0, addr
);
207 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
208 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
215 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
216 struct ieee80211_key_conf
*key
)
218 struct ath10k
*ar
= arvif
->ar
;
219 struct ath10k_peer
*peer
;
226 lockdep_assert_held(&ar
->conf_mutex
);
229 /* since ath10k_install_key we can't hold data_lock all the
230 * time, so we try to remove the keys incrementally */
231 spin_lock_bh(&ar
->data_lock
);
233 list_for_each_entry(peer
, &ar
->peers
, list
) {
234 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
235 if (peer
->keys
[i
] == key
) {
236 ether_addr_copy(addr
, peer
->addr
);
237 peer
->keys
[i
] = NULL
;
242 if (i
< ARRAY_SIZE(peer
->keys
))
245 spin_unlock_bh(&ar
->data_lock
);
247 if (i
== ARRAY_SIZE(peer
->keys
))
249 /* key flags are not required to delete the key */
250 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
251 if (ret
&& first_errno
== 0)
255 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
262 static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif
*arvif
)
264 struct ath10k
*ar
= arvif
->ar
;
265 enum nl80211_iftype iftype
= arvif
->vif
->type
;
266 struct ieee80211_key_conf
*key
;
272 lockdep_assert_held(&ar
->conf_mutex
);
274 if (iftype
!= NL80211_IFTYPE_STATION
)
277 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
278 if (arvif
->wep_keys
[i
]) {
279 key
= arvif
->wep_keys
[i
];
287 flags
|= WMI_KEY_PAIRWISE
;
288 flags
|= WMI_KEY_TX_USAGE
;
290 ret
= ath10k_install_key(arvif
, key
, SET_KEY
, arvif
->bssid
, flags
);
292 ath10k_warn(ar
, "failed to install key %i on vdev %i: %d\n",
293 key
->keyidx
, arvif
->vdev_id
, ret
);
300 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
301 struct ieee80211_key_conf
*key
)
303 struct ath10k
*ar
= arvif
->ar
;
304 struct ath10k_peer
*peer
;
307 lockdep_assert_held(&ar
->conf_mutex
);
309 list_for_each_entry(peer
, &ar
->peers
, list
) {
310 if (!memcmp(peer
->addr
, arvif
->vif
->addr
, ETH_ALEN
))
313 if (!memcmp(peer
->addr
, arvif
->bssid
, ETH_ALEN
))
316 if (peer
->keys
[key
->keyidx
] == key
)
319 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
320 arvif
->vdev_id
, key
->keyidx
);
322 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
324 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
325 arvif
->vdev_id
, peer
->addr
, ret
);
333 /*********************/
334 /* General utilities */
335 /*********************/
337 static inline enum wmi_phy_mode
338 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
340 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
342 switch (chandef
->chan
->band
) {
343 case IEEE80211_BAND_2GHZ
:
344 switch (chandef
->width
) {
345 case NL80211_CHAN_WIDTH_20_NOHT
:
346 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
351 case NL80211_CHAN_WIDTH_20
:
352 phymode
= MODE_11NG_HT20
;
354 case NL80211_CHAN_WIDTH_40
:
355 phymode
= MODE_11NG_HT40
;
357 case NL80211_CHAN_WIDTH_5
:
358 case NL80211_CHAN_WIDTH_10
:
359 case NL80211_CHAN_WIDTH_80
:
360 case NL80211_CHAN_WIDTH_80P80
:
361 case NL80211_CHAN_WIDTH_160
:
362 phymode
= MODE_UNKNOWN
;
366 case IEEE80211_BAND_5GHZ
:
367 switch (chandef
->width
) {
368 case NL80211_CHAN_WIDTH_20_NOHT
:
371 case NL80211_CHAN_WIDTH_20
:
372 phymode
= MODE_11NA_HT20
;
374 case NL80211_CHAN_WIDTH_40
:
375 phymode
= MODE_11NA_HT40
;
377 case NL80211_CHAN_WIDTH_80
:
378 phymode
= MODE_11AC_VHT80
;
380 case NL80211_CHAN_WIDTH_5
:
381 case NL80211_CHAN_WIDTH_10
:
382 case NL80211_CHAN_WIDTH_80P80
:
383 case NL80211_CHAN_WIDTH_160
:
384 phymode
= MODE_UNKNOWN
;
392 WARN_ON(phymode
== MODE_UNKNOWN
);
396 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
399 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
400 * 0 for no restriction
409 switch (mpdudensity
) {
415 /* Our lower layer calculations limit our precision to
431 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
435 lockdep_assert_held(&ar
->conf_mutex
);
437 if (ar
->num_peers
>= ar
->max_num_peers
)
440 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
);
442 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
447 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
449 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
459 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
461 struct ath10k
*ar
= arvif
->ar
;
465 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
466 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
467 ATH10K_KICKOUT_THRESHOLD
);
469 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
470 arvif
->vdev_id
, ret
);
474 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
475 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
476 ATH10K_KEEPALIVE_MIN_IDLE
);
478 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
479 arvif
->vdev_id
, ret
);
483 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
484 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
485 ATH10K_KEEPALIVE_MAX_IDLE
);
487 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
488 arvif
->vdev_id
, ret
);
492 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
493 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
494 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
496 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
497 arvif
->vdev_id
, ret
);
504 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
506 struct ath10k
*ar
= arvif
->ar
;
509 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
510 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
513 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
515 struct ath10k
*ar
= arvif
->ar
;
518 if (value
!= 0xFFFFFFFF)
519 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
520 ATH10K_FRAGMT_THRESHOLD_MIN
,
521 ATH10K_FRAGMT_THRESHOLD_MAX
);
523 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
524 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
527 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
531 lockdep_assert_held(&ar
->conf_mutex
);
533 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
537 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
546 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
548 struct ath10k_peer
*peer
, *tmp
;
550 lockdep_assert_held(&ar
->conf_mutex
);
552 spin_lock_bh(&ar
->data_lock
);
553 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
554 if (peer
->vdev_id
!= vdev_id
)
557 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
558 peer
->addr
, vdev_id
);
560 list_del(&peer
->list
);
564 spin_unlock_bh(&ar
->data_lock
);
567 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
569 struct ath10k_peer
*peer
, *tmp
;
571 lockdep_assert_held(&ar
->conf_mutex
);
573 spin_lock_bh(&ar
->data_lock
);
574 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
575 list_del(&peer
->list
);
578 spin_unlock_bh(&ar
->data_lock
);
581 ar
->num_stations
= 0;
584 /************************/
585 /* Interface management */
586 /************************/
588 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
590 struct ath10k
*ar
= arvif
->ar
;
592 lockdep_assert_held(&ar
->data_lock
);
597 if (!arvif
->beacon_buf
)
598 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
599 arvif
->beacon
->len
, DMA_TO_DEVICE
);
601 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
602 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
605 dev_kfree_skb_any(arvif
->beacon
);
607 arvif
->beacon
= NULL
;
608 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
611 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
613 struct ath10k
*ar
= arvif
->ar
;
615 lockdep_assert_held(&ar
->data_lock
);
617 ath10k_mac_vif_beacon_free(arvif
);
619 if (arvif
->beacon_buf
) {
620 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
621 arvif
->beacon_buf
, arvif
->beacon_paddr
);
622 arvif
->beacon_buf
= NULL
;
626 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
630 lockdep_assert_held(&ar
->conf_mutex
);
632 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
635 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
636 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
643 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
645 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
646 struct ieee80211_channel
*channel
= chandef
->chan
;
647 struct wmi_vdev_start_request_arg arg
= {};
650 lockdep_assert_held(&ar
->conf_mutex
);
652 arg
.vdev_id
= vdev_id
;
653 arg
.channel
.freq
= channel
->center_freq
;
654 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
656 /* TODO setup this dynamically, what in case we
657 don't have any vifs? */
658 arg
.channel
.mode
= chan_to_phymode(chandef
);
659 arg
.channel
.chan_radar
=
660 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
662 arg
.channel
.min_power
= 0;
663 arg
.channel
.max_power
= channel
->max_power
* 2;
664 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
665 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
667 reinit_completion(&ar
->vdev_setup_done
);
669 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
671 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
676 ret
= ath10k_vdev_setup_sync(ar
);
678 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
683 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
685 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
690 ar
->monitor_vdev_id
= vdev_id
;
692 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
693 ar
->monitor_vdev_id
);
697 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
699 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
700 ar
->monitor_vdev_id
, ret
);
705 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
709 lockdep_assert_held(&ar
->conf_mutex
);
711 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
713 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
714 ar
->monitor_vdev_id
, ret
);
716 reinit_completion(&ar
->vdev_setup_done
);
718 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
720 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
721 ar
->monitor_vdev_id
, ret
);
723 ret
= ath10k_vdev_setup_sync(ar
);
725 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
726 ar
->monitor_vdev_id
, ret
);
728 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
729 ar
->monitor_vdev_id
);
733 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
737 lockdep_assert_held(&ar
->conf_mutex
);
739 if (ar
->free_vdev_map
== 0) {
740 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
744 bit
= __ffs64(ar
->free_vdev_map
);
746 ar
->monitor_vdev_id
= bit
;
748 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
749 WMI_VDEV_TYPE_MONITOR
,
752 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
753 ar
->monitor_vdev_id
, ret
);
757 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
758 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
759 ar
->monitor_vdev_id
);
764 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
768 lockdep_assert_held(&ar
->conf_mutex
);
770 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
772 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
773 ar
->monitor_vdev_id
, ret
);
777 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
779 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
780 ar
->monitor_vdev_id
);
784 static int ath10k_monitor_start(struct ath10k
*ar
)
788 lockdep_assert_held(&ar
->conf_mutex
);
790 ret
= ath10k_monitor_vdev_create(ar
);
792 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
796 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
798 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
799 ath10k_monitor_vdev_delete(ar
);
803 ar
->monitor_started
= true;
804 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
809 static int ath10k_monitor_stop(struct ath10k
*ar
)
813 lockdep_assert_held(&ar
->conf_mutex
);
815 ret
= ath10k_monitor_vdev_stop(ar
);
817 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
821 ret
= ath10k_monitor_vdev_delete(ar
);
823 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
827 ar
->monitor_started
= false;
828 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
833 static int ath10k_monitor_recalc(struct ath10k
*ar
)
837 lockdep_assert_held(&ar
->conf_mutex
);
839 should_start
= ar
->monitor
||
840 ar
->filter_flags
& FIF_PROMISC_IN_BSS
||
841 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
843 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
844 "mac monitor recalc started? %d should? %d\n",
845 ar
->monitor_started
, should_start
);
847 if (should_start
== ar
->monitor_started
)
851 return ath10k_monitor_start(ar
);
853 return ath10k_monitor_stop(ar
);
856 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
858 struct ath10k
*ar
= arvif
->ar
;
859 u32 vdev_param
, rts_cts
= 0;
861 lockdep_assert_held(&ar
->conf_mutex
);
863 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
865 if (arvif
->use_cts_prot
|| arvif
->num_legacy_stations
> 0)
866 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
868 if (arvif
->num_legacy_stations
> 0)
869 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
872 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
876 static int ath10k_start_cac(struct ath10k
*ar
)
880 lockdep_assert_held(&ar
->conf_mutex
);
882 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
884 ret
= ath10k_monitor_recalc(ar
);
886 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
887 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
891 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
892 ar
->monitor_vdev_id
);
897 static int ath10k_stop_cac(struct ath10k
*ar
)
899 lockdep_assert_held(&ar
->conf_mutex
);
901 /* CAC is not running - do nothing */
902 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
905 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
906 ath10k_monitor_stop(ar
);
908 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
913 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
917 lockdep_assert_held(&ar
->conf_mutex
);
921 if (!ar
->radar_enabled
)
924 if (ar
->num_started_vdevs
> 0)
927 ret
= ath10k_start_cac(ar
);
930 * Not possible to start CAC on current channel so starting
931 * radiation is not allowed, make this channel DFS_UNAVAILABLE
932 * by indicating that radar was detected.
934 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
935 ieee80211_radar_detected(ar
->hw
);
939 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
, bool restart
)
941 struct ath10k
*ar
= arvif
->ar
;
942 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
943 struct wmi_vdev_start_request_arg arg
= {};
946 lockdep_assert_held(&ar
->conf_mutex
);
948 reinit_completion(&ar
->vdev_setup_done
);
950 arg
.vdev_id
= arvif
->vdev_id
;
951 arg
.dtim_period
= arvif
->dtim_period
;
952 arg
.bcn_intval
= arvif
->beacon_interval
;
954 arg
.channel
.freq
= chandef
->chan
->center_freq
;
955 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
956 arg
.channel
.mode
= chan_to_phymode(chandef
);
958 arg
.channel
.min_power
= 0;
959 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
960 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
961 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
963 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
964 arg
.ssid
= arvif
->u
.ap
.ssid
;
965 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
966 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
968 /* For now allow DFS for AP mode */
969 arg
.channel
.chan_radar
=
970 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
971 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
972 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
973 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
976 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
977 "mac vdev %d start center_freq %d phymode %s\n",
978 arg
.vdev_id
, arg
.channel
.freq
,
979 ath10k_wmi_phymode_str(arg
.channel
.mode
));
982 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
984 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
987 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
992 ret
= ath10k_vdev_setup_sync(ar
);
995 "failed to synchronize setup for vdev %i restart %d: %d\n",
996 arg
.vdev_id
, restart
, ret
);
1000 ar
->num_started_vdevs
++;
1001 ath10k_recalc_radar_detection(ar
);
1006 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
1008 return ath10k_vdev_start_restart(arvif
, false);
1011 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
)
1013 return ath10k_vdev_start_restart(arvif
, true);
1016 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1018 struct ath10k
*ar
= arvif
->ar
;
1021 lockdep_assert_held(&ar
->conf_mutex
);
1023 reinit_completion(&ar
->vdev_setup_done
);
1025 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1027 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1028 arvif
->vdev_id
, ret
);
1032 ret
= ath10k_vdev_setup_sync(ar
);
1034 ath10k_warn(ar
, "failed to synchronize setup for vdev %i stop: %d\n",
1035 arvif
->vdev_id
, ret
);
1039 WARN_ON(ar
->num_started_vdevs
== 0);
1041 if (ar
->num_started_vdevs
!= 0) {
1042 ar
->num_started_vdevs
--;
1043 ath10k_recalc_radar_detection(ar
);
1049 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1050 struct sk_buff
*bcn
)
1052 struct ath10k
*ar
= arvif
->ar
;
1053 struct ieee80211_mgmt
*mgmt
;
1057 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1060 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1063 mgmt
= (void *)bcn
->data
;
1064 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1065 mgmt
->u
.beacon
.variable
,
1066 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1071 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1073 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1074 arvif
->vdev_id
, ret
);
1081 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1082 u8 oui_type
, size_t ie_offset
)
1089 if (WARN_ON(skb
->len
< ie_offset
))
1092 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1093 skb
->data
+ ie_offset
,
1094 skb
->len
- ie_offset
);
1099 end
= skb
->data
+ skb
->len
;
1102 if (WARN_ON(next
> end
))
1105 memmove(ie
, next
, end
- next
);
1106 skb_trim(skb
, skb
->len
- len
);
1111 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1113 struct ath10k
*ar
= arvif
->ar
;
1114 struct ieee80211_hw
*hw
= ar
->hw
;
1115 struct ieee80211_vif
*vif
= arvif
->vif
;
1116 struct ieee80211_mutable_offsets offs
= {};
1117 struct sk_buff
*bcn
;
1120 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1123 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1124 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1127 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1129 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1133 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1135 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1140 /* P2P IE is inserted by firmware automatically (as configured above)
1141 * so remove it from the base beacon template to avoid duplicate P2P
1142 * IEs in beacon frames.
1144 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1145 offsetof(struct ieee80211_mgmt
,
1146 u
.beacon
.variable
));
1148 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1153 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1161 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1163 struct ath10k
*ar
= arvif
->ar
;
1164 struct ieee80211_hw
*hw
= ar
->hw
;
1165 struct ieee80211_vif
*vif
= arvif
->vif
;
1166 struct sk_buff
*prb
;
1169 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1172 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1175 prb
= ieee80211_proberesp_get(hw
, vif
);
1177 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1181 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1185 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1193 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1194 struct ieee80211_bss_conf
*info
)
1196 struct ath10k
*ar
= arvif
->ar
;
1199 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1201 if (!info
->enable_beacon
) {
1202 ath10k_vdev_stop(arvif
);
1204 spin_lock_bh(&arvif
->ar
->data_lock
);
1205 arvif
->is_started
= false;
1206 arvif
->is_up
= false;
1207 ath10k_mac_vif_beacon_free(arvif
);
1208 spin_unlock_bh(&arvif
->ar
->data_lock
);
1213 arvif
->tx_seq_no
= 0x1000;
1215 ret
= ath10k_vdev_start(arvif
);
1220 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1222 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1225 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1226 arvif
->vdev_id
, ret
);
1227 ath10k_vdev_stop(arvif
);
1231 arvif
->is_started
= true;
1232 arvif
->is_up
= true;
1234 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1237 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1238 struct ieee80211_bss_conf
*info
,
1239 const u8 self_peer
[ETH_ALEN
])
1241 struct ath10k
*ar
= arvif
->ar
;
1245 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1247 if (!info
->ibss_joined
) {
1248 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
1250 ath10k_warn(ar
, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1251 self_peer
, arvif
->vdev_id
, ret
);
1253 if (is_zero_ether_addr(arvif
->bssid
))
1256 memset(arvif
->bssid
, 0, ETH_ALEN
);
1261 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
1263 ath10k_warn(ar
, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1264 self_peer
, arvif
->vdev_id
, ret
);
1268 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1269 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1270 ATH10K_DEFAULT_ATIM
);
1272 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1273 arvif
->vdev_id
, ret
);
1276 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1278 struct ath10k
*ar
= arvif
->ar
;
1283 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1285 if (arvif
->u
.sta
.uapsd
)
1286 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1288 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1290 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1291 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1293 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1294 value
, arvif
->vdev_id
, ret
);
1301 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1303 struct ath10k
*ar
= arvif
->ar
;
1308 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1310 if (arvif
->u
.sta
.uapsd
)
1311 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1313 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1315 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1316 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1319 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1320 value
, arvif
->vdev_id
, ret
);
1327 static int ath10k_mac_ps_vif_count(struct ath10k
*ar
)
1329 struct ath10k_vif
*arvif
;
1332 lockdep_assert_held(&ar
->conf_mutex
);
1334 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1341 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1343 struct ath10k
*ar
= arvif
->ar
;
1344 struct ieee80211_vif
*vif
= arvif
->vif
;
1345 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1346 enum wmi_sta_powersave_param param
;
1347 enum wmi_sta_ps_mode psmode
;
1352 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1354 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1357 enable_ps
= arvif
->ps
;
1359 if (enable_ps
&& ath10k_mac_ps_vif_count(ar
) > 1 &&
1360 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1362 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1368 psmode
= WMI_STA_PS_MODE_ENABLED
;
1369 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1371 ps_timeout
= conf
->dynamic_ps_timeout
;
1372 if (ps_timeout
== 0) {
1373 /* Firmware doesn't like 0 */
1374 ps_timeout
= ieee80211_tu_to_usec(
1375 vif
->bss_conf
.beacon_int
) / 1000;
1378 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1381 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1382 arvif
->vdev_id
, ret
);
1386 psmode
= WMI_STA_PS_MODE_DISABLED
;
1389 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1390 arvif
->vdev_id
, psmode
? "enable" : "disable");
1392 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1394 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1395 psmode
, arvif
->vdev_id
, ret
);
1402 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1404 struct ath10k
*ar
= arvif
->ar
;
1405 struct wmi_sta_keepalive_arg arg
= {};
1408 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1410 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1413 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1416 /* Some firmware revisions have a bug and ignore the `enabled` field.
1417 * Instead use the interval to disable the keepalive.
1419 arg
.vdev_id
= arvif
->vdev_id
;
1421 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1422 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1424 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1426 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1427 arvif
->vdev_id
, ret
);
1434 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
1436 struct ath10k
*ar
= arvif
->ar
;
1437 struct ieee80211_vif
*vif
= arvif
->vif
;
1440 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1443 if (!vif
->csa_active
)
1449 if (!ieee80211_csa_is_complete(vif
)) {
1450 ieee80211_csa_update_counter(vif
);
1452 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1454 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
1457 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1459 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
1462 ieee80211_csa_finish(vif
);
1466 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
1468 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1470 struct ath10k
*ar
= arvif
->ar
;
1472 mutex_lock(&ar
->conf_mutex
);
1473 ath10k_mac_vif_ap_csa_count_down(arvif
);
1474 mutex_unlock(&ar
->conf_mutex
);
1477 /**********************/
1478 /* Station management */
1479 /**********************/
1481 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1482 struct ieee80211_vif
*vif
)
1484 /* Some firmware revisions have unstable STA powersave when listen
1485 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1486 * generate NullFunc frames properly even if buffered frames have been
1487 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1488 * buffered frames. Often pinging the device from AP would simply fail.
1490 * As a workaround set it to 1.
1492 if (vif
->type
== NL80211_IFTYPE_STATION
)
1495 return ar
->hw
->conf
.listen_interval
;
1498 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1499 struct ieee80211_vif
*vif
,
1500 struct ieee80211_sta
*sta
,
1501 struct wmi_peer_assoc_complete_arg
*arg
)
1503 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1505 lockdep_assert_held(&ar
->conf_mutex
);
1507 ether_addr_copy(arg
->addr
, sta
->addr
);
1508 arg
->vdev_id
= arvif
->vdev_id
;
1509 arg
->peer_aid
= sta
->aid
;
1510 arg
->peer_flags
|= WMI_PEER_AUTH
;
1511 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1512 arg
->peer_num_spatial_streams
= 1;
1513 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1516 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1517 struct ieee80211_vif
*vif
,
1518 struct wmi_peer_assoc_complete_arg
*arg
)
1520 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1521 struct cfg80211_bss
*bss
;
1522 const u8
*rsnie
= NULL
;
1523 const u8
*wpaie
= NULL
;
1525 lockdep_assert_held(&ar
->conf_mutex
);
1527 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
1528 info
->bssid
, NULL
, 0, 0, 0);
1530 const struct cfg80211_bss_ies
*ies
;
1533 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1535 ies
= rcu_dereference(bss
->ies
);
1537 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1538 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1542 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1545 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1546 if (rsnie
|| wpaie
) {
1547 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1548 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1552 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1553 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1557 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1558 struct ieee80211_sta
*sta
,
1559 struct wmi_peer_assoc_complete_arg
*arg
)
1561 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
1562 const struct ieee80211_supported_band
*sband
;
1563 const struct ieee80211_rate
*rates
;
1567 lockdep_assert_held(&ar
->conf_mutex
);
1569 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
1570 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
1571 rates
= sband
->bitrates
;
1573 rateset
->num_rates
= 0;
1575 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
1576 if (!(ratemask
& 1))
1579 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
1580 rateset
->num_rates
++;
1584 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
1585 struct ieee80211_sta
*sta
,
1586 struct wmi_peer_assoc_complete_arg
*arg
)
1588 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1592 lockdep_assert_held(&ar
->conf_mutex
);
1594 if (!ht_cap
->ht_supported
)
1597 arg
->peer_flags
|= WMI_PEER_HT
;
1598 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1599 ht_cap
->ampdu_factor
)) - 1;
1601 arg
->peer_mpdu_density
=
1602 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
1604 arg
->peer_ht_caps
= ht_cap
->cap
;
1605 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
1607 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
1608 arg
->peer_flags
|= WMI_PEER_LDPC
;
1610 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
1611 arg
->peer_flags
|= WMI_PEER_40MHZ
;
1612 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
1615 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
1616 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1618 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
1619 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1621 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
1622 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
1623 arg
->peer_flags
|= WMI_PEER_STBC
;
1626 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
1627 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
1628 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
1629 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
1630 arg
->peer_rate_caps
|= stbc
;
1631 arg
->peer_flags
|= WMI_PEER_STBC
;
1634 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
1635 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
1636 else if (ht_cap
->mcs
.rx_mask
[1])
1637 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
1639 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
1640 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
1641 arg
->peer_ht_rates
.rates
[n
++] = i
;
1644 * This is a workaround for HT-enabled STAs which break the spec
1645 * and have no HT capabilities RX mask (no HT RX MCS map).
1647 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1648 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1650 * Firmware asserts if such situation occurs.
1653 arg
->peer_ht_rates
.num_rates
= 8;
1654 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
1655 arg
->peer_ht_rates
.rates
[i
] = i
;
1657 arg
->peer_ht_rates
.num_rates
= n
;
1658 arg
->peer_num_spatial_streams
= sta
->rx_nss
;
1661 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
1663 arg
->peer_ht_rates
.num_rates
,
1664 arg
->peer_num_spatial_streams
);
1667 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
1668 struct ath10k_vif
*arvif
,
1669 struct ieee80211_sta
*sta
)
1675 lockdep_assert_held(&ar
->conf_mutex
);
1677 if (sta
->wme
&& sta
->uapsd_queues
) {
1678 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
1679 sta
->uapsd_queues
, sta
->max_sp
);
1681 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1682 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
1683 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
1684 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1685 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
1686 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
1687 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1688 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
1689 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
1690 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1691 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
1692 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
1694 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
1695 max_sp
= sta
->max_sp
;
1697 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1699 WMI_AP_PS_PEER_PARAM_UAPSD
,
1702 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1703 arvif
->vdev_id
, ret
);
1707 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1709 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1712 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1713 arvif
->vdev_id
, ret
);
1717 /* TODO setup this based on STA listen interval and
1718 beacon interval. Currently we don't know
1719 sta->listen_interval - mac80211 patch required.
1720 Currently use 10 seconds */
1721 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
1722 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
1725 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1726 arvif
->vdev_id
, ret
);
1734 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1735 struct ieee80211_sta
*sta
,
1736 struct wmi_peer_assoc_complete_arg
*arg
)
1738 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1741 if (!vht_cap
->vht_supported
)
1744 arg
->peer_flags
|= WMI_PEER_VHT
;
1746 if (ar
->hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
1747 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
1749 arg
->peer_vht_caps
= vht_cap
->cap
;
1751 ampdu_factor
= (vht_cap
->cap
&
1752 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1753 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1755 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1756 * zero in VHT IE. Using it would result in degraded throughput.
1757 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1758 * it if VHT max_mpdu is smaller. */
1759 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1760 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1761 ampdu_factor
)) - 1);
1763 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1764 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1766 arg
->peer_vht_rates
.rx_max_rate
=
1767 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1768 arg
->peer_vht_rates
.rx_mcs_set
=
1769 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1770 arg
->peer_vht_rates
.tx_max_rate
=
1771 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1772 arg
->peer_vht_rates
.tx_mcs_set
=
1773 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1775 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1776 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1779 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1780 struct ieee80211_vif
*vif
,
1781 struct ieee80211_sta
*sta
,
1782 struct wmi_peer_assoc_complete_arg
*arg
)
1784 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1786 switch (arvif
->vdev_type
) {
1787 case WMI_VDEV_TYPE_AP
:
1789 arg
->peer_flags
|= WMI_PEER_QOS
;
1791 if (sta
->wme
&& sta
->uapsd_queues
) {
1792 arg
->peer_flags
|= WMI_PEER_APSD
;
1793 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
1796 case WMI_VDEV_TYPE_STA
:
1797 if (vif
->bss_conf
.qos
)
1798 arg
->peer_flags
|= WMI_PEER_QOS
;
1800 case WMI_VDEV_TYPE_IBSS
:
1802 arg
->peer_flags
|= WMI_PEER_QOS
;
1808 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
1809 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
1812 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta
*sta
)
1814 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1815 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >> 4;
1818 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1819 struct ieee80211_vif
*vif
,
1820 struct ieee80211_sta
*sta
,
1821 struct wmi_peer_assoc_complete_arg
*arg
)
1823 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1825 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1826 case IEEE80211_BAND_2GHZ
:
1827 if (sta
->vht_cap
.vht_supported
) {
1828 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1829 phymode
= MODE_11AC_VHT40
;
1831 phymode
= MODE_11AC_VHT20
;
1832 } else if (sta
->ht_cap
.ht_supported
) {
1833 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1834 phymode
= MODE_11NG_HT40
;
1836 phymode
= MODE_11NG_HT20
;
1837 } else if (ath10k_mac_sta_has_11g_rates(sta
)) {
1844 case IEEE80211_BAND_5GHZ
:
1848 if (sta
->vht_cap
.vht_supported
) {
1849 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1850 phymode
= MODE_11AC_VHT80
;
1851 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1852 phymode
= MODE_11AC_VHT40
;
1853 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1854 phymode
= MODE_11AC_VHT20
;
1855 } else if (sta
->ht_cap
.ht_supported
) {
1856 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1857 phymode
= MODE_11NA_HT40
;
1859 phymode
= MODE_11NA_HT20
;
1869 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
1870 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
1872 arg
->peer_phymode
= phymode
;
1873 WARN_ON(phymode
== MODE_UNKNOWN
);
1876 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
1877 struct ieee80211_vif
*vif
,
1878 struct ieee80211_sta
*sta
,
1879 struct wmi_peer_assoc_complete_arg
*arg
)
1881 lockdep_assert_held(&ar
->conf_mutex
);
1883 memset(arg
, 0, sizeof(*arg
));
1885 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
1886 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
1887 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
1888 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
1889 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
1890 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
1891 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
1896 static const u32 ath10k_smps_map
[] = {
1897 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
1898 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
1899 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
1900 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
1903 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1905 const struct ieee80211_sta_ht_cap
*ht_cap
)
1909 if (!ht_cap
->ht_supported
)
1912 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
1913 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
1915 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
1918 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
1919 WMI_PEER_SMPS_STATE
,
1920 ath10k_smps_map
[smps
]);
1923 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
1924 struct ieee80211_vif
*vif
,
1925 struct ieee80211_sta_vht_cap vht_cap
)
1927 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1932 if (!(ar
->vht_cap_info
&
1933 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
1934 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
1935 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
1936 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
1939 param
= ar
->wmi
.vdev_param
->txbf
;
1942 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
1945 /* The following logic is correct. If a remote STA advertises support
1946 * for being a beamformer then we should enable us being a beamformee.
1949 if (ar
->vht_cap_info
&
1950 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
1951 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
1952 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
1953 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
1955 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
1956 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
1959 if (ar
->vht_cap_info
&
1960 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
1961 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
1962 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
1963 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
1965 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
1966 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
1969 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
1970 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
1972 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
1973 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
1975 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
1977 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
1985 /* can be called only in mac80211 callbacks due to `key_count` usage */
1986 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1987 struct ieee80211_vif
*vif
,
1988 struct ieee80211_bss_conf
*bss_conf
)
1990 struct ath10k
*ar
= hw
->priv
;
1991 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1992 struct ieee80211_sta_ht_cap ht_cap
;
1993 struct ieee80211_sta_vht_cap vht_cap
;
1994 struct wmi_peer_assoc_complete_arg peer_arg
;
1995 struct ieee80211_sta
*ap_sta
;
1998 lockdep_assert_held(&ar
->conf_mutex
);
2000 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2001 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2005 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2007 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2008 bss_conf
->bssid
, arvif
->vdev_id
);
2013 /* ap_sta must be accessed only within rcu section which must be left
2014 * before calling ath10k_setup_peer_smps() which might sleep. */
2015 ht_cap
= ap_sta
->ht_cap
;
2016 vht_cap
= ap_sta
->vht_cap
;
2018 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2020 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2021 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2028 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2030 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2031 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2035 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2037 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2038 arvif
->vdev_id
, ret
);
2042 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2044 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2045 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2049 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2050 "mac vdev %d up (associated) bssid %pM aid %d\n",
2051 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2053 WARN_ON(arvif
->is_up
);
2055 arvif
->aid
= bss_conf
->aid
;
2056 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2058 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2060 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2061 arvif
->vdev_id
, ret
);
2065 spin_lock_bh(&arvif
->ar
->data_lock
);
2066 arvif
->is_up
= true;
2067 spin_unlock_bh(&arvif
->ar
->data_lock
);
2069 /* Workaround: Some firmware revisions (tested with qca6174
2070 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2071 * poked with peer param command.
2073 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2074 WMI_PEER_DUMMY_VAR
, 1);
2076 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2077 arvif
->bssid
, arvif
->vdev_id
, ret
);
2082 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2083 struct ieee80211_vif
*vif
)
2085 struct ath10k
*ar
= hw
->priv
;
2086 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2087 struct ieee80211_sta_vht_cap vht_cap
= {};
2090 lockdep_assert_held(&ar
->conf_mutex
);
2092 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2093 arvif
->vdev_id
, arvif
->bssid
);
2095 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2097 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
2098 arvif
->vdev_id
, ret
);
2100 arvif
->def_wep_key_idx
= -1;
2102 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2104 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2105 arvif
->vdev_id
, ret
);
2109 spin_lock_bh(&arvif
->ar
->data_lock
);
2110 arvif
->is_up
= false;
2111 spin_unlock_bh(&arvif
->ar
->data_lock
);
2114 static int ath10k_station_assoc(struct ath10k
*ar
,
2115 struct ieee80211_vif
*vif
,
2116 struct ieee80211_sta
*sta
,
2119 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2120 struct wmi_peer_assoc_complete_arg peer_arg
;
2123 lockdep_assert_held(&ar
->conf_mutex
);
2125 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2127 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2128 sta
->addr
, arvif
->vdev_id
, ret
);
2132 peer_arg
.peer_reassoc
= reassoc
;
2133 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2135 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2136 sta
->addr
, arvif
->vdev_id
, ret
);
2140 /* Re-assoc is run only to update supported rates for given station. It
2141 * doesn't make much sense to reconfigure the peer completely.
2144 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2147 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2148 arvif
->vdev_id
, ret
);
2152 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2154 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2155 sta
->addr
, arvif
->vdev_id
, ret
);
2160 arvif
->num_legacy_stations
++;
2161 ret
= ath10k_recalc_rtscts_prot(arvif
);
2163 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2164 arvif
->vdev_id
, ret
);
2169 /* Plumb cached keys only for static WEP */
2170 if (arvif
->def_wep_key_idx
!= -1) {
2171 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2173 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2174 arvif
->vdev_id
, ret
);
2183 static int ath10k_station_disassoc(struct ath10k
*ar
,
2184 struct ieee80211_vif
*vif
,
2185 struct ieee80211_sta
*sta
)
2187 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2190 lockdep_assert_held(&ar
->conf_mutex
);
2193 arvif
->num_legacy_stations
--;
2194 ret
= ath10k_recalc_rtscts_prot(arvif
);
2196 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2197 arvif
->vdev_id
, ret
);
2202 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2204 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2205 arvif
->vdev_id
, ret
);
2216 static int ath10k_update_channel_list(struct ath10k
*ar
)
2218 struct ieee80211_hw
*hw
= ar
->hw
;
2219 struct ieee80211_supported_band
**bands
;
2220 enum ieee80211_band band
;
2221 struct ieee80211_channel
*channel
;
2222 struct wmi_scan_chan_list_arg arg
= {0};
2223 struct wmi_channel_arg
*ch
;
2229 lockdep_assert_held(&ar
->conf_mutex
);
2231 bands
= hw
->wiphy
->bands
;
2232 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2236 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2237 if (bands
[band
]->channels
[i
].flags
&
2238 IEEE80211_CHAN_DISABLED
)
2245 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2246 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2251 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2255 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2256 channel
= &bands
[band
]->channels
[i
];
2258 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2261 ch
->allow_ht
= true;
2263 /* FIXME: when should we really allow VHT? */
2264 ch
->allow_vht
= true;
2267 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2270 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2273 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2275 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2276 ch
->passive
= passive
;
2278 ch
->freq
= channel
->center_freq
;
2279 ch
->band_center_freq1
= channel
->center_freq
;
2281 ch
->max_power
= channel
->max_power
* 2;
2282 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2283 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2284 ch
->reg_class_id
= 0; /* FIXME */
2286 /* FIXME: why use only legacy modes, why not any
2287 * HT/VHT modes? Would that even make any
2289 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2290 ch
->mode
= MODE_11G
;
2292 ch
->mode
= MODE_11A
;
2294 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2297 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2298 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2299 ch
- arg
.channels
, arg
.n_channels
,
2300 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2301 ch
->max_antenna_gain
, ch
->mode
);
2307 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2308 kfree(arg
.channels
);
2313 static enum wmi_dfs_region
2314 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2316 switch (dfs_region
) {
2317 case NL80211_DFS_UNSET
:
2318 return WMI_UNINIT_DFS_DOMAIN
;
2319 case NL80211_DFS_FCC
:
2320 return WMI_FCC_DFS_DOMAIN
;
2321 case NL80211_DFS_ETSI
:
2322 return WMI_ETSI_DFS_DOMAIN
;
2323 case NL80211_DFS_JP
:
2324 return WMI_MKK4_DFS_DOMAIN
;
2326 return WMI_UNINIT_DFS_DOMAIN
;
2329 static void ath10k_regd_update(struct ath10k
*ar
)
2331 struct reg_dmn_pair_mapping
*regpair
;
2333 enum wmi_dfs_region wmi_dfs_reg
;
2334 enum nl80211_dfs_regions nl_dfs_reg
;
2336 lockdep_assert_held(&ar
->conf_mutex
);
2338 ret
= ath10k_update_channel_list(ar
);
2340 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2342 regpair
= ar
->ath_common
.regulatory
.regpair
;
2344 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2345 nl_dfs_reg
= ar
->dfs_detector
->region
;
2346 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2348 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2351 /* Target allows setting up per-band regdomain but ath_common provides
2352 * a combined one only */
2353 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2354 regpair
->reg_domain
,
2355 regpair
->reg_domain
, /* 2ghz */
2356 regpair
->reg_domain
, /* 5ghz */
2357 regpair
->reg_2ghz_ctl
,
2358 regpair
->reg_5ghz_ctl
,
2361 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2364 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2365 struct regulatory_request
*request
)
2367 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2368 struct ath10k
*ar
= hw
->priv
;
2371 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2373 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2374 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
2375 request
->dfs_region
);
2376 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
2377 request
->dfs_region
);
2379 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2380 request
->dfs_region
);
2383 mutex_lock(&ar
->conf_mutex
);
2384 if (ar
->state
== ATH10K_STATE_ON
)
2385 ath10k_regd_update(ar
);
2386 mutex_unlock(&ar
->conf_mutex
);
2393 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
2395 if (ieee80211_is_mgmt(hdr
->frame_control
))
2396 return HTT_DATA_TX_EXT_TID_MGMT
;
2398 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2399 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2401 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
2402 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2404 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
2407 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
2410 return ath10k_vif_to_arvif(vif
)->vdev_id
;
2412 if (ar
->monitor_started
)
2413 return ar
->monitor_vdev_id
;
2415 ath10k_warn(ar
, "failed to resolve vdev id\n");
2419 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2420 * Control in the header.
2422 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2424 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
2425 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
2428 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2431 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
2432 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
2433 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
2434 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
2436 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2437 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2438 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2439 * it is safe to downgrade to NullFunc.
2441 hdr
= (void *)skb
->data
;
2442 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
)) {
2443 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2444 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2448 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
2449 struct ieee80211_vif
*vif
,
2450 struct sk_buff
*skb
)
2452 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2453 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2455 /* This is case only for P2P_GO */
2456 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
2457 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
2460 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
2461 spin_lock_bh(&ar
->data_lock
);
2462 if (arvif
->u
.ap
.noa_data
)
2463 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
2465 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
2466 arvif
->u
.ap
.noa_data
,
2467 arvif
->u
.ap
.noa_len
);
2468 spin_unlock_bh(&ar
->data_lock
);
2472 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
2474 /* FIXME: Not really sure since when the behaviour changed. At some
2475 * point new firmware stopped requiring creation of peer entries for
2476 * offchannel tx (and actually creating them causes issues with wmi-htc
2477 * tx credit replenishment and reliability). Assuming it's at least 3.4
2478 * because that's when the `freq` was introduced to TX_FRM HTT command.
2480 return !(ar
->htt
.target_version_major
>= 3 &&
2481 ar
->htt
.target_version_minor
>= 4);
2484 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
2486 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2489 if (ar
->htt
.target_version_major
>= 3) {
2490 /* Since HTT 3.0 there is no separate mgmt tx command */
2491 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
2495 if (ieee80211_is_mgmt(hdr
->frame_control
)) {
2496 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2498 if (skb_queue_len(&ar
->wmi_mgmt_tx_queue
) >=
2499 ATH10K_MAX_NUM_MGMT_PENDING
) {
2500 ath10k_warn(ar
, "reached WMI management transmit queue limit\n");
2505 skb_queue_tail(&ar
->wmi_mgmt_tx_queue
, skb
);
2506 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
2508 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
2510 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2512 ieee80211_is_nullfunc(hdr
->frame_control
)) {
2513 /* FW does not report tx status properly for NullFunc frames
2514 * unless they are sent through mgmt tx path. mac80211 sends
2515 * those frames when it detects link/beacon loss and depends
2516 * on the tx status to be correct. */
2517 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
2519 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
2524 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
2526 ieee80211_free_txskb(ar
->hw
, skb
);
2530 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
2532 struct sk_buff
*skb
;
2535 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2539 ieee80211_free_txskb(ar
->hw
, skb
);
2543 void ath10k_offchan_tx_work(struct work_struct
*work
)
2545 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
2546 struct ath10k_peer
*peer
;
2547 struct ieee80211_hdr
*hdr
;
2548 struct sk_buff
*skb
;
2549 const u8
*peer_addr
;
2553 /* FW requirement: We must create a peer before FW will send out
2554 * an offchannel frame. Otherwise the frame will be stuck and
2555 * never transmitted. We delete the peer upon tx completion.
2556 * It is unlikely that a peer for offchannel tx will already be
2557 * present. However it may be in some rare cases so account for that.
2558 * Otherwise we might remove a legitimate peer and break stuff. */
2561 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2565 mutex_lock(&ar
->conf_mutex
);
2567 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
2570 hdr
= (struct ieee80211_hdr
*)skb
->data
;
2571 peer_addr
= ieee80211_get_DA(hdr
);
2572 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
2574 spin_lock_bh(&ar
->data_lock
);
2575 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
2576 spin_unlock_bh(&ar
->data_lock
);
2579 /* FIXME: should this use ath10k_warn()? */
2580 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
2581 peer_addr
, vdev_id
);
2584 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
2586 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
2587 peer_addr
, vdev_id
, ret
);
2590 spin_lock_bh(&ar
->data_lock
);
2591 reinit_completion(&ar
->offchan_tx_completed
);
2592 ar
->offchan_tx_skb
= skb
;
2593 spin_unlock_bh(&ar
->data_lock
);
2595 ath10k_tx_htt(ar
, skb
);
2597 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
2600 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
2604 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
2606 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
2607 peer_addr
, vdev_id
, ret
);
2610 mutex_unlock(&ar
->conf_mutex
);
2614 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
2616 struct sk_buff
*skb
;
2619 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2623 ieee80211_free_txskb(ar
->hw
, skb
);
2627 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
2629 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
2630 struct sk_buff
*skb
;
2634 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2638 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
2640 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
2642 ieee80211_free_txskb(ar
->hw
, skb
);
2651 void __ath10k_scan_finish(struct ath10k
*ar
)
2653 lockdep_assert_held(&ar
->data_lock
);
2655 switch (ar
->scan
.state
) {
2656 case ATH10K_SCAN_IDLE
:
2658 case ATH10K_SCAN_RUNNING
:
2659 if (ar
->scan
.is_roc
)
2660 ieee80211_remain_on_channel_expired(ar
->hw
);
2662 case ATH10K_SCAN_ABORTING
:
2663 if (!ar
->scan
.is_roc
)
2664 ieee80211_scan_completed(ar
->hw
,
2666 ATH10K_SCAN_ABORTING
));
2668 case ATH10K_SCAN_STARTING
:
2669 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
2670 ar
->scan_channel
= NULL
;
2671 ath10k_offchan_tx_purge(ar
);
2672 cancel_delayed_work(&ar
->scan
.timeout
);
2673 complete_all(&ar
->scan
.completed
);
2678 void ath10k_scan_finish(struct ath10k
*ar
)
2680 spin_lock_bh(&ar
->data_lock
);
2681 __ath10k_scan_finish(ar
);
2682 spin_unlock_bh(&ar
->data_lock
);
2685 static int ath10k_scan_stop(struct ath10k
*ar
)
2687 struct wmi_stop_scan_arg arg
= {
2688 .req_id
= 1, /* FIXME */
2689 .req_type
= WMI_SCAN_STOP_ONE
,
2690 .u
.scan_id
= ATH10K_SCAN_ID
,
2694 lockdep_assert_held(&ar
->conf_mutex
);
2696 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
2698 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
2702 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
2704 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
2706 } else if (ret
> 0) {
2711 /* Scan state should be updated upon scan completion but in case
2712 * firmware fails to deliver the event (for whatever reason) it is
2713 * desired to clean up scan state anyway. Firmware may have just
2714 * dropped the scan completion event delivery due to transport pipe
2715 * being overflown with data and/or it can recover on its own before
2716 * next scan request is submitted.
2718 spin_lock_bh(&ar
->data_lock
);
2719 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
2720 __ath10k_scan_finish(ar
);
2721 spin_unlock_bh(&ar
->data_lock
);
2726 static void ath10k_scan_abort(struct ath10k
*ar
)
2730 lockdep_assert_held(&ar
->conf_mutex
);
2732 spin_lock_bh(&ar
->data_lock
);
2734 switch (ar
->scan
.state
) {
2735 case ATH10K_SCAN_IDLE
:
2736 /* This can happen if timeout worker kicked in and called
2737 * abortion while scan completion was being processed.
2740 case ATH10K_SCAN_STARTING
:
2741 case ATH10K_SCAN_ABORTING
:
2742 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2743 ath10k_scan_state_str(ar
->scan
.state
),
2746 case ATH10K_SCAN_RUNNING
:
2747 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
2748 spin_unlock_bh(&ar
->data_lock
);
2750 ret
= ath10k_scan_stop(ar
);
2752 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
2754 spin_lock_bh(&ar
->data_lock
);
2758 spin_unlock_bh(&ar
->data_lock
);
2761 void ath10k_scan_timeout_work(struct work_struct
*work
)
2763 struct ath10k
*ar
= container_of(work
, struct ath10k
,
2766 mutex_lock(&ar
->conf_mutex
);
2767 ath10k_scan_abort(ar
);
2768 mutex_unlock(&ar
->conf_mutex
);
2771 static int ath10k_start_scan(struct ath10k
*ar
,
2772 const struct wmi_start_scan_arg
*arg
)
2776 lockdep_assert_held(&ar
->conf_mutex
);
2778 ret
= ath10k_wmi_start_scan(ar
, arg
);
2782 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
2784 ret
= ath10k_scan_stop(ar
);
2786 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
2791 /* If we failed to start the scan, return error code at
2792 * this point. This is probably due to some issue in the
2793 * firmware, but no need to wedge the driver due to that...
2795 spin_lock_bh(&ar
->data_lock
);
2796 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
2797 spin_unlock_bh(&ar
->data_lock
);
2800 spin_unlock_bh(&ar
->data_lock
);
2802 /* Add a 200ms margin to account for event/command processing */
2803 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
2804 msecs_to_jiffies(arg
->max_scan_time
+200));
2808 /**********************/
2809 /* mac80211 callbacks */
2810 /**********************/
2812 static void ath10k_tx(struct ieee80211_hw
*hw
,
2813 struct ieee80211_tx_control
*control
,
2814 struct sk_buff
*skb
)
2816 struct ath10k
*ar
= hw
->priv
;
2817 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2818 struct ieee80211_vif
*vif
= info
->control
.vif
;
2819 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2821 /* We should disable CCK RATE due to P2P */
2822 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
2823 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2825 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
2826 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
2827 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
2829 /* it makes no sense to process injected frames like that */
2830 if (vif
&& vif
->type
!= NL80211_IFTYPE_MONITOR
) {
2831 ath10k_tx_h_nwifi(hw
, skb
);
2832 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
2833 ath10k_tx_h_seq_no(vif
, skb
);
2836 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
2837 spin_lock_bh(&ar
->data_lock
);
2838 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
2839 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
2840 spin_unlock_bh(&ar
->data_lock
);
2842 if (ath10k_mac_need_offchan_tx_work(ar
)) {
2843 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
2844 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
2846 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
2849 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
2850 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
2855 ath10k_tx_htt(ar
, skb
);
2858 /* Must not be called with conf_mutex held as workers can use that also. */
2859 void ath10k_drain_tx(struct ath10k
*ar
)
2861 /* make sure rcu-protected mac80211 tx path itself is drained */
2864 ath10k_offchan_tx_purge(ar
);
2865 ath10k_mgmt_over_wmi_tx_purge(ar
);
2867 cancel_work_sync(&ar
->offchan_tx_work
);
2868 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
2871 void ath10k_halt(struct ath10k
*ar
)
2873 struct ath10k_vif
*arvif
;
2875 lockdep_assert_held(&ar
->conf_mutex
);
2877 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
2878 ar
->filter_flags
= 0;
2879 ar
->monitor
= false;
2881 if (ar
->monitor_started
)
2882 ath10k_monitor_stop(ar
);
2884 ar
->monitor_started
= false;
2886 ath10k_scan_finish(ar
);
2887 ath10k_peer_cleanup_all(ar
);
2888 ath10k_core_stop(ar
);
2889 ath10k_hif_power_down(ar
);
2891 spin_lock_bh(&ar
->data_lock
);
2892 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
2893 ath10k_mac_vif_beacon_cleanup(arvif
);
2894 spin_unlock_bh(&ar
->data_lock
);
2897 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
2899 struct ath10k
*ar
= hw
->priv
;
2901 mutex_lock(&ar
->conf_mutex
);
2903 if (ar
->cfg_tx_chainmask
) {
2904 *tx_ant
= ar
->cfg_tx_chainmask
;
2905 *rx_ant
= ar
->cfg_rx_chainmask
;
2907 *tx_ant
= ar
->supp_tx_chainmask
;
2908 *rx_ant
= ar
->supp_rx_chainmask
;
2911 mutex_unlock(&ar
->conf_mutex
);
2916 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
2918 /* It is not clear that allowing gaps in chainmask
2919 * is helpful. Probably it will not do what user
2920 * is hoping for, so warn in that case.
2922 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
2925 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2929 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
2933 lockdep_assert_held(&ar
->conf_mutex
);
2935 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
2936 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
2938 ar
->cfg_tx_chainmask
= tx_ant
;
2939 ar
->cfg_rx_chainmask
= rx_ant
;
2941 if ((ar
->state
!= ATH10K_STATE_ON
) &&
2942 (ar
->state
!= ATH10K_STATE_RESTARTED
))
2945 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
2948 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
2953 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
2956 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
2964 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
2966 struct ath10k
*ar
= hw
->priv
;
2969 mutex_lock(&ar
->conf_mutex
);
2970 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
2971 mutex_unlock(&ar
->conf_mutex
);
2975 static int ath10k_start(struct ieee80211_hw
*hw
)
2977 struct ath10k
*ar
= hw
->priv
;
2981 * This makes sense only when restarting hw. It is harmless to call
2982 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2983 * commands will be submitted while restarting.
2985 ath10k_drain_tx(ar
);
2987 mutex_lock(&ar
->conf_mutex
);
2989 switch (ar
->state
) {
2990 case ATH10K_STATE_OFF
:
2991 ar
->state
= ATH10K_STATE_ON
;
2993 case ATH10K_STATE_RESTARTING
:
2995 ar
->state
= ATH10K_STATE_RESTARTED
;
2997 case ATH10K_STATE_ON
:
2998 case ATH10K_STATE_RESTARTED
:
2999 case ATH10K_STATE_WEDGED
:
3003 case ATH10K_STATE_UTF
:
3008 ret
= ath10k_hif_power_up(ar
);
3010 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
3014 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
3016 ath10k_err(ar
, "Could not init core: %d\n", ret
);
3017 goto err_power_down
;
3020 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
3022 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
3026 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
3028 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
3032 if (ar
->cfg_tx_chainmask
)
3033 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
3034 ar
->cfg_rx_chainmask
);
3037 * By default FW set ARP frames ac to voice (6). In that case ARP
3038 * exchange is not working properly for UAPSD enabled AP. ARP requests
3039 * which arrives with access category 0 are processed by network stack
3040 * and send back with access category 0, but FW changes access category
3041 * to 6. Set ARP frames access category to best effort (0) solves
3045 ret
= ath10k_wmi_pdev_set_param(ar
,
3046 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
3048 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
3053 ar
->num_started_vdevs
= 0;
3054 ath10k_regd_update(ar
);
3056 ath10k_spectral_start(ar
);
3058 mutex_unlock(&ar
->conf_mutex
);
3062 ath10k_core_stop(ar
);
3065 ath10k_hif_power_down(ar
);
3068 ar
->state
= ATH10K_STATE_OFF
;
3071 mutex_unlock(&ar
->conf_mutex
);
3075 static void ath10k_stop(struct ieee80211_hw
*hw
)
3077 struct ath10k
*ar
= hw
->priv
;
3079 ath10k_drain_tx(ar
);
3081 mutex_lock(&ar
->conf_mutex
);
3082 if (ar
->state
!= ATH10K_STATE_OFF
) {
3084 ar
->state
= ATH10K_STATE_OFF
;
3086 mutex_unlock(&ar
->conf_mutex
);
3088 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3089 cancel_work_sync(&ar
->restart_work
);
3092 static int ath10k_config_ps(struct ath10k
*ar
)
3094 struct ath10k_vif
*arvif
;
3097 lockdep_assert_held(&ar
->conf_mutex
);
3099 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3100 ret
= ath10k_mac_vif_setup_ps(arvif
);
3102 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
3110 static const char *chandef_get_width(enum nl80211_chan_width width
)
3113 case NL80211_CHAN_WIDTH_20_NOHT
:
3115 case NL80211_CHAN_WIDTH_20
:
3117 case NL80211_CHAN_WIDTH_40
:
3119 case NL80211_CHAN_WIDTH_80
:
3121 case NL80211_CHAN_WIDTH_80P80
:
3123 case NL80211_CHAN_WIDTH_160
:
3125 case NL80211_CHAN_WIDTH_5
:
3127 case NL80211_CHAN_WIDTH_10
:
3133 static void ath10k_config_chan(struct ath10k
*ar
)
3135 struct ath10k_vif
*arvif
;
3138 lockdep_assert_held(&ar
->conf_mutex
);
3140 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3141 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3142 ar
->chandef
.chan
->center_freq
,
3143 ar
->chandef
.center_freq1
,
3144 ar
->chandef
.center_freq2
,
3145 chandef_get_width(ar
->chandef
.width
));
3147 /* First stop monitor interface. Some FW versions crash if there's a
3148 * lone monitor interface. */
3149 if (ar
->monitor_started
)
3150 ath10k_monitor_stop(ar
);
3152 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3153 if (!arvif
->is_started
)
3159 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3162 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
3164 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
3165 arvif
->vdev_id
, ret
);
3170 /* all vdevs are downed now - attempt to restart and re-up them */
3172 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3173 if (!arvif
->is_started
)
3176 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3179 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3181 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
3184 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
3186 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
3189 ret
= ath10k_vdev_restart(arvif
);
3191 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
3192 arvif
->vdev_id
, ret
);
3199 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
3202 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
3203 arvif
->vdev_id
, ret
);
3208 ath10k_monitor_recalc(ar
);
3211 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
3216 lockdep_assert_held(&ar
->conf_mutex
);
3218 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
3220 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
3221 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3223 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
3228 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
3229 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3231 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
3239 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
3241 struct ath10k_vif
*arvif
;
3242 int ret
, txpower
= -1;
3244 lockdep_assert_held(&ar
->conf_mutex
);
3246 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3247 WARN_ON(arvif
->txpower
< 0);
3250 txpower
= arvif
->txpower
;
3252 txpower
= min(txpower
, arvif
->txpower
);
3255 if (WARN_ON(txpower
== -1))
3258 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
3260 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
3268 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
3270 struct ath10k
*ar
= hw
->priv
;
3271 struct ieee80211_conf
*conf
= &hw
->conf
;
3274 mutex_lock(&ar
->conf_mutex
);
3276 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
3277 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3278 "mac config channel %dMHz flags 0x%x radar %d\n",
3279 conf
->chandef
.chan
->center_freq
,
3280 conf
->chandef
.chan
->flags
,
3281 conf
->radar_enabled
);
3283 spin_lock_bh(&ar
->data_lock
);
3284 ar
->rx_channel
= conf
->chandef
.chan
;
3285 spin_unlock_bh(&ar
->data_lock
);
3287 ar
->radar_enabled
= conf
->radar_enabled
;
3288 ath10k_recalc_radar_detection(ar
);
3290 if (!cfg80211_chandef_identical(&ar
->chandef
, &conf
->chandef
)) {
3291 ar
->chandef
= conf
->chandef
;
3292 ath10k_config_chan(ar
);
3296 if (changed
& IEEE80211_CONF_CHANGE_PS
)
3297 ath10k_config_ps(ar
);
3299 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
3300 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
3301 ret
= ath10k_monitor_recalc(ar
);
3303 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
3306 mutex_unlock(&ar
->conf_mutex
);
3310 static u32
get_nss_from_chainmask(u16 chain_mask
)
3312 if ((chain_mask
& 0x15) == 0x15)
3314 else if ((chain_mask
& 0x7) == 0x7)
3316 else if ((chain_mask
& 0x3) == 0x3)
3323 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3324 * because we will send mgmt frames without CCK. This requirement
3325 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3328 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
3329 struct ieee80211_vif
*vif
)
3331 struct ath10k
*ar
= hw
->priv
;
3332 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3333 enum wmi_sta_powersave_param param
;
3339 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
3341 mutex_lock(&ar
->conf_mutex
);
3343 memset(arvif
, 0, sizeof(*arvif
));
3348 INIT_LIST_HEAD(&arvif
->list
);
3349 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
3351 if (ar
->free_vdev_map
== 0) {
3352 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
3356 bit
= __ffs64(ar
->free_vdev_map
);
3358 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
3359 bit
, ar
->free_vdev_map
);
3361 arvif
->vdev_id
= bit
;
3362 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
3364 switch (vif
->type
) {
3365 case NL80211_IFTYPE_P2P_DEVICE
:
3366 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
3367 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
3369 case NL80211_IFTYPE_UNSPECIFIED
:
3370 case NL80211_IFTYPE_STATION
:
3371 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
3373 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
3375 case NL80211_IFTYPE_ADHOC
:
3376 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
3378 case NL80211_IFTYPE_AP
:
3379 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
3382 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
3384 case NL80211_IFTYPE_MONITOR
:
3385 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
3392 /* Some firmware revisions don't wait for beacon tx completion before
3393 * sending another SWBA event. This could lead to hardware using old
3394 * (freed) beacon data in some cases, e.g. tx credit starvation
3395 * combined with missed TBTT. This is very very rare.
3397 * On non-IOMMU-enabled hosts this could be a possible security issue
3398 * because hw could beacon some random data on the air. On
3399 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3400 * device would crash.
3402 * Since there are no beacon tx completions (implicit nor explicit)
3403 * propagated to host the only workaround for this is to allocate a
3404 * DMA-coherent buffer for a lifetime of a vif and use it for all
3405 * beacon tx commands. Worst case for this approach is some beacons may
3406 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3408 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
3409 vif
->type
== NL80211_IFTYPE_AP
) {
3410 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
3411 IEEE80211_MAX_FRAME_LEN
,
3412 &arvif
->beacon_paddr
,
3414 if (!arvif
->beacon_buf
) {
3416 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
3422 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3423 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
3424 arvif
->beacon_buf
? "single-buf" : "per-skb");
3426 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
3427 arvif
->vdev_subtype
, vif
->addr
);
3429 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
3430 arvif
->vdev_id
, ret
);
3434 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
3435 list_add(&arvif
->list
, &ar
->arvifs
);
3437 /* It makes no sense to have firmware do keepalives. mac80211 already
3438 * takes care of this with idle connection polling.
3440 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
3442 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
3443 arvif
->vdev_id
, ret
);
3444 goto err_vdev_delete
;
3447 arvif
->def_wep_key_idx
= -1;
3449 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
3450 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3451 ATH10K_HW_TXRX_NATIVE_WIFI
);
3452 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3453 if (ret
&& ret
!= -EOPNOTSUPP
) {
3454 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
3455 arvif
->vdev_id
, ret
);
3456 goto err_vdev_delete
;
3459 if (ar
->cfg_tx_chainmask
) {
3460 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
3462 vdev_param
= ar
->wmi
.vdev_param
->nss
;
3463 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3466 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3467 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
3469 goto err_vdev_delete
;
3473 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3474 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
3476 ath10k_warn(ar
, "failed to create vdev %i peer for AP: %d\n",
3477 arvif
->vdev_id
, ret
);
3478 goto err_vdev_delete
;
3481 ret
= ath10k_mac_set_kickout(arvif
);
3483 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
3484 arvif
->vdev_id
, ret
);
3485 goto err_peer_delete
;
3489 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
3490 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
3491 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
3492 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3495 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
3496 arvif
->vdev_id
, ret
);
3497 goto err_peer_delete
;
3500 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
3502 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
3503 arvif
->vdev_id
, ret
);
3504 goto err_peer_delete
;
3507 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
3509 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
3510 arvif
->vdev_id
, ret
);
3511 goto err_peer_delete
;
3515 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
3517 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
3518 arvif
->vdev_id
, ret
);
3519 goto err_peer_delete
;
3522 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
3524 ath10k_warn(ar
, "failed to set frag threshold for vdev %d: %d\n",
3525 arvif
->vdev_id
, ret
);
3526 goto err_peer_delete
;
3529 arvif
->txpower
= vif
->bss_conf
.txpower
;
3530 ret
= ath10k_mac_txpower_recalc(ar
);
3532 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
3533 goto err_peer_delete
;
3536 mutex_unlock(&ar
->conf_mutex
);
3540 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
3541 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
3544 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
3545 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
3546 list_del(&arvif
->list
);
3549 if (arvif
->beacon_buf
) {
3550 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
3551 arvif
->beacon_buf
, arvif
->beacon_paddr
);
3552 arvif
->beacon_buf
= NULL
;
3555 mutex_unlock(&ar
->conf_mutex
);
3560 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
3561 struct ieee80211_vif
*vif
)
3563 struct ath10k
*ar
= hw
->priv
;
3564 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3567 cancel_work_sync(&arvif
->ap_csa_work
);
3569 mutex_lock(&ar
->conf_mutex
);
3571 spin_lock_bh(&ar
->data_lock
);
3572 ath10k_mac_vif_beacon_cleanup(arvif
);
3573 spin_unlock_bh(&ar
->data_lock
);
3575 ret
= ath10k_spectral_vif_stop(arvif
);
3577 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
3578 arvif
->vdev_id
, ret
);
3580 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
3581 list_del(&arvif
->list
);
3583 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3584 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
3587 ath10k_warn(ar
, "failed to submit AP self-peer removal on vdev %i: %d\n",
3588 arvif
->vdev_id
, ret
);
3590 kfree(arvif
->u
.ap
.noa_data
);
3593 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
3596 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
3598 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
3599 arvif
->vdev_id
, ret
);
3601 /* Some firmware revisions don't notify host about self-peer removal
3602 * until after associated vdev is deleted.
3604 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3605 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
3608 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
3609 arvif
->vdev_id
, ret
);
3611 spin_lock_bh(&ar
->data_lock
);
3613 spin_unlock_bh(&ar
->data_lock
);
3616 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
3618 mutex_unlock(&ar
->conf_mutex
);
3622 * FIXME: Has to be verified.
3624 #define SUPPORTED_FILTERS \
3625 (FIF_PROMISC_IN_BSS | \
3630 FIF_BCN_PRBRESP_PROMISC | \
3634 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
3635 unsigned int changed_flags
,
3636 unsigned int *total_flags
,
3639 struct ath10k
*ar
= hw
->priv
;
3642 mutex_lock(&ar
->conf_mutex
);
3644 changed_flags
&= SUPPORTED_FILTERS
;
3645 *total_flags
&= SUPPORTED_FILTERS
;
3646 ar
->filter_flags
= *total_flags
;
3648 ret
= ath10k_monitor_recalc(ar
);
3650 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
3652 mutex_unlock(&ar
->conf_mutex
);
3655 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
3656 struct ieee80211_vif
*vif
,
3657 struct ieee80211_bss_conf
*info
,
3660 struct ath10k
*ar
= hw
->priv
;
3661 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3663 u32 vdev_param
, pdev_param
, slottime
, preamble
;
3665 mutex_lock(&ar
->conf_mutex
);
3667 if (changed
& BSS_CHANGED_IBSS
)
3668 ath10k_control_ibss(arvif
, info
, vif
->addr
);
3670 if (changed
& BSS_CHANGED_BEACON_INT
) {
3671 arvif
->beacon_interval
= info
->beacon_int
;
3672 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
3673 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3674 arvif
->beacon_interval
);
3675 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3676 "mac vdev %d beacon_interval %d\n",
3677 arvif
->vdev_id
, arvif
->beacon_interval
);
3680 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
3681 arvif
->vdev_id
, ret
);
3684 if (changed
& BSS_CHANGED_BEACON
) {
3685 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3686 "vdev %d set beacon tx mode to staggered\n",
3689 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
3690 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
3691 WMI_BEACON_STAGGERED_MODE
);
3693 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
3694 arvif
->vdev_id
, ret
);
3696 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3698 ath10k_warn(ar
, "failed to update beacon template: %d\n",
3702 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
3703 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
3705 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
3706 arvif
->vdev_id
, ret
);
3709 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
3710 arvif
->dtim_period
= info
->dtim_period
;
3712 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3713 "mac vdev %d dtim_period %d\n",
3714 arvif
->vdev_id
, arvif
->dtim_period
);
3716 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
3717 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3718 arvif
->dtim_period
);
3720 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
3721 arvif
->vdev_id
, ret
);
3724 if (changed
& BSS_CHANGED_SSID
&&
3725 vif
->type
== NL80211_IFTYPE_AP
) {
3726 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
3728 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
3729 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
3732 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
3733 ether_addr_copy(arvif
->bssid
, info
->bssid
);
3735 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
3736 ath10k_control_beaconing(arvif
, info
);
3738 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3739 arvif
->use_cts_prot
= info
->use_cts_prot
;
3740 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
3741 arvif
->vdev_id
, info
->use_cts_prot
);
3743 ret
= ath10k_recalc_rtscts_prot(arvif
);
3745 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3746 arvif
->vdev_id
, ret
);
3749 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3750 if (info
->use_short_slot
)
3751 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
3754 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
3756 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
3757 arvif
->vdev_id
, slottime
);
3759 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
3760 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3763 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
3764 arvif
->vdev_id
, ret
);
3767 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3768 if (info
->use_short_preamble
)
3769 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
3771 preamble
= WMI_VDEV_PREAMBLE_LONG
;
3773 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3774 "mac vdev %d preamble %dn",
3775 arvif
->vdev_id
, preamble
);
3777 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
3778 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3781 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
3782 arvif
->vdev_id
, ret
);
3785 if (changed
& BSS_CHANGED_ASSOC
) {
3787 /* Workaround: Make sure monitor vdev is not running
3788 * when associating to prevent some firmware revisions
3789 * (e.g. 10.1 and 10.2) from crashing.
3791 if (ar
->monitor_started
)
3792 ath10k_monitor_stop(ar
);
3793 ath10k_bss_assoc(hw
, vif
, info
);
3794 ath10k_monitor_recalc(ar
);
3796 ath10k_bss_disassoc(hw
, vif
);
3800 if (changed
& BSS_CHANGED_TXPOWER
) {
3801 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
3802 arvif
->vdev_id
, info
->txpower
);
3804 arvif
->txpower
= info
->txpower
;
3805 ret
= ath10k_mac_txpower_recalc(ar
);
3807 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
3810 if (changed
& BSS_CHANGED_PS
) {
3811 arvif
->ps
= vif
->bss_conf
.ps
;
3813 ret
= ath10k_config_ps(ar
);
3815 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
3816 arvif
->vdev_id
, ret
);
3819 mutex_unlock(&ar
->conf_mutex
);
3822 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
3823 struct ieee80211_vif
*vif
,
3824 struct ieee80211_scan_request
*hw_req
)
3826 struct ath10k
*ar
= hw
->priv
;
3827 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3828 struct cfg80211_scan_request
*req
= &hw_req
->req
;
3829 struct wmi_start_scan_arg arg
;
3833 mutex_lock(&ar
->conf_mutex
);
3835 spin_lock_bh(&ar
->data_lock
);
3836 switch (ar
->scan
.state
) {
3837 case ATH10K_SCAN_IDLE
:
3838 reinit_completion(&ar
->scan
.started
);
3839 reinit_completion(&ar
->scan
.completed
);
3840 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
3841 ar
->scan
.is_roc
= false;
3842 ar
->scan
.vdev_id
= arvif
->vdev_id
;
3845 case ATH10K_SCAN_STARTING
:
3846 case ATH10K_SCAN_RUNNING
:
3847 case ATH10K_SCAN_ABORTING
:
3851 spin_unlock_bh(&ar
->data_lock
);
3856 memset(&arg
, 0, sizeof(arg
));
3857 ath10k_wmi_start_scan_init(ar
, &arg
);
3858 arg
.vdev_id
= arvif
->vdev_id
;
3859 arg
.scan_id
= ATH10K_SCAN_ID
;
3862 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
3865 arg
.ie_len
= req
->ie_len
;
3866 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
3870 arg
.n_ssids
= req
->n_ssids
;
3871 for (i
= 0; i
< arg
.n_ssids
; i
++) {
3872 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
3873 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
3876 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
3879 if (req
->n_channels
) {
3880 arg
.n_channels
= req
->n_channels
;
3881 for (i
= 0; i
< arg
.n_channels
; i
++)
3882 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
3885 ret
= ath10k_start_scan(ar
, &arg
);
3887 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
3888 spin_lock_bh(&ar
->data_lock
);
3889 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3890 spin_unlock_bh(&ar
->data_lock
);
3894 mutex_unlock(&ar
->conf_mutex
);
3898 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
3899 struct ieee80211_vif
*vif
)
3901 struct ath10k
*ar
= hw
->priv
;
3903 mutex_lock(&ar
->conf_mutex
);
3904 ath10k_scan_abort(ar
);
3905 mutex_unlock(&ar
->conf_mutex
);
3907 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3910 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
3911 struct ath10k_vif
*arvif
,
3912 enum set_key_cmd cmd
,
3913 struct ieee80211_key_conf
*key
)
3915 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
3918 /* 10.1 firmware branch requires default key index to be set to group
3919 * key index after installing it. Otherwise FW/HW Txes corrupted
3920 * frames with multi-vif APs. This is not required for main firmware
3921 * branch (e.g. 636).
3923 * FIXME: This has been tested only in AP. It remains unknown if this
3924 * is required for multi-vif STA interfaces on 10.1 */
3926 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
3929 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
3932 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
3935 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3941 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3944 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
3945 arvif
->vdev_id
, ret
);
3948 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3949 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
3950 struct ieee80211_key_conf
*key
)
3952 struct ath10k
*ar
= hw
->priv
;
3953 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3954 struct ath10k_peer
*peer
;
3955 const u8
*peer_addr
;
3956 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3957 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
3961 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
3964 mutex_lock(&ar
->conf_mutex
);
3967 peer_addr
= sta
->addr
;
3968 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
3969 peer_addr
= vif
->bss_conf
.bssid
;
3971 peer_addr
= vif
->addr
;
3973 key
->hw_key_idx
= key
->keyidx
;
3975 /* the peer should not disappear in mid-way (unless FW goes awry) since
3976 * we already hold conf_mutex. we just make sure its there now. */
3977 spin_lock_bh(&ar
->data_lock
);
3978 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3979 spin_unlock_bh(&ar
->data_lock
);
3982 if (cmd
== SET_KEY
) {
3983 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
3988 /* if the peer doesn't exist there is no key to disable
3996 arvif
->wep_keys
[key
->keyidx
] = key
;
3998 arvif
->wep_keys
[key
->keyidx
] = NULL
;
4000 if (cmd
== DISABLE_KEY
)
4001 ath10k_clear_vdev_key(arvif
, key
);
4003 /* When WEP keys are uploaded it's possible that there are
4004 * stations associated already (e.g. when merging) without any
4005 * keys. Static WEP needs an explicit per-peer key upload.
4007 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
4009 ath10k_mac_vif_update_wep_key(arvif
, key
);
4011 /* 802.1x never sets the def_wep_key_idx so each set_key()
4012 * call changes default tx key.
4014 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4015 * after first set_key().
4017 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
4018 flags
|= WMI_KEY_TX_USAGE
;
4021 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4022 flags
|= WMI_KEY_PAIRWISE
;
4024 flags
|= WMI_KEY_GROUP
;
4026 /* mac80211 uploads static WEP keys as groupwise while fw/hw requires
4027 * pairwise keys for non-self peers, i.e. BSSID in STA mode and
4028 * associated stations in AP/IBSS.
4030 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys work
4031 * fine when mapped directly from mac80211.
4033 * Note: When installing first static WEP groupwise key (which should
4034 * be pairwise) def_wep_key_idx isn't known yet (it's equal to -1).
4035 * Since .set_default_unicast_key is called only for static WEP it's
4036 * used to re-upload the key as pairwise.
4038 if (arvif
->def_wep_key_idx
>= 0 &&
4039 memcmp(peer_addr
, arvif
->vif
->addr
, ETH_ALEN
)) {
4040 flags
&= ~WMI_KEY_GROUP
;
4041 flags
|= WMI_KEY_PAIRWISE
;
4044 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
4046 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
4047 arvif
->vdev_id
, peer_addr
, ret
);
4051 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
4053 spin_lock_bh(&ar
->data_lock
);
4054 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4055 if (peer
&& cmd
== SET_KEY
)
4056 peer
->keys
[key
->keyidx
] = key
;
4057 else if (peer
&& cmd
== DISABLE_KEY
)
4058 peer
->keys
[key
->keyidx
] = NULL
;
4059 else if (peer
== NULL
)
4060 /* impossible unless FW goes crazy */
4061 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
4062 spin_unlock_bh(&ar
->data_lock
);
4065 mutex_unlock(&ar
->conf_mutex
);
4069 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
4070 struct ieee80211_vif
*vif
,
4073 struct ath10k
*ar
= hw
->priv
;
4074 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4077 mutex_lock(&arvif
->ar
->conf_mutex
);
4079 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
4082 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
4083 arvif
->vdev_id
, keyidx
);
4085 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
4087 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
4091 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
4097 arvif
->def_wep_key_idx
= keyidx
;
4099 ret
= ath10k_mac_vif_sta_fix_wep_key(arvif
);
4101 ath10k_warn(ar
, "failed to fix sta wep key on vdev %i: %d\n",
4102 arvif
->vdev_id
, ret
);
4107 mutex_unlock(&arvif
->ar
->conf_mutex
);
4110 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
4113 struct ath10k_vif
*arvif
;
4114 struct ath10k_sta
*arsta
;
4115 struct ieee80211_sta
*sta
;
4116 u32 changed
, bw
, nss
, smps
;
4119 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
4120 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
4121 arvif
= arsta
->arvif
;
4124 spin_lock_bh(&ar
->data_lock
);
4126 changed
= arsta
->changed
;
4133 spin_unlock_bh(&ar
->data_lock
);
4135 mutex_lock(&ar
->conf_mutex
);
4137 if (changed
& IEEE80211_RC_BW_CHANGED
) {
4138 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
4141 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4142 WMI_PEER_CHAN_WIDTH
, bw
);
4144 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
4145 sta
->addr
, bw
, err
);
4148 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
4149 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
4152 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4155 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
4156 sta
->addr
, nss
, err
);
4159 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
4160 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
4163 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4164 WMI_PEER_SMPS_STATE
, smps
);
4166 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
4167 sta
->addr
, smps
, err
);
4170 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
||
4171 changed
& IEEE80211_RC_NSS_CHANGED
) {
4172 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates/nss\n",
4175 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
4177 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
4181 mutex_unlock(&ar
->conf_mutex
);
4184 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
)
4186 struct ath10k
*ar
= arvif
->ar
;
4188 lockdep_assert_held(&ar
->conf_mutex
);
4190 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
4191 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
4194 if (ar
->num_stations
>= ar
->max_num_stations
)
4202 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
)
4204 struct ath10k
*ar
= arvif
->ar
;
4206 lockdep_assert_held(&ar
->conf_mutex
);
4208 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
4209 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
4215 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
4216 struct ieee80211_vif
*vif
,
4217 struct ieee80211_sta
*sta
,
4218 enum ieee80211_sta_state old_state
,
4219 enum ieee80211_sta_state new_state
)
4221 struct ath10k
*ar
= hw
->priv
;
4222 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4223 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4226 if (old_state
== IEEE80211_STA_NOTEXIST
&&
4227 new_state
== IEEE80211_STA_NONE
) {
4228 memset(arsta
, 0, sizeof(*arsta
));
4229 arsta
->arvif
= arvif
;
4230 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
4233 /* cancel must be done outside the mutex to avoid deadlock */
4234 if ((old_state
== IEEE80211_STA_NONE
&&
4235 new_state
== IEEE80211_STA_NOTEXIST
))
4236 cancel_work_sync(&arsta
->update_wk
);
4238 mutex_lock(&ar
->conf_mutex
);
4240 if (old_state
== IEEE80211_STA_NOTEXIST
&&
4241 new_state
== IEEE80211_STA_NONE
) {
4243 * New station addition.
4245 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4246 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4247 arvif
->vdev_id
, sta
->addr
,
4248 ar
->num_stations
+ 1, ar
->max_num_stations
,
4249 ar
->num_peers
+ 1, ar
->max_num_peers
);
4251 ret
= ath10k_mac_inc_num_stations(arvif
);
4253 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
4254 ar
->max_num_stations
);
4258 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
4260 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
4261 sta
->addr
, arvif
->vdev_id
, ret
);
4262 ath10k_mac_dec_num_stations(arvif
);
4266 if (vif
->type
== NL80211_IFTYPE_STATION
) {
4267 WARN_ON(arvif
->is_started
);
4269 ret
= ath10k_vdev_start(arvif
);
4271 ath10k_warn(ar
, "failed to start vdev %i: %d\n",
4272 arvif
->vdev_id
, ret
);
4273 WARN_ON(ath10k_peer_delete(ar
, arvif
->vdev_id
,
4275 ath10k_mac_dec_num_stations(arvif
);
4279 arvif
->is_started
= true;
4281 } else if ((old_state
== IEEE80211_STA_NONE
&&
4282 new_state
== IEEE80211_STA_NOTEXIST
)) {
4284 * Existing station deletion.
4286 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4287 "mac vdev %d peer delete %pM (sta gone)\n",
4288 arvif
->vdev_id
, sta
->addr
);
4290 if (vif
->type
== NL80211_IFTYPE_STATION
) {
4291 WARN_ON(!arvif
->is_started
);
4293 ret
= ath10k_vdev_stop(arvif
);
4295 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
4296 arvif
->vdev_id
, ret
);
4298 arvif
->is_started
= false;
4301 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
4303 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
4304 sta
->addr
, arvif
->vdev_id
, ret
);
4306 ath10k_mac_dec_num_stations(arvif
);
4307 } else if (old_state
== IEEE80211_STA_AUTH
&&
4308 new_state
== IEEE80211_STA_ASSOC
&&
4309 (vif
->type
== NL80211_IFTYPE_AP
||
4310 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
4314 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
4317 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
4319 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
4320 sta
->addr
, arvif
->vdev_id
, ret
);
4321 } else if (old_state
== IEEE80211_STA_ASSOC
&&
4322 new_state
== IEEE80211_STA_AUTH
&&
4323 (vif
->type
== NL80211_IFTYPE_AP
||
4324 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
4328 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
4331 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
4333 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
4334 sta
->addr
, arvif
->vdev_id
, ret
);
4337 mutex_unlock(&ar
->conf_mutex
);
4341 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
4342 u16 ac
, bool enable
)
4344 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4345 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
4346 u32 prio
= 0, acc
= 0;
4350 lockdep_assert_held(&ar
->conf_mutex
);
4352 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
4356 case IEEE80211_AC_VO
:
4357 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
4358 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
4362 case IEEE80211_AC_VI
:
4363 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
4364 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
4368 case IEEE80211_AC_BE
:
4369 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
4370 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
4374 case IEEE80211_AC_BK
:
4375 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
4376 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
4383 arvif
->u
.sta
.uapsd
|= value
;
4385 arvif
->u
.sta
.uapsd
&= ~value
;
4387 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4388 WMI_STA_PS_PARAM_UAPSD
,
4389 arvif
->u
.sta
.uapsd
);
4391 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
4395 if (arvif
->u
.sta
.uapsd
)
4396 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
4398 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4400 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4401 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
4404 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
4406 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4408 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4409 arvif
->vdev_id
, ret
);
4413 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4415 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4416 arvif
->vdev_id
, ret
);
4420 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
4421 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
4422 /* Only userspace can make an educated decision when to send
4423 * trigger frame. The following effectively disables u-UAPSD
4424 * autotrigger in firmware (which is enabled by default
4425 * provided the autotrigger service is available).
4429 arg
.user_priority
= prio
;
4430 arg
.service_interval
= 0;
4431 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
4432 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
4434 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
4435 arvif
->bssid
, &arg
, 1);
4437 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
4447 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
4448 struct ieee80211_vif
*vif
, u16 ac
,
4449 const struct ieee80211_tx_queue_params
*params
)
4451 struct ath10k
*ar
= hw
->priv
;
4452 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4453 struct wmi_wmm_params_arg
*p
= NULL
;
4456 mutex_lock(&ar
->conf_mutex
);
4459 case IEEE80211_AC_VO
:
4460 p
= &arvif
->wmm_params
.ac_vo
;
4462 case IEEE80211_AC_VI
:
4463 p
= &arvif
->wmm_params
.ac_vi
;
4465 case IEEE80211_AC_BE
:
4466 p
= &arvif
->wmm_params
.ac_be
;
4468 case IEEE80211_AC_BK
:
4469 p
= &arvif
->wmm_params
.ac_bk
;
4478 p
->cwmin
= params
->cw_min
;
4479 p
->cwmax
= params
->cw_max
;
4480 p
->aifs
= params
->aifs
;
4483 * The channel time duration programmed in the HW is in absolute
4484 * microseconds, while mac80211 gives the txop in units of
4487 p
->txop
= params
->txop
* 32;
4489 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
4490 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
4491 &arvif
->wmm_params
);
4493 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
4494 arvif
->vdev_id
, ret
);
4498 /* This won't work well with multi-interface cases but it's
4499 * better than nothing.
4501 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
4503 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
4508 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
4510 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
4513 mutex_unlock(&ar
->conf_mutex
);
4517 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4519 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
4520 struct ieee80211_vif
*vif
,
4521 struct ieee80211_channel
*chan
,
4523 enum ieee80211_roc_type type
)
4525 struct ath10k
*ar
= hw
->priv
;
4526 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4527 struct wmi_start_scan_arg arg
;
4530 mutex_lock(&ar
->conf_mutex
);
4532 spin_lock_bh(&ar
->data_lock
);
4533 switch (ar
->scan
.state
) {
4534 case ATH10K_SCAN_IDLE
:
4535 reinit_completion(&ar
->scan
.started
);
4536 reinit_completion(&ar
->scan
.completed
);
4537 reinit_completion(&ar
->scan
.on_channel
);
4538 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4539 ar
->scan
.is_roc
= true;
4540 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4541 ar
->scan
.roc_freq
= chan
->center_freq
;
4544 case ATH10K_SCAN_STARTING
:
4545 case ATH10K_SCAN_RUNNING
:
4546 case ATH10K_SCAN_ABORTING
:
4550 spin_unlock_bh(&ar
->data_lock
);
4555 duration
= max(duration
, WMI_SCAN_CHAN_MIN_TIME_MSEC
);
4557 memset(&arg
, 0, sizeof(arg
));
4558 ath10k_wmi_start_scan_init(ar
, &arg
);
4559 arg
.vdev_id
= arvif
->vdev_id
;
4560 arg
.scan_id
= ATH10K_SCAN_ID
;
4562 arg
.channels
[0] = chan
->center_freq
;
4563 arg
.dwell_time_active
= duration
;
4564 arg
.dwell_time_passive
= duration
;
4565 arg
.max_scan_time
= 2 * duration
;
4566 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4567 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
4569 ret
= ath10k_start_scan(ar
, &arg
);
4571 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
4572 spin_lock_bh(&ar
->data_lock
);
4573 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4574 spin_unlock_bh(&ar
->data_lock
);
4578 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
4580 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
4582 ret
= ath10k_scan_stop(ar
);
4584 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
4592 mutex_unlock(&ar
->conf_mutex
);
4596 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
4598 struct ath10k
*ar
= hw
->priv
;
4600 mutex_lock(&ar
->conf_mutex
);
4601 ath10k_scan_abort(ar
);
4602 mutex_unlock(&ar
->conf_mutex
);
4604 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4610 * Both RTS and Fragmentation threshold are interface-specific
4611 * in ath10k, but device-specific in mac80211.
4614 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
4616 struct ath10k
*ar
= hw
->priv
;
4617 struct ath10k_vif
*arvif
;
4620 mutex_lock(&ar
->conf_mutex
);
4621 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
4622 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
4623 arvif
->vdev_id
, value
);
4625 ret
= ath10k_mac_set_rts(arvif
, value
);
4627 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
4628 arvif
->vdev_id
, ret
);
4632 mutex_unlock(&ar
->conf_mutex
);
4637 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4638 u32 queues
, bool drop
)
4640 struct ath10k
*ar
= hw
->priv
;
4644 /* mac80211 doesn't care if we really xmit queued frames or not
4645 * we'll collect those frames either way if we stop/delete vdevs */
4649 mutex_lock(&ar
->conf_mutex
);
4651 if (ar
->state
== ATH10K_STATE_WEDGED
)
4654 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
4657 spin_lock_bh(&ar
->htt
.tx_lock
);
4658 empty
= (ar
->htt
.num_pending_tx
== 0);
4659 spin_unlock_bh(&ar
->htt
.tx_lock
);
4661 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
4662 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
4666 }), ATH10K_FLUSH_TIMEOUT_HZ
);
4668 if (ret
<= 0 || skip
)
4669 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4670 skip
, ar
->state
, ret
);
4673 mutex_unlock(&ar
->conf_mutex
);
4676 /* TODO: Implement this function properly
4677 * For now it is needed to reply to Probe Requests in IBSS mode.
4678 * Propably we need this information from FW.
4680 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
4686 static int ath10k_suspend(struct ieee80211_hw
*hw
,
4687 struct cfg80211_wowlan
*wowlan
)
4689 struct ath10k
*ar
= hw
->priv
;
4692 mutex_lock(&ar
->conf_mutex
);
4694 ret
= ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND
);
4696 if (ret
== -ETIMEDOUT
)
4702 ret
= ath10k_hif_suspend(ar
);
4704 ath10k_warn(ar
, "failed to suspend hif: %d\n", ret
);
4711 ret
= ath10k_wmi_pdev_resume_target(ar
);
4713 ath10k_warn(ar
, "failed to resume target: %d\n", ret
);
4717 mutex_unlock(&ar
->conf_mutex
);
4721 static int ath10k_resume(struct ieee80211_hw
*hw
)
4723 struct ath10k
*ar
= hw
->priv
;
4726 mutex_lock(&ar
->conf_mutex
);
4728 ret
= ath10k_hif_resume(ar
);
4730 ath10k_warn(ar
, "failed to resume hif: %d\n", ret
);
4735 ret
= ath10k_wmi_pdev_resume_target(ar
);
4737 ath10k_warn(ar
, "failed to resume target: %d\n", ret
);
4744 mutex_unlock(&ar
->conf_mutex
);
4749 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
4750 enum ieee80211_reconfig_type reconfig_type
)
4752 struct ath10k
*ar
= hw
->priv
;
4754 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
4757 mutex_lock(&ar
->conf_mutex
);
4759 /* If device failed to restart it will be in a different state, e.g.
4760 * ATH10K_STATE_WEDGED */
4761 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
4762 ath10k_info(ar
, "device successfully recovered\n");
4763 ar
->state
= ATH10K_STATE_ON
;
4764 ieee80211_wake_queues(ar
->hw
);
4767 mutex_unlock(&ar
->conf_mutex
);
4770 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
4771 struct survey_info
*survey
)
4773 struct ath10k
*ar
= hw
->priv
;
4774 struct ieee80211_supported_band
*sband
;
4775 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
4778 mutex_lock(&ar
->conf_mutex
);
4780 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
4781 if (sband
&& idx
>= sband
->n_channels
) {
4782 idx
-= sband
->n_channels
;
4787 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
4789 if (!sband
|| idx
>= sband
->n_channels
) {
4794 spin_lock_bh(&ar
->data_lock
);
4795 memcpy(survey
, ar_survey
, sizeof(*survey
));
4796 spin_unlock_bh(&ar
->data_lock
);
4798 survey
->channel
= &sband
->channels
[idx
];
4800 if (ar
->rx_channel
== survey
->channel
)
4801 survey
->filled
|= SURVEY_INFO_IN_USE
;
4804 mutex_unlock(&ar
->conf_mutex
);
4808 /* Helper table for legacy fixed_rate/bitrate_mask */
4809 static const u8 cck_ofdm_rate
[] = {
4826 /* Check if only one bit set */
4827 static int ath10k_check_single_mask(u32 mask
)
4835 mask
&= ~BIT(bit
- 1);
4843 ath10k_default_bitrate_mask(struct ath10k
*ar
,
4844 enum ieee80211_band band
,
4845 const struct cfg80211_bitrate_mask
*mask
)
4847 u32 legacy
= 0x00ff;
4850 u16 nrf
= ar
->num_rf_chains
;
4852 if (ar
->cfg_tx_chainmask
)
4853 nrf
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4856 case IEEE80211_BAND_2GHZ
:
4860 case IEEE80211_BAND_5GHZ
:
4866 if (mask
->control
[band
].legacy
!= legacy
)
4869 for (i
= 0; i
< nrf
; i
++)
4870 if (mask
->control
[band
].ht_mcs
[i
] != ht
)
4873 for (i
= 0; i
< nrf
; i
++)
4874 if (mask
->control
[band
].vht_mcs
[i
] != vht
)
4881 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask
*mask
,
4882 enum ieee80211_band band
,
4885 int ht_nss
= 0, vht_nss
= 0, i
;
4888 if (ath10k_check_single_mask(mask
->control
[band
].legacy
))
4892 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4893 if (mask
->control
[band
].ht_mcs
[i
] == 0xff)
4895 else if (mask
->control
[band
].ht_mcs
[i
] == 0x00)
4904 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4905 if (mask
->control
[band
].vht_mcs
[i
] == 0x03ff)
4907 else if (mask
->control
[band
].vht_mcs
[i
] == 0x0000)
4915 if (ht_nss
> 0 && vht_nss
> 0)
4919 *fixed_nss
= ht_nss
;
4921 *fixed_nss
= vht_nss
;
4929 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask
*mask
,
4930 enum ieee80211_band band
,
4931 enum wmi_rate_preamble
*preamble
)
4933 int legacy
= 0, ht
= 0, vht
= 0, i
;
4935 *preamble
= WMI_RATE_PREAMBLE_OFDM
;
4938 legacy
= ath10k_check_single_mask(mask
->control
[band
].legacy
);
4943 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4944 ht
+= ath10k_check_single_mask(mask
->control
[band
].ht_mcs
[i
]);
4949 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4950 vht
+= ath10k_check_single_mask(mask
->control
[band
].vht_mcs
[i
]);
4954 /* Currently we support only one fixed_rate */
4955 if ((legacy
+ ht
+ vht
) != 1)
4959 *preamble
= WMI_RATE_PREAMBLE_HT
;
4961 *preamble
= WMI_RATE_PREAMBLE_VHT
;
4967 ath10k_bitrate_mask_rate(struct ath10k
*ar
,
4968 const struct cfg80211_bitrate_mask
*mask
,
4969 enum ieee80211_band band
,
4973 u8 rate
= 0, pream
= 0, nss
= 0, i
;
4974 enum wmi_rate_preamble preamble
;
4976 /* Check if single rate correct */
4977 if (!ath10k_bitrate_mask_correct(mask
, band
, &preamble
))
4983 case WMI_RATE_PREAMBLE_CCK
:
4984 case WMI_RATE_PREAMBLE_OFDM
:
4985 i
= ffs(mask
->control
[band
].legacy
) - 1;
4987 if (band
== IEEE80211_BAND_2GHZ
&& i
< 4)
4988 pream
= WMI_RATE_PREAMBLE_CCK
;
4990 if (band
== IEEE80211_BAND_5GHZ
)
4993 if (i
>= ARRAY_SIZE(cck_ofdm_rate
))
4996 rate
= cck_ofdm_rate
[i
];
4998 case WMI_RATE_PREAMBLE_HT
:
4999 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
5000 if (mask
->control
[band
].ht_mcs
[i
])
5003 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
5006 rate
= ffs(mask
->control
[band
].ht_mcs
[i
]) - 1;
5009 case WMI_RATE_PREAMBLE_VHT
:
5010 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
5011 if (mask
->control
[band
].vht_mcs
[i
])
5014 if (i
== NL80211_VHT_NSS_MAX
)
5017 rate
= ffs(mask
->control
[band
].vht_mcs
[i
]) - 1;
5022 *fixed_nss
= nss
+ 1;
5026 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
5029 *fixed_rate
= pream
| nss
| rate
;
5034 static bool ath10k_get_fixed_rate_nss(struct ath10k
*ar
,
5035 const struct cfg80211_bitrate_mask
*mask
,
5036 enum ieee80211_band band
,
5040 /* First check full NSS mask, if we can simply limit NSS */
5041 if (ath10k_bitrate_mask_nss(mask
, band
, fixed_nss
))
5044 /* Next Check single rate is set */
5045 return ath10k_bitrate_mask_rate(ar
, mask
, band
, fixed_rate
, fixed_nss
);
5048 static int ath10k_set_fixed_rate_param(struct ath10k_vif
*arvif
,
5053 struct ath10k
*ar
= arvif
->ar
;
5057 mutex_lock(&ar
->conf_mutex
);
5059 if (arvif
->fixed_rate
== fixed_rate
&&
5060 arvif
->fixed_nss
== fixed_nss
&&
5061 arvif
->force_sgi
== force_sgi
)
5064 if (fixed_rate
== WMI_FIXED_RATE_NONE
)
5065 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac disable fixed bitrate mask\n");
5068 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac force sgi\n");
5070 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
5071 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5072 vdev_param
, fixed_rate
);
5074 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
5080 arvif
->fixed_rate
= fixed_rate
;
5082 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5083 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5084 vdev_param
, fixed_nss
);
5087 ath10k_warn(ar
, "failed to set fixed nss param %d: %d\n",
5093 arvif
->fixed_nss
= fixed_nss
;
5095 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
5096 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5100 ath10k_warn(ar
, "failed to set sgi param %d: %d\n",
5106 arvif
->force_sgi
= force_sgi
;
5109 mutex_unlock(&ar
->conf_mutex
);
5113 static int ath10k_set_bitrate_mask(struct ieee80211_hw
*hw
,
5114 struct ieee80211_vif
*vif
,
5115 const struct cfg80211_bitrate_mask
*mask
)
5117 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5118 struct ath10k
*ar
= arvif
->ar
;
5119 enum ieee80211_band band
= ar
->hw
->conf
.chandef
.chan
->band
;
5120 u8 fixed_rate
= WMI_FIXED_RATE_NONE
;
5121 u8 fixed_nss
= ar
->num_rf_chains
;
5124 if (ar
->cfg_tx_chainmask
)
5125 fixed_nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
5127 force_sgi
= mask
->control
[band
].gi
;
5128 if (force_sgi
== NL80211_TXRATE_FORCE_LGI
)
5131 if (!ath10k_default_bitrate_mask(ar
, band
, mask
)) {
5132 if (!ath10k_get_fixed_rate_nss(ar
, mask
, band
,
5138 if (fixed_rate
== WMI_FIXED_RATE_NONE
&& force_sgi
) {
5139 ath10k_warn(ar
, "failed to force SGI usage for default rate settings\n");
5143 return ath10k_set_fixed_rate_param(arvif
, fixed_rate
,
5144 fixed_nss
, force_sgi
);
5147 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
5148 struct ieee80211_vif
*vif
,
5149 struct ieee80211_sta
*sta
,
5152 struct ath10k
*ar
= hw
->priv
;
5153 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5156 spin_lock_bh(&ar
->data_lock
);
5158 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5159 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5160 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
5163 if (changed
& IEEE80211_RC_BW_CHANGED
) {
5164 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5166 switch (sta
->bandwidth
) {
5167 case IEEE80211_STA_RX_BW_20
:
5168 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5170 case IEEE80211_STA_RX_BW_40
:
5171 bw
= WMI_PEER_CHWIDTH_40MHZ
;
5173 case IEEE80211_STA_RX_BW_80
:
5174 bw
= WMI_PEER_CHWIDTH_80MHZ
;
5176 case IEEE80211_STA_RX_BW_160
:
5177 ath10k_warn(ar
, "Invalid bandwith %d in rc update for %pM\n",
5178 sta
->bandwidth
, sta
->addr
);
5179 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5186 if (changed
& IEEE80211_RC_NSS_CHANGED
)
5187 arsta
->nss
= sta
->rx_nss
;
5189 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5190 smps
= WMI_PEER_SMPS_PS_NONE
;
5192 switch (sta
->smps_mode
) {
5193 case IEEE80211_SMPS_AUTOMATIC
:
5194 case IEEE80211_SMPS_OFF
:
5195 smps
= WMI_PEER_SMPS_PS_NONE
;
5197 case IEEE80211_SMPS_STATIC
:
5198 smps
= WMI_PEER_SMPS_STATIC
;
5200 case IEEE80211_SMPS_DYNAMIC
:
5201 smps
= WMI_PEER_SMPS_DYNAMIC
;
5203 case IEEE80211_SMPS_NUM_MODES
:
5204 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
5205 sta
->smps_mode
, sta
->addr
);
5206 smps
= WMI_PEER_SMPS_PS_NONE
;
5213 arsta
->changed
|= changed
;
5215 spin_unlock_bh(&ar
->data_lock
);
5217 ieee80211_queue_work(hw
, &arsta
->update_wk
);
5220 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
5223 * FIXME: Return 0 for time being. Need to figure out whether FW
5224 * has the API to fetch 64-bit local TSF
5230 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
5231 struct ieee80211_vif
*vif
,
5232 enum ieee80211_ampdu_mlme_action action
,
5233 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
5236 struct ath10k
*ar
= hw
->priv
;
5237 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5239 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
5240 arvif
->vdev_id
, sta
->addr
, tid
, action
);
5243 case IEEE80211_AMPDU_RX_START
:
5244 case IEEE80211_AMPDU_RX_STOP
:
5245 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5246 * creation/removal. Do we need to verify this?
5249 case IEEE80211_AMPDU_TX_START
:
5250 case IEEE80211_AMPDU_TX_STOP_CONT
:
5251 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
5252 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
5253 case IEEE80211_AMPDU_TX_OPERATIONAL
:
5254 /* Firmware offloads Tx aggregation entirely so deny mac80211
5255 * Tx aggregation requests.
5263 static const struct ieee80211_ops ath10k_ops
= {
5265 .start
= ath10k_start
,
5266 .stop
= ath10k_stop
,
5267 .config
= ath10k_config
,
5268 .add_interface
= ath10k_add_interface
,
5269 .remove_interface
= ath10k_remove_interface
,
5270 .configure_filter
= ath10k_configure_filter
,
5271 .bss_info_changed
= ath10k_bss_info_changed
,
5272 .hw_scan
= ath10k_hw_scan
,
5273 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
5274 .set_key
= ath10k_set_key
,
5275 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
5276 .sta_state
= ath10k_sta_state
,
5277 .conf_tx
= ath10k_conf_tx
,
5278 .remain_on_channel
= ath10k_remain_on_channel
,
5279 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
5280 .set_rts_threshold
= ath10k_set_rts_threshold
,
5281 .flush
= ath10k_flush
,
5282 .tx_last_beacon
= ath10k_tx_last_beacon
,
5283 .set_antenna
= ath10k_set_antenna
,
5284 .get_antenna
= ath10k_get_antenna
,
5285 .reconfig_complete
= ath10k_reconfig_complete
,
5286 .get_survey
= ath10k_get_survey
,
5287 .set_bitrate_mask
= ath10k_set_bitrate_mask
,
5288 .sta_rc_update
= ath10k_sta_rc_update
,
5289 .get_tsf
= ath10k_get_tsf
,
5290 .ampdu_action
= ath10k_ampdu_action
,
5291 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
5292 .get_et_stats
= ath10k_debug_get_et_stats
,
5293 .get_et_strings
= ath10k_debug_get_et_strings
,
5295 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
5298 .suspend
= ath10k_suspend
,
5299 .resume
= ath10k_resume
,
5301 #ifdef CONFIG_MAC80211_DEBUGFS
5302 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
5306 #define RATETAB_ENT(_rate, _rateid, _flags) { \
5307 .bitrate = (_rate), \
5308 .flags = (_flags), \
5309 .hw_value = (_rateid), \
5312 #define CHAN2G(_channel, _freq, _flags) { \
5313 .band = IEEE80211_BAND_2GHZ, \
5314 .hw_value = (_channel), \
5315 .center_freq = (_freq), \
5316 .flags = (_flags), \
5317 .max_antenna_gain = 0, \
5321 #define CHAN5G(_channel, _freq, _flags) { \
5322 .band = IEEE80211_BAND_5GHZ, \
5323 .hw_value = (_channel), \
5324 .center_freq = (_freq), \
5325 .flags = (_flags), \
5326 .max_antenna_gain = 0, \
5330 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
5340 CHAN2G(10, 2457, 0),
5341 CHAN2G(11, 2462, 0),
5342 CHAN2G(12, 2467, 0),
5343 CHAN2G(13, 2472, 0),
5344 CHAN2G(14, 2484, 0),
5347 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
5348 CHAN5G(36, 5180, 0),
5349 CHAN5G(40, 5200, 0),
5350 CHAN5G(44, 5220, 0),
5351 CHAN5G(48, 5240, 0),
5352 CHAN5G(52, 5260, 0),
5353 CHAN5G(56, 5280, 0),
5354 CHAN5G(60, 5300, 0),
5355 CHAN5G(64, 5320, 0),
5356 CHAN5G(100, 5500, 0),
5357 CHAN5G(104, 5520, 0),
5358 CHAN5G(108, 5540, 0),
5359 CHAN5G(112, 5560, 0),
5360 CHAN5G(116, 5580, 0),
5361 CHAN5G(120, 5600, 0),
5362 CHAN5G(124, 5620, 0),
5363 CHAN5G(128, 5640, 0),
5364 CHAN5G(132, 5660, 0),
5365 CHAN5G(136, 5680, 0),
5366 CHAN5G(140, 5700, 0),
5367 CHAN5G(149, 5745, 0),
5368 CHAN5G(153, 5765, 0),
5369 CHAN5G(157, 5785, 0),
5370 CHAN5G(161, 5805, 0),
5371 CHAN5G(165, 5825, 0),
5374 /* Note: Be careful if you re-order these. There is code which depends on this
5377 static struct ieee80211_rate ath10k_rates
[] = {
5379 RATETAB_ENT(10, 0x82, 0),
5380 RATETAB_ENT(20, 0x84, 0),
5381 RATETAB_ENT(55, 0x8b, 0),
5382 RATETAB_ENT(110, 0x96, 0),
5384 RATETAB_ENT(60, 0x0c, 0),
5385 RATETAB_ENT(90, 0x12, 0),
5386 RATETAB_ENT(120, 0x18, 0),
5387 RATETAB_ENT(180, 0x24, 0),
5388 RATETAB_ENT(240, 0x30, 0),
5389 RATETAB_ENT(360, 0x48, 0),
5390 RATETAB_ENT(480, 0x60, 0),
5391 RATETAB_ENT(540, 0x6c, 0),
5394 #define ath10k_a_rates (ath10k_rates + 4)
5395 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5396 #define ath10k_g_rates (ath10k_rates + 0)
5397 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5399 struct ath10k
*ath10k_mac_create(size_t priv_size
)
5401 struct ieee80211_hw
*hw
;
5404 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
5414 void ath10k_mac_destroy(struct ath10k
*ar
)
5416 ieee80211_free_hw(ar
->hw
);
5419 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
5422 .types
= BIT(NL80211_IFTYPE_STATION
)
5423 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
5427 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
5431 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5435 .types
= BIT(NL80211_IFTYPE_AP
)
5439 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
5442 .types
= BIT(NL80211_IFTYPE_AP
)
5446 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
5448 .limits
= ath10k_if_limits
,
5449 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
5450 .max_interfaces
= 8,
5451 .num_different_channels
= 1,
5452 .beacon_int_infra_match
= true,
5456 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
5458 .limits
= ath10k_10x_if_limits
,
5459 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
5460 .max_interfaces
= 8,
5461 .num_different_channels
= 1,
5462 .beacon_int_infra_match
= true,
5463 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
5464 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
5465 BIT(NL80211_CHAN_WIDTH_20
) |
5466 BIT(NL80211_CHAN_WIDTH_40
) |
5467 BIT(NL80211_CHAN_WIDTH_80
),
5472 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
5474 struct ieee80211_sta_vht_cap vht_cap
= {0};
5479 vht_cap
.vht_supported
= 1;
5480 vht_cap
.cap
= ar
->vht_cap_info
;
5482 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
5483 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
5484 val
= ar
->num_rf_chains
- 1;
5485 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
5486 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
5491 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
5492 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
5493 val
= ar
->num_rf_chains
- 1;
5494 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
5495 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
5501 for (i
= 0; i
< 8; i
++) {
5502 if (i
< ar
->num_rf_chains
)
5503 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
5505 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
5508 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
5509 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
5514 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
5517 struct ieee80211_sta_ht_cap ht_cap
= {0};
5519 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
5522 ht_cap
.ht_supported
= 1;
5523 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
5524 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
5525 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5526 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
5527 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
5529 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
5530 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
5532 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
5533 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
5535 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
5538 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
5539 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
5544 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
5545 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
5547 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
5550 stbc
= ar
->ht_cap_info
;
5551 stbc
&= WMI_HT_CAP_RX_STBC
;
5552 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
5553 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
5554 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
5559 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
5560 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
5562 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
5563 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
5565 /* max AMSDU is implicitly taken from vht_cap_info */
5566 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
5567 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
5569 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
5570 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
5572 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
5577 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
5578 struct ieee80211_vif
*vif
)
5580 struct ath10k_vif_iter
*arvif_iter
= data
;
5581 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5583 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
5584 arvif_iter
->arvif
= arvif
;
5587 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
5589 struct ath10k_vif_iter arvif_iter
;
5592 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
5593 arvif_iter
.vdev_id
= vdev_id
;
5595 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
5596 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
5598 ath10k_get_arvif_iter
,
5600 if (!arvif_iter
.arvif
) {
5601 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
5605 return arvif_iter
.arvif
;
5608 int ath10k_mac_register(struct ath10k
*ar
)
5610 static const u32 cipher_suites
[] = {
5611 WLAN_CIPHER_SUITE_WEP40
,
5612 WLAN_CIPHER_SUITE_WEP104
,
5613 WLAN_CIPHER_SUITE_TKIP
,
5614 WLAN_CIPHER_SUITE_CCMP
,
5615 WLAN_CIPHER_SUITE_AES_CMAC
,
5617 struct ieee80211_supported_band
*band
;
5618 struct ieee80211_sta_vht_cap vht_cap
;
5619 struct ieee80211_sta_ht_cap ht_cap
;
5623 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
5625 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
5627 ht_cap
= ath10k_get_ht_cap(ar
);
5628 vht_cap
= ath10k_create_vht_cap(ar
);
5630 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
5631 channels
= kmemdup(ath10k_2ghz_channels
,
5632 sizeof(ath10k_2ghz_channels
),
5639 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
5640 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
5641 band
->channels
= channels
;
5642 band
->n_bitrates
= ath10k_g_rates_size
;
5643 band
->bitrates
= ath10k_g_rates
;
5644 band
->ht_cap
= ht_cap
;
5646 /* Enable the VHT support at 2.4 GHz */
5647 band
->vht_cap
= vht_cap
;
5649 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
5652 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
5653 channels
= kmemdup(ath10k_5ghz_channels
,
5654 sizeof(ath10k_5ghz_channels
),
5661 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
5662 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
5663 band
->channels
= channels
;
5664 band
->n_bitrates
= ath10k_a_rates_size
;
5665 band
->bitrates
= ath10k_a_rates
;
5666 band
->ht_cap
= ht_cap
;
5667 band
->vht_cap
= vht_cap
;
5668 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
5671 ar
->hw
->wiphy
->interface_modes
=
5672 BIT(NL80211_IFTYPE_STATION
) |
5673 BIT(NL80211_IFTYPE_AP
);
5675 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
5676 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
5678 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
5679 ar
->hw
->wiphy
->interface_modes
|=
5680 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
5681 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5682 BIT(NL80211_IFTYPE_P2P_GO
);
5684 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
5685 IEEE80211_HW_SUPPORTS_PS
|
5686 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
5687 IEEE80211_HW_MFP_CAPABLE
|
5688 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
5689 IEEE80211_HW_HAS_RATE_CONTROL
|
5690 IEEE80211_HW_AP_LINK_PS
|
5691 IEEE80211_HW_SPECTRUM_MGMT
|
5692 IEEE80211_HW_SW_CRYPTO_CONTROL
;
5694 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
5696 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
5697 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
5699 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
5700 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
5701 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
5704 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
5705 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
5707 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
5708 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
5710 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
5712 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
5713 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5715 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5716 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5717 * correct Probe Responses. This is more of a hack advert..
5719 ar
->hw
->wiphy
->probe_resp_offload
|=
5720 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5721 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5722 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5725 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
5726 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
5727 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
5729 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
5730 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
5733 * on LL hardware queues are managed entirely by the FW
5734 * so we only advertise to mac we can do the queues thing
5738 switch (ar
->wmi
.op_version
) {
5739 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
5740 case ATH10K_FW_WMI_OP_VERSION_TLV
:
5741 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
5742 ar
->hw
->wiphy
->n_iface_combinations
=
5743 ARRAY_SIZE(ath10k_if_comb
);
5744 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
5746 case ATH10K_FW_WMI_OP_VERSION_10_1
:
5747 case ATH10K_FW_WMI_OP_VERSION_10_2
:
5748 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
5749 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
5750 ar
->hw
->wiphy
->n_iface_combinations
=
5751 ARRAY_SIZE(ath10k_10x_if_comb
);
5753 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
5754 case ATH10K_FW_WMI_OP_VERSION_MAX
:
5760 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
5762 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
5763 /* Init ath dfs pattern detector */
5764 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
5765 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
5768 if (!ar
->dfs_detector
)
5769 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
5772 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
5773 ath10k_reg_notifier
);
5775 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
5779 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
5780 ar
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
5782 ret
= ieee80211_register_hw(ar
->hw
);
5784 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
5788 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
5789 ret
= regulatory_hint(ar
->hw
->wiphy
,
5790 ar
->ath_common
.regulatory
.alpha2
);
5792 goto err_unregister
;
5798 ieee80211_unregister_hw(ar
->hw
);
5800 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
5801 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
5806 void ath10k_mac_unregister(struct ath10k
*ar
)
5808 ieee80211_unregister_hw(ar
->hw
);
5810 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
5811 ar
->dfs_detector
->exit(ar
->dfs_detector
);
5813 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
5814 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
5816 SET_IEEE80211_DEV(ar
->hw
, NULL
);