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
, bool def_idx
)
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
,
51 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
53 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
54 arg
.key_flags
= WMI_KEY_PAIRWISE
;
56 arg
.key_flags
= WMI_KEY_GROUP
;
58 switch (key
->cipher
) {
59 case WLAN_CIPHER_SUITE_CCMP
:
60 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
61 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
63 case WLAN_CIPHER_SUITE_TKIP
:
64 arg
.key_cipher
= WMI_CIPHER_TKIP
;
65 arg
.key_txmic_len
= 8;
66 arg
.key_rxmic_len
= 8;
68 case WLAN_CIPHER_SUITE_WEP40
:
69 case WLAN_CIPHER_SUITE_WEP104
:
70 arg
.key_cipher
= WMI_CIPHER_WEP
;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr
, arvif
->vif
->addr
, ETH_ALEN
))
74 arg
.key_flags
= WMI_KEY_PAIRWISE
;
77 arg
.key_flags
|= WMI_KEY_TX_USAGE
;
80 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
84 if (cmd
== DISABLE_KEY
) {
85 arg
.key_cipher
= WMI_CIPHER_NONE
;
89 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
92 static int ath10k_install_key(struct ath10k_vif
*arvif
,
93 struct ieee80211_key_conf
*key
,
95 const u8
*macaddr
, bool def_idx
)
97 struct ath10k
*ar
= arvif
->ar
;
100 lockdep_assert_held(&ar
->conf_mutex
);
102 reinit_completion(&ar
->install_key_done
);
104 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, def_idx
);
108 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
115 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
118 struct ath10k
*ar
= arvif
->ar
;
119 struct ath10k_peer
*peer
;
124 lockdep_assert_held(&ar
->conf_mutex
);
126 spin_lock_bh(&ar
->data_lock
);
127 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
128 spin_unlock_bh(&ar
->data_lock
);
133 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
134 if (arvif
->wep_keys
[i
] == NULL
)
136 /* set TX_USAGE flag for default key id */
137 if (arvif
->def_wep_key_idx
== i
)
142 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
147 spin_lock_bh(&ar
->data_lock
);
148 peer
->keys
[i
] = arvif
->wep_keys
[i
];
149 spin_unlock_bh(&ar
->data_lock
);
155 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
158 struct ath10k
*ar
= arvif
->ar
;
159 struct ath10k_peer
*peer
;
164 lockdep_assert_held(&ar
->conf_mutex
);
166 spin_lock_bh(&ar
->data_lock
);
167 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
168 spin_unlock_bh(&ar
->data_lock
);
173 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
174 if (peer
->keys
[i
] == NULL
)
177 /* key flags are not required to delete the key */
178 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
179 DISABLE_KEY
, addr
, false);
180 if (ret
&& first_errno
== 0)
184 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
187 spin_lock_bh(&ar
->data_lock
);
188 peer
->keys
[i
] = NULL
;
189 spin_unlock_bh(&ar
->data_lock
);
195 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
198 struct ath10k_peer
*peer
;
201 lockdep_assert_held(&ar
->data_lock
);
203 /* We don't know which vdev this peer belongs to,
204 * since WMI doesn't give us that information.
206 * FIXME: multi-bss needs to be handled.
208 peer
= ath10k_peer_find(ar
, 0, addr
);
212 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
213 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
220 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
221 struct ieee80211_key_conf
*key
)
223 struct ath10k
*ar
= arvif
->ar
;
224 struct ath10k_peer
*peer
;
230 lockdep_assert_held(&ar
->conf_mutex
);
233 /* since ath10k_install_key we can't hold data_lock all the
234 * time, so we try to remove the keys incrementally */
235 spin_lock_bh(&ar
->data_lock
);
237 list_for_each_entry(peer
, &ar
->peers
, list
) {
238 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
239 if (peer
->keys
[i
] == key
) {
240 ether_addr_copy(addr
, peer
->addr
);
241 peer
->keys
[i
] = NULL
;
246 if (i
< ARRAY_SIZE(peer
->keys
))
249 spin_unlock_bh(&ar
->data_lock
);
251 if (i
== ARRAY_SIZE(peer
->keys
))
253 /* key flags are not required to delete the key */
254 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, false);
255 if (ret
&& first_errno
== 0)
259 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
266 /*********************/
267 /* General utilities */
268 /*********************/
270 static inline enum wmi_phy_mode
271 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
273 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
275 switch (chandef
->chan
->band
) {
276 case IEEE80211_BAND_2GHZ
:
277 switch (chandef
->width
) {
278 case NL80211_CHAN_WIDTH_20_NOHT
:
279 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
284 case NL80211_CHAN_WIDTH_20
:
285 phymode
= MODE_11NG_HT20
;
287 case NL80211_CHAN_WIDTH_40
:
288 phymode
= MODE_11NG_HT40
;
290 case NL80211_CHAN_WIDTH_5
:
291 case NL80211_CHAN_WIDTH_10
:
292 case NL80211_CHAN_WIDTH_80
:
293 case NL80211_CHAN_WIDTH_80P80
:
294 case NL80211_CHAN_WIDTH_160
:
295 phymode
= MODE_UNKNOWN
;
299 case IEEE80211_BAND_5GHZ
:
300 switch (chandef
->width
) {
301 case NL80211_CHAN_WIDTH_20_NOHT
:
304 case NL80211_CHAN_WIDTH_20
:
305 phymode
= MODE_11NA_HT20
;
307 case NL80211_CHAN_WIDTH_40
:
308 phymode
= MODE_11NA_HT40
;
310 case NL80211_CHAN_WIDTH_80
:
311 phymode
= MODE_11AC_VHT80
;
313 case NL80211_CHAN_WIDTH_5
:
314 case NL80211_CHAN_WIDTH_10
:
315 case NL80211_CHAN_WIDTH_80P80
:
316 case NL80211_CHAN_WIDTH_160
:
317 phymode
= MODE_UNKNOWN
;
325 WARN_ON(phymode
== MODE_UNKNOWN
);
329 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
332 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
333 * 0 for no restriction
342 switch (mpdudensity
) {
348 /* Our lower layer calculations limit our precision to
364 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
368 lockdep_assert_held(&ar
->conf_mutex
);
370 if (ar
->num_peers
>= ar
->max_num_peers
)
373 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
);
375 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
380 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
382 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
392 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
394 struct ath10k
*ar
= arvif
->ar
;
398 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
399 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
400 ATH10K_KICKOUT_THRESHOLD
);
402 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
403 arvif
->vdev_id
, ret
);
407 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
408 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
409 ATH10K_KEEPALIVE_MIN_IDLE
);
411 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
412 arvif
->vdev_id
, ret
);
416 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
417 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
418 ATH10K_KEEPALIVE_MAX_IDLE
);
420 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
421 arvif
->vdev_id
, ret
);
425 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
426 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
427 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
429 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
430 arvif
->vdev_id
, ret
);
437 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
439 struct ath10k
*ar
= arvif
->ar
;
442 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
443 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
446 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
448 struct ath10k
*ar
= arvif
->ar
;
451 if (value
!= 0xFFFFFFFF)
452 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
453 ATH10K_FRAGMT_THRESHOLD_MIN
,
454 ATH10K_FRAGMT_THRESHOLD_MAX
);
456 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
457 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
460 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
464 lockdep_assert_held(&ar
->conf_mutex
);
466 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
470 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
479 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
481 struct ath10k_peer
*peer
, *tmp
;
483 lockdep_assert_held(&ar
->conf_mutex
);
485 spin_lock_bh(&ar
->data_lock
);
486 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
487 if (peer
->vdev_id
!= vdev_id
)
490 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
491 peer
->addr
, vdev_id
);
493 list_del(&peer
->list
);
497 spin_unlock_bh(&ar
->data_lock
);
500 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
502 struct ath10k_peer
*peer
, *tmp
;
504 lockdep_assert_held(&ar
->conf_mutex
);
506 spin_lock_bh(&ar
->data_lock
);
507 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
508 list_del(&peer
->list
);
511 spin_unlock_bh(&ar
->data_lock
);
514 ar
->num_stations
= 0;
517 /************************/
518 /* Interface management */
519 /************************/
521 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
523 struct ath10k
*ar
= arvif
->ar
;
525 lockdep_assert_held(&ar
->data_lock
);
530 if (!arvif
->beacon_buf
)
531 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
532 arvif
->beacon
->len
, DMA_TO_DEVICE
);
534 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
535 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
538 dev_kfree_skb_any(arvif
->beacon
);
540 arvif
->beacon
= NULL
;
541 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
544 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
546 struct ath10k
*ar
= arvif
->ar
;
548 lockdep_assert_held(&ar
->data_lock
);
550 ath10k_mac_vif_beacon_free(arvif
);
552 if (arvif
->beacon_buf
) {
553 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
554 arvif
->beacon_buf
, arvif
->beacon_paddr
);
555 arvif
->beacon_buf
= NULL
;
559 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
563 lockdep_assert_held(&ar
->conf_mutex
);
565 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
568 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
569 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
576 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
578 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
579 struct ieee80211_channel
*channel
= chandef
->chan
;
580 struct wmi_vdev_start_request_arg arg
= {};
583 lockdep_assert_held(&ar
->conf_mutex
);
585 arg
.vdev_id
= vdev_id
;
586 arg
.channel
.freq
= channel
->center_freq
;
587 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
589 /* TODO setup this dynamically, what in case we
590 don't have any vifs? */
591 arg
.channel
.mode
= chan_to_phymode(chandef
);
592 arg
.channel
.chan_radar
=
593 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
595 arg
.channel
.min_power
= 0;
596 arg
.channel
.max_power
= channel
->max_power
* 2;
597 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
598 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
600 reinit_completion(&ar
->vdev_setup_done
);
602 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
604 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
609 ret
= ath10k_vdev_setup_sync(ar
);
611 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
616 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
618 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
623 ar
->monitor_vdev_id
= vdev_id
;
625 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
626 ar
->monitor_vdev_id
);
630 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
632 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
633 ar
->monitor_vdev_id
, ret
);
638 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
642 lockdep_assert_held(&ar
->conf_mutex
);
644 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
646 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
647 ar
->monitor_vdev_id
, ret
);
649 reinit_completion(&ar
->vdev_setup_done
);
651 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
653 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
654 ar
->monitor_vdev_id
, ret
);
656 ret
= ath10k_vdev_setup_sync(ar
);
658 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
659 ar
->monitor_vdev_id
, ret
);
661 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
662 ar
->monitor_vdev_id
);
666 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
670 lockdep_assert_held(&ar
->conf_mutex
);
672 if (ar
->free_vdev_map
== 0) {
673 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
677 bit
= __ffs64(ar
->free_vdev_map
);
679 ar
->monitor_vdev_id
= bit
;
681 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
682 WMI_VDEV_TYPE_MONITOR
,
685 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
686 ar
->monitor_vdev_id
, ret
);
690 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
691 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
692 ar
->monitor_vdev_id
);
697 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
701 lockdep_assert_held(&ar
->conf_mutex
);
703 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
705 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
706 ar
->monitor_vdev_id
, ret
);
710 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
712 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
713 ar
->monitor_vdev_id
);
717 static int ath10k_monitor_start(struct ath10k
*ar
)
721 lockdep_assert_held(&ar
->conf_mutex
);
723 ret
= ath10k_monitor_vdev_create(ar
);
725 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
729 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
731 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
732 ath10k_monitor_vdev_delete(ar
);
736 ar
->monitor_started
= true;
737 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
742 static int ath10k_monitor_stop(struct ath10k
*ar
)
746 lockdep_assert_held(&ar
->conf_mutex
);
748 ret
= ath10k_monitor_vdev_stop(ar
);
750 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
754 ret
= ath10k_monitor_vdev_delete(ar
);
756 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
760 ar
->monitor_started
= false;
761 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
766 static int ath10k_monitor_recalc(struct ath10k
*ar
)
770 lockdep_assert_held(&ar
->conf_mutex
);
772 should_start
= ar
->monitor
||
773 ar
->filter_flags
& FIF_PROMISC_IN_BSS
||
774 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
776 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
777 "mac monitor recalc started? %d should? %d\n",
778 ar
->monitor_started
, should_start
);
780 if (should_start
== ar
->monitor_started
)
784 return ath10k_monitor_start(ar
);
786 return ath10k_monitor_stop(ar
);
789 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
791 struct ath10k
*ar
= arvif
->ar
;
792 u32 vdev_param
, rts_cts
= 0;
794 lockdep_assert_held(&ar
->conf_mutex
);
796 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
798 if (arvif
->use_cts_prot
|| arvif
->num_legacy_stations
> 0)
799 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
801 if (arvif
->num_legacy_stations
> 0)
802 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
805 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
809 static int ath10k_start_cac(struct ath10k
*ar
)
813 lockdep_assert_held(&ar
->conf_mutex
);
815 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
817 ret
= ath10k_monitor_recalc(ar
);
819 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
820 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
824 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
825 ar
->monitor_vdev_id
);
830 static int ath10k_stop_cac(struct ath10k
*ar
)
832 lockdep_assert_held(&ar
->conf_mutex
);
834 /* CAC is not running - do nothing */
835 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
838 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
839 ath10k_monitor_stop(ar
);
841 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
846 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
850 lockdep_assert_held(&ar
->conf_mutex
);
854 if (!ar
->radar_enabled
)
857 if (ar
->num_started_vdevs
> 0)
860 ret
= ath10k_start_cac(ar
);
863 * Not possible to start CAC on current channel so starting
864 * radiation is not allowed, make this channel DFS_UNAVAILABLE
865 * by indicating that radar was detected.
867 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
868 ieee80211_radar_detected(ar
->hw
);
872 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
, bool restart
)
874 struct ath10k
*ar
= arvif
->ar
;
875 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
876 struct wmi_vdev_start_request_arg arg
= {};
879 lockdep_assert_held(&ar
->conf_mutex
);
881 reinit_completion(&ar
->vdev_setup_done
);
883 arg
.vdev_id
= arvif
->vdev_id
;
884 arg
.dtim_period
= arvif
->dtim_period
;
885 arg
.bcn_intval
= arvif
->beacon_interval
;
887 arg
.channel
.freq
= chandef
->chan
->center_freq
;
888 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
889 arg
.channel
.mode
= chan_to_phymode(chandef
);
891 arg
.channel
.min_power
= 0;
892 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
893 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
894 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
896 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
897 arg
.ssid
= arvif
->u
.ap
.ssid
;
898 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
899 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
901 /* For now allow DFS for AP mode */
902 arg
.channel
.chan_radar
=
903 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
904 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
905 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
906 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
909 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
910 "mac vdev %d start center_freq %d phymode %s\n",
911 arg
.vdev_id
, arg
.channel
.freq
,
912 ath10k_wmi_phymode_str(arg
.channel
.mode
));
915 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
917 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
920 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
925 ret
= ath10k_vdev_setup_sync(ar
);
928 "failed to synchronize setup for vdev %i restart %d: %d\n",
929 arg
.vdev_id
, restart
, ret
);
933 ar
->num_started_vdevs
++;
934 ath10k_recalc_radar_detection(ar
);
939 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
941 return ath10k_vdev_start_restart(arvif
, false);
944 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
)
946 return ath10k_vdev_start_restart(arvif
, true);
949 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
951 struct ath10k
*ar
= arvif
->ar
;
954 lockdep_assert_held(&ar
->conf_mutex
);
956 reinit_completion(&ar
->vdev_setup_done
);
958 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
960 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
961 arvif
->vdev_id
, ret
);
965 ret
= ath10k_vdev_setup_sync(ar
);
967 ath10k_warn(ar
, "failed to synchronize setup for vdev %i stop: %d\n",
968 arvif
->vdev_id
, ret
);
972 WARN_ON(ar
->num_started_vdevs
== 0);
974 if (ar
->num_started_vdevs
!= 0) {
975 ar
->num_started_vdevs
--;
976 ath10k_recalc_radar_detection(ar
);
982 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
985 struct ath10k
*ar
= arvif
->ar
;
986 struct ieee80211_mgmt
*mgmt
;
990 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
993 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
996 mgmt
= (void *)bcn
->data
;
997 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
998 mgmt
->u
.beacon
.variable
,
999 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1004 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1006 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1007 arvif
->vdev_id
, ret
);
1014 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1015 u8 oui_type
, size_t ie_offset
)
1022 if (WARN_ON(skb
->len
< ie_offset
))
1025 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1026 skb
->data
+ ie_offset
,
1027 skb
->len
- ie_offset
);
1032 end
= skb
->data
+ skb
->len
;
1035 if (WARN_ON(next
> end
))
1038 memmove(ie
, next
, end
- next
);
1039 skb_trim(skb
, skb
->len
- len
);
1044 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1046 struct ath10k
*ar
= arvif
->ar
;
1047 struct ieee80211_hw
*hw
= ar
->hw
;
1048 struct ieee80211_vif
*vif
= arvif
->vif
;
1049 struct ieee80211_mutable_offsets offs
= {};
1050 struct sk_buff
*bcn
;
1053 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1056 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1058 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1062 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1064 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1069 /* P2P IE is inserted by firmware automatically (as configured above)
1070 * so remove it from the base beacon template to avoid duplicate P2P
1071 * IEs in beacon frames.
1073 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1074 offsetof(struct ieee80211_mgmt
,
1075 u
.beacon
.variable
));
1077 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1082 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1090 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1092 struct ath10k
*ar
= arvif
->ar
;
1093 struct ieee80211_hw
*hw
= ar
->hw
;
1094 struct ieee80211_vif
*vif
= arvif
->vif
;
1095 struct sk_buff
*prb
;
1098 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1101 prb
= ieee80211_proberesp_get(hw
, vif
);
1103 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1107 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1111 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1119 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1120 struct ieee80211_bss_conf
*info
)
1122 struct ath10k
*ar
= arvif
->ar
;
1125 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1127 if (!info
->enable_beacon
) {
1128 ath10k_vdev_stop(arvif
);
1130 arvif
->is_started
= false;
1131 arvif
->is_up
= false;
1133 spin_lock_bh(&arvif
->ar
->data_lock
);
1134 ath10k_mac_vif_beacon_free(arvif
);
1135 spin_unlock_bh(&arvif
->ar
->data_lock
);
1140 arvif
->tx_seq_no
= 0x1000;
1142 ret
= ath10k_vdev_start(arvif
);
1147 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1149 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1152 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1153 arvif
->vdev_id
, ret
);
1154 ath10k_vdev_stop(arvif
);
1158 arvif
->is_started
= true;
1159 arvif
->is_up
= true;
1161 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1164 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1165 struct ieee80211_bss_conf
*info
,
1166 const u8 self_peer
[ETH_ALEN
])
1168 struct ath10k
*ar
= arvif
->ar
;
1172 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1174 if (!info
->ibss_joined
) {
1175 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
1177 ath10k_warn(ar
, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1178 self_peer
, arvif
->vdev_id
, ret
);
1180 if (is_zero_ether_addr(arvif
->bssid
))
1183 memset(arvif
->bssid
, 0, ETH_ALEN
);
1188 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
1190 ath10k_warn(ar
, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1191 self_peer
, arvif
->vdev_id
, ret
);
1195 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1196 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1197 ATH10K_DEFAULT_ATIM
);
1199 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1200 arvif
->vdev_id
, ret
);
1203 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1205 struct ath10k
*ar
= arvif
->ar
;
1210 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1212 if (arvif
->u
.sta
.uapsd
)
1213 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1215 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1217 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1218 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1220 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1221 value
, arvif
->vdev_id
, ret
);
1228 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1230 struct ath10k
*ar
= arvif
->ar
;
1235 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1237 if (arvif
->u
.sta
.uapsd
)
1238 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1240 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1242 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1243 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1246 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1247 value
, arvif
->vdev_id
, ret
);
1254 static int ath10k_mac_ps_vif_count(struct ath10k
*ar
)
1256 struct ath10k_vif
*arvif
;
1259 lockdep_assert_held(&ar
->conf_mutex
);
1261 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1268 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1270 struct ath10k
*ar
= arvif
->ar
;
1271 struct ieee80211_vif
*vif
= arvif
->vif
;
1272 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1273 enum wmi_sta_powersave_param param
;
1274 enum wmi_sta_ps_mode psmode
;
1279 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1281 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1284 enable_ps
= arvif
->ps
;
1286 if (enable_ps
&& ath10k_mac_ps_vif_count(ar
) > 1 &&
1287 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1289 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1295 psmode
= WMI_STA_PS_MODE_ENABLED
;
1296 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1298 ps_timeout
= conf
->dynamic_ps_timeout
;
1299 if (ps_timeout
== 0) {
1300 /* Firmware doesn't like 0 */
1301 ps_timeout
= ieee80211_tu_to_usec(
1302 vif
->bss_conf
.beacon_int
) / 1000;
1305 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1308 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1309 arvif
->vdev_id
, ret
);
1313 psmode
= WMI_STA_PS_MODE_DISABLED
;
1316 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1317 arvif
->vdev_id
, psmode
? "enable" : "disable");
1319 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1321 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1322 psmode
, arvif
->vdev_id
, ret
);
1329 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1331 struct ath10k
*ar
= arvif
->ar
;
1332 struct wmi_sta_keepalive_arg arg
= {};
1335 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1337 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1340 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1343 /* Some firmware revisions have a bug and ignore the `enabled` field.
1344 * Instead use the interval to disable the keepalive.
1346 arg
.vdev_id
= arvif
->vdev_id
;
1348 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1349 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1351 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1353 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1354 arvif
->vdev_id
, ret
);
1361 /**********************/
1362 /* Station management */
1363 /**********************/
1365 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1366 struct ieee80211_vif
*vif
)
1368 /* Some firmware revisions have unstable STA powersave when listen
1369 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1370 * generate NullFunc frames properly even if buffered frames have been
1371 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1372 * buffered frames. Often pinging the device from AP would simply fail.
1374 * As a workaround set it to 1.
1376 if (vif
->type
== NL80211_IFTYPE_STATION
)
1379 return ar
->hw
->conf
.listen_interval
;
1382 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1383 struct ieee80211_vif
*vif
,
1384 struct ieee80211_sta
*sta
,
1385 struct wmi_peer_assoc_complete_arg
*arg
)
1387 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1389 lockdep_assert_held(&ar
->conf_mutex
);
1391 ether_addr_copy(arg
->addr
, sta
->addr
);
1392 arg
->vdev_id
= arvif
->vdev_id
;
1393 arg
->peer_aid
= sta
->aid
;
1394 arg
->peer_flags
|= WMI_PEER_AUTH
;
1395 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1396 arg
->peer_num_spatial_streams
= 1;
1397 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1400 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1401 struct ieee80211_vif
*vif
,
1402 struct wmi_peer_assoc_complete_arg
*arg
)
1404 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1405 struct cfg80211_bss
*bss
;
1406 const u8
*rsnie
= NULL
;
1407 const u8
*wpaie
= NULL
;
1409 lockdep_assert_held(&ar
->conf_mutex
);
1411 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
1412 info
->bssid
, NULL
, 0, 0, 0);
1414 const struct cfg80211_bss_ies
*ies
;
1417 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1419 ies
= rcu_dereference(bss
->ies
);
1421 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1422 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1426 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1429 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1430 if (rsnie
|| wpaie
) {
1431 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1432 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1436 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1437 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1441 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1442 struct ieee80211_sta
*sta
,
1443 struct wmi_peer_assoc_complete_arg
*arg
)
1445 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
1446 const struct ieee80211_supported_band
*sband
;
1447 const struct ieee80211_rate
*rates
;
1451 lockdep_assert_held(&ar
->conf_mutex
);
1453 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
1454 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
1455 rates
= sband
->bitrates
;
1457 rateset
->num_rates
= 0;
1459 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
1460 if (!(ratemask
& 1))
1463 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
1464 rateset
->num_rates
++;
1468 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
1469 struct ieee80211_sta
*sta
,
1470 struct wmi_peer_assoc_complete_arg
*arg
)
1472 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1476 lockdep_assert_held(&ar
->conf_mutex
);
1478 if (!ht_cap
->ht_supported
)
1481 arg
->peer_flags
|= WMI_PEER_HT
;
1482 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1483 ht_cap
->ampdu_factor
)) - 1;
1485 arg
->peer_mpdu_density
=
1486 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
1488 arg
->peer_ht_caps
= ht_cap
->cap
;
1489 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
1491 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
1492 arg
->peer_flags
|= WMI_PEER_LDPC
;
1494 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
1495 arg
->peer_flags
|= WMI_PEER_40MHZ
;
1496 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
1499 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
1500 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1502 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
1503 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1505 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
1506 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
1507 arg
->peer_flags
|= WMI_PEER_STBC
;
1510 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
1511 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
1512 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
1513 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
1514 arg
->peer_rate_caps
|= stbc
;
1515 arg
->peer_flags
|= WMI_PEER_STBC
;
1518 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
1519 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
1520 else if (ht_cap
->mcs
.rx_mask
[1])
1521 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
1523 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
1524 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
1525 arg
->peer_ht_rates
.rates
[n
++] = i
;
1528 * This is a workaround for HT-enabled STAs which break the spec
1529 * and have no HT capabilities RX mask (no HT RX MCS map).
1531 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1532 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1534 * Firmware asserts if such situation occurs.
1537 arg
->peer_ht_rates
.num_rates
= 8;
1538 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
1539 arg
->peer_ht_rates
.rates
[i
] = i
;
1541 arg
->peer_ht_rates
.num_rates
= n
;
1542 arg
->peer_num_spatial_streams
= sta
->rx_nss
;
1545 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
1547 arg
->peer_ht_rates
.num_rates
,
1548 arg
->peer_num_spatial_streams
);
1551 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
1552 struct ath10k_vif
*arvif
,
1553 struct ieee80211_sta
*sta
)
1559 lockdep_assert_held(&ar
->conf_mutex
);
1561 if (sta
->wme
&& sta
->uapsd_queues
) {
1562 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
1563 sta
->uapsd_queues
, sta
->max_sp
);
1565 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1566 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
1567 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
1568 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1569 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
1570 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
1571 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1572 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
1573 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
1574 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1575 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
1576 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
1578 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
1579 max_sp
= sta
->max_sp
;
1581 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1583 WMI_AP_PS_PEER_PARAM_UAPSD
,
1586 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1587 arvif
->vdev_id
, ret
);
1591 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1593 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1596 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1597 arvif
->vdev_id
, ret
);
1601 /* TODO setup this based on STA listen interval and
1602 beacon interval. Currently we don't know
1603 sta->listen_interval - mac80211 patch required.
1604 Currently use 10 seconds */
1605 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
1606 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
1609 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1610 arvif
->vdev_id
, ret
);
1618 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1619 struct ieee80211_sta
*sta
,
1620 struct wmi_peer_assoc_complete_arg
*arg
)
1622 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1625 if (!vht_cap
->vht_supported
)
1628 arg
->peer_flags
|= WMI_PEER_VHT
;
1630 if (ar
->hw
->conf
.chandef
.chan
->band
== IEEE80211_BAND_2GHZ
)
1631 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
1633 arg
->peer_vht_caps
= vht_cap
->cap
;
1635 ampdu_factor
= (vht_cap
->cap
&
1636 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1637 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1639 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1640 * zero in VHT IE. Using it would result in degraded throughput.
1641 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1642 * it if VHT max_mpdu is smaller. */
1643 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1644 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1645 ampdu_factor
)) - 1);
1647 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1648 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1650 arg
->peer_vht_rates
.rx_max_rate
=
1651 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1652 arg
->peer_vht_rates
.rx_mcs_set
=
1653 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1654 arg
->peer_vht_rates
.tx_max_rate
=
1655 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1656 arg
->peer_vht_rates
.tx_mcs_set
=
1657 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1659 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1660 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1663 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1664 struct ieee80211_vif
*vif
,
1665 struct ieee80211_sta
*sta
,
1666 struct wmi_peer_assoc_complete_arg
*arg
)
1668 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1670 switch (arvif
->vdev_type
) {
1671 case WMI_VDEV_TYPE_AP
:
1673 arg
->peer_flags
|= WMI_PEER_QOS
;
1675 if (sta
->wme
&& sta
->uapsd_queues
) {
1676 arg
->peer_flags
|= WMI_PEER_APSD
;
1677 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
1680 case WMI_VDEV_TYPE_STA
:
1681 if (vif
->bss_conf
.qos
)
1682 arg
->peer_flags
|= WMI_PEER_QOS
;
1684 case WMI_VDEV_TYPE_IBSS
:
1686 arg
->peer_flags
|= WMI_PEER_QOS
;
1692 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
1693 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
1696 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta
*sta
)
1698 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1699 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >> 4;
1702 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1703 struct ieee80211_vif
*vif
,
1704 struct ieee80211_sta
*sta
,
1705 struct wmi_peer_assoc_complete_arg
*arg
)
1707 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1709 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1710 case IEEE80211_BAND_2GHZ
:
1711 if (sta
->vht_cap
.vht_supported
) {
1712 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1713 phymode
= MODE_11AC_VHT40
;
1715 phymode
= MODE_11AC_VHT20
;
1716 } else if (sta
->ht_cap
.ht_supported
) {
1717 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1718 phymode
= MODE_11NG_HT40
;
1720 phymode
= MODE_11NG_HT20
;
1721 } else if (ath10k_mac_sta_has_11g_rates(sta
)) {
1728 case IEEE80211_BAND_5GHZ
:
1732 if (sta
->vht_cap
.vht_supported
) {
1733 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1734 phymode
= MODE_11AC_VHT80
;
1735 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1736 phymode
= MODE_11AC_VHT40
;
1737 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1738 phymode
= MODE_11AC_VHT20
;
1739 } else if (sta
->ht_cap
.ht_supported
) {
1740 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1741 phymode
= MODE_11NA_HT40
;
1743 phymode
= MODE_11NA_HT20
;
1753 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
1754 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
1756 arg
->peer_phymode
= phymode
;
1757 WARN_ON(phymode
== MODE_UNKNOWN
);
1760 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
1761 struct ieee80211_vif
*vif
,
1762 struct ieee80211_sta
*sta
,
1763 struct wmi_peer_assoc_complete_arg
*arg
)
1765 lockdep_assert_held(&ar
->conf_mutex
);
1767 memset(arg
, 0, sizeof(*arg
));
1769 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
1770 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
1771 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
1772 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
1773 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
1774 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
1775 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
1780 static const u32 ath10k_smps_map
[] = {
1781 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
1782 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
1783 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
1784 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
1787 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1789 const struct ieee80211_sta_ht_cap
*ht_cap
)
1793 if (!ht_cap
->ht_supported
)
1796 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
1797 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
1799 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
1802 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
1803 WMI_PEER_SMPS_STATE
,
1804 ath10k_smps_map
[smps
]);
1807 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
1808 struct ieee80211_vif
*vif
,
1809 struct ieee80211_sta_vht_cap vht_cap
)
1811 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1816 if (!(ar
->vht_cap_info
&
1817 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
1818 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
1819 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
1820 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
1823 param
= ar
->wmi
.vdev_param
->txbf
;
1826 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
1829 /* The following logic is correct. If a remote STA advertises support
1830 * for being a beamformer then we should enable us being a beamformee.
1833 if (ar
->vht_cap_info
&
1834 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
1835 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
1836 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
1837 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
1839 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
1840 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
1843 if (ar
->vht_cap_info
&
1844 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
1845 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
1846 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
1847 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
1849 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
1850 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
1853 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
1854 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
1856 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
1857 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
1859 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
1861 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
1869 /* can be called only in mac80211 callbacks due to `key_count` usage */
1870 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1871 struct ieee80211_vif
*vif
,
1872 struct ieee80211_bss_conf
*bss_conf
)
1874 struct ath10k
*ar
= hw
->priv
;
1875 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1876 struct ieee80211_sta_ht_cap ht_cap
;
1877 struct ieee80211_sta_vht_cap vht_cap
;
1878 struct wmi_peer_assoc_complete_arg peer_arg
;
1879 struct ieee80211_sta
*ap_sta
;
1882 lockdep_assert_held(&ar
->conf_mutex
);
1884 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
1885 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
1889 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1891 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
1892 bss_conf
->bssid
, arvif
->vdev_id
);
1897 /* ap_sta must be accessed only within rcu section which must be left
1898 * before calling ath10k_setup_peer_smps() which might sleep. */
1899 ht_cap
= ap_sta
->ht_cap
;
1900 vht_cap
= ap_sta
->vht_cap
;
1902 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
1904 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1905 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
1912 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1914 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
1915 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
1919 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
1921 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
1922 arvif
->vdev_id
, ret
);
1926 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
1928 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
1929 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
1933 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1934 "mac vdev %d up (associated) bssid %pM aid %d\n",
1935 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1937 WARN_ON(arvif
->is_up
);
1939 arvif
->aid
= bss_conf
->aid
;
1940 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
1942 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
1944 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
1945 arvif
->vdev_id
, ret
);
1949 arvif
->is_up
= true;
1951 /* Workaround: Some firmware revisions (tested with qca6174
1952 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
1953 * poked with peer param command.
1955 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
1956 WMI_PEER_DUMMY_VAR
, 1);
1958 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
1959 arvif
->bssid
, arvif
->vdev_id
, ret
);
1964 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1965 struct ieee80211_vif
*vif
)
1967 struct ath10k
*ar
= hw
->priv
;
1968 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1969 struct ieee80211_sta_vht_cap vht_cap
= {};
1972 lockdep_assert_held(&ar
->conf_mutex
);
1974 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
1975 arvif
->vdev_id
, arvif
->bssid
);
1977 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1979 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
1980 arvif
->vdev_id
, ret
);
1982 arvif
->def_wep_key_idx
= -1;
1984 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
1986 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
1987 arvif
->vdev_id
, ret
);
1991 arvif
->is_up
= false;
1994 static int ath10k_station_assoc(struct ath10k
*ar
,
1995 struct ieee80211_vif
*vif
,
1996 struct ieee80211_sta
*sta
,
1999 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2000 struct wmi_peer_assoc_complete_arg peer_arg
;
2003 lockdep_assert_held(&ar
->conf_mutex
);
2005 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2007 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2008 sta
->addr
, arvif
->vdev_id
, ret
);
2012 peer_arg
.peer_reassoc
= reassoc
;
2013 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2015 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2016 sta
->addr
, arvif
->vdev_id
, ret
);
2020 /* Re-assoc is run only to update supported rates for given station. It
2021 * doesn't make much sense to reconfigure the peer completely.
2024 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2027 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2028 arvif
->vdev_id
, ret
);
2032 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2034 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2035 sta
->addr
, arvif
->vdev_id
, ret
);
2040 arvif
->num_legacy_stations
++;
2041 ret
= ath10k_recalc_rtscts_prot(arvif
);
2043 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2044 arvif
->vdev_id
, ret
);
2049 /* Plumb cached keys only for static WEP */
2050 if (arvif
->def_wep_key_idx
!= -1) {
2051 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2053 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2054 arvif
->vdev_id
, ret
);
2063 static int ath10k_station_disassoc(struct ath10k
*ar
,
2064 struct ieee80211_vif
*vif
,
2065 struct ieee80211_sta
*sta
)
2067 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2070 lockdep_assert_held(&ar
->conf_mutex
);
2073 arvif
->num_legacy_stations
--;
2074 ret
= ath10k_recalc_rtscts_prot(arvif
);
2076 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2077 arvif
->vdev_id
, ret
);
2082 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2084 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2085 arvif
->vdev_id
, ret
);
2096 static int ath10k_update_channel_list(struct ath10k
*ar
)
2098 struct ieee80211_hw
*hw
= ar
->hw
;
2099 struct ieee80211_supported_band
**bands
;
2100 enum ieee80211_band band
;
2101 struct ieee80211_channel
*channel
;
2102 struct wmi_scan_chan_list_arg arg
= {0};
2103 struct wmi_channel_arg
*ch
;
2109 lockdep_assert_held(&ar
->conf_mutex
);
2111 bands
= hw
->wiphy
->bands
;
2112 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2116 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2117 if (bands
[band
]->channels
[i
].flags
&
2118 IEEE80211_CHAN_DISABLED
)
2125 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2126 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2131 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2135 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2136 channel
= &bands
[band
]->channels
[i
];
2138 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2141 ch
->allow_ht
= true;
2143 /* FIXME: when should we really allow VHT? */
2144 ch
->allow_vht
= true;
2147 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2150 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2153 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2155 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2156 ch
->passive
= passive
;
2158 ch
->freq
= channel
->center_freq
;
2159 ch
->band_center_freq1
= channel
->center_freq
;
2161 ch
->max_power
= channel
->max_power
* 2;
2162 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2163 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2164 ch
->reg_class_id
= 0; /* FIXME */
2166 /* FIXME: why use only legacy modes, why not any
2167 * HT/VHT modes? Would that even make any
2169 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2170 ch
->mode
= MODE_11G
;
2172 ch
->mode
= MODE_11A
;
2174 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2177 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2178 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2179 ch
- arg
.channels
, arg
.n_channels
,
2180 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2181 ch
->max_antenna_gain
, ch
->mode
);
2187 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2188 kfree(arg
.channels
);
2193 static enum wmi_dfs_region
2194 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2196 switch (dfs_region
) {
2197 case NL80211_DFS_UNSET
:
2198 return WMI_UNINIT_DFS_DOMAIN
;
2199 case NL80211_DFS_FCC
:
2200 return WMI_FCC_DFS_DOMAIN
;
2201 case NL80211_DFS_ETSI
:
2202 return WMI_ETSI_DFS_DOMAIN
;
2203 case NL80211_DFS_JP
:
2204 return WMI_MKK4_DFS_DOMAIN
;
2206 return WMI_UNINIT_DFS_DOMAIN
;
2209 static void ath10k_regd_update(struct ath10k
*ar
)
2211 struct reg_dmn_pair_mapping
*regpair
;
2213 enum wmi_dfs_region wmi_dfs_reg
;
2214 enum nl80211_dfs_regions nl_dfs_reg
;
2216 lockdep_assert_held(&ar
->conf_mutex
);
2218 ret
= ath10k_update_channel_list(ar
);
2220 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2222 regpair
= ar
->ath_common
.regulatory
.regpair
;
2224 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2225 nl_dfs_reg
= ar
->dfs_detector
->region
;
2226 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2228 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2231 /* Target allows setting up per-band regdomain but ath_common provides
2232 * a combined one only */
2233 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2234 regpair
->reg_domain
,
2235 regpair
->reg_domain
, /* 2ghz */
2236 regpair
->reg_domain
, /* 5ghz */
2237 regpair
->reg_2ghz_ctl
,
2238 regpair
->reg_5ghz_ctl
,
2241 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2244 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2245 struct regulatory_request
*request
)
2247 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2248 struct ath10k
*ar
= hw
->priv
;
2251 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2253 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2254 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
2255 request
->dfs_region
);
2256 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
2257 request
->dfs_region
);
2259 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2260 request
->dfs_region
);
2263 mutex_lock(&ar
->conf_mutex
);
2264 if (ar
->state
== ATH10K_STATE_ON
)
2265 ath10k_regd_update(ar
);
2266 mutex_unlock(&ar
->conf_mutex
);
2273 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
2275 if (ieee80211_is_mgmt(hdr
->frame_control
))
2276 return HTT_DATA_TX_EXT_TID_MGMT
;
2278 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2279 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2281 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
2282 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2284 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
2287 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
2290 return ath10k_vif_to_arvif(vif
)->vdev_id
;
2292 if (ar
->monitor_started
)
2293 return ar
->monitor_vdev_id
;
2295 ath10k_warn(ar
, "failed to resolve vdev id\n");
2299 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2300 * Control in the header.
2302 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2304 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
2305 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
2308 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2311 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
2312 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
2313 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
2314 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
2316 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2317 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2318 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2319 * it is safe to downgrade to NullFunc.
2321 hdr
= (void *)skb
->data
;
2322 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
)) {
2323 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2324 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
2328 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
2329 struct ieee80211_vif
*vif
,
2330 struct sk_buff
*skb
)
2332 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2333 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2335 /* This is case only for P2P_GO */
2336 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
2337 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
2340 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
2341 spin_lock_bh(&ar
->data_lock
);
2342 if (arvif
->u
.ap
.noa_data
)
2343 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
2345 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
2346 arvif
->u
.ap
.noa_data
,
2347 arvif
->u
.ap
.noa_len
);
2348 spin_unlock_bh(&ar
->data_lock
);
2352 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
2354 /* FIXME: Not really sure since when the behaviour changed. At some
2355 * point new firmware stopped requiring creation of peer entries for
2356 * offchannel tx (and actually creating them causes issues with wmi-htc
2357 * tx credit replenishment and reliability). Assuming it's at least 3.4
2358 * because that's when the `freq` was introduced to TX_FRM HTT command.
2360 return !(ar
->htt
.target_version_major
>= 3 &&
2361 ar
->htt
.target_version_minor
>= 4);
2364 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
2366 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2369 if (ar
->htt
.target_version_major
>= 3) {
2370 /* Since HTT 3.0 there is no separate mgmt tx command */
2371 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
2375 if (ieee80211_is_mgmt(hdr
->frame_control
)) {
2376 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2378 if (skb_queue_len(&ar
->wmi_mgmt_tx_queue
) >=
2379 ATH10K_MAX_NUM_MGMT_PENDING
) {
2380 ath10k_warn(ar
, "reached WMI management transmit queue limit\n");
2385 skb_queue_tail(&ar
->wmi_mgmt_tx_queue
, skb
);
2386 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
2388 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
2390 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2392 ieee80211_is_nullfunc(hdr
->frame_control
)) {
2393 /* FW does not report tx status properly for NullFunc frames
2394 * unless they are sent through mgmt tx path. mac80211 sends
2395 * those frames when it detects link/beacon loss and depends
2396 * on the tx status to be correct. */
2397 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
2399 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
2404 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
2406 ieee80211_free_txskb(ar
->hw
, skb
);
2410 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
2412 struct sk_buff
*skb
;
2415 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2419 ieee80211_free_txskb(ar
->hw
, skb
);
2423 void ath10k_offchan_tx_work(struct work_struct
*work
)
2425 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
2426 struct ath10k_peer
*peer
;
2427 struct ieee80211_hdr
*hdr
;
2428 struct sk_buff
*skb
;
2429 const u8
*peer_addr
;
2433 /* FW requirement: We must create a peer before FW will send out
2434 * an offchannel frame. Otherwise the frame will be stuck and
2435 * never transmitted. We delete the peer upon tx completion.
2436 * It is unlikely that a peer for offchannel tx will already be
2437 * present. However it may be in some rare cases so account for that.
2438 * Otherwise we might remove a legitimate peer and break stuff. */
2441 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2445 mutex_lock(&ar
->conf_mutex
);
2447 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
2450 hdr
= (struct ieee80211_hdr
*)skb
->data
;
2451 peer_addr
= ieee80211_get_DA(hdr
);
2452 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
2454 spin_lock_bh(&ar
->data_lock
);
2455 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
2456 spin_unlock_bh(&ar
->data_lock
);
2459 /* FIXME: should this use ath10k_warn()? */
2460 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
2461 peer_addr
, vdev_id
);
2464 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
2466 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
2467 peer_addr
, vdev_id
, ret
);
2470 spin_lock_bh(&ar
->data_lock
);
2471 reinit_completion(&ar
->offchan_tx_completed
);
2472 ar
->offchan_tx_skb
= skb
;
2473 spin_unlock_bh(&ar
->data_lock
);
2475 ath10k_tx_htt(ar
, skb
);
2477 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
2480 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
2484 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
2486 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
2487 peer_addr
, vdev_id
, ret
);
2490 mutex_unlock(&ar
->conf_mutex
);
2494 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
2496 struct sk_buff
*skb
;
2499 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2503 ieee80211_free_txskb(ar
->hw
, skb
);
2507 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
2509 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
2510 struct sk_buff
*skb
;
2514 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2518 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
2520 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
2522 ieee80211_free_txskb(ar
->hw
, skb
);
2531 void __ath10k_scan_finish(struct ath10k
*ar
)
2533 lockdep_assert_held(&ar
->data_lock
);
2535 switch (ar
->scan
.state
) {
2536 case ATH10K_SCAN_IDLE
:
2538 case ATH10K_SCAN_RUNNING
:
2539 if (ar
->scan
.is_roc
)
2540 ieee80211_remain_on_channel_expired(ar
->hw
);
2542 case ATH10K_SCAN_ABORTING
:
2543 if (!ar
->scan
.is_roc
)
2544 ieee80211_scan_completed(ar
->hw
,
2546 ATH10K_SCAN_ABORTING
));
2548 case ATH10K_SCAN_STARTING
:
2549 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
2550 ar
->scan_channel
= NULL
;
2551 ath10k_offchan_tx_purge(ar
);
2552 cancel_delayed_work(&ar
->scan
.timeout
);
2553 complete_all(&ar
->scan
.completed
);
2558 void ath10k_scan_finish(struct ath10k
*ar
)
2560 spin_lock_bh(&ar
->data_lock
);
2561 __ath10k_scan_finish(ar
);
2562 spin_unlock_bh(&ar
->data_lock
);
2565 static int ath10k_scan_stop(struct ath10k
*ar
)
2567 struct wmi_stop_scan_arg arg
= {
2568 .req_id
= 1, /* FIXME */
2569 .req_type
= WMI_SCAN_STOP_ONE
,
2570 .u
.scan_id
= ATH10K_SCAN_ID
,
2574 lockdep_assert_held(&ar
->conf_mutex
);
2576 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
2578 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
2582 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
2584 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
2586 } else if (ret
> 0) {
2591 /* Scan state should be updated upon scan completion but in case
2592 * firmware fails to deliver the event (for whatever reason) it is
2593 * desired to clean up scan state anyway. Firmware may have just
2594 * dropped the scan completion event delivery due to transport pipe
2595 * being overflown with data and/or it can recover on its own before
2596 * next scan request is submitted.
2598 spin_lock_bh(&ar
->data_lock
);
2599 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
2600 __ath10k_scan_finish(ar
);
2601 spin_unlock_bh(&ar
->data_lock
);
2606 static void ath10k_scan_abort(struct ath10k
*ar
)
2610 lockdep_assert_held(&ar
->conf_mutex
);
2612 spin_lock_bh(&ar
->data_lock
);
2614 switch (ar
->scan
.state
) {
2615 case ATH10K_SCAN_IDLE
:
2616 /* This can happen if timeout worker kicked in and called
2617 * abortion while scan completion was being processed.
2620 case ATH10K_SCAN_STARTING
:
2621 case ATH10K_SCAN_ABORTING
:
2622 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2623 ath10k_scan_state_str(ar
->scan
.state
),
2626 case ATH10K_SCAN_RUNNING
:
2627 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
2628 spin_unlock_bh(&ar
->data_lock
);
2630 ret
= ath10k_scan_stop(ar
);
2632 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
2634 spin_lock_bh(&ar
->data_lock
);
2638 spin_unlock_bh(&ar
->data_lock
);
2641 void ath10k_scan_timeout_work(struct work_struct
*work
)
2643 struct ath10k
*ar
= container_of(work
, struct ath10k
,
2646 mutex_lock(&ar
->conf_mutex
);
2647 ath10k_scan_abort(ar
);
2648 mutex_unlock(&ar
->conf_mutex
);
2651 static int ath10k_start_scan(struct ath10k
*ar
,
2652 const struct wmi_start_scan_arg
*arg
)
2656 lockdep_assert_held(&ar
->conf_mutex
);
2658 ret
= ath10k_wmi_start_scan(ar
, arg
);
2662 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
2664 ret
= ath10k_scan_stop(ar
);
2666 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
2671 /* If we failed to start the scan, return error code at
2672 * this point. This is probably due to some issue in the
2673 * firmware, but no need to wedge the driver due to that...
2675 spin_lock_bh(&ar
->data_lock
);
2676 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
2677 spin_unlock_bh(&ar
->data_lock
);
2680 spin_unlock_bh(&ar
->data_lock
);
2682 /* Add a 200ms margin to account for event/command processing */
2683 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
2684 msecs_to_jiffies(arg
->max_scan_time
+200));
2688 /**********************/
2689 /* mac80211 callbacks */
2690 /**********************/
2692 static void ath10k_tx(struct ieee80211_hw
*hw
,
2693 struct ieee80211_tx_control
*control
,
2694 struct sk_buff
*skb
)
2696 struct ath10k
*ar
= hw
->priv
;
2697 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2698 struct ieee80211_vif
*vif
= info
->control
.vif
;
2699 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2701 /* We should disable CCK RATE due to P2P */
2702 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
2703 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2705 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
2706 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
2707 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
2709 /* it makes no sense to process injected frames like that */
2710 if (vif
&& vif
->type
!= NL80211_IFTYPE_MONITOR
) {
2711 ath10k_tx_h_nwifi(hw
, skb
);
2712 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
2713 ath10k_tx_h_seq_no(vif
, skb
);
2716 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
2717 spin_lock_bh(&ar
->data_lock
);
2718 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
2719 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
2720 spin_unlock_bh(&ar
->data_lock
);
2722 if (ath10k_mac_need_offchan_tx_work(ar
)) {
2723 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
2724 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
2726 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
2729 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
2730 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
2735 ath10k_tx_htt(ar
, skb
);
2738 /* Must not be called with conf_mutex held as workers can use that also. */
2739 void ath10k_drain_tx(struct ath10k
*ar
)
2741 /* make sure rcu-protected mac80211 tx path itself is drained */
2744 ath10k_offchan_tx_purge(ar
);
2745 ath10k_mgmt_over_wmi_tx_purge(ar
);
2747 cancel_work_sync(&ar
->offchan_tx_work
);
2748 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
2751 void ath10k_halt(struct ath10k
*ar
)
2753 struct ath10k_vif
*arvif
;
2755 lockdep_assert_held(&ar
->conf_mutex
);
2757 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
2758 ar
->filter_flags
= 0;
2759 ar
->monitor
= false;
2761 if (ar
->monitor_started
)
2762 ath10k_monitor_stop(ar
);
2764 ar
->monitor_started
= false;
2766 ath10k_scan_finish(ar
);
2767 ath10k_peer_cleanup_all(ar
);
2768 ath10k_core_stop(ar
);
2769 ath10k_hif_power_down(ar
);
2771 spin_lock_bh(&ar
->data_lock
);
2772 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
2773 ath10k_mac_vif_beacon_cleanup(arvif
);
2774 spin_unlock_bh(&ar
->data_lock
);
2777 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
2779 struct ath10k
*ar
= hw
->priv
;
2781 mutex_lock(&ar
->conf_mutex
);
2783 if (ar
->cfg_tx_chainmask
) {
2784 *tx_ant
= ar
->cfg_tx_chainmask
;
2785 *rx_ant
= ar
->cfg_rx_chainmask
;
2787 *tx_ant
= ar
->supp_tx_chainmask
;
2788 *rx_ant
= ar
->supp_rx_chainmask
;
2791 mutex_unlock(&ar
->conf_mutex
);
2796 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
2798 /* It is not clear that allowing gaps in chainmask
2799 * is helpful. Probably it will not do what user
2800 * is hoping for, so warn in that case.
2802 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
2805 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2809 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
2813 lockdep_assert_held(&ar
->conf_mutex
);
2815 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
2816 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
2818 ar
->cfg_tx_chainmask
= tx_ant
;
2819 ar
->cfg_rx_chainmask
= rx_ant
;
2821 if ((ar
->state
!= ATH10K_STATE_ON
) &&
2822 (ar
->state
!= ATH10K_STATE_RESTARTED
))
2825 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
2828 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
2833 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
2836 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
2844 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
2846 struct ath10k
*ar
= hw
->priv
;
2849 mutex_lock(&ar
->conf_mutex
);
2850 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
2851 mutex_unlock(&ar
->conf_mutex
);
2855 static int ath10k_start(struct ieee80211_hw
*hw
)
2857 struct ath10k
*ar
= hw
->priv
;
2861 * This makes sense only when restarting hw. It is harmless to call
2862 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2863 * commands will be submitted while restarting.
2865 ath10k_drain_tx(ar
);
2867 mutex_lock(&ar
->conf_mutex
);
2869 switch (ar
->state
) {
2870 case ATH10K_STATE_OFF
:
2871 ar
->state
= ATH10K_STATE_ON
;
2873 case ATH10K_STATE_RESTARTING
:
2875 ar
->state
= ATH10K_STATE_RESTARTED
;
2877 case ATH10K_STATE_ON
:
2878 case ATH10K_STATE_RESTARTED
:
2879 case ATH10K_STATE_WEDGED
:
2883 case ATH10K_STATE_UTF
:
2888 ret
= ath10k_hif_power_up(ar
);
2890 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
2894 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
2896 ath10k_err(ar
, "Could not init core: %d\n", ret
);
2897 goto err_power_down
;
2900 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
2902 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
2906 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
2908 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
2912 if (ar
->cfg_tx_chainmask
)
2913 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
2914 ar
->cfg_rx_chainmask
);
2917 * By default FW set ARP frames ac to voice (6). In that case ARP
2918 * exchange is not working properly for UAPSD enabled AP. ARP requests
2919 * which arrives with access category 0 are processed by network stack
2920 * and send back with access category 0, but FW changes access category
2921 * to 6. Set ARP frames access category to best effort (0) solves
2925 ret
= ath10k_wmi_pdev_set_param(ar
,
2926 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
2928 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
2933 ar
->num_started_vdevs
= 0;
2934 ath10k_regd_update(ar
);
2936 ath10k_spectral_start(ar
);
2938 mutex_unlock(&ar
->conf_mutex
);
2942 ath10k_core_stop(ar
);
2945 ath10k_hif_power_down(ar
);
2948 ar
->state
= ATH10K_STATE_OFF
;
2951 mutex_unlock(&ar
->conf_mutex
);
2955 static void ath10k_stop(struct ieee80211_hw
*hw
)
2957 struct ath10k
*ar
= hw
->priv
;
2959 ath10k_drain_tx(ar
);
2961 mutex_lock(&ar
->conf_mutex
);
2962 if (ar
->state
!= ATH10K_STATE_OFF
) {
2964 ar
->state
= ATH10K_STATE_OFF
;
2966 mutex_unlock(&ar
->conf_mutex
);
2968 cancel_delayed_work_sync(&ar
->scan
.timeout
);
2969 cancel_work_sync(&ar
->restart_work
);
2972 static int ath10k_config_ps(struct ath10k
*ar
)
2974 struct ath10k_vif
*arvif
;
2977 lockdep_assert_held(&ar
->conf_mutex
);
2979 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2980 ret
= ath10k_mac_vif_setup_ps(arvif
);
2982 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
2990 static const char *chandef_get_width(enum nl80211_chan_width width
)
2993 case NL80211_CHAN_WIDTH_20_NOHT
:
2995 case NL80211_CHAN_WIDTH_20
:
2997 case NL80211_CHAN_WIDTH_40
:
2999 case NL80211_CHAN_WIDTH_80
:
3001 case NL80211_CHAN_WIDTH_80P80
:
3003 case NL80211_CHAN_WIDTH_160
:
3005 case NL80211_CHAN_WIDTH_5
:
3007 case NL80211_CHAN_WIDTH_10
:
3013 static void ath10k_config_chan(struct ath10k
*ar
)
3015 struct ath10k_vif
*arvif
;
3018 lockdep_assert_held(&ar
->conf_mutex
);
3020 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3021 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3022 ar
->chandef
.chan
->center_freq
,
3023 ar
->chandef
.center_freq1
,
3024 ar
->chandef
.center_freq2
,
3025 chandef_get_width(ar
->chandef
.width
));
3027 /* First stop monitor interface. Some FW versions crash if there's a
3028 * lone monitor interface. */
3029 if (ar
->monitor_started
)
3030 ath10k_monitor_stop(ar
);
3032 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3033 if (!arvif
->is_started
)
3039 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3042 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
3044 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
3045 arvif
->vdev_id
, ret
);
3050 /* all vdevs are downed now - attempt to restart and re-up them */
3052 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3053 if (!arvif
->is_started
)
3056 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3059 ret
= ath10k_vdev_restart(arvif
);
3061 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
3062 arvif
->vdev_id
, ret
);
3069 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
3072 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
3073 arvif
->vdev_id
, ret
);
3078 ath10k_monitor_recalc(ar
);
3081 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
3086 lockdep_assert_held(&ar
->conf_mutex
);
3088 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
3090 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
3091 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3093 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
3098 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
3099 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3101 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
3109 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
3111 struct ath10k_vif
*arvif
;
3112 int ret
, txpower
= -1;
3114 lockdep_assert_held(&ar
->conf_mutex
);
3116 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3117 WARN_ON(arvif
->txpower
< 0);
3120 txpower
= arvif
->txpower
;
3122 txpower
= min(txpower
, arvif
->txpower
);
3125 if (WARN_ON(txpower
== -1))
3128 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
3130 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
3138 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
3140 struct ath10k
*ar
= hw
->priv
;
3141 struct ieee80211_conf
*conf
= &hw
->conf
;
3144 mutex_lock(&ar
->conf_mutex
);
3146 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
3147 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3148 "mac config channel %dMHz flags 0x%x radar %d\n",
3149 conf
->chandef
.chan
->center_freq
,
3150 conf
->chandef
.chan
->flags
,
3151 conf
->radar_enabled
);
3153 spin_lock_bh(&ar
->data_lock
);
3154 ar
->rx_channel
= conf
->chandef
.chan
;
3155 spin_unlock_bh(&ar
->data_lock
);
3157 ar
->radar_enabled
= conf
->radar_enabled
;
3158 ath10k_recalc_radar_detection(ar
);
3160 if (!cfg80211_chandef_identical(&ar
->chandef
, &conf
->chandef
)) {
3161 ar
->chandef
= conf
->chandef
;
3162 ath10k_config_chan(ar
);
3166 if (changed
& IEEE80211_CONF_CHANGE_PS
)
3167 ath10k_config_ps(ar
);
3169 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
3170 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
3171 ret
= ath10k_monitor_recalc(ar
);
3173 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
3176 mutex_unlock(&ar
->conf_mutex
);
3180 static u32
get_nss_from_chainmask(u16 chain_mask
)
3182 if ((chain_mask
& 0x15) == 0x15)
3184 else if ((chain_mask
& 0x7) == 0x7)
3186 else if ((chain_mask
& 0x3) == 0x3)
3193 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3194 * because we will send mgmt frames without CCK. This requirement
3195 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3198 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
3199 struct ieee80211_vif
*vif
)
3201 struct ath10k
*ar
= hw
->priv
;
3202 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3203 enum wmi_sta_powersave_param param
;
3209 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
3211 mutex_lock(&ar
->conf_mutex
);
3213 memset(arvif
, 0, sizeof(*arvif
));
3218 INIT_LIST_HEAD(&arvif
->list
);
3220 if (ar
->free_vdev_map
== 0) {
3221 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
3225 bit
= __ffs64(ar
->free_vdev_map
);
3227 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
3228 bit
, ar
->free_vdev_map
);
3230 arvif
->vdev_id
= bit
;
3231 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
3233 switch (vif
->type
) {
3234 case NL80211_IFTYPE_P2P_DEVICE
:
3235 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
3236 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
3238 case NL80211_IFTYPE_UNSPECIFIED
:
3239 case NL80211_IFTYPE_STATION
:
3240 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
3242 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
3244 case NL80211_IFTYPE_ADHOC
:
3245 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
3247 case NL80211_IFTYPE_AP
:
3248 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
3251 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
3253 case NL80211_IFTYPE_MONITOR
:
3254 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
3261 /* Some firmware revisions don't wait for beacon tx completion before
3262 * sending another SWBA event. This could lead to hardware using old
3263 * (freed) beacon data in some cases, e.g. tx credit starvation
3264 * combined with missed TBTT. This is very very rare.
3266 * On non-IOMMU-enabled hosts this could be a possible security issue
3267 * because hw could beacon some random data on the air. On
3268 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3269 * device would crash.
3271 * Since there are no beacon tx completions (implicit nor explicit)
3272 * propagated to host the only workaround for this is to allocate a
3273 * DMA-coherent buffer for a lifetime of a vif and use it for all
3274 * beacon tx commands. Worst case for this approach is some beacons may
3275 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3277 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
3278 vif
->type
== NL80211_IFTYPE_AP
) {
3279 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
3280 IEEE80211_MAX_FRAME_LEN
,
3281 &arvif
->beacon_paddr
,
3283 if (!arvif
->beacon_buf
) {
3285 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
3291 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3292 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
3293 arvif
->beacon_buf
? "single-buf" : "per-skb");
3295 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
3296 arvif
->vdev_subtype
, vif
->addr
);
3298 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
3299 arvif
->vdev_id
, ret
);
3303 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
3304 list_add(&arvif
->list
, &ar
->arvifs
);
3306 /* It makes no sense to have firmware do keepalives. mac80211 already
3307 * takes care of this with idle connection polling.
3309 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
3311 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
3312 arvif
->vdev_id
, ret
);
3313 goto err_vdev_delete
;
3316 arvif
->def_wep_key_idx
= -1;
3318 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
3319 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3320 ATH10K_HW_TXRX_NATIVE_WIFI
);
3321 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3322 if (ret
&& ret
!= -EOPNOTSUPP
) {
3323 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
3324 arvif
->vdev_id
, ret
);
3325 goto err_vdev_delete
;
3328 if (ar
->cfg_tx_chainmask
) {
3329 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
3331 vdev_param
= ar
->wmi
.vdev_param
->nss
;
3332 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3335 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3336 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
3338 goto err_vdev_delete
;
3342 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3343 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
3345 ath10k_warn(ar
, "failed to create vdev %i peer for AP: %d\n",
3346 arvif
->vdev_id
, ret
);
3347 goto err_vdev_delete
;
3350 ret
= ath10k_mac_set_kickout(arvif
);
3352 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
3353 arvif
->vdev_id
, ret
);
3354 goto err_peer_delete
;
3358 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
3359 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
3360 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
3361 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3364 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
3365 arvif
->vdev_id
, ret
);
3366 goto err_peer_delete
;
3369 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
3371 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
3372 arvif
->vdev_id
, ret
);
3373 goto err_peer_delete
;
3376 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
3378 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
3379 arvif
->vdev_id
, ret
);
3380 goto err_peer_delete
;
3384 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
3386 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
3387 arvif
->vdev_id
, ret
);
3388 goto err_peer_delete
;
3391 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
3393 ath10k_warn(ar
, "failed to set frag threshold for vdev %d: %d\n",
3394 arvif
->vdev_id
, ret
);
3395 goto err_peer_delete
;
3398 arvif
->txpower
= vif
->bss_conf
.txpower
;
3399 ret
= ath10k_mac_txpower_recalc(ar
);
3401 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
3402 goto err_peer_delete
;
3405 mutex_unlock(&ar
->conf_mutex
);
3409 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
3410 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
3413 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
3414 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
3415 list_del(&arvif
->list
);
3418 if (arvif
->beacon_buf
) {
3419 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
3420 arvif
->beacon_buf
, arvif
->beacon_paddr
);
3421 arvif
->beacon_buf
= NULL
;
3424 mutex_unlock(&ar
->conf_mutex
);
3429 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
3430 struct ieee80211_vif
*vif
)
3432 struct ath10k
*ar
= hw
->priv
;
3433 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3436 mutex_lock(&ar
->conf_mutex
);
3438 spin_lock_bh(&ar
->data_lock
);
3439 ath10k_mac_vif_beacon_cleanup(arvif
);
3440 spin_unlock_bh(&ar
->data_lock
);
3442 ret
= ath10k_spectral_vif_stop(arvif
);
3444 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
3445 arvif
->vdev_id
, ret
);
3447 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
3448 list_del(&arvif
->list
);
3450 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3451 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
3454 ath10k_warn(ar
, "failed to submit AP self-peer removal on vdev %i: %d\n",
3455 arvif
->vdev_id
, ret
);
3457 kfree(arvif
->u
.ap
.noa_data
);
3460 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
3463 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
3465 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
3466 arvif
->vdev_id
, ret
);
3468 /* Some firmware revisions don't notify host about self-peer removal
3469 * until after associated vdev is deleted.
3471 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
3472 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
3475 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
3476 arvif
->vdev_id
, ret
);
3478 spin_lock_bh(&ar
->data_lock
);
3480 spin_unlock_bh(&ar
->data_lock
);
3483 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
3485 mutex_unlock(&ar
->conf_mutex
);
3489 * FIXME: Has to be verified.
3491 #define SUPPORTED_FILTERS \
3492 (FIF_PROMISC_IN_BSS | \
3497 FIF_BCN_PRBRESP_PROMISC | \
3501 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
3502 unsigned int changed_flags
,
3503 unsigned int *total_flags
,
3506 struct ath10k
*ar
= hw
->priv
;
3509 mutex_lock(&ar
->conf_mutex
);
3511 changed_flags
&= SUPPORTED_FILTERS
;
3512 *total_flags
&= SUPPORTED_FILTERS
;
3513 ar
->filter_flags
= *total_flags
;
3515 ret
= ath10k_monitor_recalc(ar
);
3517 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
3519 mutex_unlock(&ar
->conf_mutex
);
3522 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
3523 struct ieee80211_vif
*vif
,
3524 struct ieee80211_bss_conf
*info
,
3527 struct ath10k
*ar
= hw
->priv
;
3528 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3530 u32 vdev_param
, pdev_param
, slottime
, preamble
;
3532 mutex_lock(&ar
->conf_mutex
);
3534 if (changed
& BSS_CHANGED_IBSS
)
3535 ath10k_control_ibss(arvif
, info
, vif
->addr
);
3537 if (changed
& BSS_CHANGED_BEACON_INT
) {
3538 arvif
->beacon_interval
= info
->beacon_int
;
3539 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
3540 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3541 arvif
->beacon_interval
);
3542 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3543 "mac vdev %d beacon_interval %d\n",
3544 arvif
->vdev_id
, arvif
->beacon_interval
);
3547 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
3548 arvif
->vdev_id
, ret
);
3551 if (changed
& BSS_CHANGED_BEACON
) {
3552 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3553 "vdev %d set beacon tx mode to staggered\n",
3556 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
3557 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
3558 WMI_BEACON_STAGGERED_MODE
);
3560 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
3561 arvif
->vdev_id
, ret
);
3563 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3565 ath10k_warn(ar
, "failed to update beacon template: %d\n",
3569 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
3570 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
3572 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
3573 arvif
->vdev_id
, ret
);
3576 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
3577 arvif
->dtim_period
= info
->dtim_period
;
3579 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3580 "mac vdev %d dtim_period %d\n",
3581 arvif
->vdev_id
, arvif
->dtim_period
);
3583 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
3584 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3585 arvif
->dtim_period
);
3587 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
3588 arvif
->vdev_id
, ret
);
3591 if (changed
& BSS_CHANGED_SSID
&&
3592 vif
->type
== NL80211_IFTYPE_AP
) {
3593 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
3595 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
3596 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
3599 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
3600 ether_addr_copy(arvif
->bssid
, info
->bssid
);
3602 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
3603 ath10k_control_beaconing(arvif
, info
);
3605 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3606 arvif
->use_cts_prot
= info
->use_cts_prot
;
3607 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
3608 arvif
->vdev_id
, info
->use_cts_prot
);
3610 ret
= ath10k_recalc_rtscts_prot(arvif
);
3612 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3613 arvif
->vdev_id
, ret
);
3616 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3617 if (info
->use_short_slot
)
3618 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
3621 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
3623 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
3624 arvif
->vdev_id
, slottime
);
3626 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
3627 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3630 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
3631 arvif
->vdev_id
, ret
);
3634 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3635 if (info
->use_short_preamble
)
3636 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
3638 preamble
= WMI_VDEV_PREAMBLE_LONG
;
3640 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3641 "mac vdev %d preamble %dn",
3642 arvif
->vdev_id
, preamble
);
3644 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
3645 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3648 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
3649 arvif
->vdev_id
, ret
);
3652 if (changed
& BSS_CHANGED_ASSOC
) {
3654 /* Workaround: Make sure monitor vdev is not running
3655 * when associating to prevent some firmware revisions
3656 * (e.g. 10.1 and 10.2) from crashing.
3658 if (ar
->monitor_started
)
3659 ath10k_monitor_stop(ar
);
3660 ath10k_bss_assoc(hw
, vif
, info
);
3661 ath10k_monitor_recalc(ar
);
3663 ath10k_bss_disassoc(hw
, vif
);
3667 if (changed
& BSS_CHANGED_TXPOWER
) {
3668 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
3669 arvif
->vdev_id
, info
->txpower
);
3671 arvif
->txpower
= info
->txpower
;
3672 ret
= ath10k_mac_txpower_recalc(ar
);
3674 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
3677 if (changed
& BSS_CHANGED_PS
) {
3678 arvif
->ps
= vif
->bss_conf
.ps
;
3680 ret
= ath10k_config_ps(ar
);
3682 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
3683 arvif
->vdev_id
, ret
);
3686 mutex_unlock(&ar
->conf_mutex
);
3689 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
3690 struct ieee80211_vif
*vif
,
3691 struct ieee80211_scan_request
*hw_req
)
3693 struct ath10k
*ar
= hw
->priv
;
3694 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3695 struct cfg80211_scan_request
*req
= &hw_req
->req
;
3696 struct wmi_start_scan_arg arg
;
3700 mutex_lock(&ar
->conf_mutex
);
3702 spin_lock_bh(&ar
->data_lock
);
3703 switch (ar
->scan
.state
) {
3704 case ATH10K_SCAN_IDLE
:
3705 reinit_completion(&ar
->scan
.started
);
3706 reinit_completion(&ar
->scan
.completed
);
3707 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
3708 ar
->scan
.is_roc
= false;
3709 ar
->scan
.vdev_id
= arvif
->vdev_id
;
3712 case ATH10K_SCAN_STARTING
:
3713 case ATH10K_SCAN_RUNNING
:
3714 case ATH10K_SCAN_ABORTING
:
3718 spin_unlock_bh(&ar
->data_lock
);
3723 memset(&arg
, 0, sizeof(arg
));
3724 ath10k_wmi_start_scan_init(ar
, &arg
);
3725 arg
.vdev_id
= arvif
->vdev_id
;
3726 arg
.scan_id
= ATH10K_SCAN_ID
;
3729 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
3732 arg
.ie_len
= req
->ie_len
;
3733 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
3737 arg
.n_ssids
= req
->n_ssids
;
3738 for (i
= 0; i
< arg
.n_ssids
; i
++) {
3739 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
3740 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
3743 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
3746 if (req
->n_channels
) {
3747 arg
.n_channels
= req
->n_channels
;
3748 for (i
= 0; i
< arg
.n_channels
; i
++)
3749 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
3752 ret
= ath10k_start_scan(ar
, &arg
);
3754 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
3755 spin_lock_bh(&ar
->data_lock
);
3756 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3757 spin_unlock_bh(&ar
->data_lock
);
3761 mutex_unlock(&ar
->conf_mutex
);
3765 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
3766 struct ieee80211_vif
*vif
)
3768 struct ath10k
*ar
= hw
->priv
;
3770 mutex_lock(&ar
->conf_mutex
);
3771 ath10k_scan_abort(ar
);
3772 mutex_unlock(&ar
->conf_mutex
);
3774 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3777 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
3778 struct ath10k_vif
*arvif
,
3779 enum set_key_cmd cmd
,
3780 struct ieee80211_key_conf
*key
)
3782 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
3785 /* 10.1 firmware branch requires default key index to be set to group
3786 * key index after installing it. Otherwise FW/HW Txes corrupted
3787 * frames with multi-vif APs. This is not required for main firmware
3788 * branch (e.g. 636).
3790 * FIXME: This has been tested only in AP. It remains unknown if this
3791 * is required for multi-vif STA interfaces on 10.1 */
3793 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
3796 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
3799 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
3802 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3808 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3811 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
3812 arvif
->vdev_id
, ret
);
3815 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3816 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
3817 struct ieee80211_key_conf
*key
)
3819 struct ath10k
*ar
= hw
->priv
;
3820 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3821 struct ath10k_peer
*peer
;
3822 const u8
*peer_addr
;
3823 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3824 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
3825 bool def_idx
= false;
3828 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
3831 mutex_lock(&ar
->conf_mutex
);
3834 peer_addr
= sta
->addr
;
3835 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
3836 peer_addr
= vif
->bss_conf
.bssid
;
3838 peer_addr
= vif
->addr
;
3840 key
->hw_key_idx
= key
->keyidx
;
3842 /* the peer should not disappear in mid-way (unless FW goes awry) since
3843 * we already hold conf_mutex. we just make sure its there now. */
3844 spin_lock_bh(&ar
->data_lock
);
3845 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3846 spin_unlock_bh(&ar
->data_lock
);
3849 if (cmd
== SET_KEY
) {
3850 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
3855 /* if the peer doesn't exist there is no key to disable
3863 arvif
->wep_keys
[key
->keyidx
] = key
;
3865 arvif
->wep_keys
[key
->keyidx
] = NULL
;
3867 if (cmd
== DISABLE_KEY
)
3868 ath10k_clear_vdev_key(arvif
, key
);
3871 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3872 * static WEP, do not set this flag for the keys whose key id
3873 * is greater than default key id.
3875 if (arvif
->def_wep_key_idx
== -1)
3878 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, def_idx
);
3880 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
3881 arvif
->vdev_id
, peer_addr
, ret
);
3885 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
3887 spin_lock_bh(&ar
->data_lock
);
3888 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3889 if (peer
&& cmd
== SET_KEY
)
3890 peer
->keys
[key
->keyidx
] = key
;
3891 else if (peer
&& cmd
== DISABLE_KEY
)
3892 peer
->keys
[key
->keyidx
] = NULL
;
3893 else if (peer
== NULL
)
3894 /* impossible unless FW goes crazy */
3895 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
3896 spin_unlock_bh(&ar
->data_lock
);
3899 mutex_unlock(&ar
->conf_mutex
);
3903 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
3904 struct ieee80211_vif
*vif
,
3907 struct ath10k
*ar
= hw
->priv
;
3908 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3911 mutex_lock(&arvif
->ar
->conf_mutex
);
3913 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
3916 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
3917 arvif
->vdev_id
, keyidx
);
3919 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
3921 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
3925 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
3931 arvif
->def_wep_key_idx
= keyidx
;
3933 mutex_unlock(&arvif
->ar
->conf_mutex
);
3936 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
3939 struct ath10k_vif
*arvif
;
3940 struct ath10k_sta
*arsta
;
3941 struct ieee80211_sta
*sta
;
3942 u32 changed
, bw
, nss
, smps
;
3945 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
3946 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
3947 arvif
= arsta
->arvif
;
3950 spin_lock_bh(&ar
->data_lock
);
3952 changed
= arsta
->changed
;
3959 spin_unlock_bh(&ar
->data_lock
);
3961 mutex_lock(&ar
->conf_mutex
);
3963 if (changed
& IEEE80211_RC_BW_CHANGED
) {
3964 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
3967 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3968 WMI_PEER_CHAN_WIDTH
, bw
);
3970 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
3971 sta
->addr
, bw
, err
);
3974 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
3975 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
3978 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3981 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
3982 sta
->addr
, nss
, err
);
3985 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
3986 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
3989 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3990 WMI_PEER_SMPS_STATE
, smps
);
3992 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
3993 sta
->addr
, smps
, err
);
3996 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
||
3997 changed
& IEEE80211_RC_NSS_CHANGED
) {
3998 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates/nss\n",
4001 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
4003 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
4007 mutex_unlock(&ar
->conf_mutex
);
4010 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
)
4012 struct ath10k
*ar
= arvif
->ar
;
4014 lockdep_assert_held(&ar
->conf_mutex
);
4016 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
4017 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
4020 if (ar
->num_stations
>= ar
->max_num_stations
)
4028 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
)
4030 struct ath10k
*ar
= arvif
->ar
;
4032 lockdep_assert_held(&ar
->conf_mutex
);
4034 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
4035 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
4041 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
4042 struct ieee80211_vif
*vif
,
4043 struct ieee80211_sta
*sta
,
4044 enum ieee80211_sta_state old_state
,
4045 enum ieee80211_sta_state new_state
)
4047 struct ath10k
*ar
= hw
->priv
;
4048 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4049 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4052 if (old_state
== IEEE80211_STA_NOTEXIST
&&
4053 new_state
== IEEE80211_STA_NONE
) {
4054 memset(arsta
, 0, sizeof(*arsta
));
4055 arsta
->arvif
= arvif
;
4056 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
4059 /* cancel must be done outside the mutex to avoid deadlock */
4060 if ((old_state
== IEEE80211_STA_NONE
&&
4061 new_state
== IEEE80211_STA_NOTEXIST
))
4062 cancel_work_sync(&arsta
->update_wk
);
4064 mutex_lock(&ar
->conf_mutex
);
4066 if (old_state
== IEEE80211_STA_NOTEXIST
&&
4067 new_state
== IEEE80211_STA_NONE
) {
4069 * New station addition.
4071 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4072 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4073 arvif
->vdev_id
, sta
->addr
,
4074 ar
->num_stations
+ 1, ar
->max_num_stations
,
4075 ar
->num_peers
+ 1, ar
->max_num_peers
);
4077 ret
= ath10k_mac_inc_num_stations(arvif
);
4079 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
4080 ar
->max_num_stations
);
4084 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
4086 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
4087 sta
->addr
, arvif
->vdev_id
, ret
);
4088 ath10k_mac_dec_num_stations(arvif
);
4092 if (vif
->type
== NL80211_IFTYPE_STATION
) {
4093 WARN_ON(arvif
->is_started
);
4095 ret
= ath10k_vdev_start(arvif
);
4097 ath10k_warn(ar
, "failed to start vdev %i: %d\n",
4098 arvif
->vdev_id
, ret
);
4099 WARN_ON(ath10k_peer_delete(ar
, arvif
->vdev_id
,
4101 ath10k_mac_dec_num_stations(arvif
);
4105 arvif
->is_started
= true;
4107 } else if ((old_state
== IEEE80211_STA_NONE
&&
4108 new_state
== IEEE80211_STA_NOTEXIST
)) {
4110 * Existing station deletion.
4112 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4113 "mac vdev %d peer delete %pM (sta gone)\n",
4114 arvif
->vdev_id
, sta
->addr
);
4116 if (vif
->type
== NL80211_IFTYPE_STATION
) {
4117 WARN_ON(!arvif
->is_started
);
4119 ret
= ath10k_vdev_stop(arvif
);
4121 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
4122 arvif
->vdev_id
, ret
);
4124 arvif
->is_started
= false;
4127 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
4129 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
4130 sta
->addr
, arvif
->vdev_id
, ret
);
4132 ath10k_mac_dec_num_stations(arvif
);
4133 } else if (old_state
== IEEE80211_STA_AUTH
&&
4134 new_state
== IEEE80211_STA_ASSOC
&&
4135 (vif
->type
== NL80211_IFTYPE_AP
||
4136 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
4140 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
4143 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
4145 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
4146 sta
->addr
, arvif
->vdev_id
, ret
);
4147 } else if (old_state
== IEEE80211_STA_ASSOC
&&
4148 new_state
== IEEE80211_STA_AUTH
&&
4149 (vif
->type
== NL80211_IFTYPE_AP
||
4150 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
4154 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
4157 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
4159 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
4160 sta
->addr
, arvif
->vdev_id
, ret
);
4163 mutex_unlock(&ar
->conf_mutex
);
4167 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
4168 u16 ac
, bool enable
)
4170 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4171 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
4172 u32 prio
= 0, acc
= 0;
4176 lockdep_assert_held(&ar
->conf_mutex
);
4178 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
4182 case IEEE80211_AC_VO
:
4183 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
4184 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
4188 case IEEE80211_AC_VI
:
4189 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
4190 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
4194 case IEEE80211_AC_BE
:
4195 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
4196 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
4200 case IEEE80211_AC_BK
:
4201 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
4202 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
4209 arvif
->u
.sta
.uapsd
|= value
;
4211 arvif
->u
.sta
.uapsd
&= ~value
;
4213 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4214 WMI_STA_PS_PARAM_UAPSD
,
4215 arvif
->u
.sta
.uapsd
);
4217 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
4221 if (arvif
->u
.sta
.uapsd
)
4222 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
4224 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4226 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4227 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
4230 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
4232 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4234 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4235 arvif
->vdev_id
, ret
);
4239 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4241 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4242 arvif
->vdev_id
, ret
);
4246 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
4247 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
4248 /* Only userspace can make an educated decision when to send
4249 * trigger frame. The following effectively disables u-UAPSD
4250 * autotrigger in firmware (which is enabled by default
4251 * provided the autotrigger service is available).
4255 arg
.user_priority
= prio
;
4256 arg
.service_interval
= 0;
4257 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
4258 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
4260 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
4261 arvif
->bssid
, &arg
, 1);
4263 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
4273 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
4274 struct ieee80211_vif
*vif
, u16 ac
,
4275 const struct ieee80211_tx_queue_params
*params
)
4277 struct ath10k
*ar
= hw
->priv
;
4278 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4279 struct wmi_wmm_params_arg
*p
= NULL
;
4282 mutex_lock(&ar
->conf_mutex
);
4285 case IEEE80211_AC_VO
:
4286 p
= &arvif
->wmm_params
.ac_vo
;
4288 case IEEE80211_AC_VI
:
4289 p
= &arvif
->wmm_params
.ac_vi
;
4291 case IEEE80211_AC_BE
:
4292 p
= &arvif
->wmm_params
.ac_be
;
4294 case IEEE80211_AC_BK
:
4295 p
= &arvif
->wmm_params
.ac_bk
;
4304 p
->cwmin
= params
->cw_min
;
4305 p
->cwmax
= params
->cw_max
;
4306 p
->aifs
= params
->aifs
;
4309 * The channel time duration programmed in the HW is in absolute
4310 * microseconds, while mac80211 gives the txop in units of
4313 p
->txop
= params
->txop
* 32;
4315 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
4316 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
4317 &arvif
->wmm_params
);
4319 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
4320 arvif
->vdev_id
, ret
);
4324 /* This won't work well with multi-interface cases but it's
4325 * better than nothing.
4327 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
4329 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
4334 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
4336 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
4339 mutex_unlock(&ar
->conf_mutex
);
4343 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4345 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
4346 struct ieee80211_vif
*vif
,
4347 struct ieee80211_channel
*chan
,
4349 enum ieee80211_roc_type type
)
4351 struct ath10k
*ar
= hw
->priv
;
4352 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4353 struct wmi_start_scan_arg arg
;
4356 mutex_lock(&ar
->conf_mutex
);
4358 spin_lock_bh(&ar
->data_lock
);
4359 switch (ar
->scan
.state
) {
4360 case ATH10K_SCAN_IDLE
:
4361 reinit_completion(&ar
->scan
.started
);
4362 reinit_completion(&ar
->scan
.completed
);
4363 reinit_completion(&ar
->scan
.on_channel
);
4364 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4365 ar
->scan
.is_roc
= true;
4366 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4367 ar
->scan
.roc_freq
= chan
->center_freq
;
4370 case ATH10K_SCAN_STARTING
:
4371 case ATH10K_SCAN_RUNNING
:
4372 case ATH10K_SCAN_ABORTING
:
4376 spin_unlock_bh(&ar
->data_lock
);
4381 duration
= max(duration
, WMI_SCAN_CHAN_MIN_TIME_MSEC
);
4383 memset(&arg
, 0, sizeof(arg
));
4384 ath10k_wmi_start_scan_init(ar
, &arg
);
4385 arg
.vdev_id
= arvif
->vdev_id
;
4386 arg
.scan_id
= ATH10K_SCAN_ID
;
4388 arg
.channels
[0] = chan
->center_freq
;
4389 arg
.dwell_time_active
= duration
;
4390 arg
.dwell_time_passive
= duration
;
4391 arg
.max_scan_time
= 2 * duration
;
4392 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4393 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
4395 ret
= ath10k_start_scan(ar
, &arg
);
4397 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
4398 spin_lock_bh(&ar
->data_lock
);
4399 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4400 spin_unlock_bh(&ar
->data_lock
);
4404 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
4406 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
4408 ret
= ath10k_scan_stop(ar
);
4410 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
4418 mutex_unlock(&ar
->conf_mutex
);
4422 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
4424 struct ath10k
*ar
= hw
->priv
;
4426 mutex_lock(&ar
->conf_mutex
);
4427 ath10k_scan_abort(ar
);
4428 mutex_unlock(&ar
->conf_mutex
);
4430 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4436 * Both RTS and Fragmentation threshold are interface-specific
4437 * in ath10k, but device-specific in mac80211.
4440 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
4442 struct ath10k
*ar
= hw
->priv
;
4443 struct ath10k_vif
*arvif
;
4446 mutex_lock(&ar
->conf_mutex
);
4447 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
4448 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
4449 arvif
->vdev_id
, value
);
4451 ret
= ath10k_mac_set_rts(arvif
, value
);
4453 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
4454 arvif
->vdev_id
, ret
);
4458 mutex_unlock(&ar
->conf_mutex
);
4463 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4464 u32 queues
, bool drop
)
4466 struct ath10k
*ar
= hw
->priv
;
4470 /* mac80211 doesn't care if we really xmit queued frames or not
4471 * we'll collect those frames either way if we stop/delete vdevs */
4475 mutex_lock(&ar
->conf_mutex
);
4477 if (ar
->state
== ATH10K_STATE_WEDGED
)
4480 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
4483 spin_lock_bh(&ar
->htt
.tx_lock
);
4484 empty
= (ar
->htt
.num_pending_tx
== 0);
4485 spin_unlock_bh(&ar
->htt
.tx_lock
);
4487 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
4488 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
4492 }), ATH10K_FLUSH_TIMEOUT_HZ
);
4494 if (ret
<= 0 || skip
)
4495 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4496 skip
, ar
->state
, ret
);
4499 mutex_unlock(&ar
->conf_mutex
);
4502 /* TODO: Implement this function properly
4503 * For now it is needed to reply to Probe Requests in IBSS mode.
4504 * Propably we need this information from FW.
4506 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
4512 static int ath10k_suspend(struct ieee80211_hw
*hw
,
4513 struct cfg80211_wowlan
*wowlan
)
4515 struct ath10k
*ar
= hw
->priv
;
4518 mutex_lock(&ar
->conf_mutex
);
4520 ret
= ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND
);
4522 if (ret
== -ETIMEDOUT
)
4528 ret
= ath10k_hif_suspend(ar
);
4530 ath10k_warn(ar
, "failed to suspend hif: %d\n", ret
);
4537 ret
= ath10k_wmi_pdev_resume_target(ar
);
4539 ath10k_warn(ar
, "failed to resume target: %d\n", ret
);
4543 mutex_unlock(&ar
->conf_mutex
);
4547 static int ath10k_resume(struct ieee80211_hw
*hw
)
4549 struct ath10k
*ar
= hw
->priv
;
4552 mutex_lock(&ar
->conf_mutex
);
4554 ret
= ath10k_hif_resume(ar
);
4556 ath10k_warn(ar
, "failed to resume hif: %d\n", ret
);
4561 ret
= ath10k_wmi_pdev_resume_target(ar
);
4563 ath10k_warn(ar
, "failed to resume target: %d\n", ret
);
4570 mutex_unlock(&ar
->conf_mutex
);
4575 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
4576 enum ieee80211_reconfig_type reconfig_type
)
4578 struct ath10k
*ar
= hw
->priv
;
4580 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
4583 mutex_lock(&ar
->conf_mutex
);
4585 /* If device failed to restart it will be in a different state, e.g.
4586 * ATH10K_STATE_WEDGED */
4587 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
4588 ath10k_info(ar
, "device successfully recovered\n");
4589 ar
->state
= ATH10K_STATE_ON
;
4590 ieee80211_wake_queues(ar
->hw
);
4593 mutex_unlock(&ar
->conf_mutex
);
4596 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
4597 struct survey_info
*survey
)
4599 struct ath10k
*ar
= hw
->priv
;
4600 struct ieee80211_supported_band
*sband
;
4601 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
4604 mutex_lock(&ar
->conf_mutex
);
4606 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
4607 if (sband
&& idx
>= sband
->n_channels
) {
4608 idx
-= sband
->n_channels
;
4613 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
4615 if (!sband
|| idx
>= sband
->n_channels
) {
4620 spin_lock_bh(&ar
->data_lock
);
4621 memcpy(survey
, ar_survey
, sizeof(*survey
));
4622 spin_unlock_bh(&ar
->data_lock
);
4624 survey
->channel
= &sband
->channels
[idx
];
4626 if (ar
->rx_channel
== survey
->channel
)
4627 survey
->filled
|= SURVEY_INFO_IN_USE
;
4630 mutex_unlock(&ar
->conf_mutex
);
4634 /* Helper table for legacy fixed_rate/bitrate_mask */
4635 static const u8 cck_ofdm_rate
[] = {
4652 /* Check if only one bit set */
4653 static int ath10k_check_single_mask(u32 mask
)
4661 mask
&= ~BIT(bit
- 1);
4669 ath10k_default_bitrate_mask(struct ath10k
*ar
,
4670 enum ieee80211_band band
,
4671 const struct cfg80211_bitrate_mask
*mask
)
4673 u32 legacy
= 0x00ff;
4676 u16 nrf
= ar
->num_rf_chains
;
4678 if (ar
->cfg_tx_chainmask
)
4679 nrf
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4682 case IEEE80211_BAND_2GHZ
:
4686 case IEEE80211_BAND_5GHZ
:
4692 if (mask
->control
[band
].legacy
!= legacy
)
4695 for (i
= 0; i
< nrf
; i
++)
4696 if (mask
->control
[band
].ht_mcs
[i
] != ht
)
4699 for (i
= 0; i
< nrf
; i
++)
4700 if (mask
->control
[band
].vht_mcs
[i
] != vht
)
4707 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask
*mask
,
4708 enum ieee80211_band band
,
4711 int ht_nss
= 0, vht_nss
= 0, i
;
4714 if (ath10k_check_single_mask(mask
->control
[band
].legacy
))
4718 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4719 if (mask
->control
[band
].ht_mcs
[i
] == 0xff)
4721 else if (mask
->control
[band
].ht_mcs
[i
] == 0x00)
4730 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4731 if (mask
->control
[band
].vht_mcs
[i
] == 0x03ff)
4733 else if (mask
->control
[band
].vht_mcs
[i
] == 0x0000)
4741 if (ht_nss
> 0 && vht_nss
> 0)
4745 *fixed_nss
= ht_nss
;
4747 *fixed_nss
= vht_nss
;
4755 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask
*mask
,
4756 enum ieee80211_band band
,
4757 enum wmi_rate_preamble
*preamble
)
4759 int legacy
= 0, ht
= 0, vht
= 0, i
;
4761 *preamble
= WMI_RATE_PREAMBLE_OFDM
;
4764 legacy
= ath10k_check_single_mask(mask
->control
[band
].legacy
);
4769 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4770 ht
+= ath10k_check_single_mask(mask
->control
[band
].ht_mcs
[i
]);
4775 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4776 vht
+= ath10k_check_single_mask(mask
->control
[band
].vht_mcs
[i
]);
4780 /* Currently we support only one fixed_rate */
4781 if ((legacy
+ ht
+ vht
) != 1)
4785 *preamble
= WMI_RATE_PREAMBLE_HT
;
4787 *preamble
= WMI_RATE_PREAMBLE_VHT
;
4793 ath10k_bitrate_mask_rate(struct ath10k
*ar
,
4794 const struct cfg80211_bitrate_mask
*mask
,
4795 enum ieee80211_band band
,
4799 u8 rate
= 0, pream
= 0, nss
= 0, i
;
4800 enum wmi_rate_preamble preamble
;
4802 /* Check if single rate correct */
4803 if (!ath10k_bitrate_mask_correct(mask
, band
, &preamble
))
4809 case WMI_RATE_PREAMBLE_CCK
:
4810 case WMI_RATE_PREAMBLE_OFDM
:
4811 i
= ffs(mask
->control
[band
].legacy
) - 1;
4813 if (band
== IEEE80211_BAND_2GHZ
&& i
< 4)
4814 pream
= WMI_RATE_PREAMBLE_CCK
;
4816 if (band
== IEEE80211_BAND_5GHZ
)
4819 if (i
>= ARRAY_SIZE(cck_ofdm_rate
))
4822 rate
= cck_ofdm_rate
[i
];
4824 case WMI_RATE_PREAMBLE_HT
:
4825 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4826 if (mask
->control
[band
].ht_mcs
[i
])
4829 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
4832 rate
= ffs(mask
->control
[band
].ht_mcs
[i
]) - 1;
4835 case WMI_RATE_PREAMBLE_VHT
:
4836 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4837 if (mask
->control
[band
].vht_mcs
[i
])
4840 if (i
== NL80211_VHT_NSS_MAX
)
4843 rate
= ffs(mask
->control
[band
].vht_mcs
[i
]) - 1;
4848 *fixed_nss
= nss
+ 1;
4852 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4855 *fixed_rate
= pream
| nss
| rate
;
4860 static bool ath10k_get_fixed_rate_nss(struct ath10k
*ar
,
4861 const struct cfg80211_bitrate_mask
*mask
,
4862 enum ieee80211_band band
,
4866 /* First check full NSS mask, if we can simply limit NSS */
4867 if (ath10k_bitrate_mask_nss(mask
, band
, fixed_nss
))
4870 /* Next Check single rate is set */
4871 return ath10k_bitrate_mask_rate(ar
, mask
, band
, fixed_rate
, fixed_nss
);
4874 static int ath10k_set_fixed_rate_param(struct ath10k_vif
*arvif
,
4879 struct ath10k
*ar
= arvif
->ar
;
4883 mutex_lock(&ar
->conf_mutex
);
4885 if (arvif
->fixed_rate
== fixed_rate
&&
4886 arvif
->fixed_nss
== fixed_nss
&&
4887 arvif
->force_sgi
== force_sgi
)
4890 if (fixed_rate
== WMI_FIXED_RATE_NONE
)
4891 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac disable fixed bitrate mask\n");
4894 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac force sgi\n");
4896 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
4897 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
4898 vdev_param
, fixed_rate
);
4900 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
4906 arvif
->fixed_rate
= fixed_rate
;
4908 vdev_param
= ar
->wmi
.vdev_param
->nss
;
4909 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
4910 vdev_param
, fixed_nss
);
4913 ath10k_warn(ar
, "failed to set fixed nss param %d: %d\n",
4919 arvif
->fixed_nss
= fixed_nss
;
4921 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
4922 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4926 ath10k_warn(ar
, "failed to set sgi param %d: %d\n",
4932 arvif
->force_sgi
= force_sgi
;
4935 mutex_unlock(&ar
->conf_mutex
);
4939 static int ath10k_set_bitrate_mask(struct ieee80211_hw
*hw
,
4940 struct ieee80211_vif
*vif
,
4941 const struct cfg80211_bitrate_mask
*mask
)
4943 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4944 struct ath10k
*ar
= arvif
->ar
;
4945 enum ieee80211_band band
= ar
->hw
->conf
.chandef
.chan
->band
;
4946 u8 fixed_rate
= WMI_FIXED_RATE_NONE
;
4947 u8 fixed_nss
= ar
->num_rf_chains
;
4950 if (ar
->cfg_tx_chainmask
)
4951 fixed_nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4953 force_sgi
= mask
->control
[band
].gi
;
4954 if (force_sgi
== NL80211_TXRATE_FORCE_LGI
)
4957 if (!ath10k_default_bitrate_mask(ar
, band
, mask
)) {
4958 if (!ath10k_get_fixed_rate_nss(ar
, mask
, band
,
4964 if (fixed_rate
== WMI_FIXED_RATE_NONE
&& force_sgi
) {
4965 ath10k_warn(ar
, "failed to force SGI usage for default rate settings\n");
4969 return ath10k_set_fixed_rate_param(arvif
, fixed_rate
,
4970 fixed_nss
, force_sgi
);
4973 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
4974 struct ieee80211_vif
*vif
,
4975 struct ieee80211_sta
*sta
,
4978 struct ath10k
*ar
= hw
->priv
;
4979 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4982 spin_lock_bh(&ar
->data_lock
);
4984 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4985 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4986 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
4989 if (changed
& IEEE80211_RC_BW_CHANGED
) {
4990 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4992 switch (sta
->bandwidth
) {
4993 case IEEE80211_STA_RX_BW_20
:
4994 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4996 case IEEE80211_STA_RX_BW_40
:
4997 bw
= WMI_PEER_CHWIDTH_40MHZ
;
4999 case IEEE80211_STA_RX_BW_80
:
5000 bw
= WMI_PEER_CHWIDTH_80MHZ
;
5002 case IEEE80211_STA_RX_BW_160
:
5003 ath10k_warn(ar
, "Invalid bandwith %d in rc update for %pM\n",
5004 sta
->bandwidth
, sta
->addr
);
5005 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5012 if (changed
& IEEE80211_RC_NSS_CHANGED
)
5013 arsta
->nss
= sta
->rx_nss
;
5015 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5016 smps
= WMI_PEER_SMPS_PS_NONE
;
5018 switch (sta
->smps_mode
) {
5019 case IEEE80211_SMPS_AUTOMATIC
:
5020 case IEEE80211_SMPS_OFF
:
5021 smps
= WMI_PEER_SMPS_PS_NONE
;
5023 case IEEE80211_SMPS_STATIC
:
5024 smps
= WMI_PEER_SMPS_STATIC
;
5026 case IEEE80211_SMPS_DYNAMIC
:
5027 smps
= WMI_PEER_SMPS_DYNAMIC
;
5029 case IEEE80211_SMPS_NUM_MODES
:
5030 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
5031 sta
->smps_mode
, sta
->addr
);
5032 smps
= WMI_PEER_SMPS_PS_NONE
;
5039 arsta
->changed
|= changed
;
5041 spin_unlock_bh(&ar
->data_lock
);
5043 ieee80211_queue_work(hw
, &arsta
->update_wk
);
5046 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
5049 * FIXME: Return 0 for time being. Need to figure out whether FW
5050 * has the API to fetch 64-bit local TSF
5056 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
5057 struct ieee80211_vif
*vif
,
5058 enum ieee80211_ampdu_mlme_action action
,
5059 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
5062 struct ath10k
*ar
= hw
->priv
;
5063 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5065 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
5066 arvif
->vdev_id
, sta
->addr
, tid
, action
);
5069 case IEEE80211_AMPDU_RX_START
:
5070 case IEEE80211_AMPDU_RX_STOP
:
5071 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5072 * creation/removal. Do we need to verify this?
5075 case IEEE80211_AMPDU_TX_START
:
5076 case IEEE80211_AMPDU_TX_STOP_CONT
:
5077 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
5078 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
5079 case IEEE80211_AMPDU_TX_OPERATIONAL
:
5080 /* Firmware offloads Tx aggregation entirely so deny mac80211
5081 * Tx aggregation requests.
5089 static const struct ieee80211_ops ath10k_ops
= {
5091 .start
= ath10k_start
,
5092 .stop
= ath10k_stop
,
5093 .config
= ath10k_config
,
5094 .add_interface
= ath10k_add_interface
,
5095 .remove_interface
= ath10k_remove_interface
,
5096 .configure_filter
= ath10k_configure_filter
,
5097 .bss_info_changed
= ath10k_bss_info_changed
,
5098 .hw_scan
= ath10k_hw_scan
,
5099 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
5100 .set_key
= ath10k_set_key
,
5101 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
5102 .sta_state
= ath10k_sta_state
,
5103 .conf_tx
= ath10k_conf_tx
,
5104 .remain_on_channel
= ath10k_remain_on_channel
,
5105 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
5106 .set_rts_threshold
= ath10k_set_rts_threshold
,
5107 .flush
= ath10k_flush
,
5108 .tx_last_beacon
= ath10k_tx_last_beacon
,
5109 .set_antenna
= ath10k_set_antenna
,
5110 .get_antenna
= ath10k_get_antenna
,
5111 .reconfig_complete
= ath10k_reconfig_complete
,
5112 .get_survey
= ath10k_get_survey
,
5113 .set_bitrate_mask
= ath10k_set_bitrate_mask
,
5114 .sta_rc_update
= ath10k_sta_rc_update
,
5115 .get_tsf
= ath10k_get_tsf
,
5116 .ampdu_action
= ath10k_ampdu_action
,
5117 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
5118 .get_et_stats
= ath10k_debug_get_et_stats
,
5119 .get_et_strings
= ath10k_debug_get_et_strings
,
5121 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
5124 .suspend
= ath10k_suspend
,
5125 .resume
= ath10k_resume
,
5127 #ifdef CONFIG_MAC80211_DEBUGFS
5128 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
5132 #define RATETAB_ENT(_rate, _rateid, _flags) { \
5133 .bitrate = (_rate), \
5134 .flags = (_flags), \
5135 .hw_value = (_rateid), \
5138 #define CHAN2G(_channel, _freq, _flags) { \
5139 .band = IEEE80211_BAND_2GHZ, \
5140 .hw_value = (_channel), \
5141 .center_freq = (_freq), \
5142 .flags = (_flags), \
5143 .max_antenna_gain = 0, \
5147 #define CHAN5G(_channel, _freq, _flags) { \
5148 .band = IEEE80211_BAND_5GHZ, \
5149 .hw_value = (_channel), \
5150 .center_freq = (_freq), \
5151 .flags = (_flags), \
5152 .max_antenna_gain = 0, \
5156 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
5166 CHAN2G(10, 2457, 0),
5167 CHAN2G(11, 2462, 0),
5168 CHAN2G(12, 2467, 0),
5169 CHAN2G(13, 2472, 0),
5170 CHAN2G(14, 2484, 0),
5173 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
5174 CHAN5G(36, 5180, 0),
5175 CHAN5G(40, 5200, 0),
5176 CHAN5G(44, 5220, 0),
5177 CHAN5G(48, 5240, 0),
5178 CHAN5G(52, 5260, 0),
5179 CHAN5G(56, 5280, 0),
5180 CHAN5G(60, 5300, 0),
5181 CHAN5G(64, 5320, 0),
5182 CHAN5G(100, 5500, 0),
5183 CHAN5G(104, 5520, 0),
5184 CHAN5G(108, 5540, 0),
5185 CHAN5G(112, 5560, 0),
5186 CHAN5G(116, 5580, 0),
5187 CHAN5G(120, 5600, 0),
5188 CHAN5G(124, 5620, 0),
5189 CHAN5G(128, 5640, 0),
5190 CHAN5G(132, 5660, 0),
5191 CHAN5G(136, 5680, 0),
5192 CHAN5G(140, 5700, 0),
5193 CHAN5G(149, 5745, 0),
5194 CHAN5G(153, 5765, 0),
5195 CHAN5G(157, 5785, 0),
5196 CHAN5G(161, 5805, 0),
5197 CHAN5G(165, 5825, 0),
5200 /* Note: Be careful if you re-order these. There is code which depends on this
5203 static struct ieee80211_rate ath10k_rates
[] = {
5205 RATETAB_ENT(10, 0x82, 0),
5206 RATETAB_ENT(20, 0x84, 0),
5207 RATETAB_ENT(55, 0x8b, 0),
5208 RATETAB_ENT(110, 0x96, 0),
5210 RATETAB_ENT(60, 0x0c, 0),
5211 RATETAB_ENT(90, 0x12, 0),
5212 RATETAB_ENT(120, 0x18, 0),
5213 RATETAB_ENT(180, 0x24, 0),
5214 RATETAB_ENT(240, 0x30, 0),
5215 RATETAB_ENT(360, 0x48, 0),
5216 RATETAB_ENT(480, 0x60, 0),
5217 RATETAB_ENT(540, 0x6c, 0),
5220 #define ath10k_a_rates (ath10k_rates + 4)
5221 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5222 #define ath10k_g_rates (ath10k_rates + 0)
5223 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5225 struct ath10k
*ath10k_mac_create(size_t priv_size
)
5227 struct ieee80211_hw
*hw
;
5230 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
5240 void ath10k_mac_destroy(struct ath10k
*ar
)
5242 ieee80211_free_hw(ar
->hw
);
5245 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
5248 .types
= BIT(NL80211_IFTYPE_STATION
)
5249 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
5253 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
5257 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5261 .types
= BIT(NL80211_IFTYPE_AP
)
5265 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
5268 .types
= BIT(NL80211_IFTYPE_AP
)
5272 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
5274 .limits
= ath10k_if_limits
,
5275 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
5276 .max_interfaces
= 8,
5277 .num_different_channels
= 1,
5278 .beacon_int_infra_match
= true,
5282 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
5284 .limits
= ath10k_10x_if_limits
,
5285 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
5286 .max_interfaces
= 8,
5287 .num_different_channels
= 1,
5288 .beacon_int_infra_match
= true,
5289 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
5290 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
5291 BIT(NL80211_CHAN_WIDTH_20
) |
5292 BIT(NL80211_CHAN_WIDTH_40
) |
5293 BIT(NL80211_CHAN_WIDTH_80
),
5298 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
5300 struct ieee80211_sta_vht_cap vht_cap
= {0};
5304 vht_cap
.vht_supported
= 1;
5305 vht_cap
.cap
= ar
->vht_cap_info
;
5308 for (i
= 0; i
< 8; i
++) {
5309 if (i
< ar
->num_rf_chains
)
5310 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
5312 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
5315 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
5316 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
5321 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
5324 struct ieee80211_sta_ht_cap ht_cap
= {0};
5326 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
5329 ht_cap
.ht_supported
= 1;
5330 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
5331 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
5332 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5333 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
5334 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
5336 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
5337 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
5339 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
5340 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
5342 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
5345 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
5346 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
5351 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
5352 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
5354 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
5357 stbc
= ar
->ht_cap_info
;
5358 stbc
&= WMI_HT_CAP_RX_STBC
;
5359 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
5360 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
5361 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
5366 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
5367 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
5369 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
5370 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
5372 /* max AMSDU is implicitly taken from vht_cap_info */
5373 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
5374 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
5376 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
5377 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
5379 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
5384 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
5385 struct ieee80211_vif
*vif
)
5387 struct ath10k_vif_iter
*arvif_iter
= data
;
5388 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5390 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
5391 arvif_iter
->arvif
= arvif
;
5394 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
5396 struct ath10k_vif_iter arvif_iter
;
5399 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
5400 arvif_iter
.vdev_id
= vdev_id
;
5402 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
5403 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
5405 ath10k_get_arvif_iter
,
5407 if (!arvif_iter
.arvif
) {
5408 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
5412 return arvif_iter
.arvif
;
5415 int ath10k_mac_register(struct ath10k
*ar
)
5417 struct ieee80211_supported_band
*band
;
5418 struct ieee80211_sta_vht_cap vht_cap
;
5419 struct ieee80211_sta_ht_cap ht_cap
;
5423 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
5425 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
5427 ht_cap
= ath10k_get_ht_cap(ar
);
5428 vht_cap
= ath10k_create_vht_cap(ar
);
5430 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
5431 channels
= kmemdup(ath10k_2ghz_channels
,
5432 sizeof(ath10k_2ghz_channels
),
5439 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
5440 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
5441 band
->channels
= channels
;
5442 band
->n_bitrates
= ath10k_g_rates_size
;
5443 band
->bitrates
= ath10k_g_rates
;
5444 band
->ht_cap
= ht_cap
;
5446 /* Enable the VHT support at 2.4 GHz */
5447 band
->vht_cap
= vht_cap
;
5449 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
5452 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
5453 channels
= kmemdup(ath10k_5ghz_channels
,
5454 sizeof(ath10k_5ghz_channels
),
5461 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
5462 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
5463 band
->channels
= channels
;
5464 band
->n_bitrates
= ath10k_a_rates_size
;
5465 band
->bitrates
= ath10k_a_rates
;
5466 band
->ht_cap
= ht_cap
;
5467 band
->vht_cap
= vht_cap
;
5468 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
5471 ar
->hw
->wiphy
->interface_modes
=
5472 BIT(NL80211_IFTYPE_STATION
) |
5473 BIT(NL80211_IFTYPE_AP
);
5475 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
5476 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
5478 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
5479 ar
->hw
->wiphy
->interface_modes
|=
5480 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
5481 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5482 BIT(NL80211_IFTYPE_P2P_GO
);
5484 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
5485 IEEE80211_HW_SUPPORTS_PS
|
5486 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
5487 IEEE80211_HW_MFP_CAPABLE
|
5488 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
5489 IEEE80211_HW_HAS_RATE_CONTROL
|
5490 IEEE80211_HW_AP_LINK_PS
|
5491 IEEE80211_HW_SPECTRUM_MGMT
;
5493 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
5495 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
5496 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
5498 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
5499 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
5500 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
5503 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
5504 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
5506 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
5507 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
5509 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
5511 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
5512 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5514 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5515 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5516 * correct Probe Responses. This is more of a hack advert..
5518 ar
->hw
->wiphy
->probe_resp_offload
|=
5519 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5520 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5521 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5524 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
5525 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
5526 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
5528 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
5529 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
5532 * on LL hardware queues are managed entirely by the FW
5533 * so we only advertise to mac we can do the queues thing
5537 switch (ar
->wmi
.op_version
) {
5538 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
5539 case ATH10K_FW_WMI_OP_VERSION_TLV
:
5540 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
5541 ar
->hw
->wiphy
->n_iface_combinations
=
5542 ARRAY_SIZE(ath10k_if_comb
);
5543 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
5545 case ATH10K_FW_WMI_OP_VERSION_10_1
:
5546 case ATH10K_FW_WMI_OP_VERSION_10_2
:
5547 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
5548 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
5549 ar
->hw
->wiphy
->n_iface_combinations
=
5550 ARRAY_SIZE(ath10k_10x_if_comb
);
5552 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
5553 case ATH10K_FW_WMI_OP_VERSION_MAX
:
5559 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
5561 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
5562 /* Init ath dfs pattern detector */
5563 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
5564 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
5567 if (!ar
->dfs_detector
)
5568 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
5571 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
5572 ath10k_reg_notifier
);
5574 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
5578 ret
= ieee80211_register_hw(ar
->hw
);
5580 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
5584 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
5585 ret
= regulatory_hint(ar
->hw
->wiphy
,
5586 ar
->ath_common
.regulatory
.alpha2
);
5588 goto err_unregister
;
5594 ieee80211_unregister_hw(ar
->hw
);
5596 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
5597 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
5602 void ath10k_mac_unregister(struct ath10k
*ar
)
5604 ieee80211_unregister_hw(ar
->hw
);
5606 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
5607 ar
->dfs_detector
->exit(ar
->dfs_detector
);
5609 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
5610 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
5612 SET_IEEE80211_DEV(ar
->hw
, NULL
);