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>
39 static struct ieee80211_rate ath10k_rates
[] = {
41 .hw_value
= ATH10K_HW_RATE_CCK_LP_1M
},
43 .hw_value
= ATH10K_HW_RATE_CCK_LP_2M
,
44 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_2M
,
45 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
47 .hw_value
= ATH10K_HW_RATE_CCK_LP_5_5M
,
48 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_5_5M
,
49 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
51 .hw_value
= ATH10K_HW_RATE_CCK_LP_11M
,
52 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_11M
,
53 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
55 { .bitrate
= 60, .hw_value
= ATH10K_HW_RATE_OFDM_6M
},
56 { .bitrate
= 90, .hw_value
= ATH10K_HW_RATE_OFDM_9M
},
57 { .bitrate
= 120, .hw_value
= ATH10K_HW_RATE_OFDM_12M
},
58 { .bitrate
= 180, .hw_value
= ATH10K_HW_RATE_OFDM_18M
},
59 { .bitrate
= 240, .hw_value
= ATH10K_HW_RATE_OFDM_24M
},
60 { .bitrate
= 360, .hw_value
= ATH10K_HW_RATE_OFDM_36M
},
61 { .bitrate
= 480, .hw_value
= ATH10K_HW_RATE_OFDM_48M
},
62 { .bitrate
= 540, .hw_value
= ATH10K_HW_RATE_OFDM_54M
},
65 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
67 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
70 #define ath10k_g_rates (ath10k_rates + 0)
71 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
73 static bool ath10k_mac_bitrate_is_cck(int bitrate
)
86 static u8
ath10k_mac_bitrate_to_rate(int bitrate
)
88 return DIV_ROUND_UP(bitrate
, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate
) ? BIT(7) : 0);
92 u8
ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band
*sband
,
95 const struct ieee80211_rate
*rate
;
98 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
99 rate
= &sband
->bitrates
[i
];
101 if (rate
->hw_value
== hw_rate
)
103 else if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
&&
104 rate
->hw_value_short
== hw_rate
)
111 u8
ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band
*sband
,
116 for (i
= 0; i
< sband
->n_bitrates
; i
++)
117 if (sband
->bitrates
[i
].bitrate
== bitrate
)
123 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map
, int nss
)
125 switch ((mcs_map
>> (2 * nss
)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7
: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8
: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9
: return BIT(10) - 1;
137 static int ath10k_send_key(struct ath10k_vif
*arvif
,
138 struct ieee80211_key_conf
*key
,
139 enum set_key_cmd cmd
,
140 const u8
*macaddr
, u32 flags
)
142 struct ath10k
*ar
= arvif
->ar
;
143 struct wmi_vdev_install_key_arg arg
= {
144 .vdev_id
= arvif
->vdev_id
,
145 .key_idx
= key
->keyidx
,
146 .key_len
= key
->keylen
,
147 .key_data
= key
->key
,
152 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
154 switch (key
->cipher
) {
155 case WLAN_CIPHER_SUITE_CCMP
:
156 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
157 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
159 case WLAN_CIPHER_SUITE_TKIP
:
160 arg
.key_cipher
= WMI_CIPHER_TKIP
;
161 arg
.key_txmic_len
= 8;
162 arg
.key_rxmic_len
= 8;
164 case WLAN_CIPHER_SUITE_WEP40
:
165 case WLAN_CIPHER_SUITE_WEP104
:
166 arg
.key_cipher
= WMI_CIPHER_WEP
;
168 case WLAN_CIPHER_SUITE_AES_CMAC
:
172 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
176 if (cmd
== DISABLE_KEY
) {
177 arg
.key_cipher
= WMI_CIPHER_NONE
;
181 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
184 static int ath10k_install_key(struct ath10k_vif
*arvif
,
185 struct ieee80211_key_conf
*key
,
186 enum set_key_cmd cmd
,
187 const u8
*macaddr
, u32 flags
)
189 struct ath10k
*ar
= arvif
->ar
;
191 unsigned long time_left
;
193 lockdep_assert_held(&ar
->conf_mutex
);
195 reinit_completion(&ar
->install_key_done
);
197 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
201 time_left
= wait_for_completion_timeout(&ar
->install_key_done
, 3 * HZ
);
208 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
211 struct ath10k
*ar
= arvif
->ar
;
212 struct ath10k_peer
*peer
;
217 lockdep_assert_held(&ar
->conf_mutex
);
219 spin_lock_bh(&ar
->data_lock
);
220 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
221 spin_unlock_bh(&ar
->data_lock
);
226 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
227 if (arvif
->wep_keys
[i
] == NULL
)
231 flags
|= WMI_KEY_PAIRWISE
;
233 /* set TX_USAGE flag for default key id */
234 if (arvif
->def_wep_key_idx
== i
)
235 flags
|= WMI_KEY_TX_USAGE
;
237 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
242 spin_lock_bh(&ar
->data_lock
);
243 peer
->keys
[i
] = arvif
->wep_keys
[i
];
244 spin_unlock_bh(&ar
->data_lock
);
250 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
253 struct ath10k
*ar
= arvif
->ar
;
254 struct ath10k_peer
*peer
;
260 lockdep_assert_held(&ar
->conf_mutex
);
262 spin_lock_bh(&ar
->data_lock
);
263 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
264 spin_unlock_bh(&ar
->data_lock
);
269 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
270 if (peer
->keys
[i
] == NULL
)
273 /* key flags are not required to delete the key */
274 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
275 DISABLE_KEY
, addr
, flags
);
276 if (ret
&& first_errno
== 0)
280 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
283 spin_lock_bh(&ar
->data_lock
);
284 peer
->keys
[i
] = NULL
;
285 spin_unlock_bh(&ar
->data_lock
);
291 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
294 struct ath10k_peer
*peer
;
297 lockdep_assert_held(&ar
->data_lock
);
299 /* We don't know which vdev this peer belongs to,
300 * since WMI doesn't give us that information.
302 * FIXME: multi-bss needs to be handled.
304 peer
= ath10k_peer_find(ar
, 0, addr
);
308 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
309 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
316 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
317 struct ieee80211_key_conf
*key
)
319 struct ath10k
*ar
= arvif
->ar
;
320 struct ath10k_peer
*peer
;
327 lockdep_assert_held(&ar
->conf_mutex
);
330 /* since ath10k_install_key we can't hold data_lock all the
331 * time, so we try to remove the keys incrementally */
332 spin_lock_bh(&ar
->data_lock
);
334 list_for_each_entry(peer
, &ar
->peers
, list
) {
335 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
336 if (peer
->keys
[i
] == key
) {
337 ether_addr_copy(addr
, peer
->addr
);
338 peer
->keys
[i
] = NULL
;
343 if (i
< ARRAY_SIZE(peer
->keys
))
346 spin_unlock_bh(&ar
->data_lock
);
348 if (i
== ARRAY_SIZE(peer
->keys
))
350 /* key flags are not required to delete the key */
351 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
352 if (ret
&& first_errno
== 0)
356 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
363 static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif
*arvif
)
365 struct ath10k
*ar
= arvif
->ar
;
366 enum nl80211_iftype iftype
= arvif
->vif
->type
;
367 struct ieee80211_key_conf
*key
;
373 lockdep_assert_held(&ar
->conf_mutex
);
375 if (iftype
!= NL80211_IFTYPE_STATION
)
378 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
379 if (arvif
->wep_keys
[i
]) {
380 key
= arvif
->wep_keys
[i
];
388 flags
|= WMI_KEY_PAIRWISE
;
389 flags
|= WMI_KEY_TX_USAGE
;
391 ret
= ath10k_install_key(arvif
, key
, SET_KEY
, arvif
->bssid
, flags
);
393 ath10k_warn(ar
, "failed to install key %i on vdev %i: %d\n",
394 key
->keyidx
, arvif
->vdev_id
, ret
);
401 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
402 struct ieee80211_key_conf
*key
)
404 struct ath10k
*ar
= arvif
->ar
;
405 struct ath10k_peer
*peer
;
408 lockdep_assert_held(&ar
->conf_mutex
);
410 list_for_each_entry(peer
, &ar
->peers
, list
) {
411 if (!memcmp(peer
->addr
, arvif
->vif
->addr
, ETH_ALEN
))
414 if (!memcmp(peer
->addr
, arvif
->bssid
, ETH_ALEN
))
417 if (peer
->keys
[key
->keyidx
] == key
)
420 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
421 arvif
->vdev_id
, key
->keyidx
);
423 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
425 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
426 arvif
->vdev_id
, peer
->addr
, ret
);
434 /*********************/
435 /* General utilities */
436 /*********************/
438 static inline enum wmi_phy_mode
439 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
441 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
443 switch (chandef
->chan
->band
) {
444 case IEEE80211_BAND_2GHZ
:
445 switch (chandef
->width
) {
446 case NL80211_CHAN_WIDTH_20_NOHT
:
447 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
452 case NL80211_CHAN_WIDTH_20
:
453 phymode
= MODE_11NG_HT20
;
455 case NL80211_CHAN_WIDTH_40
:
456 phymode
= MODE_11NG_HT40
;
458 case NL80211_CHAN_WIDTH_5
:
459 case NL80211_CHAN_WIDTH_10
:
460 case NL80211_CHAN_WIDTH_80
:
461 case NL80211_CHAN_WIDTH_80P80
:
462 case NL80211_CHAN_WIDTH_160
:
463 phymode
= MODE_UNKNOWN
;
467 case IEEE80211_BAND_5GHZ
:
468 switch (chandef
->width
) {
469 case NL80211_CHAN_WIDTH_20_NOHT
:
472 case NL80211_CHAN_WIDTH_20
:
473 phymode
= MODE_11NA_HT20
;
475 case NL80211_CHAN_WIDTH_40
:
476 phymode
= MODE_11NA_HT40
;
478 case NL80211_CHAN_WIDTH_80
:
479 phymode
= MODE_11AC_VHT80
;
481 case NL80211_CHAN_WIDTH_5
:
482 case NL80211_CHAN_WIDTH_10
:
483 case NL80211_CHAN_WIDTH_80P80
:
484 case NL80211_CHAN_WIDTH_160
:
485 phymode
= MODE_UNKNOWN
;
493 WARN_ON(phymode
== MODE_UNKNOWN
);
497 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
500 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
501 * 0 for no restriction
510 switch (mpdudensity
) {
516 /* Our lower layer calculations limit our precision to
532 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
533 struct cfg80211_chan_def
*def
)
535 struct ieee80211_chanctx_conf
*conf
;
538 conf
= rcu_dereference(vif
->chanctx_conf
);
550 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
551 struct ieee80211_chanctx_conf
*conf
,
559 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
563 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
564 ath10k_mac_num_chanctxs_iter
,
571 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
572 struct ieee80211_chanctx_conf
*conf
,
575 struct cfg80211_chan_def
**def
= data
;
580 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
,
581 enum wmi_peer_type peer_type
)
585 lockdep_assert_held(&ar
->conf_mutex
);
587 if (ar
->num_peers
>= ar
->max_num_peers
)
590 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
592 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
597 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
599 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
609 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
611 struct ath10k
*ar
= arvif
->ar
;
615 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
616 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
617 ATH10K_KICKOUT_THRESHOLD
);
619 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
620 arvif
->vdev_id
, ret
);
624 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
625 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
626 ATH10K_KEEPALIVE_MIN_IDLE
);
628 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
629 arvif
->vdev_id
, ret
);
633 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
634 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
635 ATH10K_KEEPALIVE_MAX_IDLE
);
637 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
638 arvif
->vdev_id
, ret
);
642 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
643 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
644 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
646 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
647 arvif
->vdev_id
, ret
);
654 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
656 struct ath10k
*ar
= arvif
->ar
;
659 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
660 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
663 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
665 struct ath10k
*ar
= arvif
->ar
;
668 if (value
!= 0xFFFFFFFF)
669 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
670 ATH10K_FRAGMT_THRESHOLD_MIN
,
671 ATH10K_FRAGMT_THRESHOLD_MAX
);
673 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
674 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
677 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
681 lockdep_assert_held(&ar
->conf_mutex
);
683 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
687 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
696 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
698 struct ath10k_peer
*peer
, *tmp
;
700 lockdep_assert_held(&ar
->conf_mutex
);
702 spin_lock_bh(&ar
->data_lock
);
703 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
704 if (peer
->vdev_id
!= vdev_id
)
707 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
708 peer
->addr
, vdev_id
);
710 list_del(&peer
->list
);
714 spin_unlock_bh(&ar
->data_lock
);
717 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
719 struct ath10k_peer
*peer
, *tmp
;
721 lockdep_assert_held(&ar
->conf_mutex
);
723 spin_lock_bh(&ar
->data_lock
);
724 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
725 list_del(&peer
->list
);
728 spin_unlock_bh(&ar
->data_lock
);
731 ar
->num_stations
= 0;
734 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
735 struct ieee80211_sta
*sta
,
736 enum wmi_tdls_peer_state state
)
739 struct wmi_tdls_peer_update_cmd_arg arg
= {};
740 struct wmi_tdls_peer_capab_arg cap
= {};
741 struct wmi_channel_arg chan_arg
= {};
743 lockdep_assert_held(&ar
->conf_mutex
);
745 arg
.vdev_id
= vdev_id
;
746 arg
.peer_state
= state
;
747 ether_addr_copy(arg
.addr
, sta
->addr
);
749 cap
.peer_max_sp
= sta
->max_sp
;
750 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
752 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
753 !sta
->tdls_initiator
)
754 cap
.is_peer_responder
= 1;
756 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
758 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
759 arg
.addr
, vdev_id
, ret
);
766 /************************/
767 /* Interface management */
768 /************************/
770 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
772 struct ath10k
*ar
= arvif
->ar
;
774 lockdep_assert_held(&ar
->data_lock
);
779 if (!arvif
->beacon_buf
)
780 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
781 arvif
->beacon
->len
, DMA_TO_DEVICE
);
783 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
784 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
787 dev_kfree_skb_any(arvif
->beacon
);
789 arvif
->beacon
= NULL
;
790 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
793 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
795 struct ath10k
*ar
= arvif
->ar
;
797 lockdep_assert_held(&ar
->data_lock
);
799 ath10k_mac_vif_beacon_free(arvif
);
801 if (arvif
->beacon_buf
) {
802 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
803 arvif
->beacon_buf
, arvif
->beacon_paddr
);
804 arvif
->beacon_buf
= NULL
;
808 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
810 unsigned long time_left
;
812 lockdep_assert_held(&ar
->conf_mutex
);
814 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
817 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
818 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
825 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
827 struct cfg80211_chan_def
*chandef
= NULL
;
828 struct ieee80211_channel
*channel
= chandef
->chan
;
829 struct wmi_vdev_start_request_arg arg
= {};
832 lockdep_assert_held(&ar
->conf_mutex
);
834 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
835 ath10k_mac_get_any_chandef_iter
,
837 if (WARN_ON_ONCE(!chandef
))
840 channel
= chandef
->chan
;
842 arg
.vdev_id
= vdev_id
;
843 arg
.channel
.freq
= channel
->center_freq
;
844 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
846 /* TODO setup this dynamically, what in case we
847 don't have any vifs? */
848 arg
.channel
.mode
= chan_to_phymode(chandef
);
849 arg
.channel
.chan_radar
=
850 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
852 arg
.channel
.min_power
= 0;
853 arg
.channel
.max_power
= channel
->max_power
* 2;
854 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
855 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
857 reinit_completion(&ar
->vdev_setup_done
);
859 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
861 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
866 ret
= ath10k_vdev_setup_sync(ar
);
868 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
873 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
875 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
880 ar
->monitor_vdev_id
= vdev_id
;
882 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
883 ar
->monitor_vdev_id
);
887 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
889 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
890 ar
->monitor_vdev_id
, ret
);
895 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
899 lockdep_assert_held(&ar
->conf_mutex
);
901 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
903 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
904 ar
->monitor_vdev_id
, ret
);
906 reinit_completion(&ar
->vdev_setup_done
);
908 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
910 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
911 ar
->monitor_vdev_id
, ret
);
913 ret
= ath10k_vdev_setup_sync(ar
);
915 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
916 ar
->monitor_vdev_id
, ret
);
918 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
919 ar
->monitor_vdev_id
);
923 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
927 lockdep_assert_held(&ar
->conf_mutex
);
929 if (ar
->free_vdev_map
== 0) {
930 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
934 bit
= __ffs64(ar
->free_vdev_map
);
936 ar
->monitor_vdev_id
= bit
;
938 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
939 WMI_VDEV_TYPE_MONITOR
,
942 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
943 ar
->monitor_vdev_id
, ret
);
947 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
948 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
949 ar
->monitor_vdev_id
);
954 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
958 lockdep_assert_held(&ar
->conf_mutex
);
960 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
962 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
963 ar
->monitor_vdev_id
, ret
);
967 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
969 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
970 ar
->monitor_vdev_id
);
974 static int ath10k_monitor_start(struct ath10k
*ar
)
978 lockdep_assert_held(&ar
->conf_mutex
);
980 ret
= ath10k_monitor_vdev_create(ar
);
982 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
986 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
988 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
989 ath10k_monitor_vdev_delete(ar
);
993 ar
->monitor_started
= true;
994 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
999 static int ath10k_monitor_stop(struct ath10k
*ar
)
1003 lockdep_assert_held(&ar
->conf_mutex
);
1005 ret
= ath10k_monitor_vdev_stop(ar
);
1007 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1011 ret
= ath10k_monitor_vdev_delete(ar
);
1013 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1017 ar
->monitor_started
= false;
1018 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1023 static bool ath10k_mac_should_disable_promisc(struct ath10k
*ar
)
1025 struct ath10k_vif
*arvif
;
1027 if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
))
1030 if (!ar
->num_started_vdevs
)
1033 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1034 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1037 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1038 "mac disabling promiscuous mode because vdev is started\n");
1042 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1046 /* At least one chanctx is required to derive a channel to start
1049 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1053 /* If there's already an existing special monitor interface then don't
1054 * bother creating another monitor vdev.
1056 if (ar
->monitor_arvif
)
1059 return ar
->monitor
||
1060 !ath10k_mac_should_disable_promisc(ar
) ||
1061 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1064 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1068 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1070 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1071 * shouldn't allow this but make sure to prevent handling the following
1072 * case anyway since multi-channel DFS hasn't been tested at all.
1074 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1080 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1086 lockdep_assert_held(&ar
->conf_mutex
);
1088 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1089 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1091 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1092 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1093 ar
->monitor_started
, needed
, allowed
);
1095 if (WARN_ON(needed
&& !allowed
)) {
1096 if (ar
->monitor_started
) {
1097 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1099 ret
= ath10k_monitor_stop(ar
);
1101 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n", ret
);
1108 if (needed
== ar
->monitor_started
)
1112 return ath10k_monitor_start(ar
);
1114 return ath10k_monitor_stop(ar
);
1117 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1119 struct ath10k
*ar
= arvif
->ar
;
1120 u32 vdev_param
, rts_cts
= 0;
1122 lockdep_assert_held(&ar
->conf_mutex
);
1124 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1126 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1128 if (arvif
->num_legacy_stations
> 0)
1129 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1130 WMI_RTSCTS_PROFILE
);
1132 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1133 WMI_RTSCTS_PROFILE
);
1135 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1139 static int ath10k_start_cac(struct ath10k
*ar
)
1143 lockdep_assert_held(&ar
->conf_mutex
);
1145 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1147 ret
= ath10k_monitor_recalc(ar
);
1149 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1150 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1154 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1155 ar
->monitor_vdev_id
);
1160 static int ath10k_stop_cac(struct ath10k
*ar
)
1162 lockdep_assert_held(&ar
->conf_mutex
);
1164 /* CAC is not running - do nothing */
1165 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1168 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1169 ath10k_monitor_stop(ar
);
1171 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1176 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1177 struct ieee80211_chanctx_conf
*conf
,
1182 if (!*ret
&& conf
->radar_enabled
)
1186 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1188 bool has_radar
= false;
1190 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1191 ath10k_mac_has_radar_iter
,
1197 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1201 lockdep_assert_held(&ar
->conf_mutex
);
1203 ath10k_stop_cac(ar
);
1205 if (!ath10k_mac_has_radar_enabled(ar
))
1208 if (ar
->num_started_vdevs
> 0)
1211 ret
= ath10k_start_cac(ar
);
1214 * Not possible to start CAC on current channel so starting
1215 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1216 * by indicating that radar was detected.
1218 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1219 ieee80211_radar_detected(ar
->hw
);
1223 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1225 struct ath10k
*ar
= arvif
->ar
;
1228 lockdep_assert_held(&ar
->conf_mutex
);
1230 reinit_completion(&ar
->vdev_setup_done
);
1232 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1234 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1235 arvif
->vdev_id
, ret
);
1239 ret
= ath10k_vdev_setup_sync(ar
);
1241 ath10k_warn(ar
, "failed to syncronise setup for vdev %i: %d\n",
1242 arvif
->vdev_id
, ret
);
1246 WARN_ON(ar
->num_started_vdevs
== 0);
1248 if (ar
->num_started_vdevs
!= 0) {
1249 ar
->num_started_vdevs
--;
1250 ath10k_recalc_radar_detection(ar
);
1256 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1257 const struct cfg80211_chan_def
*chandef
,
1260 struct ath10k
*ar
= arvif
->ar
;
1261 struct wmi_vdev_start_request_arg arg
= {};
1264 lockdep_assert_held(&ar
->conf_mutex
);
1266 reinit_completion(&ar
->vdev_setup_done
);
1268 arg
.vdev_id
= arvif
->vdev_id
;
1269 arg
.dtim_period
= arvif
->dtim_period
;
1270 arg
.bcn_intval
= arvif
->beacon_interval
;
1272 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1273 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1274 arg
.channel
.mode
= chan_to_phymode(chandef
);
1276 arg
.channel
.min_power
= 0;
1277 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1278 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1279 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1281 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1282 arg
.ssid
= arvif
->u
.ap
.ssid
;
1283 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1284 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1286 /* For now allow DFS for AP mode */
1287 arg
.channel
.chan_radar
=
1288 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1289 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1290 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1291 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1294 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1295 "mac vdev %d start center_freq %d phymode %s\n",
1296 arg
.vdev_id
, arg
.channel
.freq
,
1297 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1300 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1302 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1305 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1310 ret
= ath10k_vdev_setup_sync(ar
);
1313 "failed to synchronize setup for vdev %i restart %d: %d\n",
1314 arg
.vdev_id
, restart
, ret
);
1318 ar
->num_started_vdevs
++;
1319 ath10k_recalc_radar_detection(ar
);
1321 ret
= ath10k_monitor_recalc(ar
);
1323 ath10k_warn(ar
, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1324 arg
.vdev_id
, restart
, ret
);
1325 ret2
= ath10k_vdev_stop(arvif
);
1327 ath10k_warn(ar
, "mac failed to stop vdev %i restart %d: %d\n",
1328 arg
.vdev_id
, restart
, ret2
);
1334 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1335 const struct cfg80211_chan_def
*def
)
1337 return ath10k_vdev_start_restart(arvif
, def
, false);
1340 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1341 const struct cfg80211_chan_def
*def
)
1343 return ath10k_vdev_start_restart(arvif
, def
, true);
1346 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1347 struct sk_buff
*bcn
)
1349 struct ath10k
*ar
= arvif
->ar
;
1350 struct ieee80211_mgmt
*mgmt
;
1354 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1357 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1360 mgmt
= (void *)bcn
->data
;
1361 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1362 mgmt
->u
.beacon
.variable
,
1363 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1368 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1370 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1371 arvif
->vdev_id
, ret
);
1378 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1379 u8 oui_type
, size_t ie_offset
)
1386 if (WARN_ON(skb
->len
< ie_offset
))
1389 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1390 skb
->data
+ ie_offset
,
1391 skb
->len
- ie_offset
);
1396 end
= skb
->data
+ skb
->len
;
1399 if (WARN_ON(next
> end
))
1402 memmove(ie
, next
, end
- next
);
1403 skb_trim(skb
, skb
->len
- len
);
1408 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1410 struct ath10k
*ar
= arvif
->ar
;
1411 struct ieee80211_hw
*hw
= ar
->hw
;
1412 struct ieee80211_vif
*vif
= arvif
->vif
;
1413 struct ieee80211_mutable_offsets offs
= {};
1414 struct sk_buff
*bcn
;
1417 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1420 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1421 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1424 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1426 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1430 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1432 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1437 /* P2P IE is inserted by firmware automatically (as configured above)
1438 * so remove it from the base beacon template to avoid duplicate P2P
1439 * IEs in beacon frames.
1441 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1442 offsetof(struct ieee80211_mgmt
,
1443 u
.beacon
.variable
));
1445 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1450 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1458 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1460 struct ath10k
*ar
= arvif
->ar
;
1461 struct ieee80211_hw
*hw
= ar
->hw
;
1462 struct ieee80211_vif
*vif
= arvif
->vif
;
1463 struct sk_buff
*prb
;
1466 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1469 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1472 prb
= ieee80211_proberesp_get(hw
, vif
);
1474 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1478 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1482 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1490 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1492 struct ath10k
*ar
= arvif
->ar
;
1493 struct cfg80211_chan_def def
;
1496 /* When originally vdev is started during assign_vif_chanctx() some
1497 * information is missing, notably SSID. Firmware revisions with beacon
1498 * offloading require the SSID to be provided during vdev (re)start to
1499 * handle hidden SSID properly.
1501 * Vdev restart must be done after vdev has been both started and
1502 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1503 * deliver vdev restart response event causing timeouts during vdev
1504 * syncing in ath10k.
1506 * Note: The vdev down/up and template reinstallation could be skipped
1507 * since only wmi-tlv firmware are known to have beacon offload and
1508 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1509 * response delivery. It's probably more robust to keep it as is.
1511 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1514 if (WARN_ON(!arvif
->is_started
))
1517 if (WARN_ON(!arvif
->is_up
))
1520 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1523 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1525 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1526 arvif
->vdev_id
, ret
);
1530 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1531 * firmware will crash upon vdev up.
1534 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1536 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1540 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1542 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1546 ret
= ath10k_vdev_restart(arvif
, &def
);
1548 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1549 arvif
->vdev_id
, ret
);
1553 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1556 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1557 arvif
->vdev_id
, ret
);
1564 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1565 struct ieee80211_bss_conf
*info
)
1567 struct ath10k
*ar
= arvif
->ar
;
1570 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1572 if (!info
->enable_beacon
) {
1573 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1575 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1576 arvif
->vdev_id
, ret
);
1578 arvif
->is_up
= false;
1580 spin_lock_bh(&arvif
->ar
->data_lock
);
1581 ath10k_mac_vif_beacon_free(arvif
);
1582 spin_unlock_bh(&arvif
->ar
->data_lock
);
1587 arvif
->tx_seq_no
= 0x1000;
1590 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1592 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1595 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1596 arvif
->vdev_id
, ret
);
1600 arvif
->is_up
= true;
1602 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1604 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1605 arvif
->vdev_id
, ret
);
1609 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1612 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1613 struct ieee80211_bss_conf
*info
,
1614 const u8 self_peer
[ETH_ALEN
])
1616 struct ath10k
*ar
= arvif
->ar
;
1620 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1622 if (!info
->ibss_joined
) {
1623 if (is_zero_ether_addr(arvif
->bssid
))
1626 memset(arvif
->bssid
, 0, ETH_ALEN
);
1631 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1632 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1633 ATH10K_DEFAULT_ATIM
);
1635 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1636 arvif
->vdev_id
, ret
);
1639 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1641 struct ath10k
*ar
= arvif
->ar
;
1646 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1648 if (arvif
->u
.sta
.uapsd
)
1649 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1651 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1653 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1654 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1656 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1657 value
, arvif
->vdev_id
, ret
);
1664 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1666 struct ath10k
*ar
= arvif
->ar
;
1671 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1673 if (arvif
->u
.sta
.uapsd
)
1674 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1676 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1678 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1679 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1682 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1683 value
, arvif
->vdev_id
, ret
);
1690 static int ath10k_mac_ps_vif_count(struct ath10k
*ar
)
1692 struct ath10k_vif
*arvif
;
1695 lockdep_assert_held(&ar
->conf_mutex
);
1697 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1704 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1706 struct ath10k
*ar
= arvif
->ar
;
1707 struct ieee80211_vif
*vif
= arvif
->vif
;
1708 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1709 enum wmi_sta_powersave_param param
;
1710 enum wmi_sta_ps_mode psmode
;
1715 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1717 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1720 enable_ps
= arvif
->ps
;
1722 if (enable_ps
&& ath10k_mac_ps_vif_count(ar
) > 1 &&
1723 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1725 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1731 psmode
= WMI_STA_PS_MODE_ENABLED
;
1732 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1734 ps_timeout
= conf
->dynamic_ps_timeout
;
1735 if (ps_timeout
== 0) {
1736 /* Firmware doesn't like 0 */
1737 ps_timeout
= ieee80211_tu_to_usec(
1738 vif
->bss_conf
.beacon_int
) / 1000;
1741 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1744 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1745 arvif
->vdev_id
, ret
);
1749 psmode
= WMI_STA_PS_MODE_DISABLED
;
1752 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1753 arvif
->vdev_id
, psmode
? "enable" : "disable");
1755 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1757 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1758 psmode
, arvif
->vdev_id
, ret
);
1765 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1767 struct ath10k
*ar
= arvif
->ar
;
1768 struct wmi_sta_keepalive_arg arg
= {};
1771 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1773 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1776 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1779 /* Some firmware revisions have a bug and ignore the `enabled` field.
1780 * Instead use the interval to disable the keepalive.
1782 arg
.vdev_id
= arvif
->vdev_id
;
1784 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1785 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1787 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1789 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1790 arvif
->vdev_id
, ret
);
1797 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
1799 struct ath10k
*ar
= arvif
->ar
;
1800 struct ieee80211_vif
*vif
= arvif
->vif
;
1803 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1805 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
1808 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1811 if (!vif
->csa_active
)
1817 if (!ieee80211_csa_is_complete(vif
)) {
1818 ieee80211_csa_update_counter(vif
);
1820 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1822 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
1825 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1827 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
1830 ieee80211_csa_finish(vif
);
1834 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
1836 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1838 struct ath10k
*ar
= arvif
->ar
;
1840 mutex_lock(&ar
->conf_mutex
);
1841 ath10k_mac_vif_ap_csa_count_down(arvif
);
1842 mutex_unlock(&ar
->conf_mutex
);
1845 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
1846 struct ieee80211_vif
*vif
)
1848 struct sk_buff
*skb
= data
;
1849 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1850 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1852 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1855 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
1858 cancel_delayed_work(&arvif
->connection_loss_work
);
1861 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
1863 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1864 IEEE80211_IFACE_ITER_NORMAL
,
1865 ath10k_mac_handle_beacon_iter
,
1869 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
1870 struct ieee80211_vif
*vif
)
1872 u32
*vdev_id
= data
;
1873 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1874 struct ath10k
*ar
= arvif
->ar
;
1875 struct ieee80211_hw
*hw
= ar
->hw
;
1877 if (arvif
->vdev_id
!= *vdev_id
)
1883 ieee80211_beacon_loss(vif
);
1885 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1886 * (done by mac80211) succeeds but beacons do not resume then it
1887 * doesn't make sense to continue operation. Queue connection loss work
1888 * which can be cancelled when beacon is received.
1890 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
1891 ATH10K_CONNECTION_LOSS_HZ
);
1894 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
1896 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1897 IEEE80211_IFACE_ITER_NORMAL
,
1898 ath10k_mac_handle_beacon_miss_iter
,
1902 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
1904 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1905 connection_loss_work
.work
);
1906 struct ieee80211_vif
*vif
= arvif
->vif
;
1911 ieee80211_connection_loss(vif
);
1914 /**********************/
1915 /* Station management */
1916 /**********************/
1918 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1919 struct ieee80211_vif
*vif
)
1921 /* Some firmware revisions have unstable STA powersave when listen
1922 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1923 * generate NullFunc frames properly even if buffered frames have been
1924 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1925 * buffered frames. Often pinging the device from AP would simply fail.
1927 * As a workaround set it to 1.
1929 if (vif
->type
== NL80211_IFTYPE_STATION
)
1932 return ar
->hw
->conf
.listen_interval
;
1935 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1936 struct ieee80211_vif
*vif
,
1937 struct ieee80211_sta
*sta
,
1938 struct wmi_peer_assoc_complete_arg
*arg
)
1940 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1943 lockdep_assert_held(&ar
->conf_mutex
);
1945 if (vif
->type
== NL80211_IFTYPE_STATION
)
1946 aid
= vif
->bss_conf
.aid
;
1950 ether_addr_copy(arg
->addr
, sta
->addr
);
1951 arg
->vdev_id
= arvif
->vdev_id
;
1952 arg
->peer_aid
= aid
;
1953 arg
->peer_flags
|= WMI_PEER_AUTH
;
1954 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1955 arg
->peer_num_spatial_streams
= 1;
1956 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1959 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1960 struct ieee80211_vif
*vif
,
1961 struct wmi_peer_assoc_complete_arg
*arg
)
1963 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1964 struct cfg80211_chan_def def
;
1965 struct cfg80211_bss
*bss
;
1966 const u8
*rsnie
= NULL
;
1967 const u8
*wpaie
= NULL
;
1969 lockdep_assert_held(&ar
->conf_mutex
);
1971 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
1974 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
, NULL
, 0,
1975 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
1977 const struct cfg80211_bss_ies
*ies
;
1980 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1982 ies
= rcu_dereference(bss
->ies
);
1984 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1985 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1989 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1992 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1993 if (rsnie
|| wpaie
) {
1994 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1995 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1999 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
2000 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
2004 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
2005 struct ieee80211_vif
*vif
,
2006 struct ieee80211_sta
*sta
,
2007 struct wmi_peer_assoc_complete_arg
*arg
)
2009 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
2010 struct cfg80211_chan_def def
;
2011 const struct ieee80211_supported_band
*sband
;
2012 const struct ieee80211_rate
*rates
;
2017 lockdep_assert_held(&ar
->conf_mutex
);
2019 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2022 sband
= ar
->hw
->wiphy
->bands
[def
.chan
->band
];
2023 ratemask
= sta
->supp_rates
[def
.chan
->band
];
2024 rates
= sband
->bitrates
;
2026 rateset
->num_rates
= 0;
2028 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2029 if (!(ratemask
& 1))
2032 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2033 rateset
->rates
[rateset
->num_rates
] = rate
;
2034 rateset
->num_rates
++;
2038 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2039 struct ieee80211_sta
*sta
,
2040 struct wmi_peer_assoc_complete_arg
*arg
)
2042 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2046 lockdep_assert_held(&ar
->conf_mutex
);
2048 if (!ht_cap
->ht_supported
)
2051 arg
->peer_flags
|= WMI_PEER_HT
;
2052 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2053 ht_cap
->ampdu_factor
)) - 1;
2055 arg
->peer_mpdu_density
=
2056 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2058 arg
->peer_ht_caps
= ht_cap
->cap
;
2059 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2061 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2062 arg
->peer_flags
|= WMI_PEER_LDPC
;
2064 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2065 arg
->peer_flags
|= WMI_PEER_40MHZ
;
2066 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2069 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2070 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2072 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2073 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2075 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2076 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2077 arg
->peer_flags
|= WMI_PEER_STBC
;
2080 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2081 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2082 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2083 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2084 arg
->peer_rate_caps
|= stbc
;
2085 arg
->peer_flags
|= WMI_PEER_STBC
;
2088 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2089 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2090 else if (ht_cap
->mcs
.rx_mask
[1])
2091 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2093 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
2094 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
2095 arg
->peer_ht_rates
.rates
[n
++] = i
;
2098 * This is a workaround for HT-enabled STAs which break the spec
2099 * and have no HT capabilities RX mask (no HT RX MCS map).
2101 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2102 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2104 * Firmware asserts if such situation occurs.
2107 arg
->peer_ht_rates
.num_rates
= 8;
2108 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2109 arg
->peer_ht_rates
.rates
[i
] = i
;
2111 arg
->peer_ht_rates
.num_rates
= n
;
2112 arg
->peer_num_spatial_streams
= sta
->rx_nss
;
2115 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2117 arg
->peer_ht_rates
.num_rates
,
2118 arg
->peer_num_spatial_streams
);
2121 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2122 struct ath10k_vif
*arvif
,
2123 struct ieee80211_sta
*sta
)
2129 lockdep_assert_held(&ar
->conf_mutex
);
2131 if (sta
->wme
&& sta
->uapsd_queues
) {
2132 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2133 sta
->uapsd_queues
, sta
->max_sp
);
2135 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2136 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2137 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2138 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2139 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2140 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2141 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2142 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2143 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2144 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2145 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2146 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2148 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2149 max_sp
= sta
->max_sp
;
2151 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2153 WMI_AP_PS_PEER_PARAM_UAPSD
,
2156 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2157 arvif
->vdev_id
, ret
);
2161 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2163 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2166 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2167 arvif
->vdev_id
, ret
);
2171 /* TODO setup this based on STA listen interval and
2172 beacon interval. Currently we don't know
2173 sta->listen_interval - mac80211 patch required.
2174 Currently use 10 seconds */
2175 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2176 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2179 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2180 arvif
->vdev_id
, ret
);
2188 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2189 struct ieee80211_vif
*vif
,
2190 struct ieee80211_sta
*sta
,
2191 struct wmi_peer_assoc_complete_arg
*arg
)
2193 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
2194 struct cfg80211_chan_def def
;
2197 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2200 if (!vht_cap
->vht_supported
)
2203 arg
->peer_flags
|= WMI_PEER_VHT
;
2205 if (def
.chan
->band
== IEEE80211_BAND_2GHZ
)
2206 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
2208 arg
->peer_vht_caps
= vht_cap
->cap
;
2210 ampdu_factor
= (vht_cap
->cap
&
2211 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2212 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2214 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2215 * zero in VHT IE. Using it would result in degraded throughput.
2216 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2217 * it if VHT max_mpdu is smaller. */
2218 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2219 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2220 ampdu_factor
)) - 1);
2222 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2223 arg
->peer_flags
|= WMI_PEER_80MHZ
;
2225 arg
->peer_vht_rates
.rx_max_rate
=
2226 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2227 arg
->peer_vht_rates
.rx_mcs_set
=
2228 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2229 arg
->peer_vht_rates
.tx_max_rate
=
2230 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2231 arg
->peer_vht_rates
.tx_mcs_set
=
2232 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
2234 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2235 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
2238 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2239 struct ieee80211_vif
*vif
,
2240 struct ieee80211_sta
*sta
,
2241 struct wmi_peer_assoc_complete_arg
*arg
)
2243 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2245 switch (arvif
->vdev_type
) {
2246 case WMI_VDEV_TYPE_AP
:
2248 arg
->peer_flags
|= WMI_PEER_QOS
;
2250 if (sta
->wme
&& sta
->uapsd_queues
) {
2251 arg
->peer_flags
|= WMI_PEER_APSD
;
2252 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2255 case WMI_VDEV_TYPE_STA
:
2256 if (vif
->bss_conf
.qos
)
2257 arg
->peer_flags
|= WMI_PEER_QOS
;
2259 case WMI_VDEV_TYPE_IBSS
:
2261 arg
->peer_flags
|= WMI_PEER_QOS
;
2267 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2268 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
2271 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2273 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >>
2274 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2277 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2278 struct ieee80211_vif
*vif
,
2279 struct ieee80211_sta
*sta
,
2280 struct wmi_peer_assoc_complete_arg
*arg
)
2282 struct cfg80211_chan_def def
;
2283 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2285 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2288 switch (def
.chan
->band
) {
2289 case IEEE80211_BAND_2GHZ
:
2290 if (sta
->vht_cap
.vht_supported
) {
2291 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2292 phymode
= MODE_11AC_VHT40
;
2294 phymode
= MODE_11AC_VHT20
;
2295 } else if (sta
->ht_cap
.ht_supported
) {
2296 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2297 phymode
= MODE_11NG_HT40
;
2299 phymode
= MODE_11NG_HT20
;
2300 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2307 case IEEE80211_BAND_5GHZ
:
2311 if (sta
->vht_cap
.vht_supported
) {
2312 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2313 phymode
= MODE_11AC_VHT80
;
2314 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2315 phymode
= MODE_11AC_VHT40
;
2316 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2317 phymode
= MODE_11AC_VHT20
;
2318 } else if (sta
->ht_cap
.ht_supported
) {
2319 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2320 phymode
= MODE_11NA_HT40
;
2322 phymode
= MODE_11NA_HT20
;
2332 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2333 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2335 arg
->peer_phymode
= phymode
;
2336 WARN_ON(phymode
== MODE_UNKNOWN
);
2339 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2340 struct ieee80211_vif
*vif
,
2341 struct ieee80211_sta
*sta
,
2342 struct wmi_peer_assoc_complete_arg
*arg
)
2344 lockdep_assert_held(&ar
->conf_mutex
);
2346 memset(arg
, 0, sizeof(*arg
));
2348 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2349 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
2350 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2351 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
2352 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2353 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2354 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2359 static const u32 ath10k_smps_map
[] = {
2360 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2361 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2362 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2363 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2366 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2368 const struct ieee80211_sta_ht_cap
*ht_cap
)
2372 if (!ht_cap
->ht_supported
)
2375 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2376 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2378 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2381 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2382 WMI_PEER_SMPS_STATE
,
2383 ath10k_smps_map
[smps
]);
2386 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2387 struct ieee80211_vif
*vif
,
2388 struct ieee80211_sta_vht_cap vht_cap
)
2390 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2395 if (!(ar
->vht_cap_info
&
2396 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2397 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2398 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2399 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2402 param
= ar
->wmi
.vdev_param
->txbf
;
2405 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2408 /* The following logic is correct. If a remote STA advertises support
2409 * for being a beamformer then we should enable us being a beamformee.
2412 if (ar
->vht_cap_info
&
2413 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2414 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2415 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2416 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2418 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2419 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2422 if (ar
->vht_cap_info
&
2423 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2424 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2425 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2426 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2428 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2429 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2432 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2433 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2435 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2436 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2438 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2440 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2448 /* can be called only in mac80211 callbacks due to `key_count` usage */
2449 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2450 struct ieee80211_vif
*vif
,
2451 struct ieee80211_bss_conf
*bss_conf
)
2453 struct ath10k
*ar
= hw
->priv
;
2454 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2455 struct ieee80211_sta_ht_cap ht_cap
;
2456 struct ieee80211_sta_vht_cap vht_cap
;
2457 struct wmi_peer_assoc_complete_arg peer_arg
;
2458 struct ieee80211_sta
*ap_sta
;
2461 lockdep_assert_held(&ar
->conf_mutex
);
2463 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2464 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2468 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2470 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2471 bss_conf
->bssid
, arvif
->vdev_id
);
2476 /* ap_sta must be accessed only within rcu section which must be left
2477 * before calling ath10k_setup_peer_smps() which might sleep. */
2478 ht_cap
= ap_sta
->ht_cap
;
2479 vht_cap
= ap_sta
->vht_cap
;
2481 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2483 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2484 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2491 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2493 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2494 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2498 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2500 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2501 arvif
->vdev_id
, ret
);
2505 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2507 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2508 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2512 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2513 "mac vdev %d up (associated) bssid %pM aid %d\n",
2514 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2516 WARN_ON(arvif
->is_up
);
2518 arvif
->aid
= bss_conf
->aid
;
2519 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2521 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2523 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2524 arvif
->vdev_id
, ret
);
2528 arvif
->is_up
= true;
2530 /* Workaround: Some firmware revisions (tested with qca6174
2531 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2532 * poked with peer param command.
2534 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2535 WMI_PEER_DUMMY_VAR
, 1);
2537 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2538 arvif
->bssid
, arvif
->vdev_id
, ret
);
2543 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2544 struct ieee80211_vif
*vif
)
2546 struct ath10k
*ar
= hw
->priv
;
2547 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2548 struct ieee80211_sta_vht_cap vht_cap
= {};
2551 lockdep_assert_held(&ar
->conf_mutex
);
2553 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2554 arvif
->vdev_id
, arvif
->bssid
);
2556 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2558 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
2559 arvif
->vdev_id
, ret
);
2561 arvif
->def_wep_key_idx
= -1;
2563 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2565 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2566 arvif
->vdev_id
, ret
);
2570 arvif
->is_up
= false;
2572 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
2575 static int ath10k_station_assoc(struct ath10k
*ar
,
2576 struct ieee80211_vif
*vif
,
2577 struct ieee80211_sta
*sta
,
2580 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2581 struct wmi_peer_assoc_complete_arg peer_arg
;
2584 lockdep_assert_held(&ar
->conf_mutex
);
2586 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2588 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2589 sta
->addr
, arvif
->vdev_id
, ret
);
2593 peer_arg
.peer_reassoc
= reassoc
;
2594 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2596 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2597 sta
->addr
, arvif
->vdev_id
, ret
);
2601 /* Re-assoc is run only to update supported rates for given station. It
2602 * doesn't make much sense to reconfigure the peer completely.
2605 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2608 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2609 arvif
->vdev_id
, ret
);
2613 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2615 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2616 sta
->addr
, arvif
->vdev_id
, ret
);
2621 arvif
->num_legacy_stations
++;
2622 ret
= ath10k_recalc_rtscts_prot(arvif
);
2624 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2625 arvif
->vdev_id
, ret
);
2630 /* Plumb cached keys only for static WEP */
2631 if (arvif
->def_wep_key_idx
!= -1) {
2632 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2634 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2635 arvif
->vdev_id
, ret
);
2644 static int ath10k_station_disassoc(struct ath10k
*ar
,
2645 struct ieee80211_vif
*vif
,
2646 struct ieee80211_sta
*sta
)
2648 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2651 lockdep_assert_held(&ar
->conf_mutex
);
2654 arvif
->num_legacy_stations
--;
2655 ret
= ath10k_recalc_rtscts_prot(arvif
);
2657 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2658 arvif
->vdev_id
, ret
);
2663 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2665 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2666 arvif
->vdev_id
, ret
);
2677 static int ath10k_update_channel_list(struct ath10k
*ar
)
2679 struct ieee80211_hw
*hw
= ar
->hw
;
2680 struct ieee80211_supported_band
**bands
;
2681 enum ieee80211_band band
;
2682 struct ieee80211_channel
*channel
;
2683 struct wmi_scan_chan_list_arg arg
= {0};
2684 struct wmi_channel_arg
*ch
;
2690 lockdep_assert_held(&ar
->conf_mutex
);
2692 bands
= hw
->wiphy
->bands
;
2693 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2697 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2698 if (bands
[band
]->channels
[i
].flags
&
2699 IEEE80211_CHAN_DISABLED
)
2706 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2707 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2712 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2716 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2717 channel
= &bands
[band
]->channels
[i
];
2719 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2722 ch
->allow_ht
= true;
2724 /* FIXME: when should we really allow VHT? */
2725 ch
->allow_vht
= true;
2728 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2731 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2734 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2736 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2737 ch
->passive
= passive
;
2739 ch
->freq
= channel
->center_freq
;
2740 ch
->band_center_freq1
= channel
->center_freq
;
2742 ch
->max_power
= channel
->max_power
* 2;
2743 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2744 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2745 ch
->reg_class_id
= 0; /* FIXME */
2747 /* FIXME: why use only legacy modes, why not any
2748 * HT/VHT modes? Would that even make any
2750 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2751 ch
->mode
= MODE_11G
;
2753 ch
->mode
= MODE_11A
;
2755 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2758 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2759 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2760 ch
- arg
.channels
, arg
.n_channels
,
2761 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2762 ch
->max_antenna_gain
, ch
->mode
);
2768 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2769 kfree(arg
.channels
);
2774 static enum wmi_dfs_region
2775 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2777 switch (dfs_region
) {
2778 case NL80211_DFS_UNSET
:
2779 return WMI_UNINIT_DFS_DOMAIN
;
2780 case NL80211_DFS_FCC
:
2781 return WMI_FCC_DFS_DOMAIN
;
2782 case NL80211_DFS_ETSI
:
2783 return WMI_ETSI_DFS_DOMAIN
;
2784 case NL80211_DFS_JP
:
2785 return WMI_MKK4_DFS_DOMAIN
;
2787 return WMI_UNINIT_DFS_DOMAIN
;
2790 static void ath10k_regd_update(struct ath10k
*ar
)
2792 struct reg_dmn_pair_mapping
*regpair
;
2794 enum wmi_dfs_region wmi_dfs_reg
;
2795 enum nl80211_dfs_regions nl_dfs_reg
;
2797 lockdep_assert_held(&ar
->conf_mutex
);
2799 ret
= ath10k_update_channel_list(ar
);
2801 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2803 regpair
= ar
->ath_common
.regulatory
.regpair
;
2805 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2806 nl_dfs_reg
= ar
->dfs_detector
->region
;
2807 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2809 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2812 /* Target allows setting up per-band regdomain but ath_common provides
2813 * a combined one only */
2814 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2815 regpair
->reg_domain
,
2816 regpair
->reg_domain
, /* 2ghz */
2817 regpair
->reg_domain
, /* 5ghz */
2818 regpair
->reg_2ghz_ctl
,
2819 regpair
->reg_5ghz_ctl
,
2822 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2825 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2826 struct regulatory_request
*request
)
2828 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2829 struct ath10k
*ar
= hw
->priv
;
2832 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2834 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2835 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
2836 request
->dfs_region
);
2837 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
2838 request
->dfs_region
);
2840 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2841 request
->dfs_region
);
2844 mutex_lock(&ar
->conf_mutex
);
2845 if (ar
->state
== ATH10K_STATE_ON
)
2846 ath10k_regd_update(ar
);
2847 mutex_unlock(&ar
->conf_mutex
);
2854 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
2856 lockdep_assert_held(&ar
->htt
.tx_lock
);
2858 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
2859 ar
->tx_paused
|= BIT(reason
);
2860 ieee80211_stop_queues(ar
->hw
);
2863 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
2864 struct ieee80211_vif
*vif
)
2866 struct ath10k
*ar
= data
;
2867 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2869 if (arvif
->tx_paused
)
2872 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
2875 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
2877 lockdep_assert_held(&ar
->htt
.tx_lock
);
2879 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
2880 ar
->tx_paused
&= ~BIT(reason
);
2885 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2886 IEEE80211_IFACE_ITER_RESUME_ALL
,
2887 ath10k_mac_tx_unlock_iter
,
2891 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
2893 struct ath10k
*ar
= arvif
->ar
;
2895 lockdep_assert_held(&ar
->htt
.tx_lock
);
2897 WARN_ON(reason
>= BITS_PER_LONG
);
2898 arvif
->tx_paused
|= BIT(reason
);
2899 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
2902 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
2904 struct ath10k
*ar
= arvif
->ar
;
2906 lockdep_assert_held(&ar
->htt
.tx_lock
);
2908 WARN_ON(reason
>= BITS_PER_LONG
);
2909 arvif
->tx_paused
&= ~BIT(reason
);
2914 if (arvif
->tx_paused
)
2917 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
2920 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
2921 enum wmi_tlv_tx_pause_id pause_id
,
2922 enum wmi_tlv_tx_pause_action action
)
2924 struct ath10k
*ar
= arvif
->ar
;
2926 lockdep_assert_held(&ar
->htt
.tx_lock
);
2929 case WMI_TLV_TX_PAUSE_ID_MCC
:
2930 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA
:
2931 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS
:
2932 case WMI_TLV_TX_PAUSE_ID_AP_PS
:
2933 case WMI_TLV_TX_PAUSE_ID_IBSS_PS
:
2935 case WMI_TLV_TX_PAUSE_ACTION_STOP
:
2936 ath10k_mac_vif_tx_lock(arvif
, pause_id
);
2938 case WMI_TLV_TX_PAUSE_ACTION_WAKE
:
2939 ath10k_mac_vif_tx_unlock(arvif
, pause_id
);
2942 ath10k_warn(ar
, "received unknown tx pause action %d on vdev %i, ignoring\n",
2943 action
, arvif
->vdev_id
);
2947 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS
:
2948 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD
:
2949 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA
:
2950 case WMI_TLV_TX_PAUSE_ID_HOST
:
2952 /* FIXME: Some pause_ids aren't vdev specific. Instead they
2953 * target peer_id and tid. Implementing these could improve
2954 * traffic scheduling fairness across multiple connected
2955 * stations in AP/IBSS modes.
2957 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2958 "mac ignoring unsupported tx pause vdev %i id %d\n",
2959 arvif
->vdev_id
, pause_id
);
2964 struct ath10k_mac_tx_pause
{
2966 enum wmi_tlv_tx_pause_id pause_id
;
2967 enum wmi_tlv_tx_pause_action action
;
2970 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
2971 struct ieee80211_vif
*vif
)
2973 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2974 struct ath10k_mac_tx_pause
*arg
= data
;
2976 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
2979 void ath10k_mac_handle_tx_pause(struct ath10k
*ar
, u32 vdev_id
,
2980 enum wmi_tlv_tx_pause_id pause_id
,
2981 enum wmi_tlv_tx_pause_action action
)
2983 struct ath10k_mac_tx_pause arg
= {
2985 .pause_id
= pause_id
,
2989 spin_lock_bh(&ar
->htt
.tx_lock
);
2990 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2991 IEEE80211_IFACE_ITER_RESUME_ALL
,
2992 ath10k_mac_handle_tx_pause_iter
,
2994 spin_unlock_bh(&ar
->htt
.tx_lock
);
2997 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
2999 if (ieee80211_is_mgmt(hdr
->frame_control
))
3000 return HTT_DATA_TX_EXT_TID_MGMT
;
3002 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3003 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3005 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
3006 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3008 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
3011 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
3014 return ath10k_vif_to_arvif(vif
)->vdev_id
;
3016 if (ar
->monitor_started
)
3017 return ar
->monitor_vdev_id
;
3019 ath10k_warn(ar
, "failed to resolve vdev id\n");
3023 static enum ath10k_hw_txrx_mode
3024 ath10k_tx_h_get_txmode(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
3025 struct ieee80211_sta
*sta
, struct sk_buff
*skb
)
3027 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3028 __le16 fc
= hdr
->frame_control
;
3030 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3031 return ATH10K_HW_TXRX_RAW
;
3033 if (ieee80211_is_mgmt(fc
))
3034 return ATH10K_HW_TXRX_MGMT
;
3038 * NullFunc frames are mostly used to ping if a client or AP are still
3039 * reachable and responsive. This implies tx status reports must be
3040 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3041 * come to a conclusion that the other end disappeared and tear down
3042 * BSS connection or it can never disconnect from BSS/client (which is
3045 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3046 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3047 * which seems to deliver correct tx reports for NullFunc frames. The
3048 * downside of using it is it ignores client powersave state so it can
3049 * end up disconnecting sleeping clients in AP mode. It should fix STA
3050 * mode though because AP don't sleep.
3052 if (ar
->htt
.target_version_major
< 3 &&
3053 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3054 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
, ar
->fw_features
))
3055 return ATH10K_HW_TXRX_MGMT
;
3059 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3060 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3061 * to work with Ethernet txmode so use it.
3063 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3064 return ATH10K_HW_TXRX_ETHERNET
;
3066 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3069 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3070 * Control in the header.
3072 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3074 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3075 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3078 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3081 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3082 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3083 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3084 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3086 /* Some firmware revisions don't handle sending QoS NullFunc well.
3087 * These frames are mainly used for CQM purposes so it doesn't really
3088 * matter whether QoS NullFunc or NullFunc are sent.
3090 hdr
= (void *)skb
->data
;
3091 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3092 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3094 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3097 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3099 struct ieee80211_hdr
*hdr
;
3100 struct rfc1042_hdr
*rfc1042
;
3107 hdr
= (void *)skb
->data
;
3108 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3109 rfc1042
= (void *)skb
->data
+ hdrlen
;
3111 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3112 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3113 type
= rfc1042
->snap_type
;
3115 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3116 skb_push(skb
, sizeof(*eth
));
3118 eth
= (void *)skb
->data
;
3119 ether_addr_copy(eth
->h_dest
, da
);
3120 ether_addr_copy(eth
->h_source
, sa
);
3121 eth
->h_proto
= type
;
3124 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3125 struct ieee80211_vif
*vif
,
3126 struct sk_buff
*skb
)
3128 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3129 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3131 /* This is case only for P2P_GO */
3132 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
3133 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
3136 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3137 spin_lock_bh(&ar
->data_lock
);
3138 if (arvif
->u
.ap
.noa_data
)
3139 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3141 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
3142 arvif
->u
.ap
.noa_data
,
3143 arvif
->u
.ap
.noa_len
);
3144 spin_unlock_bh(&ar
->data_lock
);
3148 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
3150 /* FIXME: Not really sure since when the behaviour changed. At some
3151 * point new firmware stopped requiring creation of peer entries for
3152 * offchannel tx (and actually creating them causes issues with wmi-htc
3153 * tx credit replenishment and reliability). Assuming it's at least 3.4
3154 * because that's when the `freq` was introduced to TX_FRM HTT command.
3156 return !(ar
->htt
.target_version_major
>= 3 &&
3157 ar
->htt
.target_version_minor
>= 4);
3160 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3162 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3165 spin_lock_bh(&ar
->data_lock
);
3167 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
3168 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3173 __skb_queue_tail(q
, skb
);
3174 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3177 spin_unlock_bh(&ar
->data_lock
);
3182 static void ath10k_mac_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
3184 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3185 struct ath10k_htt
*htt
= &ar
->htt
;
3188 switch (cb
->txmode
) {
3189 case ATH10K_HW_TXRX_RAW
:
3190 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3191 case ATH10K_HW_TXRX_ETHERNET
:
3192 ret
= ath10k_htt_tx(htt
, skb
);
3194 case ATH10K_HW_TXRX_MGMT
:
3195 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3197 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
3198 else if (ar
->htt
.target_version_major
>= 3)
3199 ret
= ath10k_htt_tx(htt
, skb
);
3201 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
3206 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
3208 ieee80211_free_txskb(ar
->hw
, skb
);
3212 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
3214 struct sk_buff
*skb
;
3217 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3221 ieee80211_free_txskb(ar
->hw
, skb
);
3225 void ath10k_offchan_tx_work(struct work_struct
*work
)
3227 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
3228 struct ath10k_peer
*peer
;
3229 struct ieee80211_hdr
*hdr
;
3230 struct sk_buff
*skb
;
3231 const u8
*peer_addr
;
3234 unsigned long time_left
;
3236 /* FW requirement: We must create a peer before FW will send out
3237 * an offchannel frame. Otherwise the frame will be stuck and
3238 * never transmitted. We delete the peer upon tx completion.
3239 * It is unlikely that a peer for offchannel tx will already be
3240 * present. However it may be in some rare cases so account for that.
3241 * Otherwise we might remove a legitimate peer and break stuff. */
3244 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3248 mutex_lock(&ar
->conf_mutex
);
3250 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
3253 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3254 peer_addr
= ieee80211_get_DA(hdr
);
3255 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
3257 spin_lock_bh(&ar
->data_lock
);
3258 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
3259 spin_unlock_bh(&ar
->data_lock
);
3262 /* FIXME: should this use ath10k_warn()? */
3263 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
3264 peer_addr
, vdev_id
);
3267 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
,
3268 WMI_PEER_TYPE_DEFAULT
);
3270 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
3271 peer_addr
, vdev_id
, ret
);
3274 spin_lock_bh(&ar
->data_lock
);
3275 reinit_completion(&ar
->offchan_tx_completed
);
3276 ar
->offchan_tx_skb
= skb
;
3277 spin_unlock_bh(&ar
->data_lock
);
3279 ath10k_mac_tx(ar
, skb
);
3282 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
3284 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
3288 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
3290 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
3291 peer_addr
, vdev_id
, ret
);
3294 mutex_unlock(&ar
->conf_mutex
);
3298 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
3300 struct sk_buff
*skb
;
3303 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3307 ieee80211_free_txskb(ar
->hw
, skb
);
3311 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
3313 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
3314 struct sk_buff
*skb
;
3318 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3322 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
3324 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
3326 ieee80211_free_txskb(ar
->hw
, skb
);
3335 void __ath10k_scan_finish(struct ath10k
*ar
)
3337 lockdep_assert_held(&ar
->data_lock
);
3339 switch (ar
->scan
.state
) {
3340 case ATH10K_SCAN_IDLE
:
3342 case ATH10K_SCAN_RUNNING
:
3343 if (ar
->scan
.is_roc
)
3344 ieee80211_remain_on_channel_expired(ar
->hw
);
3346 case ATH10K_SCAN_ABORTING
:
3347 if (!ar
->scan
.is_roc
)
3348 ieee80211_scan_completed(ar
->hw
,
3350 ATH10K_SCAN_ABORTING
));
3352 case ATH10K_SCAN_STARTING
:
3353 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3354 ar
->scan_channel
= NULL
;
3355 ath10k_offchan_tx_purge(ar
);
3356 cancel_delayed_work(&ar
->scan
.timeout
);
3357 complete_all(&ar
->scan
.completed
);
3362 void ath10k_scan_finish(struct ath10k
*ar
)
3364 spin_lock_bh(&ar
->data_lock
);
3365 __ath10k_scan_finish(ar
);
3366 spin_unlock_bh(&ar
->data_lock
);
3369 static int ath10k_scan_stop(struct ath10k
*ar
)
3371 struct wmi_stop_scan_arg arg
= {
3372 .req_id
= 1, /* FIXME */
3373 .req_type
= WMI_SCAN_STOP_ONE
,
3374 .u
.scan_id
= ATH10K_SCAN_ID
,
3378 lockdep_assert_held(&ar
->conf_mutex
);
3380 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
3382 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
3386 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
3388 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
3390 } else if (ret
> 0) {
3395 /* Scan state should be updated upon scan completion but in case
3396 * firmware fails to deliver the event (for whatever reason) it is
3397 * desired to clean up scan state anyway. Firmware may have just
3398 * dropped the scan completion event delivery due to transport pipe
3399 * being overflown with data and/or it can recover on its own before
3400 * next scan request is submitted.
3402 spin_lock_bh(&ar
->data_lock
);
3403 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
3404 __ath10k_scan_finish(ar
);
3405 spin_unlock_bh(&ar
->data_lock
);
3410 static void ath10k_scan_abort(struct ath10k
*ar
)
3414 lockdep_assert_held(&ar
->conf_mutex
);
3416 spin_lock_bh(&ar
->data_lock
);
3418 switch (ar
->scan
.state
) {
3419 case ATH10K_SCAN_IDLE
:
3420 /* This can happen if timeout worker kicked in and called
3421 * abortion while scan completion was being processed.
3424 case ATH10K_SCAN_STARTING
:
3425 case ATH10K_SCAN_ABORTING
:
3426 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3427 ath10k_scan_state_str(ar
->scan
.state
),
3430 case ATH10K_SCAN_RUNNING
:
3431 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
3432 spin_unlock_bh(&ar
->data_lock
);
3434 ret
= ath10k_scan_stop(ar
);
3436 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
3438 spin_lock_bh(&ar
->data_lock
);
3442 spin_unlock_bh(&ar
->data_lock
);
3445 void ath10k_scan_timeout_work(struct work_struct
*work
)
3447 struct ath10k
*ar
= container_of(work
, struct ath10k
,
3450 mutex_lock(&ar
->conf_mutex
);
3451 ath10k_scan_abort(ar
);
3452 mutex_unlock(&ar
->conf_mutex
);
3455 static int ath10k_start_scan(struct ath10k
*ar
,
3456 const struct wmi_start_scan_arg
*arg
)
3460 lockdep_assert_held(&ar
->conf_mutex
);
3462 ret
= ath10k_wmi_start_scan(ar
, arg
);
3466 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
3468 ret
= ath10k_scan_stop(ar
);
3470 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
3475 /* If we failed to start the scan, return error code at
3476 * this point. This is probably due to some issue in the
3477 * firmware, but no need to wedge the driver due to that...
3479 spin_lock_bh(&ar
->data_lock
);
3480 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
3481 spin_unlock_bh(&ar
->data_lock
);
3484 spin_unlock_bh(&ar
->data_lock
);
3486 /* Add a 200ms margin to account for event/command processing */
3487 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
3488 msecs_to_jiffies(arg
->max_scan_time
+200));
3492 /**********************/
3493 /* mac80211 callbacks */
3494 /**********************/
3496 static void ath10k_tx(struct ieee80211_hw
*hw
,
3497 struct ieee80211_tx_control
*control
,
3498 struct sk_buff
*skb
)
3500 struct ath10k
*ar
= hw
->priv
;
3501 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3502 struct ieee80211_vif
*vif
= info
->control
.vif
;
3503 struct ieee80211_sta
*sta
= control
->sta
;
3504 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3505 __le16 fc
= hdr
->frame_control
;
3507 /* We should disable CCK RATE due to P2P */
3508 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3509 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3511 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
3512 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3513 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
3514 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
3515 ATH10K_SKB_CB(skb
)->txmode
= ath10k_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3516 ATH10K_SKB_CB(skb
)->is_protected
= ieee80211_has_protected(fc
);
3518 switch (ATH10K_SKB_CB(skb
)->txmode
) {
3519 case ATH10K_HW_TXRX_MGMT
:
3520 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3521 ath10k_tx_h_nwifi(hw
, skb
);
3522 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3523 ath10k_tx_h_seq_no(vif
, skb
);
3525 case ATH10K_HW_TXRX_ETHERNET
:
3526 ath10k_tx_h_8023(skb
);
3528 case ATH10K_HW_TXRX_RAW
:
3529 /* FIXME: Packet injection isn't implemented. It should be
3530 * doable with firmware 10.2 on qca988x.
3533 ieee80211_free_txskb(hw
, skb
);
3537 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3538 spin_lock_bh(&ar
->data_lock
);
3539 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
3540 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
3541 spin_unlock_bh(&ar
->data_lock
);
3543 if (ath10k_mac_need_offchan_tx_work(ar
)) {
3544 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3545 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
3547 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
3550 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3551 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3556 ath10k_mac_tx(ar
, skb
);
3559 /* Must not be called with conf_mutex held as workers can use that also. */
3560 void ath10k_drain_tx(struct ath10k
*ar
)
3562 /* make sure rcu-protected mac80211 tx path itself is drained */
3565 ath10k_offchan_tx_purge(ar
);
3566 ath10k_mgmt_over_wmi_tx_purge(ar
);
3568 cancel_work_sync(&ar
->offchan_tx_work
);
3569 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
3572 void ath10k_halt(struct ath10k
*ar
)
3574 struct ath10k_vif
*arvif
;
3576 lockdep_assert_held(&ar
->conf_mutex
);
3578 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
3579 ar
->filter_flags
= 0;
3580 ar
->monitor
= false;
3581 ar
->monitor_arvif
= NULL
;
3583 if (ar
->monitor_started
)
3584 ath10k_monitor_stop(ar
);
3586 ar
->monitor_started
= false;
3589 ath10k_scan_finish(ar
);
3590 ath10k_peer_cleanup_all(ar
);
3591 ath10k_core_stop(ar
);
3592 ath10k_hif_power_down(ar
);
3594 spin_lock_bh(&ar
->data_lock
);
3595 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
3596 ath10k_mac_vif_beacon_cleanup(arvif
);
3597 spin_unlock_bh(&ar
->data_lock
);
3600 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
3602 struct ath10k
*ar
= hw
->priv
;
3604 mutex_lock(&ar
->conf_mutex
);
3606 if (ar
->cfg_tx_chainmask
) {
3607 *tx_ant
= ar
->cfg_tx_chainmask
;
3608 *rx_ant
= ar
->cfg_rx_chainmask
;
3610 *tx_ant
= ar
->supp_tx_chainmask
;
3611 *rx_ant
= ar
->supp_rx_chainmask
;
3614 mutex_unlock(&ar
->conf_mutex
);
3619 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
3621 /* It is not clear that allowing gaps in chainmask
3622 * is helpful. Probably it will not do what user
3623 * is hoping for, so warn in that case.
3625 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
3628 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3632 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
3636 lockdep_assert_held(&ar
->conf_mutex
);
3638 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
3639 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
3641 ar
->cfg_tx_chainmask
= tx_ant
;
3642 ar
->cfg_rx_chainmask
= rx_ant
;
3644 if ((ar
->state
!= ATH10K_STATE_ON
) &&
3645 (ar
->state
!= ATH10K_STATE_RESTARTED
))
3648 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
3651 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
3656 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
3659 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
3667 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
3669 struct ath10k
*ar
= hw
->priv
;
3672 mutex_lock(&ar
->conf_mutex
);
3673 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
3674 mutex_unlock(&ar
->conf_mutex
);
3678 static int ath10k_start(struct ieee80211_hw
*hw
)
3680 struct ath10k
*ar
= hw
->priv
;
3685 * This makes sense only when restarting hw. It is harmless to call
3686 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3687 * commands will be submitted while restarting.
3689 ath10k_drain_tx(ar
);
3691 mutex_lock(&ar
->conf_mutex
);
3693 switch (ar
->state
) {
3694 case ATH10K_STATE_OFF
:
3695 ar
->state
= ATH10K_STATE_ON
;
3697 case ATH10K_STATE_RESTARTING
:
3699 ar
->state
= ATH10K_STATE_RESTARTED
;
3701 case ATH10K_STATE_ON
:
3702 case ATH10K_STATE_RESTARTED
:
3703 case ATH10K_STATE_WEDGED
:
3707 case ATH10K_STATE_UTF
:
3712 ret
= ath10k_hif_power_up(ar
);
3714 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
3718 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
3720 ath10k_err(ar
, "Could not init core: %d\n", ret
);
3721 goto err_power_down
;
3724 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
3726 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
3730 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
3732 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
3736 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
3737 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
3739 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
3745 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
3746 burst_enable
= ar
->wmi
.pdev_param
->burst_enable
;
3747 ret
= ath10k_wmi_pdev_set_param(ar
, burst_enable
, 0);
3749 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
3754 if (ar
->cfg_tx_chainmask
)
3755 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
3756 ar
->cfg_rx_chainmask
);
3759 * By default FW set ARP frames ac to voice (6). In that case ARP
3760 * exchange is not working properly for UAPSD enabled AP. ARP requests
3761 * which arrives with access category 0 are processed by network stack
3762 * and send back with access category 0, but FW changes access category
3763 * to 6. Set ARP frames access category to best effort (0) solves
3767 ret
= ath10k_wmi_pdev_set_param(ar
,
3768 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
3770 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
3775 ret
= ath10k_wmi_pdev_set_param(ar
,
3776 ar
->wmi
.pdev_param
->ani_enable
, 1);
3778 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
3783 ar
->ani_enabled
= true;
3785 ar
->num_started_vdevs
= 0;
3786 ath10k_regd_update(ar
);
3788 ath10k_spectral_start(ar
);
3789 ath10k_thermal_set_throttling(ar
);
3791 mutex_unlock(&ar
->conf_mutex
);
3795 ath10k_core_stop(ar
);
3798 ath10k_hif_power_down(ar
);
3801 ar
->state
= ATH10K_STATE_OFF
;
3804 mutex_unlock(&ar
->conf_mutex
);
3808 static void ath10k_stop(struct ieee80211_hw
*hw
)
3810 struct ath10k
*ar
= hw
->priv
;
3812 ath10k_drain_tx(ar
);
3814 mutex_lock(&ar
->conf_mutex
);
3815 if (ar
->state
!= ATH10K_STATE_OFF
) {
3817 ar
->state
= ATH10K_STATE_OFF
;
3819 mutex_unlock(&ar
->conf_mutex
);
3821 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3822 cancel_work_sync(&ar
->restart_work
);
3825 static int ath10k_config_ps(struct ath10k
*ar
)
3827 struct ath10k_vif
*arvif
;
3830 lockdep_assert_held(&ar
->conf_mutex
);
3832 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3833 ret
= ath10k_mac_vif_setup_ps(arvif
);
3835 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
3843 static void ath10k_mac_chan_reconfigure(struct ath10k
*ar
)
3845 struct ath10k_vif
*arvif
;
3846 struct cfg80211_chan_def def
;
3849 lockdep_assert_held(&ar
->conf_mutex
);
3851 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac chan reconfigure\n");
3853 /* First stop monitor interface. Some FW versions crash if there's a
3854 * lone monitor interface. */
3855 if (ar
->monitor_started
)
3856 ath10k_monitor_stop(ar
);
3858 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3859 if (!arvif
->is_started
)
3865 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3868 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
3870 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
3871 arvif
->vdev_id
, ret
);
3876 /* all vdevs are downed now - attempt to restart and re-up them */
3878 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3879 if (!arvif
->is_started
)
3882 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3885 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3887 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
3890 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
3892 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
3895 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
3898 ret
= ath10k_vdev_restart(arvif
, &def
);
3900 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
3901 arvif
->vdev_id
, ret
);
3908 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
3911 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
3912 arvif
->vdev_id
, ret
);
3917 ath10k_monitor_recalc(ar
);
3920 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
3925 lockdep_assert_held(&ar
->conf_mutex
);
3927 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
3929 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
3930 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3932 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
3937 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
3938 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3940 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
3948 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
3950 struct ath10k_vif
*arvif
;
3951 int ret
, txpower
= -1;
3953 lockdep_assert_held(&ar
->conf_mutex
);
3955 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3956 WARN_ON(arvif
->txpower
< 0);
3959 txpower
= arvif
->txpower
;
3961 txpower
= min(txpower
, arvif
->txpower
);
3964 if (WARN_ON(txpower
== -1))
3967 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
3969 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
3977 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
3979 struct ath10k
*ar
= hw
->priv
;
3980 struct ieee80211_conf
*conf
= &hw
->conf
;
3983 mutex_lock(&ar
->conf_mutex
);
3985 if (changed
& IEEE80211_CONF_CHANGE_PS
)
3986 ath10k_config_ps(ar
);
3988 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
3989 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
3990 ret
= ath10k_monitor_recalc(ar
);
3992 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
3995 mutex_unlock(&ar
->conf_mutex
);
3999 static u32
get_nss_from_chainmask(u16 chain_mask
)
4001 if ((chain_mask
& 0x15) == 0x15)
4003 else if ((chain_mask
& 0x7) == 0x7)
4005 else if ((chain_mask
& 0x3) == 0x3)
4012 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4013 * because we will send mgmt frames without CCK. This requirement
4014 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4017 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
4018 struct ieee80211_vif
*vif
)
4020 struct ath10k
*ar
= hw
->priv
;
4021 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4022 enum wmi_sta_powersave_param param
;
4029 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
4031 mutex_lock(&ar
->conf_mutex
);
4033 memset(arvif
, 0, sizeof(*arvif
));
4038 INIT_LIST_HEAD(&arvif
->list
);
4039 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
4040 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
4041 ath10k_mac_vif_sta_connection_loss_work
);
4043 if (ar
->free_vdev_map
== 0) {
4044 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
4048 bit
= __ffs64(ar
->free_vdev_map
);
4050 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
4051 bit
, ar
->free_vdev_map
);
4053 arvif
->vdev_id
= bit
;
4054 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
4056 switch (vif
->type
) {
4057 case NL80211_IFTYPE_P2P_DEVICE
:
4058 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4059 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
4061 case NL80211_IFTYPE_UNSPECIFIED
:
4062 case NL80211_IFTYPE_STATION
:
4063 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4065 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
4067 case NL80211_IFTYPE_ADHOC
:
4068 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
4070 case NL80211_IFTYPE_AP
:
4071 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
4074 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
4076 case NL80211_IFTYPE_MONITOR
:
4077 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
4084 /* Using vdev_id as queue number will make it very easy to do per-vif
4085 * tx queue locking. This shouldn't wrap due to interface combinations
4086 * but do a modulo for correctness sake and prevent using offchannel tx
4087 * queues for regular vif tx.
4089 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4090 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
4091 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4093 /* Some firmware revisions don't wait for beacon tx completion before
4094 * sending another SWBA event. This could lead to hardware using old
4095 * (freed) beacon data in some cases, e.g. tx credit starvation
4096 * combined with missed TBTT. This is very very rare.
4098 * On non-IOMMU-enabled hosts this could be a possible security issue
4099 * because hw could beacon some random data on the air. On
4100 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4101 * device would crash.
4103 * Since there are no beacon tx completions (implicit nor explicit)
4104 * propagated to host the only workaround for this is to allocate a
4105 * DMA-coherent buffer for a lifetime of a vif and use it for all
4106 * beacon tx commands. Worst case for this approach is some beacons may
4107 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4109 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
4110 vif
->type
== NL80211_IFTYPE_AP
) {
4111 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
4112 IEEE80211_MAX_FRAME_LEN
,
4113 &arvif
->beacon_paddr
,
4115 if (!arvif
->beacon_buf
) {
4117 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
4123 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4124 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
4125 arvif
->beacon_buf
? "single-buf" : "per-skb");
4127 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
4128 arvif
->vdev_subtype
, vif
->addr
);
4130 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
4131 arvif
->vdev_id
, ret
);
4135 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
4136 list_add(&arvif
->list
, &ar
->arvifs
);
4138 /* It makes no sense to have firmware do keepalives. mac80211 already
4139 * takes care of this with idle connection polling.
4141 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
4143 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
4144 arvif
->vdev_id
, ret
);
4145 goto err_vdev_delete
;
4148 arvif
->def_wep_key_idx
= -1;
4150 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
4151 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4152 ATH10K_HW_TXRX_NATIVE_WIFI
);
4153 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4154 if (ret
&& ret
!= -EOPNOTSUPP
) {
4155 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
4156 arvif
->vdev_id
, ret
);
4157 goto err_vdev_delete
;
4160 if (ar
->cfg_tx_chainmask
) {
4161 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4163 vdev_param
= ar
->wmi
.vdev_param
->nss
;
4164 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4167 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4168 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
4170 goto err_vdev_delete
;
4174 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4175 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4176 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
,
4177 WMI_PEER_TYPE_DEFAULT
);
4179 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
4180 arvif
->vdev_id
, ret
);
4181 goto err_vdev_delete
;
4185 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
4186 ret
= ath10k_mac_set_kickout(arvif
);
4188 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
4189 arvif
->vdev_id
, ret
);
4190 goto err_peer_delete
;
4194 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
4195 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
4196 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4197 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4200 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
4201 arvif
->vdev_id
, ret
);
4202 goto err_peer_delete
;
4205 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4207 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4208 arvif
->vdev_id
, ret
);
4209 goto err_peer_delete
;
4212 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4214 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4215 arvif
->vdev_id
, ret
);
4216 goto err_peer_delete
;
4220 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
4222 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
4223 arvif
->vdev_id
, ret
);
4224 goto err_peer_delete
;
4227 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
4229 ath10k_warn(ar
, "failed to set frag threshold for vdev %d: %d\n",
4230 arvif
->vdev_id
, ret
);
4231 goto err_peer_delete
;
4234 arvif
->txpower
= vif
->bss_conf
.txpower
;
4235 ret
= ath10k_mac_txpower_recalc(ar
);
4237 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4238 goto err_peer_delete
;
4241 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4242 ar
->monitor_arvif
= arvif
;
4243 ret
= ath10k_monitor_recalc(ar
);
4245 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4246 goto err_peer_delete
;
4250 mutex_unlock(&ar
->conf_mutex
);
4254 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4255 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
)
4256 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
4259 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4260 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4261 list_del(&arvif
->list
);
4264 if (arvif
->beacon_buf
) {
4265 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
4266 arvif
->beacon_buf
, arvif
->beacon_paddr
);
4267 arvif
->beacon_buf
= NULL
;
4270 mutex_unlock(&ar
->conf_mutex
);
4275 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
4279 for (i
= 0; i
< BITS_PER_LONG
; i
++)
4280 ath10k_mac_vif_tx_unlock(arvif
, i
);
4283 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
4284 struct ieee80211_vif
*vif
)
4286 struct ath10k
*ar
= hw
->priv
;
4287 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4290 cancel_work_sync(&arvif
->ap_csa_work
);
4291 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
4293 mutex_lock(&ar
->conf_mutex
);
4295 spin_lock_bh(&ar
->data_lock
);
4296 ath10k_mac_vif_beacon_cleanup(arvif
);
4297 spin_unlock_bh(&ar
->data_lock
);
4299 ret
= ath10k_spectral_vif_stop(arvif
);
4301 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
4302 arvif
->vdev_id
, ret
);
4304 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4305 list_del(&arvif
->list
);
4307 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4308 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4309 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
4312 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4313 arvif
->vdev_id
, ret
);
4315 kfree(arvif
->u
.ap
.noa_data
);
4318 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
4321 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4323 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
4324 arvif
->vdev_id
, ret
);
4326 /* Some firmware revisions don't notify host about self-peer removal
4327 * until after associated vdev is deleted.
4329 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4330 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4331 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
4334 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
4335 arvif
->vdev_id
, ret
);
4337 spin_lock_bh(&ar
->data_lock
);
4339 spin_unlock_bh(&ar
->data_lock
);
4342 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
4344 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4345 ar
->monitor_arvif
= NULL
;
4346 ret
= ath10k_monitor_recalc(ar
);
4348 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4351 spin_lock_bh(&ar
->htt
.tx_lock
);
4352 ath10k_mac_vif_tx_unlock_all(arvif
);
4353 spin_unlock_bh(&ar
->htt
.tx_lock
);
4355 mutex_unlock(&ar
->conf_mutex
);
4359 * FIXME: Has to be verified.
4361 #define SUPPORTED_FILTERS \
4362 (FIF_PROMISC_IN_BSS | \
4367 FIF_BCN_PRBRESP_PROMISC | \
4371 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
4372 unsigned int changed_flags
,
4373 unsigned int *total_flags
,
4376 struct ath10k
*ar
= hw
->priv
;
4379 mutex_lock(&ar
->conf_mutex
);
4381 changed_flags
&= SUPPORTED_FILTERS
;
4382 *total_flags
&= SUPPORTED_FILTERS
;
4383 ar
->filter_flags
= *total_flags
;
4385 ret
= ath10k_monitor_recalc(ar
);
4387 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
4389 mutex_unlock(&ar
->conf_mutex
);
4392 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
4393 struct ieee80211_vif
*vif
,
4394 struct ieee80211_bss_conf
*info
,
4397 struct ath10k
*ar
= hw
->priv
;
4398 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4400 u32 vdev_param
, pdev_param
, slottime
, preamble
;
4402 mutex_lock(&ar
->conf_mutex
);
4404 if (changed
& BSS_CHANGED_IBSS
)
4405 ath10k_control_ibss(arvif
, info
, vif
->addr
);
4407 if (changed
& BSS_CHANGED_BEACON_INT
) {
4408 arvif
->beacon_interval
= info
->beacon_int
;
4409 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
4410 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4411 arvif
->beacon_interval
);
4412 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4413 "mac vdev %d beacon_interval %d\n",
4414 arvif
->vdev_id
, arvif
->beacon_interval
);
4417 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
4418 arvif
->vdev_id
, ret
);
4421 if (changed
& BSS_CHANGED_BEACON
) {
4422 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4423 "vdev %d set beacon tx mode to staggered\n",
4426 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
4427 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
4428 WMI_BEACON_STAGGERED_MODE
);
4430 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
4431 arvif
->vdev_id
, ret
);
4433 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
4435 ath10k_warn(ar
, "failed to update beacon template: %d\n",
4439 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
4440 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
4442 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
4443 arvif
->vdev_id
, ret
);
4446 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
4447 arvif
->dtim_period
= info
->dtim_period
;
4449 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4450 "mac vdev %d dtim_period %d\n",
4451 arvif
->vdev_id
, arvif
->dtim_period
);
4453 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
4454 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4455 arvif
->dtim_period
);
4457 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
4458 arvif
->vdev_id
, ret
);
4461 if (changed
& BSS_CHANGED_SSID
&&
4462 vif
->type
== NL80211_IFTYPE_AP
) {
4463 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
4465 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
4466 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
4469 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
4470 ether_addr_copy(arvif
->bssid
, info
->bssid
);
4472 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4473 ath10k_control_beaconing(arvif
, info
);
4475 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
4476 arvif
->use_cts_prot
= info
->use_cts_prot
;
4477 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
4478 arvif
->vdev_id
, info
->use_cts_prot
);
4480 ret
= ath10k_recalc_rtscts_prot(arvif
);
4482 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4483 arvif
->vdev_id
, ret
);
4485 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
4486 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4487 info
->use_cts_prot
? 1 : 0);
4489 ath10k_warn(ar
, "failed to set protection mode %d on vdev %i: %d\n",
4490 info
->use_cts_prot
, arvif
->vdev_id
, ret
);
4493 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4494 if (info
->use_short_slot
)
4495 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
4498 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
4500 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
4501 arvif
->vdev_id
, slottime
);
4503 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
4504 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4507 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
4508 arvif
->vdev_id
, ret
);
4511 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4512 if (info
->use_short_preamble
)
4513 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
4515 preamble
= WMI_VDEV_PREAMBLE_LONG
;
4517 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4518 "mac vdev %d preamble %dn",
4519 arvif
->vdev_id
, preamble
);
4521 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
4522 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4525 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
4526 arvif
->vdev_id
, ret
);
4529 if (changed
& BSS_CHANGED_ASSOC
) {
4531 /* Workaround: Make sure monitor vdev is not running
4532 * when associating to prevent some firmware revisions
4533 * (e.g. 10.1 and 10.2) from crashing.
4535 if (ar
->monitor_started
)
4536 ath10k_monitor_stop(ar
);
4537 ath10k_bss_assoc(hw
, vif
, info
);
4538 ath10k_monitor_recalc(ar
);
4540 ath10k_bss_disassoc(hw
, vif
);
4544 if (changed
& BSS_CHANGED_TXPOWER
) {
4545 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
4546 arvif
->vdev_id
, info
->txpower
);
4548 arvif
->txpower
= info
->txpower
;
4549 ret
= ath10k_mac_txpower_recalc(ar
);
4551 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4554 if (changed
& BSS_CHANGED_PS
) {
4555 arvif
->ps
= vif
->bss_conf
.ps
;
4557 ret
= ath10k_config_ps(ar
);
4559 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
4560 arvif
->vdev_id
, ret
);
4563 mutex_unlock(&ar
->conf_mutex
);
4566 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
4567 struct ieee80211_vif
*vif
,
4568 struct ieee80211_scan_request
*hw_req
)
4570 struct ath10k
*ar
= hw
->priv
;
4571 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4572 struct cfg80211_scan_request
*req
= &hw_req
->req
;
4573 struct wmi_start_scan_arg arg
;
4577 mutex_lock(&ar
->conf_mutex
);
4579 spin_lock_bh(&ar
->data_lock
);
4580 switch (ar
->scan
.state
) {
4581 case ATH10K_SCAN_IDLE
:
4582 reinit_completion(&ar
->scan
.started
);
4583 reinit_completion(&ar
->scan
.completed
);
4584 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4585 ar
->scan
.is_roc
= false;
4586 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4589 case ATH10K_SCAN_STARTING
:
4590 case ATH10K_SCAN_RUNNING
:
4591 case ATH10K_SCAN_ABORTING
:
4595 spin_unlock_bh(&ar
->data_lock
);
4600 memset(&arg
, 0, sizeof(arg
));
4601 ath10k_wmi_start_scan_init(ar
, &arg
);
4602 arg
.vdev_id
= arvif
->vdev_id
;
4603 arg
.scan_id
= ATH10K_SCAN_ID
;
4606 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
4609 arg
.ie_len
= req
->ie_len
;
4610 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
4614 arg
.n_ssids
= req
->n_ssids
;
4615 for (i
= 0; i
< arg
.n_ssids
; i
++) {
4616 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
4617 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
4620 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4623 if (req
->n_channels
) {
4624 arg
.n_channels
= req
->n_channels
;
4625 for (i
= 0; i
< arg
.n_channels
; i
++)
4626 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
4629 ret
= ath10k_start_scan(ar
, &arg
);
4631 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
4632 spin_lock_bh(&ar
->data_lock
);
4633 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4634 spin_unlock_bh(&ar
->data_lock
);
4638 mutex_unlock(&ar
->conf_mutex
);
4642 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
4643 struct ieee80211_vif
*vif
)
4645 struct ath10k
*ar
= hw
->priv
;
4647 mutex_lock(&ar
->conf_mutex
);
4648 ath10k_scan_abort(ar
);
4649 mutex_unlock(&ar
->conf_mutex
);
4651 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4654 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
4655 struct ath10k_vif
*arvif
,
4656 enum set_key_cmd cmd
,
4657 struct ieee80211_key_conf
*key
)
4659 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
4662 /* 10.1 firmware branch requires default key index to be set to group
4663 * key index after installing it. Otherwise FW/HW Txes corrupted
4664 * frames with multi-vif APs. This is not required for main firmware
4665 * branch (e.g. 636).
4667 * FIXME: This has been tested only in AP. It remains unknown if this
4668 * is required for multi-vif STA interfaces on 10.1 */
4670 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
4673 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
4676 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
4679 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4685 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4688 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
4689 arvif
->vdev_id
, ret
);
4692 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
4693 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
4694 struct ieee80211_key_conf
*key
)
4696 struct ath10k
*ar
= hw
->priv
;
4697 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4698 struct ath10k_peer
*peer
;
4699 const u8
*peer_addr
;
4700 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
4701 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
4705 /* this one needs to be done in software */
4706 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
4709 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
4712 mutex_lock(&ar
->conf_mutex
);
4715 peer_addr
= sta
->addr
;
4716 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
4717 peer_addr
= vif
->bss_conf
.bssid
;
4719 peer_addr
= vif
->addr
;
4721 key
->hw_key_idx
= key
->keyidx
;
4725 arvif
->wep_keys
[key
->keyidx
] = key
;
4727 arvif
->wep_keys
[key
->keyidx
] = NULL
;
4730 /* the peer should not disappear in mid-way (unless FW goes awry) since
4731 * we already hold conf_mutex. we just make sure its there now. */
4732 spin_lock_bh(&ar
->data_lock
);
4733 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4734 spin_unlock_bh(&ar
->data_lock
);
4737 if (cmd
== SET_KEY
) {
4738 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
4743 /* if the peer doesn't exist there is no key to disable
4749 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4750 flags
|= WMI_KEY_PAIRWISE
;
4752 flags
|= WMI_KEY_GROUP
;
4755 if (cmd
== DISABLE_KEY
)
4756 ath10k_clear_vdev_key(arvif
, key
);
4758 /* When WEP keys are uploaded it's possible that there are
4759 * stations associated already (e.g. when merging) without any
4760 * keys. Static WEP needs an explicit per-peer key upload.
4762 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
4764 ath10k_mac_vif_update_wep_key(arvif
, key
);
4766 /* 802.1x never sets the def_wep_key_idx so each set_key()
4767 * call changes default tx key.
4769 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4770 * after first set_key().
4772 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
4773 flags
|= WMI_KEY_TX_USAGE
;
4775 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4776 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4777 * mode and associated stations in AP/IBSS.
4779 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4780 * work fine when mapped directly from mac80211.
4782 * Note: When installing first static WEP groupwise key (which
4783 * should be pairwise) def_wep_key_idx isn't known yet (it's
4784 * equal to -1). Since .set_default_unicast_key is called only
4785 * for static WEP it's used to re-upload the key as pairwise.
4787 if (arvif
->def_wep_key_idx
>= 0 &&
4788 memcmp(peer_addr
, arvif
->vif
->addr
, ETH_ALEN
)) {
4789 flags
&= ~WMI_KEY_GROUP
;
4790 flags
|= WMI_KEY_PAIRWISE
;
4794 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
4796 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
4797 arvif
->vdev_id
, peer_addr
, ret
);
4801 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
4803 spin_lock_bh(&ar
->data_lock
);
4804 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4805 if (peer
&& cmd
== SET_KEY
)
4806 peer
->keys
[key
->keyidx
] = key
;
4807 else if (peer
&& cmd
== DISABLE_KEY
)
4808 peer
->keys
[key
->keyidx
] = NULL
;
4809 else if (peer
== NULL
)
4810 /* impossible unless FW goes crazy */
4811 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
4812 spin_unlock_bh(&ar
->data_lock
);
4815 mutex_unlock(&ar
->conf_mutex
);
4819 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
4820 struct ieee80211_vif
*vif
,
4823 struct ath10k
*ar
= hw
->priv
;
4824 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4827 mutex_lock(&arvif
->ar
->conf_mutex
);
4829 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
4832 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
4833 arvif
->vdev_id
, keyidx
);
4835 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
4837 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
4841 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
4847 arvif
->def_wep_key_idx
= keyidx
;
4849 ret
= ath10k_mac_vif_sta_fix_wep_key(arvif
);
4851 ath10k_warn(ar
, "failed to fix sta wep key on vdev %i: %d\n",
4852 arvif
->vdev_id
, ret
);
4857 mutex_unlock(&arvif
->ar
->conf_mutex
);
4860 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
4863 struct ath10k_vif
*arvif
;
4864 struct ath10k_sta
*arsta
;
4865 struct ieee80211_sta
*sta
;
4866 u32 changed
, bw
, nss
, smps
;
4869 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
4870 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
4871 arvif
= arsta
->arvif
;
4874 spin_lock_bh(&ar
->data_lock
);
4876 changed
= arsta
->changed
;
4883 spin_unlock_bh(&ar
->data_lock
);
4885 mutex_lock(&ar
->conf_mutex
);
4887 if (changed
& IEEE80211_RC_BW_CHANGED
) {
4888 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
4891 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4892 WMI_PEER_CHAN_WIDTH
, bw
);
4894 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
4895 sta
->addr
, bw
, err
);
4898 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
4899 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
4902 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4905 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
4906 sta
->addr
, nss
, err
);
4909 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
4910 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
4913 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
4914 WMI_PEER_SMPS_STATE
, smps
);
4916 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
4917 sta
->addr
, smps
, err
);
4920 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
||
4921 changed
& IEEE80211_RC_NSS_CHANGED
) {
4922 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates/nss\n",
4925 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
4927 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
4931 mutex_unlock(&ar
->conf_mutex
);
4934 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
4935 struct ieee80211_sta
*sta
)
4937 struct ath10k
*ar
= arvif
->ar
;
4939 lockdep_assert_held(&ar
->conf_mutex
);
4941 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
4944 if (ar
->num_stations
>= ar
->max_num_stations
)
4952 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
4953 struct ieee80211_sta
*sta
)
4955 struct ath10k
*ar
= arvif
->ar
;
4957 lockdep_assert_held(&ar
->conf_mutex
);
4959 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
4965 struct ath10k_mac_tdls_iter_data
{
4966 u32 num_tdls_stations
;
4967 struct ieee80211_vif
*curr_vif
;
4970 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
4971 struct ieee80211_sta
*sta
)
4973 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
4974 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4975 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
4977 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
4978 iter_data
->num_tdls_stations
++;
4981 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
4982 struct ieee80211_vif
*vif
)
4984 struct ath10k_mac_tdls_iter_data data
= {};
4986 data
.curr_vif
= vif
;
4988 ieee80211_iterate_stations_atomic(hw
,
4989 ath10k_mac_tdls_vif_stations_count_iter
,
4991 return data
.num_tdls_stations
;
4994 static void ath10k_mac_tdls_vifs_count_iter(void *data
, u8
*mac
,
4995 struct ieee80211_vif
*vif
)
4997 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4998 int *num_tdls_vifs
= data
;
5000 if (vif
->type
!= NL80211_IFTYPE_STATION
)
5003 if (ath10k_mac_tdls_vif_stations_count(arvif
->ar
->hw
, vif
) > 0)
5007 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw
*hw
)
5009 int num_tdls_vifs
= 0;
5011 ieee80211_iterate_active_interfaces_atomic(hw
,
5012 IEEE80211_IFACE_ITER_NORMAL
,
5013 ath10k_mac_tdls_vifs_count_iter
,
5015 return num_tdls_vifs
;
5018 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
5019 struct ieee80211_vif
*vif
,
5020 struct ieee80211_sta
*sta
,
5021 enum ieee80211_sta_state old_state
,
5022 enum ieee80211_sta_state new_state
)
5024 struct ath10k
*ar
= hw
->priv
;
5025 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5026 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5029 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5030 new_state
== IEEE80211_STA_NONE
) {
5031 memset(arsta
, 0, sizeof(*arsta
));
5032 arsta
->arvif
= arvif
;
5033 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
5036 /* cancel must be done outside the mutex to avoid deadlock */
5037 if ((old_state
== IEEE80211_STA_NONE
&&
5038 new_state
== IEEE80211_STA_NOTEXIST
))
5039 cancel_work_sync(&arsta
->update_wk
);
5041 mutex_lock(&ar
->conf_mutex
);
5043 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5044 new_state
== IEEE80211_STA_NONE
) {
5046 * New station addition.
5048 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
5049 u32 num_tdls_stations
;
5052 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5053 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5054 arvif
->vdev_id
, sta
->addr
,
5055 ar
->num_stations
+ 1, ar
->max_num_stations
,
5056 ar
->num_peers
+ 1, ar
->max_num_peers
);
5058 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
5060 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
5061 ar
->max_num_stations
);
5066 peer_type
= WMI_PEER_TYPE_TDLS
;
5068 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
,
5071 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5072 sta
->addr
, arvif
->vdev_id
, ret
);
5073 ath10k_mac_dec_num_stations(arvif
, sta
);
5080 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
5081 num_tdls_vifs
= ath10k_mac_tdls_vifs_count(hw
);
5083 if (num_tdls_vifs
>= ar
->max_num_tdls_vdevs
&&
5084 num_tdls_stations
== 0) {
5085 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5086 arvif
->vdev_id
, ar
->max_num_tdls_vdevs
);
5087 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5088 ath10k_mac_dec_num_stations(arvif
, sta
);
5093 if (num_tdls_stations
== 0) {
5094 /* This is the first tdls peer in current vif */
5095 enum wmi_tdls_state state
= WMI_TDLS_ENABLE_ACTIVE
;
5097 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5100 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5101 arvif
->vdev_id
, ret
);
5102 ath10k_peer_delete(ar
, arvif
->vdev_id
,
5104 ath10k_mac_dec_num_stations(arvif
, sta
);
5109 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5110 WMI_TDLS_PEER_STATE_PEERING
);
5113 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5114 sta
->addr
, arvif
->vdev_id
, ret
);
5115 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5116 ath10k_mac_dec_num_stations(arvif
, sta
);
5118 if (num_tdls_stations
!= 0)
5120 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5123 } else if ((old_state
== IEEE80211_STA_NONE
&&
5124 new_state
== IEEE80211_STA_NOTEXIST
)) {
5126 * Existing station deletion.
5128 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5129 "mac vdev %d peer delete %pM (sta gone)\n",
5130 arvif
->vdev_id
, sta
->addr
);
5132 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5134 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
5135 sta
->addr
, arvif
->vdev_id
, ret
);
5137 ath10k_mac_dec_num_stations(arvif
, sta
);
5142 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
5145 /* This was the last tdls peer in current vif */
5146 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5149 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5150 arvif
->vdev_id
, ret
);
5152 } else if (old_state
== IEEE80211_STA_AUTH
&&
5153 new_state
== IEEE80211_STA_ASSOC
&&
5154 (vif
->type
== NL80211_IFTYPE_AP
||
5155 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5159 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
5162 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5164 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
5165 sta
->addr
, arvif
->vdev_id
, ret
);
5166 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5167 new_state
== IEEE80211_STA_AUTHORIZED
&&
5170 * Tdls station authorized.
5172 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
5175 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5177 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
5178 sta
->addr
, arvif
->vdev_id
, ret
);
5182 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5183 WMI_TDLS_PEER_STATE_CONNECTED
);
5185 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
5186 sta
->addr
, arvif
->vdev_id
, ret
);
5187 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5188 new_state
== IEEE80211_STA_AUTH
&&
5189 (vif
->type
== NL80211_IFTYPE_AP
||
5190 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5194 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
5197 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
5199 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
5200 sta
->addr
, arvif
->vdev_id
, ret
);
5203 mutex_unlock(&ar
->conf_mutex
);
5207 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
5208 u16 ac
, bool enable
)
5210 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5211 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
5212 u32 prio
= 0, acc
= 0;
5216 lockdep_assert_held(&ar
->conf_mutex
);
5218 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
5222 case IEEE80211_AC_VO
:
5223 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
5224 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
5228 case IEEE80211_AC_VI
:
5229 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
5230 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
5234 case IEEE80211_AC_BE
:
5235 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
5236 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
5240 case IEEE80211_AC_BK
:
5241 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
5242 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
5249 arvif
->u
.sta
.uapsd
|= value
;
5251 arvif
->u
.sta
.uapsd
&= ~value
;
5253 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5254 WMI_STA_PS_PARAM_UAPSD
,
5255 arvif
->u
.sta
.uapsd
);
5257 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
5261 if (arvif
->u
.sta
.uapsd
)
5262 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
5264 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5266 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5267 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
5270 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
5272 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5274 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5275 arvif
->vdev_id
, ret
);
5279 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5281 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5282 arvif
->vdev_id
, ret
);
5286 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
5287 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
5288 /* Only userspace can make an educated decision when to send
5289 * trigger frame. The following effectively disables u-UAPSD
5290 * autotrigger in firmware (which is enabled by default
5291 * provided the autotrigger service is available).
5295 arg
.user_priority
= prio
;
5296 arg
.service_interval
= 0;
5297 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5298 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5300 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
5301 arvif
->bssid
, &arg
, 1);
5303 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
5313 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
5314 struct ieee80211_vif
*vif
, u16 ac
,
5315 const struct ieee80211_tx_queue_params
*params
)
5317 struct ath10k
*ar
= hw
->priv
;
5318 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5319 struct wmi_wmm_params_arg
*p
= NULL
;
5322 mutex_lock(&ar
->conf_mutex
);
5325 case IEEE80211_AC_VO
:
5326 p
= &arvif
->wmm_params
.ac_vo
;
5328 case IEEE80211_AC_VI
:
5329 p
= &arvif
->wmm_params
.ac_vi
;
5331 case IEEE80211_AC_BE
:
5332 p
= &arvif
->wmm_params
.ac_be
;
5334 case IEEE80211_AC_BK
:
5335 p
= &arvif
->wmm_params
.ac_bk
;
5344 p
->cwmin
= params
->cw_min
;
5345 p
->cwmax
= params
->cw_max
;
5346 p
->aifs
= params
->aifs
;
5349 * The channel time duration programmed in the HW is in absolute
5350 * microseconds, while mac80211 gives the txop in units of
5353 p
->txop
= params
->txop
* 32;
5355 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
5356 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
5357 &arvif
->wmm_params
);
5359 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
5360 arvif
->vdev_id
, ret
);
5364 /* This won't work well with multi-interface cases but it's
5365 * better than nothing.
5367 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
5369 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
5374 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
5376 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
5379 mutex_unlock(&ar
->conf_mutex
);
5383 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5385 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
5386 struct ieee80211_vif
*vif
,
5387 struct ieee80211_channel
*chan
,
5389 enum ieee80211_roc_type type
)
5391 struct ath10k
*ar
= hw
->priv
;
5392 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5393 struct wmi_start_scan_arg arg
;
5396 mutex_lock(&ar
->conf_mutex
);
5398 spin_lock_bh(&ar
->data_lock
);
5399 switch (ar
->scan
.state
) {
5400 case ATH10K_SCAN_IDLE
:
5401 reinit_completion(&ar
->scan
.started
);
5402 reinit_completion(&ar
->scan
.completed
);
5403 reinit_completion(&ar
->scan
.on_channel
);
5404 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
5405 ar
->scan
.is_roc
= true;
5406 ar
->scan
.vdev_id
= arvif
->vdev_id
;
5407 ar
->scan
.roc_freq
= chan
->center_freq
;
5410 case ATH10K_SCAN_STARTING
:
5411 case ATH10K_SCAN_RUNNING
:
5412 case ATH10K_SCAN_ABORTING
:
5416 spin_unlock_bh(&ar
->data_lock
);
5421 duration
= max(duration
, WMI_SCAN_CHAN_MIN_TIME_MSEC
);
5423 memset(&arg
, 0, sizeof(arg
));
5424 ath10k_wmi_start_scan_init(ar
, &arg
);
5425 arg
.vdev_id
= arvif
->vdev_id
;
5426 arg
.scan_id
= ATH10K_SCAN_ID
;
5428 arg
.channels
[0] = chan
->center_freq
;
5429 arg
.dwell_time_active
= duration
;
5430 arg
.dwell_time_passive
= duration
;
5431 arg
.max_scan_time
= 2 * duration
;
5432 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
5433 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
5435 ret
= ath10k_start_scan(ar
, &arg
);
5437 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
5438 spin_lock_bh(&ar
->data_lock
);
5439 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
5440 spin_unlock_bh(&ar
->data_lock
);
5444 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
5446 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
5448 ret
= ath10k_scan_stop(ar
);
5450 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
5458 mutex_unlock(&ar
->conf_mutex
);
5462 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
5464 struct ath10k
*ar
= hw
->priv
;
5466 mutex_lock(&ar
->conf_mutex
);
5467 ath10k_scan_abort(ar
);
5468 mutex_unlock(&ar
->conf_mutex
);
5470 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5476 * Both RTS and Fragmentation threshold are interface-specific
5477 * in ath10k, but device-specific in mac80211.
5480 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5482 struct ath10k
*ar
= hw
->priv
;
5483 struct ath10k_vif
*arvif
;
5486 mutex_lock(&ar
->conf_mutex
);
5487 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5488 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
5489 arvif
->vdev_id
, value
);
5491 ret
= ath10k_mac_set_rts(arvif
, value
);
5493 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5494 arvif
->vdev_id
, ret
);
5498 mutex_unlock(&ar
->conf_mutex
);
5503 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5504 u32 queues
, bool drop
)
5506 struct ath10k
*ar
= hw
->priv
;
5510 /* mac80211 doesn't care if we really xmit queued frames or not
5511 * we'll collect those frames either way if we stop/delete vdevs */
5515 mutex_lock(&ar
->conf_mutex
);
5517 if (ar
->state
== ATH10K_STATE_WEDGED
)
5520 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
5523 spin_lock_bh(&ar
->htt
.tx_lock
);
5524 empty
= (ar
->htt
.num_pending_tx
== 0);
5525 spin_unlock_bh(&ar
->htt
.tx_lock
);
5527 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
5528 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
5532 }), ATH10K_FLUSH_TIMEOUT_HZ
);
5534 if (ret
<= 0 || skip
)
5535 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
5536 skip
, ar
->state
, ret
);
5539 mutex_unlock(&ar
->conf_mutex
);
5542 /* TODO: Implement this function properly
5543 * For now it is needed to reply to Probe Requests in IBSS mode.
5544 * Propably we need this information from FW.
5546 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
5551 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
5552 enum ieee80211_reconfig_type reconfig_type
)
5554 struct ath10k
*ar
= hw
->priv
;
5556 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
5559 mutex_lock(&ar
->conf_mutex
);
5561 /* If device failed to restart it will be in a different state, e.g.
5562 * ATH10K_STATE_WEDGED */
5563 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
5564 ath10k_info(ar
, "device successfully recovered\n");
5565 ar
->state
= ATH10K_STATE_ON
;
5566 ieee80211_wake_queues(ar
->hw
);
5569 mutex_unlock(&ar
->conf_mutex
);
5572 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5573 struct survey_info
*survey
)
5575 struct ath10k
*ar
= hw
->priv
;
5576 struct ieee80211_supported_band
*sband
;
5577 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
5580 mutex_lock(&ar
->conf_mutex
);
5582 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5583 if (sband
&& idx
>= sband
->n_channels
) {
5584 idx
-= sband
->n_channels
;
5589 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5591 if (!sband
|| idx
>= sband
->n_channels
) {
5596 spin_lock_bh(&ar
->data_lock
);
5597 memcpy(survey
, ar_survey
, sizeof(*survey
));
5598 spin_unlock_bh(&ar
->data_lock
);
5600 survey
->channel
= &sband
->channels
[idx
];
5602 if (ar
->rx_channel
== survey
->channel
)
5603 survey
->filled
|= SURVEY_INFO_IN_USE
;
5606 mutex_unlock(&ar
->conf_mutex
);
5611 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
5612 enum ieee80211_band band
,
5613 const struct cfg80211_bitrate_mask
*mask
)
5618 num_rates
+= hweight32(mask
->control
[band
].legacy
);
5620 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
5621 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
5623 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++)
5624 num_rates
+= hweight16(mask
->control
[band
].vht_mcs
[i
]);
5626 return num_rates
== 1;
5630 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
5631 enum ieee80211_band band
,
5632 const struct cfg80211_bitrate_mask
*mask
,
5635 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
5636 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
5638 u8 vht_nss_mask
= 0;
5641 if (mask
->control
[band
].legacy
)
5644 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
5645 if (mask
->control
[band
].ht_mcs
[i
] == 0)
5647 else if (mask
->control
[band
].ht_mcs
[i
] ==
5648 sband
->ht_cap
.mcs
.rx_mask
[i
])
5649 ht_nss_mask
|= BIT(i
);
5654 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
5655 if (mask
->control
[band
].vht_mcs
[i
] == 0)
5657 else if (mask
->control
[band
].vht_mcs
[i
] ==
5658 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
5659 vht_nss_mask
|= BIT(i
);
5664 if (ht_nss_mask
!= vht_nss_mask
)
5667 if (ht_nss_mask
== 0)
5670 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
5673 *nss
= fls(ht_nss_mask
);
5679 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
5680 enum ieee80211_band band
,
5681 const struct cfg80211_bitrate_mask
*mask
,
5684 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
5691 if (hweight32(mask
->control
[band
].legacy
) == 1) {
5692 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
5694 hw_rate
= sband
->bitrates
[rate_idx
].hw_value
;
5695 bitrate
= sband
->bitrates
[rate_idx
].bitrate
;
5697 if (ath10k_mac_bitrate_is_cck(bitrate
))
5698 preamble
= WMI_RATE_PREAMBLE_CCK
;
5700 preamble
= WMI_RATE_PREAMBLE_OFDM
;
5703 *rate
= preamble
<< 6 |
5710 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
5711 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
5713 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
5715 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
5721 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
5722 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
5724 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
5726 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
5735 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
5736 u8 rate
, u8 nss
, u8 sgi
)
5738 struct ath10k
*ar
= arvif
->ar
;
5742 lockdep_assert_held(&ar
->conf_mutex
);
5744 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5745 arvif
->vdev_id
, rate
, nss
, sgi
);
5747 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
5748 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
5750 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
5755 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5756 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
5758 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
5762 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
5763 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
5765 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
5772 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
5773 struct ieee80211_vif
*vif
,
5774 const struct cfg80211_bitrate_mask
*mask
)
5776 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5777 struct cfg80211_chan_def def
;
5778 struct ath10k
*ar
= arvif
->ar
;
5779 enum ieee80211_band band
;
5786 if (ath10k_mac_vif_chan(vif
, &def
))
5789 band
= def
.chan
->band
;
5791 sgi
= mask
->control
[band
].gi
;
5792 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
5795 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
)) {
5796 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
5799 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
5800 arvif
->vdev_id
, ret
);
5803 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
5805 rate
= WMI_FIXED_RATE_NONE
;
5808 rate
= WMI_FIXED_RATE_NONE
;
5809 nss
= ar
->num_rf_chains
;
5812 mutex_lock(&ar
->conf_mutex
);
5814 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
);
5816 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
5817 arvif
->vdev_id
, ret
);
5822 mutex_unlock(&ar
->conf_mutex
);
5827 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
5828 struct ieee80211_vif
*vif
,
5829 struct ieee80211_sta
*sta
,
5832 struct ath10k
*ar
= hw
->priv
;
5833 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5836 spin_lock_bh(&ar
->data_lock
);
5838 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5839 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5840 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
5843 if (changed
& IEEE80211_RC_BW_CHANGED
) {
5844 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5846 switch (sta
->bandwidth
) {
5847 case IEEE80211_STA_RX_BW_20
:
5848 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5850 case IEEE80211_STA_RX_BW_40
:
5851 bw
= WMI_PEER_CHWIDTH_40MHZ
;
5853 case IEEE80211_STA_RX_BW_80
:
5854 bw
= WMI_PEER_CHWIDTH_80MHZ
;
5856 case IEEE80211_STA_RX_BW_160
:
5857 ath10k_warn(ar
, "Invalid bandwith %d in rc update for %pM\n",
5858 sta
->bandwidth
, sta
->addr
);
5859 bw
= WMI_PEER_CHWIDTH_20MHZ
;
5866 if (changed
& IEEE80211_RC_NSS_CHANGED
)
5867 arsta
->nss
= sta
->rx_nss
;
5869 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5870 smps
= WMI_PEER_SMPS_PS_NONE
;
5872 switch (sta
->smps_mode
) {
5873 case IEEE80211_SMPS_AUTOMATIC
:
5874 case IEEE80211_SMPS_OFF
:
5875 smps
= WMI_PEER_SMPS_PS_NONE
;
5877 case IEEE80211_SMPS_STATIC
:
5878 smps
= WMI_PEER_SMPS_STATIC
;
5880 case IEEE80211_SMPS_DYNAMIC
:
5881 smps
= WMI_PEER_SMPS_DYNAMIC
;
5883 case IEEE80211_SMPS_NUM_MODES
:
5884 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
5885 sta
->smps_mode
, sta
->addr
);
5886 smps
= WMI_PEER_SMPS_PS_NONE
;
5893 arsta
->changed
|= changed
;
5895 spin_unlock_bh(&ar
->data_lock
);
5897 ieee80211_queue_work(hw
, &arsta
->update_wk
);
5900 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
5903 * FIXME: Return 0 for time being. Need to figure out whether FW
5904 * has the API to fetch 64-bit local TSF
5910 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
5911 struct ieee80211_vif
*vif
,
5912 enum ieee80211_ampdu_mlme_action action
,
5913 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
5916 struct ath10k
*ar
= hw
->priv
;
5917 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5919 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
5920 arvif
->vdev_id
, sta
->addr
, tid
, action
);
5923 case IEEE80211_AMPDU_RX_START
:
5924 case IEEE80211_AMPDU_RX_STOP
:
5925 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5926 * creation/removal. Do we need to verify this?
5929 case IEEE80211_AMPDU_TX_START
:
5930 case IEEE80211_AMPDU_TX_STOP_CONT
:
5931 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
5932 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
5933 case IEEE80211_AMPDU_TX_OPERATIONAL
:
5934 /* Firmware offloads Tx aggregation entirely so deny mac80211
5935 * Tx aggregation requests.
5944 ath10k_mac_update_rx_channel(struct ath10k
*ar
)
5946 struct cfg80211_chan_def
*def
= NULL
;
5948 /* Both locks are required because ar->rx_channel is modified. This
5949 * allows readers to hold either lock.
5951 lockdep_assert_held(&ar
->conf_mutex
);
5952 lockdep_assert_held(&ar
->data_lock
);
5954 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
5955 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
5956 * ppdu on Rx may reduce performance on low-end systems. It should be
5957 * possible to make tables/hashmaps to speed the lookup up (be vary of
5958 * cpu data cache lines though regarding sizes) but to keep the initial
5959 * implementation simple and less intrusive fallback to the slow lookup
5960 * only for multi-channel cases. Single-channel cases will remain to
5961 * use the old channel derival and thus performance should not be
5965 if (ath10k_mac_num_chanctxs(ar
) == 1) {
5966 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
5967 ath10k_mac_get_any_chandef_iter
,
5969 ar
->rx_channel
= def
->chan
;
5971 ar
->rx_channel
= NULL
;
5977 ath10k_mac_chan_ctx_init(struct ath10k
*ar
,
5978 struct ath10k_chanctx
*arctx
,
5979 struct ieee80211_chanctx_conf
*conf
)
5981 lockdep_assert_held(&ar
->conf_mutex
);
5982 lockdep_assert_held(&ar
->data_lock
);
5984 memset(arctx
, 0, sizeof(*arctx
));
5986 arctx
->conf
= *conf
;
5990 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
5991 struct ieee80211_chanctx_conf
*ctx
)
5993 struct ath10k
*ar
= hw
->priv
;
5994 struct ath10k_chanctx
*arctx
= (void *)ctx
->drv_priv
;
5996 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5997 "mac chanctx add freq %hu width %d ptr %p\n",
5998 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6000 mutex_lock(&ar
->conf_mutex
);
6002 spin_lock_bh(&ar
->data_lock
);
6003 ath10k_mac_chan_ctx_init(ar
, arctx
, ctx
);
6004 ath10k_mac_update_rx_channel(ar
);
6005 spin_unlock_bh(&ar
->data_lock
);
6007 ath10k_recalc_radar_detection(ar
);
6008 ath10k_monitor_recalc(ar
);
6010 mutex_unlock(&ar
->conf_mutex
);
6016 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
6017 struct ieee80211_chanctx_conf
*ctx
)
6019 struct ath10k
*ar
= hw
->priv
;
6021 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6022 "mac chanctx remove freq %hu width %d ptr %p\n",
6023 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6025 mutex_lock(&ar
->conf_mutex
);
6027 spin_lock_bh(&ar
->data_lock
);
6028 ath10k_mac_update_rx_channel(ar
);
6029 spin_unlock_bh(&ar
->data_lock
);
6031 ath10k_recalc_radar_detection(ar
);
6032 ath10k_monitor_recalc(ar
);
6034 mutex_unlock(&ar
->conf_mutex
);
6038 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
6039 struct ieee80211_chanctx_conf
*ctx
,
6042 struct ath10k
*ar
= hw
->priv
;
6043 struct ath10k_chanctx
*arctx
= (void *)ctx
->drv_priv
;
6045 mutex_lock(&ar
->conf_mutex
);
6047 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6048 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6049 arctx
->conf
.def
.chan
->center_freq
,
6050 ctx
->def
.chan
->center_freq
,
6051 arctx
->conf
.def
.width
, ctx
->def
.width
,
6054 /* This shouldn't really happen because channel switching should use
6055 * switch_vif_chanctx().
6057 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
6060 spin_lock_bh(&ar
->data_lock
);
6062 spin_unlock_bh(&ar
->data_lock
);
6064 ath10k_recalc_radar_detection(ar
);
6066 /* FIXME: How to configure Rx chains properly? */
6068 /* No other actions are actually necessary. Firmware maintains channel
6069 * definitions per vdev internally and there's no host-side channel
6070 * context abstraction to configure, e.g. channel width.
6074 mutex_unlock(&ar
->conf_mutex
);
6078 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
6079 struct ieee80211_vif
*vif
,
6080 struct ieee80211_chanctx_conf
*ctx
)
6082 struct ath10k
*ar
= hw
->priv
;
6083 struct ath10k_chanctx
*arctx
= (void *)ctx
->drv_priv
;
6084 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6087 mutex_lock(&ar
->conf_mutex
);
6089 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6090 "mac chanctx assign ptr %p vdev_id %i\n",
6091 ctx
, arvif
->vdev_id
);
6093 if (WARN_ON(arvif
->is_started
)) {
6094 mutex_unlock(&ar
->conf_mutex
);
6098 ret
= ath10k_vdev_start(arvif
, &arctx
->conf
.def
);
6100 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
6101 arvif
->vdev_id
, vif
->addr
,
6102 arctx
->conf
.def
.chan
->center_freq
, ret
);
6106 arvif
->is_started
= true;
6108 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6109 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
6111 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
6112 arvif
->vdev_id
, ret
);
6116 arvif
->is_up
= true;
6119 mutex_unlock(&ar
->conf_mutex
);
6123 ath10k_vdev_stop(arvif
);
6124 arvif
->is_started
= false;
6127 mutex_unlock(&ar
->conf_mutex
);
6132 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
6133 struct ieee80211_vif
*vif
,
6134 struct ieee80211_chanctx_conf
*ctx
)
6136 struct ath10k
*ar
= hw
->priv
;
6137 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6140 mutex_lock(&ar
->conf_mutex
);
6142 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6143 "mac chanctx unassign ptr %p vdev_id %i\n",
6144 ctx
, arvif
->vdev_id
);
6146 WARN_ON(!arvif
->is_started
);
6148 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6149 WARN_ON(!arvif
->is_up
);
6151 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
6153 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
6154 arvif
->vdev_id
, ret
);
6156 arvif
->is_up
= false;
6159 ret
= ath10k_vdev_stop(arvif
);
6161 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
6162 arvif
->vdev_id
, ret
);
6164 arvif
->is_started
= false;
6166 mutex_unlock(&ar
->conf_mutex
);
6170 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
6171 struct ieee80211_vif_chanctx_switch
*vifs
,
6173 enum ieee80211_chanctx_switch_mode mode
)
6175 struct ath10k
*ar
= hw
->priv
;
6176 struct ath10k_vif
*arvif
;
6177 struct ath10k_chanctx
*arctx_new
, *arctx_old
;
6180 mutex_lock(&ar
->conf_mutex
);
6182 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6183 "mac chanctx switch n_vifs %d mode %d\n",
6186 spin_lock_bh(&ar
->data_lock
);
6187 for (i
= 0; i
< n_vifs
; i
++) {
6188 arvif
= ath10k_vif_to_arvif(vifs
[i
].vif
);
6189 arctx_new
= (void *)vifs
[i
].new_ctx
->drv_priv
;
6190 arctx_old
= (void *)vifs
[i
].old_ctx
->drv_priv
;
6192 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6193 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6195 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
6196 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
6197 vifs
[i
].old_ctx
->def
.width
,
6198 vifs
[i
].new_ctx
->def
.width
,
6199 arctx_old
, arctx_new
);
6201 if (mode
== CHANCTX_SWMODE_SWAP_CONTEXTS
) {
6202 ath10k_mac_chan_ctx_init(ar
, arctx_new
,
6206 arctx_new
->conf
= *vifs
[i
].new_ctx
;
6208 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6209 * yet updated chanctx_conf pointer.
6211 arctx_old
->conf
= *vifs
[i
].new_ctx
;
6213 ath10k_mac_update_rx_channel(ar
);
6214 spin_unlock_bh(&ar
->data_lock
);
6216 /* FIXME: Reconfigure only affected vifs */
6217 ath10k_mac_chan_reconfigure(ar
);
6219 mutex_unlock(&ar
->conf_mutex
);
6223 static const struct ieee80211_ops ath10k_ops
= {
6225 .start
= ath10k_start
,
6226 .stop
= ath10k_stop
,
6227 .config
= ath10k_config
,
6228 .add_interface
= ath10k_add_interface
,
6229 .remove_interface
= ath10k_remove_interface
,
6230 .configure_filter
= ath10k_configure_filter
,
6231 .bss_info_changed
= ath10k_bss_info_changed
,
6232 .hw_scan
= ath10k_hw_scan
,
6233 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
6234 .set_key
= ath10k_set_key
,
6235 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
6236 .sta_state
= ath10k_sta_state
,
6237 .conf_tx
= ath10k_conf_tx
,
6238 .remain_on_channel
= ath10k_remain_on_channel
,
6239 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
6240 .set_rts_threshold
= ath10k_set_rts_threshold
,
6241 .flush
= ath10k_flush
,
6242 .tx_last_beacon
= ath10k_tx_last_beacon
,
6243 .set_antenna
= ath10k_set_antenna
,
6244 .get_antenna
= ath10k_get_antenna
,
6245 .reconfig_complete
= ath10k_reconfig_complete
,
6246 .get_survey
= ath10k_get_survey
,
6247 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
6248 .sta_rc_update
= ath10k_sta_rc_update
,
6249 .get_tsf
= ath10k_get_tsf
,
6250 .ampdu_action
= ath10k_ampdu_action
,
6251 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
6252 .get_et_stats
= ath10k_debug_get_et_stats
,
6253 .get_et_strings
= ath10k_debug_get_et_strings
,
6254 .add_chanctx
= ath10k_mac_op_add_chanctx
,
6255 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
6256 .change_chanctx
= ath10k_mac_op_change_chanctx
,
6257 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
6258 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
6259 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
6261 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
6264 .suspend
= ath10k_wow_op_suspend
,
6265 .resume
= ath10k_wow_op_resume
,
6267 #ifdef CONFIG_MAC80211_DEBUGFS
6268 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
6272 #define CHAN2G(_channel, _freq, _flags) { \
6273 .band = IEEE80211_BAND_2GHZ, \
6274 .hw_value = (_channel), \
6275 .center_freq = (_freq), \
6276 .flags = (_flags), \
6277 .max_antenna_gain = 0, \
6281 #define CHAN5G(_channel, _freq, _flags) { \
6282 .band = IEEE80211_BAND_5GHZ, \
6283 .hw_value = (_channel), \
6284 .center_freq = (_freq), \
6285 .flags = (_flags), \
6286 .max_antenna_gain = 0, \
6290 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
6300 CHAN2G(10, 2457, 0),
6301 CHAN2G(11, 2462, 0),
6302 CHAN2G(12, 2467, 0),
6303 CHAN2G(13, 2472, 0),
6304 CHAN2G(14, 2484, 0),
6307 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
6308 CHAN5G(36, 5180, 0),
6309 CHAN5G(40, 5200, 0),
6310 CHAN5G(44, 5220, 0),
6311 CHAN5G(48, 5240, 0),
6312 CHAN5G(52, 5260, 0),
6313 CHAN5G(56, 5280, 0),
6314 CHAN5G(60, 5300, 0),
6315 CHAN5G(64, 5320, 0),
6316 CHAN5G(100, 5500, 0),
6317 CHAN5G(104, 5520, 0),
6318 CHAN5G(108, 5540, 0),
6319 CHAN5G(112, 5560, 0),
6320 CHAN5G(116, 5580, 0),
6321 CHAN5G(120, 5600, 0),
6322 CHAN5G(124, 5620, 0),
6323 CHAN5G(128, 5640, 0),
6324 CHAN5G(132, 5660, 0),
6325 CHAN5G(136, 5680, 0),
6326 CHAN5G(140, 5700, 0),
6327 CHAN5G(144, 5720, 0),
6328 CHAN5G(149, 5745, 0),
6329 CHAN5G(153, 5765, 0),
6330 CHAN5G(157, 5785, 0),
6331 CHAN5G(161, 5805, 0),
6332 CHAN5G(165, 5825, 0),
6335 struct ath10k
*ath10k_mac_create(size_t priv_size
)
6337 struct ieee80211_hw
*hw
;
6340 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
6350 void ath10k_mac_destroy(struct ath10k
*ar
)
6352 ieee80211_free_hw(ar
->hw
);
6355 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
6358 .types
= BIT(NL80211_IFTYPE_STATION
)
6359 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
6363 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
6367 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
6371 .types
= BIT(NL80211_IFTYPE_AP
)
6375 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
6378 .types
= BIT(NL80211_IFTYPE_AP
)
6382 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
6384 .limits
= ath10k_if_limits
,
6385 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
6386 .max_interfaces
= 8,
6387 .num_different_channels
= 1,
6388 .beacon_int_infra_match
= true,
6392 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
6394 .limits
= ath10k_10x_if_limits
,
6395 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
6396 .max_interfaces
= 8,
6397 .num_different_channels
= 1,
6398 .beacon_int_infra_match
= true,
6399 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6400 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
6401 BIT(NL80211_CHAN_WIDTH_20
) |
6402 BIT(NL80211_CHAN_WIDTH_40
) |
6403 BIT(NL80211_CHAN_WIDTH_80
),
6408 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
6411 .types
= BIT(NL80211_IFTYPE_STATION
) |
6412 BIT(NL80211_IFTYPE_AP
) |
6413 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6414 BIT(NL80211_IFTYPE_P2P_GO
),
6418 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
6422 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
6425 .types
= BIT(NL80211_IFTYPE_STATION
),
6429 .types
= BIT(NL80211_IFTYPE_ADHOC
),
6433 /* FIXME: This is not thouroughly tested. These combinations may over- or
6434 * underestimate hw/fw capabilities.
6436 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
6438 .limits
= ath10k_tlv_if_limit
,
6439 .num_different_channels
= 1,
6440 .max_interfaces
= 3,
6441 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
6444 .limits
= ath10k_tlv_if_limit_ibss
,
6445 .num_different_channels
= 1,
6446 .max_interfaces
= 2,
6447 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
6451 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
6453 .limits
= ath10k_tlv_if_limit
,
6454 .num_different_channels
= 2,
6455 .max_interfaces
= 3,
6456 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
6459 .limits
= ath10k_tlv_if_limit_ibss
,
6460 .num_different_channels
= 1,
6461 .max_interfaces
= 2,
6462 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
6466 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
6468 struct ieee80211_sta_vht_cap vht_cap
= {0};
6473 vht_cap
.vht_supported
= 1;
6474 vht_cap
.cap
= ar
->vht_cap_info
;
6476 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
6477 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
6478 val
= ar
->num_rf_chains
- 1;
6479 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
6480 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
6485 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
6486 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
6487 val
= ar
->num_rf_chains
- 1;
6488 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
6489 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
6495 for (i
= 0; i
< 8; i
++) {
6496 if (i
< ar
->num_rf_chains
)
6497 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
6499 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
6502 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
6503 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
6508 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
6511 struct ieee80211_sta_ht_cap ht_cap
= {0};
6513 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
6516 ht_cap
.ht_supported
= 1;
6517 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
6518 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
6519 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
6520 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
6521 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
6523 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
6524 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
6526 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
6527 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
6529 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
6532 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
6533 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
6538 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
6539 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
6541 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
6544 stbc
= ar
->ht_cap_info
;
6545 stbc
&= WMI_HT_CAP_RX_STBC
;
6546 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
6547 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
6548 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
6553 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
6554 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
6556 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
6557 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
6559 /* max AMSDU is implicitly taken from vht_cap_info */
6560 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
6561 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
6563 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
6564 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
6566 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
6571 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
6572 struct ieee80211_vif
*vif
)
6574 struct ath10k_vif_iter
*arvif_iter
= data
;
6575 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6577 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
6578 arvif_iter
->arvif
= arvif
;
6581 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
6583 struct ath10k_vif_iter arvif_iter
;
6586 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
6587 arvif_iter
.vdev_id
= vdev_id
;
6589 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
6590 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
6592 ath10k_get_arvif_iter
,
6594 if (!arvif_iter
.arvif
) {
6595 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
6599 return arvif_iter
.arvif
;
6602 int ath10k_mac_register(struct ath10k
*ar
)
6604 static const u32 cipher_suites
[] = {
6605 WLAN_CIPHER_SUITE_WEP40
,
6606 WLAN_CIPHER_SUITE_WEP104
,
6607 WLAN_CIPHER_SUITE_TKIP
,
6608 WLAN_CIPHER_SUITE_CCMP
,
6609 WLAN_CIPHER_SUITE_AES_CMAC
,
6611 struct ieee80211_supported_band
*band
;
6612 struct ieee80211_sta_vht_cap vht_cap
;
6613 struct ieee80211_sta_ht_cap ht_cap
;
6617 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
6619 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
6621 ht_cap
= ath10k_get_ht_cap(ar
);
6622 vht_cap
= ath10k_create_vht_cap(ar
);
6624 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
6625 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
6628 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
6629 channels
= kmemdup(ath10k_2ghz_channels
,
6630 sizeof(ath10k_2ghz_channels
),
6637 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
6638 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
6639 band
->channels
= channels
;
6640 band
->n_bitrates
= ath10k_g_rates_size
;
6641 band
->bitrates
= ath10k_g_rates
;
6642 band
->ht_cap
= ht_cap
;
6644 /* Enable the VHT support at 2.4 GHz */
6645 band
->vht_cap
= vht_cap
;
6647 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
6650 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
6651 channels
= kmemdup(ath10k_5ghz_channels
,
6652 sizeof(ath10k_5ghz_channels
),
6659 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
6660 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
6661 band
->channels
= channels
;
6662 band
->n_bitrates
= ath10k_a_rates_size
;
6663 band
->bitrates
= ath10k_a_rates
;
6664 band
->ht_cap
= ht_cap
;
6665 band
->vht_cap
= vht_cap
;
6666 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
6669 ar
->hw
->wiphy
->interface_modes
=
6670 BIT(NL80211_IFTYPE_STATION
) |
6671 BIT(NL80211_IFTYPE_AP
);
6673 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
6674 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
6676 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
6677 ar
->hw
->wiphy
->interface_modes
|=
6678 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
6679 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6680 BIT(NL80211_IFTYPE_P2P_GO
);
6682 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
6683 IEEE80211_HW_SUPPORTS_PS
|
6684 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
6685 IEEE80211_HW_MFP_CAPABLE
|
6686 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
6687 IEEE80211_HW_HAS_RATE_CONTROL
|
6688 IEEE80211_HW_AP_LINK_PS
|
6689 IEEE80211_HW_SPECTRUM_MGMT
|
6690 IEEE80211_HW_SW_CRYPTO_CONTROL
|
6691 IEEE80211_HW_CONNECTION_MONITOR
|
6692 IEEE80211_HW_WANT_MONITOR_VIF
|
6693 IEEE80211_HW_CHANCTX_STA_CSA
|
6694 IEEE80211_HW_QUEUE_CONTROL
;
6696 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
6698 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
6699 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
6701 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
6702 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
6703 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
6706 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
6707 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
6709 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
6710 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
6711 ar
->hw
->chanctx_data_size
= sizeof(struct ath10k_chanctx
);
6713 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
6715 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
6716 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
6718 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6719 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6720 * correct Probe Responses. This is more of a hack advert..
6722 ar
->hw
->wiphy
->probe_resp_offload
|=
6723 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
6724 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
6725 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
6728 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
))
6729 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
6731 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
6732 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
6733 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
6735 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
6736 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
6738 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
6740 ret
= ath10k_wow_init(ar
);
6742 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
6747 * on LL hardware queues are managed entirely by the FW
6748 * so we only advertise to mac we can do the queues thing
6750 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
6752 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6753 * something that vdev_ids can't reach so that we don't stop the queue
6756 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
6758 switch (ar
->wmi
.op_version
) {
6759 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
6760 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
6761 ar
->hw
->wiphy
->n_iface_combinations
=
6762 ARRAY_SIZE(ath10k_if_comb
);
6763 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
6765 case ATH10K_FW_WMI_OP_VERSION_TLV
:
6766 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
6767 ar
->hw
->wiphy
->iface_combinations
=
6768 ath10k_tlv_qcs_if_comb
;
6769 ar
->hw
->wiphy
->n_iface_combinations
=
6770 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
6772 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
6773 ar
->hw
->wiphy
->n_iface_combinations
=
6774 ARRAY_SIZE(ath10k_tlv_if_comb
);
6776 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
6778 case ATH10K_FW_WMI_OP_VERSION_10_1
:
6779 case ATH10K_FW_WMI_OP_VERSION_10_2
:
6780 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
6781 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
6782 ar
->hw
->wiphy
->n_iface_combinations
=
6783 ARRAY_SIZE(ath10k_10x_if_comb
);
6785 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
6786 case ATH10K_FW_WMI_OP_VERSION_MAX
:
6792 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
6794 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
6795 /* Init ath dfs pattern detector */
6796 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
6797 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
6800 if (!ar
->dfs_detector
)
6801 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
6804 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
6805 ath10k_reg_notifier
);
6807 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
6811 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
6812 ar
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
6814 ret
= ieee80211_register_hw(ar
->hw
);
6816 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
6820 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
6821 ret
= regulatory_hint(ar
->hw
->wiphy
,
6822 ar
->ath_common
.regulatory
.alpha2
);
6824 goto err_unregister
;
6830 ieee80211_unregister_hw(ar
->hw
);
6832 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
6833 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
6838 void ath10k_mac_unregister(struct ath10k
*ar
)
6840 ieee80211_unregister_hw(ar
->hw
);
6842 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
6843 ar
->dfs_detector
->exit(ar
->dfs_detector
);
6845 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
6846 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
6848 SET_IEEE80211_DEV(ar
->hw
, NULL
);