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;
134 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
138 for (nss
= IEEE80211_HT_MCS_MASK_LEN
- 1; nss
>= 0; nss
--)
139 if (ht_mcs_mask
[nss
])
146 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
150 for (nss
= NL80211_VHT_NSS_MAX
- 1; nss
>= 0; nss
--)
151 if (vht_mcs_mask
[nss
])
161 static int ath10k_send_key(struct ath10k_vif
*arvif
,
162 struct ieee80211_key_conf
*key
,
163 enum set_key_cmd cmd
,
164 const u8
*macaddr
, u32 flags
)
166 struct ath10k
*ar
= arvif
->ar
;
167 struct wmi_vdev_install_key_arg arg
= {
168 .vdev_id
= arvif
->vdev_id
,
169 .key_idx
= key
->keyidx
,
170 .key_len
= key
->keylen
,
171 .key_data
= key
->key
,
176 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
178 switch (key
->cipher
) {
179 case WLAN_CIPHER_SUITE_CCMP
:
180 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
181 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
183 case WLAN_CIPHER_SUITE_TKIP
:
184 arg
.key_cipher
= WMI_CIPHER_TKIP
;
185 arg
.key_txmic_len
= 8;
186 arg
.key_rxmic_len
= 8;
188 case WLAN_CIPHER_SUITE_WEP40
:
189 case WLAN_CIPHER_SUITE_WEP104
:
190 arg
.key_cipher
= WMI_CIPHER_WEP
;
192 case WLAN_CIPHER_SUITE_AES_CMAC
:
196 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
200 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
201 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
204 if (cmd
== DISABLE_KEY
) {
205 arg
.key_cipher
= WMI_CIPHER_NONE
;
209 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
212 static int ath10k_install_key(struct ath10k_vif
*arvif
,
213 struct ieee80211_key_conf
*key
,
214 enum set_key_cmd cmd
,
215 const u8
*macaddr
, u32 flags
)
217 struct ath10k
*ar
= arvif
->ar
;
219 unsigned long time_left
;
221 lockdep_assert_held(&ar
->conf_mutex
);
223 reinit_completion(&ar
->install_key_done
);
225 if (arvif
->nohwcrypt
)
228 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
232 time_left
= wait_for_completion_timeout(&ar
->install_key_done
, 3 * HZ
);
239 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
242 struct ath10k
*ar
= arvif
->ar
;
243 struct ath10k_peer
*peer
;
248 lockdep_assert_held(&ar
->conf_mutex
);
250 spin_lock_bh(&ar
->data_lock
);
251 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
252 spin_unlock_bh(&ar
->data_lock
);
257 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
258 if (arvif
->wep_keys
[i
] == NULL
)
262 flags
|= WMI_KEY_PAIRWISE
;
264 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
270 flags
|= WMI_KEY_GROUP
;
272 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
277 spin_lock_bh(&ar
->data_lock
);
278 peer
->keys
[i
] = arvif
->wep_keys
[i
];
279 spin_unlock_bh(&ar
->data_lock
);
282 /* In some cases (notably with static WEP IBSS with multiple keys)
283 * multicast Tx becomes broken. Both pairwise and groupwise keys are
284 * installed already. Using WMI_KEY_TX_USAGE in different combinations
285 * didn't seem help. Using def_keyid vdev parameter seems to be
286 * effective so use that.
288 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
290 if (arvif
->def_wep_key_idx
== -1)
293 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
295 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
296 arvif
->def_wep_key_idx
);
298 ath10k_warn(ar
, "failed to re-set def wpa key idxon vdev %i: %d\n",
299 arvif
->vdev_id
, ret
);
306 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
309 struct ath10k
*ar
= arvif
->ar
;
310 struct ath10k_peer
*peer
;
316 lockdep_assert_held(&ar
->conf_mutex
);
318 spin_lock_bh(&ar
->data_lock
);
319 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
320 spin_unlock_bh(&ar
->data_lock
);
325 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
326 if (peer
->keys
[i
] == NULL
)
329 /* key flags are not required to delete the key */
330 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
331 DISABLE_KEY
, addr
, flags
);
332 if (ret
< 0 && first_errno
== 0)
336 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
339 spin_lock_bh(&ar
->data_lock
);
340 peer
->keys
[i
] = NULL
;
341 spin_unlock_bh(&ar
->data_lock
);
347 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
350 struct ath10k_peer
*peer
;
353 lockdep_assert_held(&ar
->data_lock
);
355 /* We don't know which vdev this peer belongs to,
356 * since WMI doesn't give us that information.
358 * FIXME: multi-bss needs to be handled.
360 peer
= ath10k_peer_find(ar
, 0, addr
);
364 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
365 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
372 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
373 struct ieee80211_key_conf
*key
)
375 struct ath10k
*ar
= arvif
->ar
;
376 struct ath10k_peer
*peer
;
383 lockdep_assert_held(&ar
->conf_mutex
);
386 /* since ath10k_install_key we can't hold data_lock all the
387 * time, so we try to remove the keys incrementally */
388 spin_lock_bh(&ar
->data_lock
);
390 list_for_each_entry(peer
, &ar
->peers
, list
) {
391 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
392 if (peer
->keys
[i
] == key
) {
393 ether_addr_copy(addr
, peer
->addr
);
394 peer
->keys
[i
] = NULL
;
399 if (i
< ARRAY_SIZE(peer
->keys
))
402 spin_unlock_bh(&ar
->data_lock
);
404 if (i
== ARRAY_SIZE(peer
->keys
))
406 /* key flags are not required to delete the key */
407 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
408 if (ret
< 0 && first_errno
== 0)
412 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
419 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
420 struct ieee80211_key_conf
*key
)
422 struct ath10k
*ar
= arvif
->ar
;
423 struct ath10k_peer
*peer
;
426 lockdep_assert_held(&ar
->conf_mutex
);
428 list_for_each_entry(peer
, &ar
->peers
, list
) {
429 if (!memcmp(peer
->addr
, arvif
->vif
->addr
, ETH_ALEN
))
432 if (!memcmp(peer
->addr
, arvif
->bssid
, ETH_ALEN
))
435 if (peer
->keys
[key
->keyidx
] == key
)
438 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
439 arvif
->vdev_id
, key
->keyidx
);
441 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
443 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
444 arvif
->vdev_id
, peer
->addr
, ret
);
452 /*********************/
453 /* General utilities */
454 /*********************/
456 static inline enum wmi_phy_mode
457 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
459 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
461 switch (chandef
->chan
->band
) {
462 case IEEE80211_BAND_2GHZ
:
463 switch (chandef
->width
) {
464 case NL80211_CHAN_WIDTH_20_NOHT
:
465 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
470 case NL80211_CHAN_WIDTH_20
:
471 phymode
= MODE_11NG_HT20
;
473 case NL80211_CHAN_WIDTH_40
:
474 phymode
= MODE_11NG_HT40
;
476 case NL80211_CHAN_WIDTH_5
:
477 case NL80211_CHAN_WIDTH_10
:
478 case NL80211_CHAN_WIDTH_80
:
479 case NL80211_CHAN_WIDTH_80P80
:
480 case NL80211_CHAN_WIDTH_160
:
481 phymode
= MODE_UNKNOWN
;
485 case IEEE80211_BAND_5GHZ
:
486 switch (chandef
->width
) {
487 case NL80211_CHAN_WIDTH_20_NOHT
:
490 case NL80211_CHAN_WIDTH_20
:
491 phymode
= MODE_11NA_HT20
;
493 case NL80211_CHAN_WIDTH_40
:
494 phymode
= MODE_11NA_HT40
;
496 case NL80211_CHAN_WIDTH_80
:
497 phymode
= MODE_11AC_VHT80
;
499 case NL80211_CHAN_WIDTH_5
:
500 case NL80211_CHAN_WIDTH_10
:
501 case NL80211_CHAN_WIDTH_80P80
:
502 case NL80211_CHAN_WIDTH_160
:
503 phymode
= MODE_UNKNOWN
;
511 WARN_ON(phymode
== MODE_UNKNOWN
);
515 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
518 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
519 * 0 for no restriction
528 switch (mpdudensity
) {
534 /* Our lower layer calculations limit our precision to
550 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
551 struct cfg80211_chan_def
*def
)
553 struct ieee80211_chanctx_conf
*conf
;
556 conf
= rcu_dereference(vif
->chanctx_conf
);
568 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
569 struct ieee80211_chanctx_conf
*conf
,
577 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
581 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
582 ath10k_mac_num_chanctxs_iter
,
589 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
590 struct ieee80211_chanctx_conf
*conf
,
593 struct cfg80211_chan_def
**def
= data
;
598 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
,
599 enum wmi_peer_type peer_type
)
601 struct ath10k_vif
*arvif
;
605 lockdep_assert_held(&ar
->conf_mutex
);
607 num_peers
= ar
->num_peers
;
609 /* Each vdev consumes a peer entry as well */
610 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
613 if (num_peers
>= ar
->max_num_peers
)
616 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
618 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
623 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
625 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
635 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
637 struct ath10k
*ar
= arvif
->ar
;
641 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
642 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
643 ATH10K_KICKOUT_THRESHOLD
);
645 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
646 arvif
->vdev_id
, ret
);
650 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
651 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
652 ATH10K_KEEPALIVE_MIN_IDLE
);
654 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
655 arvif
->vdev_id
, ret
);
659 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
660 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
661 ATH10K_KEEPALIVE_MAX_IDLE
);
663 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
664 arvif
->vdev_id
, ret
);
668 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
669 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
670 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
672 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
673 arvif
->vdev_id
, ret
);
680 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
682 struct ath10k
*ar
= arvif
->ar
;
685 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
686 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
689 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
693 lockdep_assert_held(&ar
->conf_mutex
);
695 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
699 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
708 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
710 struct ath10k_peer
*peer
, *tmp
;
712 lockdep_assert_held(&ar
->conf_mutex
);
714 spin_lock_bh(&ar
->data_lock
);
715 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
716 if (peer
->vdev_id
!= vdev_id
)
719 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
720 peer
->addr
, vdev_id
);
722 list_del(&peer
->list
);
726 spin_unlock_bh(&ar
->data_lock
);
729 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
731 struct ath10k_peer
*peer
, *tmp
;
733 lockdep_assert_held(&ar
->conf_mutex
);
735 spin_lock_bh(&ar
->data_lock
);
736 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
737 list_del(&peer
->list
);
740 spin_unlock_bh(&ar
->data_lock
);
743 ar
->num_stations
= 0;
746 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
747 struct ieee80211_sta
*sta
,
748 enum wmi_tdls_peer_state state
)
751 struct wmi_tdls_peer_update_cmd_arg arg
= {};
752 struct wmi_tdls_peer_capab_arg cap
= {};
753 struct wmi_channel_arg chan_arg
= {};
755 lockdep_assert_held(&ar
->conf_mutex
);
757 arg
.vdev_id
= vdev_id
;
758 arg
.peer_state
= state
;
759 ether_addr_copy(arg
.addr
, sta
->addr
);
761 cap
.peer_max_sp
= sta
->max_sp
;
762 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
764 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
765 !sta
->tdls_initiator
)
766 cap
.is_peer_responder
= 1;
768 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
770 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
771 arg
.addr
, vdev_id
, ret
);
778 /************************/
779 /* Interface management */
780 /************************/
782 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
784 struct ath10k
*ar
= arvif
->ar
;
786 lockdep_assert_held(&ar
->data_lock
);
791 if (!arvif
->beacon_buf
)
792 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
793 arvif
->beacon
->len
, DMA_TO_DEVICE
);
795 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
796 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
799 dev_kfree_skb_any(arvif
->beacon
);
801 arvif
->beacon
= NULL
;
802 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
805 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
807 struct ath10k
*ar
= arvif
->ar
;
809 lockdep_assert_held(&ar
->data_lock
);
811 ath10k_mac_vif_beacon_free(arvif
);
813 if (arvif
->beacon_buf
) {
814 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
815 arvif
->beacon_buf
, arvif
->beacon_paddr
);
816 arvif
->beacon_buf
= NULL
;
820 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
822 unsigned long time_left
;
824 lockdep_assert_held(&ar
->conf_mutex
);
826 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
829 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
830 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
837 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
839 struct cfg80211_chan_def
*chandef
= NULL
;
840 struct ieee80211_channel
*channel
= NULL
;
841 struct wmi_vdev_start_request_arg arg
= {};
844 lockdep_assert_held(&ar
->conf_mutex
);
846 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
847 ath10k_mac_get_any_chandef_iter
,
849 if (WARN_ON_ONCE(!chandef
))
852 channel
= chandef
->chan
;
854 arg
.vdev_id
= vdev_id
;
855 arg
.channel
.freq
= channel
->center_freq
;
856 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
858 /* TODO setup this dynamically, what in case we
859 don't have any vifs? */
860 arg
.channel
.mode
= chan_to_phymode(chandef
);
861 arg
.channel
.chan_radar
=
862 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
864 arg
.channel
.min_power
= 0;
865 arg
.channel
.max_power
= channel
->max_power
* 2;
866 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
867 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
869 reinit_completion(&ar
->vdev_setup_done
);
871 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
873 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
878 ret
= ath10k_vdev_setup_sync(ar
);
880 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
885 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
887 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
892 ar
->monitor_vdev_id
= vdev_id
;
894 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
895 ar
->monitor_vdev_id
);
899 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
901 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
902 ar
->monitor_vdev_id
, ret
);
907 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
911 lockdep_assert_held(&ar
->conf_mutex
);
913 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
915 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
916 ar
->monitor_vdev_id
, ret
);
918 reinit_completion(&ar
->vdev_setup_done
);
920 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
922 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
923 ar
->monitor_vdev_id
, ret
);
925 ret
= ath10k_vdev_setup_sync(ar
);
927 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
928 ar
->monitor_vdev_id
, ret
);
930 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
931 ar
->monitor_vdev_id
);
935 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
939 lockdep_assert_held(&ar
->conf_mutex
);
941 if (ar
->free_vdev_map
== 0) {
942 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
946 bit
= __ffs64(ar
->free_vdev_map
);
948 ar
->monitor_vdev_id
= bit
;
950 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
951 WMI_VDEV_TYPE_MONITOR
,
954 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
955 ar
->monitor_vdev_id
, ret
);
959 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
960 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
961 ar
->monitor_vdev_id
);
966 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
970 lockdep_assert_held(&ar
->conf_mutex
);
972 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
974 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
975 ar
->monitor_vdev_id
, ret
);
979 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
981 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
982 ar
->monitor_vdev_id
);
986 static int ath10k_monitor_start(struct ath10k
*ar
)
990 lockdep_assert_held(&ar
->conf_mutex
);
992 ret
= ath10k_monitor_vdev_create(ar
);
994 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
998 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
1000 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
1001 ath10k_monitor_vdev_delete(ar
);
1005 ar
->monitor_started
= true;
1006 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
1011 static int ath10k_monitor_stop(struct ath10k
*ar
)
1015 lockdep_assert_held(&ar
->conf_mutex
);
1017 ret
= ath10k_monitor_vdev_stop(ar
);
1019 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1023 ret
= ath10k_monitor_vdev_delete(ar
);
1025 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1029 ar
->monitor_started
= false;
1030 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1035 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1039 /* At least one chanctx is required to derive a channel to start
1042 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1046 /* If there's already an existing special monitor interface then don't
1047 * bother creating another monitor vdev.
1049 if (ar
->monitor_arvif
)
1052 return ar
->monitor
||
1053 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1056 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1060 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1062 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1063 * shouldn't allow this but make sure to prevent handling the following
1064 * case anyway since multi-channel DFS hasn't been tested at all.
1066 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1072 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1078 lockdep_assert_held(&ar
->conf_mutex
);
1080 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1081 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1083 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1084 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1085 ar
->monitor_started
, needed
, allowed
);
1087 if (WARN_ON(needed
&& !allowed
)) {
1088 if (ar
->monitor_started
) {
1089 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1091 ret
= ath10k_monitor_stop(ar
);
1093 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n", ret
);
1100 if (needed
== ar
->monitor_started
)
1104 return ath10k_monitor_start(ar
);
1106 return ath10k_monitor_stop(ar
);
1109 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1111 struct ath10k
*ar
= arvif
->ar
;
1112 u32 vdev_param
, rts_cts
= 0;
1114 lockdep_assert_held(&ar
->conf_mutex
);
1116 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1118 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1120 if (arvif
->num_legacy_stations
> 0)
1121 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1122 WMI_RTSCTS_PROFILE
);
1124 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1125 WMI_RTSCTS_PROFILE
);
1127 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1131 static int ath10k_start_cac(struct ath10k
*ar
)
1135 lockdep_assert_held(&ar
->conf_mutex
);
1137 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1139 ret
= ath10k_monitor_recalc(ar
);
1141 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1142 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1146 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1147 ar
->monitor_vdev_id
);
1152 static int ath10k_stop_cac(struct ath10k
*ar
)
1154 lockdep_assert_held(&ar
->conf_mutex
);
1156 /* CAC is not running - do nothing */
1157 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1160 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1161 ath10k_monitor_stop(ar
);
1163 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1168 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1169 struct ieee80211_chanctx_conf
*conf
,
1174 if (!*ret
&& conf
->radar_enabled
)
1178 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1180 bool has_radar
= false;
1182 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1183 ath10k_mac_has_radar_iter
,
1189 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1193 lockdep_assert_held(&ar
->conf_mutex
);
1195 ath10k_stop_cac(ar
);
1197 if (!ath10k_mac_has_radar_enabled(ar
))
1200 if (ar
->num_started_vdevs
> 0)
1203 ret
= ath10k_start_cac(ar
);
1206 * Not possible to start CAC on current channel so starting
1207 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1208 * by indicating that radar was detected.
1210 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1211 ieee80211_radar_detected(ar
->hw
);
1215 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1217 struct ath10k
*ar
= arvif
->ar
;
1220 lockdep_assert_held(&ar
->conf_mutex
);
1222 reinit_completion(&ar
->vdev_setup_done
);
1224 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1226 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1227 arvif
->vdev_id
, ret
);
1231 ret
= ath10k_vdev_setup_sync(ar
);
1233 ath10k_warn(ar
, "failed to syncronise setup for vdev %i: %d\n",
1234 arvif
->vdev_id
, ret
);
1238 WARN_ON(ar
->num_started_vdevs
== 0);
1240 if (ar
->num_started_vdevs
!= 0) {
1241 ar
->num_started_vdevs
--;
1242 ath10k_recalc_radar_detection(ar
);
1248 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1249 const struct cfg80211_chan_def
*chandef
,
1252 struct ath10k
*ar
= arvif
->ar
;
1253 struct wmi_vdev_start_request_arg arg
= {};
1256 lockdep_assert_held(&ar
->conf_mutex
);
1258 reinit_completion(&ar
->vdev_setup_done
);
1260 arg
.vdev_id
= arvif
->vdev_id
;
1261 arg
.dtim_period
= arvif
->dtim_period
;
1262 arg
.bcn_intval
= arvif
->beacon_interval
;
1264 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1265 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1266 arg
.channel
.mode
= chan_to_phymode(chandef
);
1268 arg
.channel
.min_power
= 0;
1269 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1270 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1271 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1273 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1274 arg
.ssid
= arvif
->u
.ap
.ssid
;
1275 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1276 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1278 /* For now allow DFS for AP mode */
1279 arg
.channel
.chan_radar
=
1280 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1281 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1282 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1283 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1286 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1287 "mac vdev %d start center_freq %d phymode %s\n",
1288 arg
.vdev_id
, arg
.channel
.freq
,
1289 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1292 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1294 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1297 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1302 ret
= ath10k_vdev_setup_sync(ar
);
1305 "failed to synchronize setup for vdev %i restart %d: %d\n",
1306 arg
.vdev_id
, restart
, ret
);
1310 ar
->num_started_vdevs
++;
1311 ath10k_recalc_radar_detection(ar
);
1316 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1317 const struct cfg80211_chan_def
*def
)
1319 return ath10k_vdev_start_restart(arvif
, def
, false);
1322 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1323 const struct cfg80211_chan_def
*def
)
1325 return ath10k_vdev_start_restart(arvif
, def
, true);
1328 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1329 struct sk_buff
*bcn
)
1331 struct ath10k
*ar
= arvif
->ar
;
1332 struct ieee80211_mgmt
*mgmt
;
1336 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1339 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1342 mgmt
= (void *)bcn
->data
;
1343 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1344 mgmt
->u
.beacon
.variable
,
1345 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1350 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1352 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1353 arvif
->vdev_id
, ret
);
1360 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1361 u8 oui_type
, size_t ie_offset
)
1368 if (WARN_ON(skb
->len
< ie_offset
))
1371 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1372 skb
->data
+ ie_offset
,
1373 skb
->len
- ie_offset
);
1378 end
= skb
->data
+ skb
->len
;
1381 if (WARN_ON(next
> end
))
1384 memmove(ie
, next
, end
- next
);
1385 skb_trim(skb
, skb
->len
- len
);
1390 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1392 struct ath10k
*ar
= arvif
->ar
;
1393 struct ieee80211_hw
*hw
= ar
->hw
;
1394 struct ieee80211_vif
*vif
= arvif
->vif
;
1395 struct ieee80211_mutable_offsets offs
= {};
1396 struct sk_buff
*bcn
;
1399 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1402 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1403 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1406 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1408 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1412 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1414 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1419 /* P2P IE is inserted by firmware automatically (as configured above)
1420 * so remove it from the base beacon template to avoid duplicate P2P
1421 * IEs in beacon frames.
1423 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1424 offsetof(struct ieee80211_mgmt
,
1425 u
.beacon
.variable
));
1427 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1432 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1440 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1442 struct ath10k
*ar
= arvif
->ar
;
1443 struct ieee80211_hw
*hw
= ar
->hw
;
1444 struct ieee80211_vif
*vif
= arvif
->vif
;
1445 struct sk_buff
*prb
;
1448 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1451 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1454 prb
= ieee80211_proberesp_get(hw
, vif
);
1456 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1460 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1464 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1472 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1474 struct ath10k
*ar
= arvif
->ar
;
1475 struct cfg80211_chan_def def
;
1478 /* When originally vdev is started during assign_vif_chanctx() some
1479 * information is missing, notably SSID. Firmware revisions with beacon
1480 * offloading require the SSID to be provided during vdev (re)start to
1481 * handle hidden SSID properly.
1483 * Vdev restart must be done after vdev has been both started and
1484 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1485 * deliver vdev restart response event causing timeouts during vdev
1486 * syncing in ath10k.
1488 * Note: The vdev down/up and template reinstallation could be skipped
1489 * since only wmi-tlv firmware are known to have beacon offload and
1490 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1491 * response delivery. It's probably more robust to keep it as is.
1493 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1496 if (WARN_ON(!arvif
->is_started
))
1499 if (WARN_ON(!arvif
->is_up
))
1502 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1505 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1507 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1508 arvif
->vdev_id
, ret
);
1512 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1513 * firmware will crash upon vdev up.
1516 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1518 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1522 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1524 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1528 ret
= ath10k_vdev_restart(arvif
, &def
);
1530 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1531 arvif
->vdev_id
, ret
);
1535 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1538 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1539 arvif
->vdev_id
, ret
);
1546 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1547 struct ieee80211_bss_conf
*info
)
1549 struct ath10k
*ar
= arvif
->ar
;
1552 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1554 if (!info
->enable_beacon
) {
1555 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1557 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1558 arvif
->vdev_id
, ret
);
1560 arvif
->is_up
= false;
1562 spin_lock_bh(&arvif
->ar
->data_lock
);
1563 ath10k_mac_vif_beacon_free(arvif
);
1564 spin_unlock_bh(&arvif
->ar
->data_lock
);
1569 arvif
->tx_seq_no
= 0x1000;
1572 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1574 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1577 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1578 arvif
->vdev_id
, ret
);
1582 arvif
->is_up
= true;
1584 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1586 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1587 arvif
->vdev_id
, ret
);
1591 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1594 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1595 struct ieee80211_bss_conf
*info
,
1596 const u8 self_peer
[ETH_ALEN
])
1598 struct ath10k
*ar
= arvif
->ar
;
1602 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1604 if (!info
->ibss_joined
) {
1605 if (is_zero_ether_addr(arvif
->bssid
))
1608 eth_zero_addr(arvif
->bssid
);
1613 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1614 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1615 ATH10K_DEFAULT_ATIM
);
1617 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1618 arvif
->vdev_id
, ret
);
1621 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1623 struct ath10k
*ar
= arvif
->ar
;
1628 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1630 if (arvif
->u
.sta
.uapsd
)
1631 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1633 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1635 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1636 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1638 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1639 value
, arvif
->vdev_id
, ret
);
1646 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1648 struct ath10k
*ar
= arvif
->ar
;
1653 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1655 if (arvif
->u
.sta
.uapsd
)
1656 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1658 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1660 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1661 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1664 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1665 value
, arvif
->vdev_id
, ret
);
1672 static int ath10k_mac_num_vifs_started(struct ath10k
*ar
)
1674 struct ath10k_vif
*arvif
;
1677 lockdep_assert_held(&ar
->conf_mutex
);
1679 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1680 if (arvif
->is_started
)
1686 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1688 struct ath10k
*ar
= arvif
->ar
;
1689 struct ieee80211_vif
*vif
= arvif
->vif
;
1690 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1691 enum wmi_sta_powersave_param param
;
1692 enum wmi_sta_ps_mode psmode
;
1697 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1699 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1702 enable_ps
= arvif
->ps
;
1704 if (enable_ps
&& ath10k_mac_num_vifs_started(ar
) > 1 &&
1705 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1707 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1712 if (!arvif
->is_started
) {
1713 /* mac80211 can update vif powersave state while disconnected.
1714 * Firmware doesn't behave nicely and consumes more power than
1715 * necessary if PS is disabled on a non-started vdev. Hence
1716 * force-enable PS for non-running vdevs.
1718 psmode
= WMI_STA_PS_MODE_ENABLED
;
1719 } else if (enable_ps
) {
1720 psmode
= WMI_STA_PS_MODE_ENABLED
;
1721 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1723 ps_timeout
= conf
->dynamic_ps_timeout
;
1724 if (ps_timeout
== 0) {
1725 /* Firmware doesn't like 0 */
1726 ps_timeout
= ieee80211_tu_to_usec(
1727 vif
->bss_conf
.beacon_int
) / 1000;
1730 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1733 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1734 arvif
->vdev_id
, ret
);
1738 psmode
= WMI_STA_PS_MODE_DISABLED
;
1741 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1742 arvif
->vdev_id
, psmode
? "enable" : "disable");
1744 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1746 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1747 psmode
, arvif
->vdev_id
, ret
);
1754 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1756 struct ath10k
*ar
= arvif
->ar
;
1757 struct wmi_sta_keepalive_arg arg
= {};
1760 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1762 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1765 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1768 /* Some firmware revisions have a bug and ignore the `enabled` field.
1769 * Instead use the interval to disable the keepalive.
1771 arg
.vdev_id
= arvif
->vdev_id
;
1773 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1774 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1776 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1778 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1779 arvif
->vdev_id
, ret
);
1786 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
1788 struct ath10k
*ar
= arvif
->ar
;
1789 struct ieee80211_vif
*vif
= arvif
->vif
;
1792 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1794 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
1797 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1800 if (!vif
->csa_active
)
1806 if (!ieee80211_csa_is_complete(vif
)) {
1807 ieee80211_csa_update_counter(vif
);
1809 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1811 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
1814 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1816 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
1819 ieee80211_csa_finish(vif
);
1823 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
1825 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1827 struct ath10k
*ar
= arvif
->ar
;
1829 mutex_lock(&ar
->conf_mutex
);
1830 ath10k_mac_vif_ap_csa_count_down(arvif
);
1831 mutex_unlock(&ar
->conf_mutex
);
1834 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
1835 struct ieee80211_vif
*vif
)
1837 struct sk_buff
*skb
= data
;
1838 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1839 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1841 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1844 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
1847 cancel_delayed_work(&arvif
->connection_loss_work
);
1850 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
1852 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1853 IEEE80211_IFACE_ITER_NORMAL
,
1854 ath10k_mac_handle_beacon_iter
,
1858 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
1859 struct ieee80211_vif
*vif
)
1861 u32
*vdev_id
= data
;
1862 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1863 struct ath10k
*ar
= arvif
->ar
;
1864 struct ieee80211_hw
*hw
= ar
->hw
;
1866 if (arvif
->vdev_id
!= *vdev_id
)
1872 ieee80211_beacon_loss(vif
);
1874 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1875 * (done by mac80211) succeeds but beacons do not resume then it
1876 * doesn't make sense to continue operation. Queue connection loss work
1877 * which can be cancelled when beacon is received.
1879 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
1880 ATH10K_CONNECTION_LOSS_HZ
);
1883 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
1885 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1886 IEEE80211_IFACE_ITER_NORMAL
,
1887 ath10k_mac_handle_beacon_miss_iter
,
1891 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
1893 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1894 connection_loss_work
.work
);
1895 struct ieee80211_vif
*vif
= arvif
->vif
;
1900 ieee80211_connection_loss(vif
);
1903 /**********************/
1904 /* Station management */
1905 /**********************/
1907 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1908 struct ieee80211_vif
*vif
)
1910 /* Some firmware revisions have unstable STA powersave when listen
1911 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1912 * generate NullFunc frames properly even if buffered frames have been
1913 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1914 * buffered frames. Often pinging the device from AP would simply fail.
1916 * As a workaround set it to 1.
1918 if (vif
->type
== NL80211_IFTYPE_STATION
)
1921 return ar
->hw
->conf
.listen_interval
;
1924 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1925 struct ieee80211_vif
*vif
,
1926 struct ieee80211_sta
*sta
,
1927 struct wmi_peer_assoc_complete_arg
*arg
)
1929 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1932 lockdep_assert_held(&ar
->conf_mutex
);
1934 if (vif
->type
== NL80211_IFTYPE_STATION
)
1935 aid
= vif
->bss_conf
.aid
;
1939 ether_addr_copy(arg
->addr
, sta
->addr
);
1940 arg
->vdev_id
= arvif
->vdev_id
;
1941 arg
->peer_aid
= aid
;
1942 arg
->peer_flags
|= WMI_PEER_AUTH
;
1943 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1944 arg
->peer_num_spatial_streams
= 1;
1945 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1948 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1949 struct ieee80211_vif
*vif
,
1950 struct wmi_peer_assoc_complete_arg
*arg
)
1952 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1953 struct cfg80211_chan_def def
;
1954 struct cfg80211_bss
*bss
;
1955 const u8
*rsnie
= NULL
;
1956 const u8
*wpaie
= NULL
;
1958 lockdep_assert_held(&ar
->conf_mutex
);
1960 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
1963 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
, NULL
, 0,
1964 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
1966 const struct cfg80211_bss_ies
*ies
;
1969 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1971 ies
= rcu_dereference(bss
->ies
);
1973 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1974 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1978 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1981 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1982 if (rsnie
|| wpaie
) {
1983 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1984 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1988 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1989 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1993 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1994 struct ieee80211_vif
*vif
,
1995 struct ieee80211_sta
*sta
,
1996 struct wmi_peer_assoc_complete_arg
*arg
)
1998 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1999 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
2000 struct cfg80211_chan_def def
;
2001 const struct ieee80211_supported_band
*sband
;
2002 const struct ieee80211_rate
*rates
;
2003 enum ieee80211_band band
;
2008 lockdep_assert_held(&ar
->conf_mutex
);
2010 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2013 band
= def
.chan
->band
;
2014 sband
= ar
->hw
->wiphy
->bands
[band
];
2015 ratemask
= sta
->supp_rates
[band
];
2016 ratemask
&= arvif
->bitrate_mask
.control
[band
].legacy
;
2017 rates
= sband
->bitrates
;
2019 rateset
->num_rates
= 0;
2021 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2022 if (!(ratemask
& 1))
2025 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2026 rateset
->rates
[rateset
->num_rates
] = rate
;
2027 rateset
->num_rates
++;
2032 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
2036 for (nss
= 0; nss
< IEEE80211_HT_MCS_MASK_LEN
; nss
++)
2037 if (ht_mcs_mask
[nss
])
2044 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
2048 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++)
2049 if (vht_mcs_mask
[nss
])
2055 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2056 struct ieee80211_vif
*vif
,
2057 struct ieee80211_sta
*sta
,
2058 struct wmi_peer_assoc_complete_arg
*arg
)
2060 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2061 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2062 struct cfg80211_chan_def def
;
2063 enum ieee80211_band band
;
2064 const u8
*ht_mcs_mask
;
2065 const u16
*vht_mcs_mask
;
2069 lockdep_assert_held(&ar
->conf_mutex
);
2071 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2074 if (!ht_cap
->ht_supported
)
2077 band
= def
.chan
->band
;
2078 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2079 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2081 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
) &&
2082 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2085 arg
->peer_flags
|= WMI_PEER_HT
;
2086 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2087 ht_cap
->ampdu_factor
)) - 1;
2089 arg
->peer_mpdu_density
=
2090 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2092 arg
->peer_ht_caps
= ht_cap
->cap
;
2093 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2095 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2096 arg
->peer_flags
|= WMI_PEER_LDPC
;
2098 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2099 arg
->peer_flags
|= WMI_PEER_40MHZ
;
2100 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2103 if (arvif
->bitrate_mask
.control
[band
].gi
!= NL80211_TXRATE_FORCE_LGI
) {
2104 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2105 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2107 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2108 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2111 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2112 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2113 arg
->peer_flags
|= WMI_PEER_STBC
;
2116 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2117 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2118 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2119 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2120 arg
->peer_rate_caps
|= stbc
;
2121 arg
->peer_flags
|= WMI_PEER_STBC
;
2124 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2125 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2126 else if (ht_cap
->mcs
.rx_mask
[1])
2127 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2129 for (i
= 0, n
= 0, max_nss
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
* 8; i
++)
2130 if ((ht_cap
->mcs
.rx_mask
[i
/ 8] & BIT(i
% 8)) &&
2131 (ht_mcs_mask
[i
/ 8] & BIT(i
% 8))) {
2132 max_nss
= (i
/ 8) + 1;
2133 arg
->peer_ht_rates
.rates
[n
++] = i
;
2137 * This is a workaround for HT-enabled STAs which break the spec
2138 * and have no HT capabilities RX mask (no HT RX MCS map).
2140 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2141 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2143 * Firmware asserts if such situation occurs.
2146 arg
->peer_ht_rates
.num_rates
= 8;
2147 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2148 arg
->peer_ht_rates
.rates
[i
] = i
;
2150 arg
->peer_ht_rates
.num_rates
= n
;
2151 arg
->peer_num_spatial_streams
= max_nss
;
2154 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2156 arg
->peer_ht_rates
.num_rates
,
2157 arg
->peer_num_spatial_streams
);
2160 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2161 struct ath10k_vif
*arvif
,
2162 struct ieee80211_sta
*sta
)
2168 lockdep_assert_held(&ar
->conf_mutex
);
2170 if (sta
->wme
&& sta
->uapsd_queues
) {
2171 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2172 sta
->uapsd_queues
, sta
->max_sp
);
2174 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2175 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2176 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2177 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2178 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2179 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2180 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2181 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2182 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2183 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2184 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2185 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2187 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2188 max_sp
= sta
->max_sp
;
2190 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2192 WMI_AP_PS_PEER_PARAM_UAPSD
,
2195 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2196 arvif
->vdev_id
, ret
);
2200 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2202 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2205 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2206 arvif
->vdev_id
, ret
);
2210 /* TODO setup this based on STA listen interval and
2211 beacon interval. Currently we don't know
2212 sta->listen_interval - mac80211 patch required.
2213 Currently use 10 seconds */
2214 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2215 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2218 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2219 arvif
->vdev_id
, ret
);
2228 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set
,
2229 const u16 vht_mcs_limit
[NL80211_VHT_NSS_MAX
])
2236 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
2237 mcs_map
= ath10k_mac_get_max_vht_mcs_map(tx_mcs_set
, nss
) &
2241 idx_limit
= fls(mcs_map
) - 1;
2245 switch (idx_limit
) {
2246 case 0: /* fall through */
2247 case 1: /* fall through */
2248 case 2: /* fall through */
2249 case 3: /* fall through */
2250 case 4: /* fall through */
2251 case 5: /* fall through */
2252 case 6: /* fall through */
2254 /* see ath10k_mac_can_set_bitrate_mask() */
2258 mcs
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
2261 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_7
;
2264 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_8
;
2267 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_9
;
2271 tx_mcs_set
&= ~(0x3 << (nss
* 2));
2272 tx_mcs_set
|= mcs
<< (nss
* 2);
2278 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2279 struct ieee80211_vif
*vif
,
2280 struct ieee80211_sta
*sta
,
2281 struct wmi_peer_assoc_complete_arg
*arg
)
2283 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
2284 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2285 struct cfg80211_chan_def def
;
2286 enum ieee80211_band band
;
2287 const u16
*vht_mcs_mask
;
2290 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2293 if (!vht_cap
->vht_supported
)
2296 band
= def
.chan
->band
;
2297 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2299 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2302 arg
->peer_flags
|= WMI_PEER_VHT
;
2304 if (def
.chan
->band
== IEEE80211_BAND_2GHZ
)
2305 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
2307 arg
->peer_vht_caps
= vht_cap
->cap
;
2309 ampdu_factor
= (vht_cap
->cap
&
2310 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2311 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2313 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2314 * zero in VHT IE. Using it would result in degraded throughput.
2315 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2316 * it if VHT max_mpdu is smaller. */
2317 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2318 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2319 ampdu_factor
)) - 1);
2321 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2322 arg
->peer_flags
|= WMI_PEER_80MHZ
;
2324 arg
->peer_vht_rates
.rx_max_rate
=
2325 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2326 arg
->peer_vht_rates
.rx_mcs_set
=
2327 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2328 arg
->peer_vht_rates
.tx_max_rate
=
2329 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2330 arg
->peer_vht_rates
.tx_mcs_set
= ath10k_peer_assoc_h_vht_limit(
2331 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
), vht_mcs_mask
);
2333 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2334 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
2337 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2338 struct ieee80211_vif
*vif
,
2339 struct ieee80211_sta
*sta
,
2340 struct wmi_peer_assoc_complete_arg
*arg
)
2342 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2344 switch (arvif
->vdev_type
) {
2345 case WMI_VDEV_TYPE_AP
:
2347 arg
->peer_flags
|= WMI_PEER_QOS
;
2349 if (sta
->wme
&& sta
->uapsd_queues
) {
2350 arg
->peer_flags
|= WMI_PEER_APSD
;
2351 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2354 case WMI_VDEV_TYPE_STA
:
2355 if (vif
->bss_conf
.qos
)
2356 arg
->peer_flags
|= WMI_PEER_QOS
;
2358 case WMI_VDEV_TYPE_IBSS
:
2360 arg
->peer_flags
|= WMI_PEER_QOS
;
2366 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2367 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
2370 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2372 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >>
2373 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2376 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2377 struct ieee80211_vif
*vif
,
2378 struct ieee80211_sta
*sta
,
2379 struct wmi_peer_assoc_complete_arg
*arg
)
2381 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2382 struct cfg80211_chan_def def
;
2383 enum ieee80211_band band
;
2384 const u8
*ht_mcs_mask
;
2385 const u16
*vht_mcs_mask
;
2386 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2388 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2391 band
= def
.chan
->band
;
2392 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2393 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2396 case IEEE80211_BAND_2GHZ
:
2397 if (sta
->vht_cap
.vht_supported
&&
2398 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2399 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2400 phymode
= MODE_11AC_VHT40
;
2402 phymode
= MODE_11AC_VHT20
;
2403 } else if (sta
->ht_cap
.ht_supported
&&
2404 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2405 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2406 phymode
= MODE_11NG_HT40
;
2408 phymode
= MODE_11NG_HT20
;
2409 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2416 case IEEE80211_BAND_5GHZ
:
2420 if (sta
->vht_cap
.vht_supported
&&
2421 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2422 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2423 phymode
= MODE_11AC_VHT80
;
2424 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2425 phymode
= MODE_11AC_VHT40
;
2426 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2427 phymode
= MODE_11AC_VHT20
;
2428 } else if (sta
->ht_cap
.ht_supported
&&
2429 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2430 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
)
2431 phymode
= MODE_11NA_HT40
;
2433 phymode
= MODE_11NA_HT20
;
2443 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2444 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2446 arg
->peer_phymode
= phymode
;
2447 WARN_ON(phymode
== MODE_UNKNOWN
);
2450 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2451 struct ieee80211_vif
*vif
,
2452 struct ieee80211_sta
*sta
,
2453 struct wmi_peer_assoc_complete_arg
*arg
)
2455 lockdep_assert_held(&ar
->conf_mutex
);
2457 memset(arg
, 0, sizeof(*arg
));
2459 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2460 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
2461 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2462 ath10k_peer_assoc_h_ht(ar
, vif
, sta
, arg
);
2463 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2464 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2465 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2470 static const u32 ath10k_smps_map
[] = {
2471 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2472 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2473 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2474 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2477 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2479 const struct ieee80211_sta_ht_cap
*ht_cap
)
2483 if (!ht_cap
->ht_supported
)
2486 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2487 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2489 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2492 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2493 WMI_PEER_SMPS_STATE
,
2494 ath10k_smps_map
[smps
]);
2497 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2498 struct ieee80211_vif
*vif
,
2499 struct ieee80211_sta_vht_cap vht_cap
)
2501 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2506 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_AFTER_ASSOC
)
2509 if (!(ar
->vht_cap_info
&
2510 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2511 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2512 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2513 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2516 param
= ar
->wmi
.vdev_param
->txbf
;
2519 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2522 /* The following logic is correct. If a remote STA advertises support
2523 * for being a beamformer then we should enable us being a beamformee.
2526 if (ar
->vht_cap_info
&
2527 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2528 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2529 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2530 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2532 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2533 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2536 if (ar
->vht_cap_info
&
2537 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2538 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2539 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2540 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2542 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2543 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2546 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2547 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2549 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2550 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2552 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2554 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2562 /* can be called only in mac80211 callbacks due to `key_count` usage */
2563 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2564 struct ieee80211_vif
*vif
,
2565 struct ieee80211_bss_conf
*bss_conf
)
2567 struct ath10k
*ar
= hw
->priv
;
2568 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2569 struct ieee80211_sta_ht_cap ht_cap
;
2570 struct ieee80211_sta_vht_cap vht_cap
;
2571 struct wmi_peer_assoc_complete_arg peer_arg
;
2572 struct ieee80211_sta
*ap_sta
;
2575 lockdep_assert_held(&ar
->conf_mutex
);
2577 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2578 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2582 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2584 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2585 bss_conf
->bssid
, arvif
->vdev_id
);
2590 /* ap_sta must be accessed only within rcu section which must be left
2591 * before calling ath10k_setup_peer_smps() which might sleep. */
2592 ht_cap
= ap_sta
->ht_cap
;
2593 vht_cap
= ap_sta
->vht_cap
;
2595 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2597 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2598 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2605 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2607 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2608 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2612 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2614 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2615 arvif
->vdev_id
, ret
);
2619 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2621 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2622 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2626 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2627 "mac vdev %d up (associated) bssid %pM aid %d\n",
2628 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2630 WARN_ON(arvif
->is_up
);
2632 arvif
->aid
= bss_conf
->aid
;
2633 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2635 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2637 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2638 arvif
->vdev_id
, ret
);
2642 arvif
->is_up
= true;
2644 /* Workaround: Some firmware revisions (tested with qca6174
2645 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2646 * poked with peer param command.
2648 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2649 WMI_PEER_DUMMY_VAR
, 1);
2651 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2652 arvif
->bssid
, arvif
->vdev_id
, ret
);
2657 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2658 struct ieee80211_vif
*vif
)
2660 struct ath10k
*ar
= hw
->priv
;
2661 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2662 struct ieee80211_sta_vht_cap vht_cap
= {};
2665 lockdep_assert_held(&ar
->conf_mutex
);
2667 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2668 arvif
->vdev_id
, arvif
->bssid
);
2670 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2672 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
2673 arvif
->vdev_id
, ret
);
2675 arvif
->def_wep_key_idx
= -1;
2677 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2679 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2680 arvif
->vdev_id
, ret
);
2684 arvif
->is_up
= false;
2686 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
2689 static int ath10k_station_assoc(struct ath10k
*ar
,
2690 struct ieee80211_vif
*vif
,
2691 struct ieee80211_sta
*sta
,
2694 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2695 struct wmi_peer_assoc_complete_arg peer_arg
;
2698 lockdep_assert_held(&ar
->conf_mutex
);
2700 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2702 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2703 sta
->addr
, arvif
->vdev_id
, ret
);
2707 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2709 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2710 sta
->addr
, arvif
->vdev_id
, ret
);
2714 /* Re-assoc is run only to update supported rates for given station. It
2715 * doesn't make much sense to reconfigure the peer completely.
2718 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2721 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2722 arvif
->vdev_id
, ret
);
2726 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2728 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2729 sta
->addr
, arvif
->vdev_id
, ret
);
2734 arvif
->num_legacy_stations
++;
2735 ret
= ath10k_recalc_rtscts_prot(arvif
);
2737 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2738 arvif
->vdev_id
, ret
);
2743 /* Plumb cached keys only for static WEP */
2744 if (arvif
->def_wep_key_idx
!= -1) {
2745 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2747 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2748 arvif
->vdev_id
, ret
);
2757 static int ath10k_station_disassoc(struct ath10k
*ar
,
2758 struct ieee80211_vif
*vif
,
2759 struct ieee80211_sta
*sta
)
2761 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2764 lockdep_assert_held(&ar
->conf_mutex
);
2767 arvif
->num_legacy_stations
--;
2768 ret
= ath10k_recalc_rtscts_prot(arvif
);
2770 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2771 arvif
->vdev_id
, ret
);
2776 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2778 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2779 arvif
->vdev_id
, ret
);
2790 static int ath10k_update_channel_list(struct ath10k
*ar
)
2792 struct ieee80211_hw
*hw
= ar
->hw
;
2793 struct ieee80211_supported_band
**bands
;
2794 enum ieee80211_band band
;
2795 struct ieee80211_channel
*channel
;
2796 struct wmi_scan_chan_list_arg arg
= {0};
2797 struct wmi_channel_arg
*ch
;
2803 lockdep_assert_held(&ar
->conf_mutex
);
2805 bands
= hw
->wiphy
->bands
;
2806 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2810 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2811 if (bands
[band
]->channels
[i
].flags
&
2812 IEEE80211_CHAN_DISABLED
)
2819 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2820 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2825 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2829 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2830 channel
= &bands
[band
]->channels
[i
];
2832 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2835 ch
->allow_ht
= true;
2837 /* FIXME: when should we really allow VHT? */
2838 ch
->allow_vht
= true;
2841 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2844 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2847 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2849 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2850 ch
->passive
= passive
;
2852 ch
->freq
= channel
->center_freq
;
2853 ch
->band_center_freq1
= channel
->center_freq
;
2855 ch
->max_power
= channel
->max_power
* 2;
2856 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2857 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2858 ch
->reg_class_id
= 0; /* FIXME */
2860 /* FIXME: why use only legacy modes, why not any
2861 * HT/VHT modes? Would that even make any
2863 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2864 ch
->mode
= MODE_11G
;
2866 ch
->mode
= MODE_11A
;
2868 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2871 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2872 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2873 ch
- arg
.channels
, arg
.n_channels
,
2874 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2875 ch
->max_antenna_gain
, ch
->mode
);
2881 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2882 kfree(arg
.channels
);
2887 static enum wmi_dfs_region
2888 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2890 switch (dfs_region
) {
2891 case NL80211_DFS_UNSET
:
2892 return WMI_UNINIT_DFS_DOMAIN
;
2893 case NL80211_DFS_FCC
:
2894 return WMI_FCC_DFS_DOMAIN
;
2895 case NL80211_DFS_ETSI
:
2896 return WMI_ETSI_DFS_DOMAIN
;
2897 case NL80211_DFS_JP
:
2898 return WMI_MKK4_DFS_DOMAIN
;
2900 return WMI_UNINIT_DFS_DOMAIN
;
2903 static void ath10k_regd_update(struct ath10k
*ar
)
2905 struct reg_dmn_pair_mapping
*regpair
;
2907 enum wmi_dfs_region wmi_dfs_reg
;
2908 enum nl80211_dfs_regions nl_dfs_reg
;
2910 lockdep_assert_held(&ar
->conf_mutex
);
2912 ret
= ath10k_update_channel_list(ar
);
2914 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2916 regpair
= ar
->ath_common
.regulatory
.regpair
;
2918 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2919 nl_dfs_reg
= ar
->dfs_detector
->region
;
2920 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2922 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2925 /* Target allows setting up per-band regdomain but ath_common provides
2926 * a combined one only */
2927 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2928 regpair
->reg_domain
,
2929 regpair
->reg_domain
, /* 2ghz */
2930 regpair
->reg_domain
, /* 5ghz */
2931 regpair
->reg_2ghz_ctl
,
2932 regpair
->reg_5ghz_ctl
,
2935 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2938 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2939 struct regulatory_request
*request
)
2941 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2942 struct ath10k
*ar
= hw
->priv
;
2945 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2947 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2948 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
2949 request
->dfs_region
);
2950 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
2951 request
->dfs_region
);
2953 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2954 request
->dfs_region
);
2957 mutex_lock(&ar
->conf_mutex
);
2958 if (ar
->state
== ATH10K_STATE_ON
)
2959 ath10k_regd_update(ar
);
2960 mutex_unlock(&ar
->conf_mutex
);
2967 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
2969 lockdep_assert_held(&ar
->htt
.tx_lock
);
2971 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
2972 ar
->tx_paused
|= BIT(reason
);
2973 ieee80211_stop_queues(ar
->hw
);
2976 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
2977 struct ieee80211_vif
*vif
)
2979 struct ath10k
*ar
= data
;
2980 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2982 if (arvif
->tx_paused
)
2985 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
2988 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
2990 lockdep_assert_held(&ar
->htt
.tx_lock
);
2992 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
2993 ar
->tx_paused
&= ~BIT(reason
);
2998 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2999 IEEE80211_IFACE_ITER_RESUME_ALL
,
3000 ath10k_mac_tx_unlock_iter
,
3003 ieee80211_wake_queue(ar
->hw
, ar
->hw
->offchannel_tx_hw_queue
);
3006 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
3008 struct ath10k
*ar
= arvif
->ar
;
3010 lockdep_assert_held(&ar
->htt
.tx_lock
);
3012 WARN_ON(reason
>= BITS_PER_LONG
);
3013 arvif
->tx_paused
|= BIT(reason
);
3014 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
3017 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
3019 struct ath10k
*ar
= arvif
->ar
;
3021 lockdep_assert_held(&ar
->htt
.tx_lock
);
3023 WARN_ON(reason
>= BITS_PER_LONG
);
3024 arvif
->tx_paused
&= ~BIT(reason
);
3029 if (arvif
->tx_paused
)
3032 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3035 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
3036 enum wmi_tlv_tx_pause_id pause_id
,
3037 enum wmi_tlv_tx_pause_action action
)
3039 struct ath10k
*ar
= arvif
->ar
;
3041 lockdep_assert_held(&ar
->htt
.tx_lock
);
3044 case WMI_TLV_TX_PAUSE_ACTION_STOP
:
3045 ath10k_mac_vif_tx_lock(arvif
, pause_id
);
3047 case WMI_TLV_TX_PAUSE_ACTION_WAKE
:
3048 ath10k_mac_vif_tx_unlock(arvif
, pause_id
);
3051 ath10k_warn(ar
, "received unknown tx pause action %d on vdev %i, ignoring\n",
3052 action
, arvif
->vdev_id
);
3057 struct ath10k_mac_tx_pause
{
3059 enum wmi_tlv_tx_pause_id pause_id
;
3060 enum wmi_tlv_tx_pause_action action
;
3063 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
3064 struct ieee80211_vif
*vif
)
3066 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3067 struct ath10k_mac_tx_pause
*arg
= data
;
3069 if (arvif
->vdev_id
!= arg
->vdev_id
)
3072 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
3075 void ath10k_mac_handle_tx_pause_vdev(struct ath10k
*ar
, u32 vdev_id
,
3076 enum wmi_tlv_tx_pause_id pause_id
,
3077 enum wmi_tlv_tx_pause_action action
)
3079 struct ath10k_mac_tx_pause arg
= {
3081 .pause_id
= pause_id
,
3085 spin_lock_bh(&ar
->htt
.tx_lock
);
3086 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3087 IEEE80211_IFACE_ITER_RESUME_ALL
,
3088 ath10k_mac_handle_tx_pause_iter
,
3090 spin_unlock_bh(&ar
->htt
.tx_lock
);
3093 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
3095 if (ieee80211_is_mgmt(hdr
->frame_control
))
3096 return HTT_DATA_TX_EXT_TID_MGMT
;
3098 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3099 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3101 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
3102 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3104 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
3107 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
3110 return ath10k_vif_to_arvif(vif
)->vdev_id
;
3112 if (ar
->monitor_started
)
3113 return ar
->monitor_vdev_id
;
3115 ath10k_warn(ar
, "failed to resolve vdev id\n");
3119 static enum ath10k_hw_txrx_mode
3120 ath10k_tx_h_get_txmode(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
3121 struct ieee80211_sta
*sta
, struct sk_buff
*skb
)
3123 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3124 __le16 fc
= hdr
->frame_control
;
3126 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3127 return ATH10K_HW_TXRX_RAW
;
3129 if (ieee80211_is_mgmt(fc
))
3130 return ATH10K_HW_TXRX_MGMT
;
3134 * NullFunc frames are mostly used to ping if a client or AP are still
3135 * reachable and responsive. This implies tx status reports must be
3136 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3137 * come to a conclusion that the other end disappeared and tear down
3138 * BSS connection or it can never disconnect from BSS/client (which is
3141 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3142 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3143 * which seems to deliver correct tx reports for NullFunc frames. The
3144 * downside of using it is it ignores client powersave state so it can
3145 * end up disconnecting sleeping clients in AP mode. It should fix STA
3146 * mode though because AP don't sleep.
3148 if (ar
->htt
.target_version_major
< 3 &&
3149 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3150 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
, ar
->fw_features
))
3151 return ATH10K_HW_TXRX_MGMT
;
3155 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3156 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3157 * to work with Ethernet txmode so use it.
3159 * FIXME: Check if raw mode works with TDLS.
3161 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3162 return ATH10K_HW_TXRX_ETHERNET
;
3164 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
3165 return ATH10K_HW_TXRX_RAW
;
3167 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3170 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif
*vif
,
3171 struct sk_buff
*skb
) {
3172 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3173 const u32 mask
= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
3174 IEEE80211_TX_CTL_INJECTED
;
3175 if ((info
->flags
& mask
) == mask
)
3178 return !ath10k_vif_to_arvif(vif
)->nohwcrypt
;
3182 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3183 * Control in the header.
3185 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3187 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3188 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3191 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3194 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3195 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3196 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3197 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3199 /* Some firmware revisions don't handle sending QoS NullFunc well.
3200 * These frames are mainly used for CQM purposes so it doesn't really
3201 * matter whether QoS NullFunc or NullFunc are sent.
3203 hdr
= (void *)skb
->data
;
3204 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3205 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3207 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3210 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3212 struct ieee80211_hdr
*hdr
;
3213 struct rfc1042_hdr
*rfc1042
;
3220 hdr
= (void *)skb
->data
;
3221 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3222 rfc1042
= (void *)skb
->data
+ hdrlen
;
3224 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3225 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3226 type
= rfc1042
->snap_type
;
3228 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3229 skb_push(skb
, sizeof(*eth
));
3231 eth
= (void *)skb
->data
;
3232 ether_addr_copy(eth
->h_dest
, da
);
3233 ether_addr_copy(eth
->h_source
, sa
);
3234 eth
->h_proto
= type
;
3237 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3238 struct ieee80211_vif
*vif
,
3239 struct sk_buff
*skb
)
3241 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3242 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3244 /* This is case only for P2P_GO */
3245 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
3246 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
3249 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3250 spin_lock_bh(&ar
->data_lock
);
3251 if (arvif
->u
.ap
.noa_data
)
3252 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3254 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
3255 arvif
->u
.ap
.noa_data
,
3256 arvif
->u
.ap
.noa_len
);
3257 spin_unlock_bh(&ar
->data_lock
);
3261 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
3263 /* FIXME: Not really sure since when the behaviour changed. At some
3264 * point new firmware stopped requiring creation of peer entries for
3265 * offchannel tx (and actually creating them causes issues with wmi-htc
3266 * tx credit replenishment and reliability). Assuming it's at least 3.4
3267 * because that's when the `freq` was introduced to TX_FRM HTT command.
3269 return !(ar
->htt
.target_version_major
>= 3 &&
3270 ar
->htt
.target_version_minor
>= 4);
3273 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3275 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3278 spin_lock_bh(&ar
->data_lock
);
3280 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
3281 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3286 __skb_queue_tail(q
, skb
);
3287 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3290 spin_unlock_bh(&ar
->data_lock
);
3295 static void ath10k_mac_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
3297 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3298 struct ath10k_htt
*htt
= &ar
->htt
;
3301 switch (cb
->txmode
) {
3302 case ATH10K_HW_TXRX_RAW
:
3303 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3304 case ATH10K_HW_TXRX_ETHERNET
:
3305 ret
= ath10k_htt_tx(htt
, skb
);
3307 case ATH10K_HW_TXRX_MGMT
:
3308 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3310 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
3311 else if (ar
->htt
.target_version_major
>= 3)
3312 ret
= ath10k_htt_tx(htt
, skb
);
3314 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
3319 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
3321 ieee80211_free_txskb(ar
->hw
, skb
);
3325 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
3327 struct sk_buff
*skb
;
3330 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3334 ieee80211_free_txskb(ar
->hw
, skb
);
3338 void ath10k_offchan_tx_work(struct work_struct
*work
)
3340 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
3341 struct ath10k_peer
*peer
;
3342 struct ieee80211_hdr
*hdr
;
3343 struct sk_buff
*skb
;
3344 const u8
*peer_addr
;
3347 unsigned long time_left
;
3348 bool tmp_peer_created
= false;
3350 /* FW requirement: We must create a peer before FW will send out
3351 * an offchannel frame. Otherwise the frame will be stuck and
3352 * never transmitted. We delete the peer upon tx completion.
3353 * It is unlikely that a peer for offchannel tx will already be
3354 * present. However it may be in some rare cases so account for that.
3355 * Otherwise we might remove a legitimate peer and break stuff. */
3358 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3362 mutex_lock(&ar
->conf_mutex
);
3364 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
3367 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3368 peer_addr
= ieee80211_get_DA(hdr
);
3369 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
3371 spin_lock_bh(&ar
->data_lock
);
3372 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
3373 spin_unlock_bh(&ar
->data_lock
);
3376 /* FIXME: should this use ath10k_warn()? */
3377 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
3378 peer_addr
, vdev_id
);
3381 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
,
3382 WMI_PEER_TYPE_DEFAULT
);
3384 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
3385 peer_addr
, vdev_id
, ret
);
3386 tmp_peer_created
= (ret
== 0);
3389 spin_lock_bh(&ar
->data_lock
);
3390 reinit_completion(&ar
->offchan_tx_completed
);
3391 ar
->offchan_tx_skb
= skb
;
3392 spin_unlock_bh(&ar
->data_lock
);
3394 ath10k_mac_tx(ar
, skb
);
3397 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
3399 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
3402 if (!peer
&& tmp_peer_created
) {
3403 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
3405 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
3406 peer_addr
, vdev_id
, ret
);
3409 mutex_unlock(&ar
->conf_mutex
);
3413 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
3415 struct sk_buff
*skb
;
3418 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3422 ieee80211_free_txskb(ar
->hw
, skb
);
3426 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
3428 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
3429 struct sk_buff
*skb
;
3433 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3437 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
3439 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
3441 ieee80211_free_txskb(ar
->hw
, skb
);
3450 void __ath10k_scan_finish(struct ath10k
*ar
)
3452 lockdep_assert_held(&ar
->data_lock
);
3454 switch (ar
->scan
.state
) {
3455 case ATH10K_SCAN_IDLE
:
3457 case ATH10K_SCAN_RUNNING
:
3458 case ATH10K_SCAN_ABORTING
:
3459 if (!ar
->scan
.is_roc
)
3460 ieee80211_scan_completed(ar
->hw
,
3462 ATH10K_SCAN_ABORTING
));
3463 else if (ar
->scan
.roc_notify
)
3464 ieee80211_remain_on_channel_expired(ar
->hw
);
3466 case ATH10K_SCAN_STARTING
:
3467 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3468 ar
->scan_channel
= NULL
;
3469 ath10k_offchan_tx_purge(ar
);
3470 cancel_delayed_work(&ar
->scan
.timeout
);
3471 complete_all(&ar
->scan
.completed
);
3476 void ath10k_scan_finish(struct ath10k
*ar
)
3478 spin_lock_bh(&ar
->data_lock
);
3479 __ath10k_scan_finish(ar
);
3480 spin_unlock_bh(&ar
->data_lock
);
3483 static int ath10k_scan_stop(struct ath10k
*ar
)
3485 struct wmi_stop_scan_arg arg
= {
3486 .req_id
= 1, /* FIXME */
3487 .req_type
= WMI_SCAN_STOP_ONE
,
3488 .u
.scan_id
= ATH10K_SCAN_ID
,
3492 lockdep_assert_held(&ar
->conf_mutex
);
3494 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
3496 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
3500 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
3502 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
3504 } else if (ret
> 0) {
3509 /* Scan state should be updated upon scan completion but in case
3510 * firmware fails to deliver the event (for whatever reason) it is
3511 * desired to clean up scan state anyway. Firmware may have just
3512 * dropped the scan completion event delivery due to transport pipe
3513 * being overflown with data and/or it can recover on its own before
3514 * next scan request is submitted.
3516 spin_lock_bh(&ar
->data_lock
);
3517 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
3518 __ath10k_scan_finish(ar
);
3519 spin_unlock_bh(&ar
->data_lock
);
3524 static void ath10k_scan_abort(struct ath10k
*ar
)
3528 lockdep_assert_held(&ar
->conf_mutex
);
3530 spin_lock_bh(&ar
->data_lock
);
3532 switch (ar
->scan
.state
) {
3533 case ATH10K_SCAN_IDLE
:
3534 /* This can happen if timeout worker kicked in and called
3535 * abortion while scan completion was being processed.
3538 case ATH10K_SCAN_STARTING
:
3539 case ATH10K_SCAN_ABORTING
:
3540 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3541 ath10k_scan_state_str(ar
->scan
.state
),
3544 case ATH10K_SCAN_RUNNING
:
3545 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
3546 spin_unlock_bh(&ar
->data_lock
);
3548 ret
= ath10k_scan_stop(ar
);
3550 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
3552 spin_lock_bh(&ar
->data_lock
);
3556 spin_unlock_bh(&ar
->data_lock
);
3559 void ath10k_scan_timeout_work(struct work_struct
*work
)
3561 struct ath10k
*ar
= container_of(work
, struct ath10k
,
3564 mutex_lock(&ar
->conf_mutex
);
3565 ath10k_scan_abort(ar
);
3566 mutex_unlock(&ar
->conf_mutex
);
3569 static int ath10k_start_scan(struct ath10k
*ar
,
3570 const struct wmi_start_scan_arg
*arg
)
3574 lockdep_assert_held(&ar
->conf_mutex
);
3576 ret
= ath10k_wmi_start_scan(ar
, arg
);
3580 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
3582 ret
= ath10k_scan_stop(ar
);
3584 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
3589 /* If we failed to start the scan, return error code at
3590 * this point. This is probably due to some issue in the
3591 * firmware, but no need to wedge the driver due to that...
3593 spin_lock_bh(&ar
->data_lock
);
3594 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
3595 spin_unlock_bh(&ar
->data_lock
);
3598 spin_unlock_bh(&ar
->data_lock
);
3600 /* Add a 200ms margin to account for event/command processing */
3601 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
3602 msecs_to_jiffies(arg
->max_scan_time
+200));
3606 /**********************/
3607 /* mac80211 callbacks */
3608 /**********************/
3610 static void ath10k_tx(struct ieee80211_hw
*hw
,
3611 struct ieee80211_tx_control
*control
,
3612 struct sk_buff
*skb
)
3614 struct ath10k
*ar
= hw
->priv
;
3615 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3616 struct ieee80211_vif
*vif
= info
->control
.vif
;
3617 struct ieee80211_sta
*sta
= control
->sta
;
3618 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3619 __le16 fc
= hdr
->frame_control
;
3621 /* We should disable CCK RATE due to P2P */
3622 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3623 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3625 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
3626 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3627 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
3628 ATH10K_SKB_CB(skb
)->htt
.nohwcrypt
= !ath10k_tx_h_use_hwcrypto(vif
, skb
);
3629 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
3630 ATH10K_SKB_CB(skb
)->txmode
= ath10k_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3631 ATH10K_SKB_CB(skb
)->is_protected
= ieee80211_has_protected(fc
);
3633 switch (ATH10K_SKB_CB(skb
)->txmode
) {
3634 case ATH10K_HW_TXRX_MGMT
:
3635 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3636 ath10k_tx_h_nwifi(hw
, skb
);
3637 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3638 ath10k_tx_h_seq_no(vif
, skb
);
3640 case ATH10K_HW_TXRX_ETHERNET
:
3641 ath10k_tx_h_8023(skb
);
3643 case ATH10K_HW_TXRX_RAW
:
3644 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
3646 ieee80211_free_txskb(hw
, skb
);
3651 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3652 spin_lock_bh(&ar
->data_lock
);
3653 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
3654 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
3655 spin_unlock_bh(&ar
->data_lock
);
3657 if (ath10k_mac_need_offchan_tx_work(ar
)) {
3658 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3659 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
3661 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
3664 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3665 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3670 ath10k_mac_tx(ar
, skb
);
3673 /* Must not be called with conf_mutex held as workers can use that also. */
3674 void ath10k_drain_tx(struct ath10k
*ar
)
3676 /* make sure rcu-protected mac80211 tx path itself is drained */
3679 ath10k_offchan_tx_purge(ar
);
3680 ath10k_mgmt_over_wmi_tx_purge(ar
);
3682 cancel_work_sync(&ar
->offchan_tx_work
);
3683 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
3686 void ath10k_halt(struct ath10k
*ar
)
3688 struct ath10k_vif
*arvif
;
3690 lockdep_assert_held(&ar
->conf_mutex
);
3692 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
3693 ar
->filter_flags
= 0;
3694 ar
->monitor
= false;
3695 ar
->monitor_arvif
= NULL
;
3697 if (ar
->monitor_started
)
3698 ath10k_monitor_stop(ar
);
3700 ar
->monitor_started
= false;
3703 ath10k_scan_finish(ar
);
3704 ath10k_peer_cleanup_all(ar
);
3705 ath10k_core_stop(ar
);
3706 ath10k_hif_power_down(ar
);
3708 spin_lock_bh(&ar
->data_lock
);
3709 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
3710 ath10k_mac_vif_beacon_cleanup(arvif
);
3711 spin_unlock_bh(&ar
->data_lock
);
3714 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
3716 struct ath10k
*ar
= hw
->priv
;
3718 mutex_lock(&ar
->conf_mutex
);
3720 if (ar
->cfg_tx_chainmask
) {
3721 *tx_ant
= ar
->cfg_tx_chainmask
;
3722 *rx_ant
= ar
->cfg_rx_chainmask
;
3724 *tx_ant
= ar
->supp_tx_chainmask
;
3725 *rx_ant
= ar
->supp_rx_chainmask
;
3728 mutex_unlock(&ar
->conf_mutex
);
3733 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
3735 /* It is not clear that allowing gaps in chainmask
3736 * is helpful. Probably it will not do what user
3737 * is hoping for, so warn in that case.
3739 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
3742 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3746 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
3750 lockdep_assert_held(&ar
->conf_mutex
);
3752 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
3753 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
3755 ar
->cfg_tx_chainmask
= tx_ant
;
3756 ar
->cfg_rx_chainmask
= rx_ant
;
3758 if ((ar
->state
!= ATH10K_STATE_ON
) &&
3759 (ar
->state
!= ATH10K_STATE_RESTARTED
))
3762 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
3765 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
3770 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
3773 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
3781 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
3783 struct ath10k
*ar
= hw
->priv
;
3786 mutex_lock(&ar
->conf_mutex
);
3787 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
3788 mutex_unlock(&ar
->conf_mutex
);
3792 static int ath10k_start(struct ieee80211_hw
*hw
)
3794 struct ath10k
*ar
= hw
->priv
;
3799 * This makes sense only when restarting hw. It is harmless to call
3800 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3801 * commands will be submitted while restarting.
3803 ath10k_drain_tx(ar
);
3805 mutex_lock(&ar
->conf_mutex
);
3807 switch (ar
->state
) {
3808 case ATH10K_STATE_OFF
:
3809 ar
->state
= ATH10K_STATE_ON
;
3811 case ATH10K_STATE_RESTARTING
:
3813 ar
->state
= ATH10K_STATE_RESTARTED
;
3815 case ATH10K_STATE_ON
:
3816 case ATH10K_STATE_RESTARTED
:
3817 case ATH10K_STATE_WEDGED
:
3821 case ATH10K_STATE_UTF
:
3826 ret
= ath10k_hif_power_up(ar
);
3828 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
3832 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
3834 ath10k_err(ar
, "Could not init core: %d\n", ret
);
3835 goto err_power_down
;
3838 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
3840 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
3844 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
3846 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
3850 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
3851 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
3853 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
3859 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
3860 burst_enable
= ar
->wmi
.pdev_param
->burst_enable
;
3861 ret
= ath10k_wmi_pdev_set_param(ar
, burst_enable
, 0);
3863 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
3868 if (ar
->cfg_tx_chainmask
)
3869 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
3870 ar
->cfg_rx_chainmask
);
3873 * By default FW set ARP frames ac to voice (6). In that case ARP
3874 * exchange is not working properly for UAPSD enabled AP. ARP requests
3875 * which arrives with access category 0 are processed by network stack
3876 * and send back with access category 0, but FW changes access category
3877 * to 6. Set ARP frames access category to best effort (0) solves
3881 ret
= ath10k_wmi_pdev_set_param(ar
,
3882 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
3884 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
3889 ret
= ath10k_wmi_pdev_set_param(ar
,
3890 ar
->wmi
.pdev_param
->ani_enable
, 1);
3892 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
3897 ar
->ani_enabled
= true;
3899 ar
->num_started_vdevs
= 0;
3900 ath10k_regd_update(ar
);
3902 ath10k_spectral_start(ar
);
3903 ath10k_thermal_set_throttling(ar
);
3905 mutex_unlock(&ar
->conf_mutex
);
3909 ath10k_core_stop(ar
);
3912 ath10k_hif_power_down(ar
);
3915 ar
->state
= ATH10K_STATE_OFF
;
3918 mutex_unlock(&ar
->conf_mutex
);
3922 static void ath10k_stop(struct ieee80211_hw
*hw
)
3924 struct ath10k
*ar
= hw
->priv
;
3926 ath10k_drain_tx(ar
);
3928 mutex_lock(&ar
->conf_mutex
);
3929 if (ar
->state
!= ATH10K_STATE_OFF
) {
3931 ar
->state
= ATH10K_STATE_OFF
;
3933 mutex_unlock(&ar
->conf_mutex
);
3935 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3936 cancel_work_sync(&ar
->restart_work
);
3939 static int ath10k_config_ps(struct ath10k
*ar
)
3941 struct ath10k_vif
*arvif
;
3944 lockdep_assert_held(&ar
->conf_mutex
);
3946 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3947 ret
= ath10k_mac_vif_setup_ps(arvif
);
3949 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
3957 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
3962 lockdep_assert_held(&ar
->conf_mutex
);
3964 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
3966 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
3967 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3969 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
3974 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
3975 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
3977 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
3985 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
3987 struct ath10k_vif
*arvif
;
3988 int ret
, txpower
= -1;
3990 lockdep_assert_held(&ar
->conf_mutex
);
3992 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3993 WARN_ON(arvif
->txpower
< 0);
3996 txpower
= arvif
->txpower
;
3998 txpower
= min(txpower
, arvif
->txpower
);
4001 if (WARN_ON(txpower
== -1))
4004 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
4006 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
4014 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
4016 struct ath10k
*ar
= hw
->priv
;
4017 struct ieee80211_conf
*conf
= &hw
->conf
;
4020 mutex_lock(&ar
->conf_mutex
);
4022 if (changed
& IEEE80211_CONF_CHANGE_PS
)
4023 ath10k_config_ps(ar
);
4025 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
4026 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
4027 ret
= ath10k_monitor_recalc(ar
);
4029 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4032 mutex_unlock(&ar
->conf_mutex
);
4036 static u32
get_nss_from_chainmask(u16 chain_mask
)
4038 if ((chain_mask
& 0x15) == 0x15)
4040 else if ((chain_mask
& 0x7) == 0x7)
4042 else if ((chain_mask
& 0x3) == 0x3)
4047 static int ath10k_mac_set_txbf_conf(struct ath10k_vif
*arvif
)
4050 struct ath10k
*ar
= arvif
->ar
;
4052 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_BEFORE_ASSOC
)
4055 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
4056 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
))
4057 value
|= SM((ar
->num_rf_chains
- 1), WMI_TXBF_STS_CAP_OFFSET
);
4059 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
4060 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
))
4061 value
|= SM((ar
->num_rf_chains
- 1), WMI_BF_SOUND_DIM_OFFSET
);
4066 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
4067 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
4069 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
4070 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER
|
4071 WMI_VDEV_PARAM_TXBF_SU_TX_BFER
);
4073 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
4074 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
4076 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
4077 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
|
4078 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
);
4080 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
4081 ar
->wmi
.vdev_param
->txbf
, value
);
4086 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4087 * because we will send mgmt frames without CCK. This requirement
4088 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4091 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
4092 struct ieee80211_vif
*vif
)
4094 struct ath10k
*ar
= hw
->priv
;
4095 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4096 enum wmi_sta_powersave_param param
;
4103 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
4105 mutex_lock(&ar
->conf_mutex
);
4107 memset(arvif
, 0, sizeof(*arvif
));
4112 INIT_LIST_HEAD(&arvif
->list
);
4113 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
4114 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
4115 ath10k_mac_vif_sta_connection_loss_work
);
4117 for (i
= 0; i
< ARRAY_SIZE(arvif
->bitrate_mask
.control
); i
++) {
4118 arvif
->bitrate_mask
.control
[i
].legacy
= 0xffffffff;
4119 memset(arvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
4120 sizeof(arvif
->bitrate_mask
.control
[i
].ht_mcs
));
4121 memset(arvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
4122 sizeof(arvif
->bitrate_mask
.control
[i
].vht_mcs
));
4125 if (ar
->num_peers
>= ar
->max_num_peers
) {
4126 ath10k_warn(ar
, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4130 if (ar
->free_vdev_map
== 0) {
4131 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
4135 bit
= __ffs64(ar
->free_vdev_map
);
4137 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
4138 bit
, ar
->free_vdev_map
);
4140 arvif
->vdev_id
= bit
;
4141 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
4143 switch (vif
->type
) {
4144 case NL80211_IFTYPE_P2P_DEVICE
:
4145 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4146 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
4148 case NL80211_IFTYPE_UNSPECIFIED
:
4149 case NL80211_IFTYPE_STATION
:
4150 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4152 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
4154 case NL80211_IFTYPE_ADHOC
:
4155 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
4157 case NL80211_IFTYPE_AP
:
4158 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
4161 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
4163 case NL80211_IFTYPE_MONITOR
:
4164 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
4171 /* Using vdev_id as queue number will make it very easy to do per-vif
4172 * tx queue locking. This shouldn't wrap due to interface combinations
4173 * but do a modulo for correctness sake and prevent using offchannel tx
4174 * queues for regular vif tx.
4176 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4177 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
4178 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4180 /* Some firmware revisions don't wait for beacon tx completion before
4181 * sending another SWBA event. This could lead to hardware using old
4182 * (freed) beacon data in some cases, e.g. tx credit starvation
4183 * combined with missed TBTT. This is very very rare.
4185 * On non-IOMMU-enabled hosts this could be a possible security issue
4186 * because hw could beacon some random data on the air. On
4187 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4188 * device would crash.
4190 * Since there are no beacon tx completions (implicit nor explicit)
4191 * propagated to host the only workaround for this is to allocate a
4192 * DMA-coherent buffer for a lifetime of a vif and use it for all
4193 * beacon tx commands. Worst case for this approach is some beacons may
4194 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4196 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
4197 vif
->type
== NL80211_IFTYPE_AP
) {
4198 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
4199 IEEE80211_MAX_FRAME_LEN
,
4200 &arvif
->beacon_paddr
,
4202 if (!arvif
->beacon_buf
) {
4204 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
4209 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
))
4210 arvif
->nohwcrypt
= true;
4212 if (arvif
->nohwcrypt
&&
4213 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
4214 ath10k_warn(ar
, "cryptmode module param needed for sw crypto\n");
4218 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4219 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
4220 arvif
->beacon_buf
? "single-buf" : "per-skb");
4222 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
4223 arvif
->vdev_subtype
, vif
->addr
);
4225 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
4226 arvif
->vdev_id
, ret
);
4230 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
4231 list_add(&arvif
->list
, &ar
->arvifs
);
4233 /* It makes no sense to have firmware do keepalives. mac80211 already
4234 * takes care of this with idle connection polling.
4236 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
4238 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
4239 arvif
->vdev_id
, ret
);
4240 goto err_vdev_delete
;
4243 arvif
->def_wep_key_idx
= -1;
4245 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
4246 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4247 ATH10K_HW_TXRX_NATIVE_WIFI
);
4248 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4249 if (ret
&& ret
!= -EOPNOTSUPP
) {
4250 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
4251 arvif
->vdev_id
, ret
);
4252 goto err_vdev_delete
;
4255 if (ar
->cfg_tx_chainmask
) {
4256 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4258 vdev_param
= ar
->wmi
.vdev_param
->nss
;
4259 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4262 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4263 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
4265 goto err_vdev_delete
;
4269 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4270 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4271 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
,
4272 WMI_PEER_TYPE_DEFAULT
);
4274 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
4275 arvif
->vdev_id
, ret
);
4276 goto err_vdev_delete
;
4280 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
4281 ret
= ath10k_mac_set_kickout(arvif
);
4283 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
4284 arvif
->vdev_id
, ret
);
4285 goto err_peer_delete
;
4289 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
4290 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
4291 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4292 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4295 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
4296 arvif
->vdev_id
, ret
);
4297 goto err_peer_delete
;
4300 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4302 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4303 arvif
->vdev_id
, ret
);
4304 goto err_peer_delete
;
4307 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4309 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4310 arvif
->vdev_id
, ret
);
4311 goto err_peer_delete
;
4315 ret
= ath10k_mac_set_txbf_conf(arvif
);
4317 ath10k_warn(ar
, "failed to set txbf for vdev %d: %d\n",
4318 arvif
->vdev_id
, ret
);
4319 goto err_peer_delete
;
4322 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
4324 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
4325 arvif
->vdev_id
, ret
);
4326 goto err_peer_delete
;
4329 arvif
->txpower
= vif
->bss_conf
.txpower
;
4330 ret
= ath10k_mac_txpower_recalc(ar
);
4332 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4333 goto err_peer_delete
;
4336 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4337 ar
->monitor_arvif
= arvif
;
4338 ret
= ath10k_monitor_recalc(ar
);
4340 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4341 goto err_peer_delete
;
4345 spin_lock_bh(&ar
->htt
.tx_lock
);
4347 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
4348 spin_unlock_bh(&ar
->htt
.tx_lock
);
4350 mutex_unlock(&ar
->conf_mutex
);
4354 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4355 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
)
4356 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
4359 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4360 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4361 list_del(&arvif
->list
);
4364 if (arvif
->beacon_buf
) {
4365 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
4366 arvif
->beacon_buf
, arvif
->beacon_paddr
);
4367 arvif
->beacon_buf
= NULL
;
4370 mutex_unlock(&ar
->conf_mutex
);
4375 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
4379 for (i
= 0; i
< BITS_PER_LONG
; i
++)
4380 ath10k_mac_vif_tx_unlock(arvif
, i
);
4383 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
4384 struct ieee80211_vif
*vif
)
4386 struct ath10k
*ar
= hw
->priv
;
4387 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4390 cancel_work_sync(&arvif
->ap_csa_work
);
4391 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
4393 mutex_lock(&ar
->conf_mutex
);
4395 spin_lock_bh(&ar
->data_lock
);
4396 ath10k_mac_vif_beacon_cleanup(arvif
);
4397 spin_unlock_bh(&ar
->data_lock
);
4399 ret
= ath10k_spectral_vif_stop(arvif
);
4401 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
4402 arvif
->vdev_id
, ret
);
4404 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4405 list_del(&arvif
->list
);
4407 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4408 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4409 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
4412 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4413 arvif
->vdev_id
, ret
);
4415 kfree(arvif
->u
.ap
.noa_data
);
4418 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
4421 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4423 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
4424 arvif
->vdev_id
, ret
);
4426 /* Some firmware revisions don't notify host about self-peer removal
4427 * until after associated vdev is deleted.
4429 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4430 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4431 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
4434 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
4435 arvif
->vdev_id
, ret
);
4437 spin_lock_bh(&ar
->data_lock
);
4439 spin_unlock_bh(&ar
->data_lock
);
4442 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
4444 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4445 ar
->monitor_arvif
= NULL
;
4446 ret
= ath10k_monitor_recalc(ar
);
4448 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4451 spin_lock_bh(&ar
->htt
.tx_lock
);
4452 ath10k_mac_vif_tx_unlock_all(arvif
);
4453 spin_unlock_bh(&ar
->htt
.tx_lock
);
4455 mutex_unlock(&ar
->conf_mutex
);
4459 * FIXME: Has to be verified.
4461 #define SUPPORTED_FILTERS \
4466 FIF_BCN_PRBRESP_PROMISC | \
4470 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
4471 unsigned int changed_flags
,
4472 unsigned int *total_flags
,
4475 struct ath10k
*ar
= hw
->priv
;
4478 mutex_lock(&ar
->conf_mutex
);
4480 changed_flags
&= SUPPORTED_FILTERS
;
4481 *total_flags
&= SUPPORTED_FILTERS
;
4482 ar
->filter_flags
= *total_flags
;
4484 ret
= ath10k_monitor_recalc(ar
);
4486 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
4488 mutex_unlock(&ar
->conf_mutex
);
4491 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
4492 struct ieee80211_vif
*vif
,
4493 struct ieee80211_bss_conf
*info
,
4496 struct ath10k
*ar
= hw
->priv
;
4497 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4499 u32 vdev_param
, pdev_param
, slottime
, preamble
;
4501 mutex_lock(&ar
->conf_mutex
);
4503 if (changed
& BSS_CHANGED_IBSS
)
4504 ath10k_control_ibss(arvif
, info
, vif
->addr
);
4506 if (changed
& BSS_CHANGED_BEACON_INT
) {
4507 arvif
->beacon_interval
= info
->beacon_int
;
4508 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
4509 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4510 arvif
->beacon_interval
);
4511 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4512 "mac vdev %d beacon_interval %d\n",
4513 arvif
->vdev_id
, arvif
->beacon_interval
);
4516 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
4517 arvif
->vdev_id
, ret
);
4520 if (changed
& BSS_CHANGED_BEACON
) {
4521 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4522 "vdev %d set beacon tx mode to staggered\n",
4525 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
4526 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
4527 WMI_BEACON_STAGGERED_MODE
);
4529 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
4530 arvif
->vdev_id
, ret
);
4532 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
4534 ath10k_warn(ar
, "failed to update beacon template: %d\n",
4538 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
4539 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
4541 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
4542 arvif
->vdev_id
, ret
);
4545 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
4546 arvif
->dtim_period
= info
->dtim_period
;
4548 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4549 "mac vdev %d dtim_period %d\n",
4550 arvif
->vdev_id
, arvif
->dtim_period
);
4552 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
4553 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4554 arvif
->dtim_period
);
4556 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
4557 arvif
->vdev_id
, ret
);
4560 if (changed
& BSS_CHANGED_SSID
&&
4561 vif
->type
== NL80211_IFTYPE_AP
) {
4562 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
4564 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
4565 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
4568 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
4569 ether_addr_copy(arvif
->bssid
, info
->bssid
);
4571 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4572 ath10k_control_beaconing(arvif
, info
);
4574 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
4575 arvif
->use_cts_prot
= info
->use_cts_prot
;
4576 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
4577 arvif
->vdev_id
, info
->use_cts_prot
);
4579 ret
= ath10k_recalc_rtscts_prot(arvif
);
4581 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4582 arvif
->vdev_id
, ret
);
4584 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
4585 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4586 info
->use_cts_prot
? 1 : 0);
4588 ath10k_warn(ar
, "failed to set protection mode %d on vdev %i: %d\n",
4589 info
->use_cts_prot
, arvif
->vdev_id
, ret
);
4592 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4593 if (info
->use_short_slot
)
4594 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
4597 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
4599 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
4600 arvif
->vdev_id
, slottime
);
4602 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
4603 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4606 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
4607 arvif
->vdev_id
, ret
);
4610 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4611 if (info
->use_short_preamble
)
4612 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
4614 preamble
= WMI_VDEV_PREAMBLE_LONG
;
4616 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4617 "mac vdev %d preamble %dn",
4618 arvif
->vdev_id
, preamble
);
4620 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
4621 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4624 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
4625 arvif
->vdev_id
, ret
);
4628 if (changed
& BSS_CHANGED_ASSOC
) {
4630 /* Workaround: Make sure monitor vdev is not running
4631 * when associating to prevent some firmware revisions
4632 * (e.g. 10.1 and 10.2) from crashing.
4634 if (ar
->monitor_started
)
4635 ath10k_monitor_stop(ar
);
4636 ath10k_bss_assoc(hw
, vif
, info
);
4637 ath10k_monitor_recalc(ar
);
4639 ath10k_bss_disassoc(hw
, vif
);
4643 if (changed
& BSS_CHANGED_TXPOWER
) {
4644 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
4645 arvif
->vdev_id
, info
->txpower
);
4647 arvif
->txpower
= info
->txpower
;
4648 ret
= ath10k_mac_txpower_recalc(ar
);
4650 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4653 if (changed
& BSS_CHANGED_PS
) {
4654 arvif
->ps
= vif
->bss_conf
.ps
;
4656 ret
= ath10k_config_ps(ar
);
4658 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
4659 arvif
->vdev_id
, ret
);
4662 mutex_unlock(&ar
->conf_mutex
);
4665 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
4666 struct ieee80211_vif
*vif
,
4667 struct ieee80211_scan_request
*hw_req
)
4669 struct ath10k
*ar
= hw
->priv
;
4670 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4671 struct cfg80211_scan_request
*req
= &hw_req
->req
;
4672 struct wmi_start_scan_arg arg
;
4676 mutex_lock(&ar
->conf_mutex
);
4678 spin_lock_bh(&ar
->data_lock
);
4679 switch (ar
->scan
.state
) {
4680 case ATH10K_SCAN_IDLE
:
4681 reinit_completion(&ar
->scan
.started
);
4682 reinit_completion(&ar
->scan
.completed
);
4683 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4684 ar
->scan
.is_roc
= false;
4685 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4688 case ATH10K_SCAN_STARTING
:
4689 case ATH10K_SCAN_RUNNING
:
4690 case ATH10K_SCAN_ABORTING
:
4694 spin_unlock_bh(&ar
->data_lock
);
4699 memset(&arg
, 0, sizeof(arg
));
4700 ath10k_wmi_start_scan_init(ar
, &arg
);
4701 arg
.vdev_id
= arvif
->vdev_id
;
4702 arg
.scan_id
= ATH10K_SCAN_ID
;
4705 arg
.ie_len
= req
->ie_len
;
4706 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
4710 arg
.n_ssids
= req
->n_ssids
;
4711 for (i
= 0; i
< arg
.n_ssids
; i
++) {
4712 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
4713 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
4716 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4719 if (req
->n_channels
) {
4720 arg
.n_channels
= req
->n_channels
;
4721 for (i
= 0; i
< arg
.n_channels
; i
++)
4722 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
4725 ret
= ath10k_start_scan(ar
, &arg
);
4727 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
4728 spin_lock_bh(&ar
->data_lock
);
4729 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4730 spin_unlock_bh(&ar
->data_lock
);
4734 mutex_unlock(&ar
->conf_mutex
);
4738 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
4739 struct ieee80211_vif
*vif
)
4741 struct ath10k
*ar
= hw
->priv
;
4743 mutex_lock(&ar
->conf_mutex
);
4744 ath10k_scan_abort(ar
);
4745 mutex_unlock(&ar
->conf_mutex
);
4747 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4750 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
4751 struct ath10k_vif
*arvif
,
4752 enum set_key_cmd cmd
,
4753 struct ieee80211_key_conf
*key
)
4755 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
4758 /* 10.1 firmware branch requires default key index to be set to group
4759 * key index after installing it. Otherwise FW/HW Txes corrupted
4760 * frames with multi-vif APs. This is not required for main firmware
4761 * branch (e.g. 636).
4763 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4765 * FIXME: It remains unknown if this is required for multi-vif STA
4766 * interfaces on 10.1.
4769 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
4770 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
4773 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
4776 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
4779 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4785 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4788 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
4789 arvif
->vdev_id
, ret
);
4792 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
4793 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
4794 struct ieee80211_key_conf
*key
)
4796 struct ath10k
*ar
= hw
->priv
;
4797 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4798 struct ath10k_peer
*peer
;
4799 const u8
*peer_addr
;
4800 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
4801 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
4807 /* this one needs to be done in software */
4808 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
4811 if (arvif
->nohwcrypt
)
4814 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
4817 mutex_lock(&ar
->conf_mutex
);
4820 peer_addr
= sta
->addr
;
4821 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
4822 peer_addr
= vif
->bss_conf
.bssid
;
4824 peer_addr
= vif
->addr
;
4826 key
->hw_key_idx
= key
->keyidx
;
4830 arvif
->wep_keys
[key
->keyidx
] = key
;
4832 arvif
->wep_keys
[key
->keyidx
] = NULL
;
4835 /* the peer should not disappear in mid-way (unless FW goes awry) since
4836 * we already hold conf_mutex. we just make sure its there now. */
4837 spin_lock_bh(&ar
->data_lock
);
4838 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4839 spin_unlock_bh(&ar
->data_lock
);
4842 if (cmd
== SET_KEY
) {
4843 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
4848 /* if the peer doesn't exist there is no key to disable
4854 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4855 flags
|= WMI_KEY_PAIRWISE
;
4857 flags
|= WMI_KEY_GROUP
;
4860 if (cmd
== DISABLE_KEY
)
4861 ath10k_clear_vdev_key(arvif
, key
);
4863 /* When WEP keys are uploaded it's possible that there are
4864 * stations associated already (e.g. when merging) without any
4865 * keys. Static WEP needs an explicit per-peer key upload.
4867 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
4869 ath10k_mac_vif_update_wep_key(arvif
, key
);
4871 /* 802.1x never sets the def_wep_key_idx so each set_key()
4872 * call changes default tx key.
4874 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4875 * after first set_key().
4877 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
4878 flags
|= WMI_KEY_TX_USAGE
;
4881 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
4884 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
4885 arvif
->vdev_id
, peer_addr
, ret
);
4889 /* mac80211 sets static WEP keys as groupwise while firmware requires
4890 * them to be installed twice as both pairwise and groupwise.
4892 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
4894 flags2
&= ~WMI_KEY_GROUP
;
4895 flags2
|= WMI_KEY_PAIRWISE
;
4897 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
4900 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4901 arvif
->vdev_id
, peer_addr
, ret
);
4902 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
4906 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4907 arvif
->vdev_id
, peer_addr
, ret2
);
4913 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
4915 spin_lock_bh(&ar
->data_lock
);
4916 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4917 if (peer
&& cmd
== SET_KEY
)
4918 peer
->keys
[key
->keyidx
] = key
;
4919 else if (peer
&& cmd
== DISABLE_KEY
)
4920 peer
->keys
[key
->keyidx
] = NULL
;
4921 else if (peer
== NULL
)
4922 /* impossible unless FW goes crazy */
4923 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
4924 spin_unlock_bh(&ar
->data_lock
);
4927 mutex_unlock(&ar
->conf_mutex
);
4931 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
4932 struct ieee80211_vif
*vif
,
4935 struct ath10k
*ar
= hw
->priv
;
4936 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4939 mutex_lock(&arvif
->ar
->conf_mutex
);
4941 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
4944 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
4945 arvif
->vdev_id
, keyidx
);
4947 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
4949 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
4953 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
4959 arvif
->def_wep_key_idx
= keyidx
;
4962 mutex_unlock(&arvif
->ar
->conf_mutex
);
4965 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
4968 struct ath10k_vif
*arvif
;
4969 struct ath10k_sta
*arsta
;
4970 struct ieee80211_sta
*sta
;
4971 struct cfg80211_chan_def def
;
4972 enum ieee80211_band band
;
4973 const u8
*ht_mcs_mask
;
4974 const u16
*vht_mcs_mask
;
4975 u32 changed
, bw
, nss
, smps
;
4978 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
4979 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
4980 arvif
= arsta
->arvif
;
4983 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
4986 band
= def
.chan
->band
;
4987 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
4988 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
4990 spin_lock_bh(&ar
->data_lock
);
4992 changed
= arsta
->changed
;
4999 spin_unlock_bh(&ar
->data_lock
);
5001 mutex_lock(&ar
->conf_mutex
);
5003 nss
= max_t(u32
, 1, nss
);
5004 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
5005 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
5007 if (changed
& IEEE80211_RC_BW_CHANGED
) {
5008 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
5011 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5012 WMI_PEER_CHAN_WIDTH
, bw
);
5014 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
5015 sta
->addr
, bw
, err
);
5018 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
5019 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
5022 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5025 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
5026 sta
->addr
, nss
, err
);
5029 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5030 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
5033 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5034 WMI_PEER_SMPS_STATE
, smps
);
5036 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
5037 sta
->addr
, smps
, err
);
5040 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
||
5041 changed
& IEEE80211_RC_NSS_CHANGED
) {
5042 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates/nss\n",
5045 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
5047 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
5051 mutex_unlock(&ar
->conf_mutex
);
5054 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
5055 struct ieee80211_sta
*sta
)
5057 struct ath10k
*ar
= arvif
->ar
;
5059 lockdep_assert_held(&ar
->conf_mutex
);
5061 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
5064 if (ar
->num_stations
>= ar
->max_num_stations
)
5072 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
5073 struct ieee80211_sta
*sta
)
5075 struct ath10k
*ar
= arvif
->ar
;
5077 lockdep_assert_held(&ar
->conf_mutex
);
5079 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
5085 struct ath10k_mac_tdls_iter_data
{
5086 u32 num_tdls_stations
;
5087 struct ieee80211_vif
*curr_vif
;
5090 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
5091 struct ieee80211_sta
*sta
)
5093 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
5094 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5095 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
5097 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
5098 iter_data
->num_tdls_stations
++;
5101 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
5102 struct ieee80211_vif
*vif
)
5104 struct ath10k_mac_tdls_iter_data data
= {};
5106 data
.curr_vif
= vif
;
5108 ieee80211_iterate_stations_atomic(hw
,
5109 ath10k_mac_tdls_vif_stations_count_iter
,
5111 return data
.num_tdls_stations
;
5114 static void ath10k_mac_tdls_vifs_count_iter(void *data
, u8
*mac
,
5115 struct ieee80211_vif
*vif
)
5117 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5118 int *num_tdls_vifs
= data
;
5120 if (vif
->type
!= NL80211_IFTYPE_STATION
)
5123 if (ath10k_mac_tdls_vif_stations_count(arvif
->ar
->hw
, vif
) > 0)
5127 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw
*hw
)
5129 int num_tdls_vifs
= 0;
5131 ieee80211_iterate_active_interfaces_atomic(hw
,
5132 IEEE80211_IFACE_ITER_NORMAL
,
5133 ath10k_mac_tdls_vifs_count_iter
,
5135 return num_tdls_vifs
;
5138 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
5139 struct ieee80211_vif
*vif
,
5140 struct ieee80211_sta
*sta
,
5141 enum ieee80211_sta_state old_state
,
5142 enum ieee80211_sta_state new_state
)
5144 struct ath10k
*ar
= hw
->priv
;
5145 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5146 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5149 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5150 new_state
== IEEE80211_STA_NONE
) {
5151 memset(arsta
, 0, sizeof(*arsta
));
5152 arsta
->arvif
= arvif
;
5153 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
5156 /* cancel must be done outside the mutex to avoid deadlock */
5157 if ((old_state
== IEEE80211_STA_NONE
&&
5158 new_state
== IEEE80211_STA_NOTEXIST
))
5159 cancel_work_sync(&arsta
->update_wk
);
5161 mutex_lock(&ar
->conf_mutex
);
5163 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5164 new_state
== IEEE80211_STA_NONE
) {
5166 * New station addition.
5168 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
5169 u32 num_tdls_stations
;
5172 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5173 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5174 arvif
->vdev_id
, sta
->addr
,
5175 ar
->num_stations
+ 1, ar
->max_num_stations
,
5176 ar
->num_peers
+ 1, ar
->max_num_peers
);
5178 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
5180 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
5181 ar
->max_num_stations
);
5186 peer_type
= WMI_PEER_TYPE_TDLS
;
5188 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
,
5191 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5192 sta
->addr
, arvif
->vdev_id
, ret
);
5193 ath10k_mac_dec_num_stations(arvif
, sta
);
5200 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
5201 num_tdls_vifs
= ath10k_mac_tdls_vifs_count(hw
);
5203 if (num_tdls_vifs
>= ar
->max_num_tdls_vdevs
&&
5204 num_tdls_stations
== 0) {
5205 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5206 arvif
->vdev_id
, ar
->max_num_tdls_vdevs
);
5207 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5208 ath10k_mac_dec_num_stations(arvif
, sta
);
5213 if (num_tdls_stations
== 0) {
5214 /* This is the first tdls peer in current vif */
5215 enum wmi_tdls_state state
= WMI_TDLS_ENABLE_ACTIVE
;
5217 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5220 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5221 arvif
->vdev_id
, ret
);
5222 ath10k_peer_delete(ar
, arvif
->vdev_id
,
5224 ath10k_mac_dec_num_stations(arvif
, sta
);
5229 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5230 WMI_TDLS_PEER_STATE_PEERING
);
5233 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5234 sta
->addr
, arvif
->vdev_id
, ret
);
5235 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5236 ath10k_mac_dec_num_stations(arvif
, sta
);
5238 if (num_tdls_stations
!= 0)
5240 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5243 } else if ((old_state
== IEEE80211_STA_NONE
&&
5244 new_state
== IEEE80211_STA_NOTEXIST
)) {
5246 * Existing station deletion.
5248 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5249 "mac vdev %d peer delete %pM (sta gone)\n",
5250 arvif
->vdev_id
, sta
->addr
);
5252 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5254 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
5255 sta
->addr
, arvif
->vdev_id
, ret
);
5257 ath10k_mac_dec_num_stations(arvif
, sta
);
5262 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
5265 /* This was the last tdls peer in current vif */
5266 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5269 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5270 arvif
->vdev_id
, ret
);
5272 } else if (old_state
== IEEE80211_STA_AUTH
&&
5273 new_state
== IEEE80211_STA_ASSOC
&&
5274 (vif
->type
== NL80211_IFTYPE_AP
||
5275 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5279 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
5282 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5284 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
5285 sta
->addr
, arvif
->vdev_id
, ret
);
5286 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5287 new_state
== IEEE80211_STA_AUTHORIZED
&&
5290 * Tdls station authorized.
5292 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
5295 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5297 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
5298 sta
->addr
, arvif
->vdev_id
, ret
);
5302 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5303 WMI_TDLS_PEER_STATE_CONNECTED
);
5305 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
5306 sta
->addr
, arvif
->vdev_id
, ret
);
5307 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5308 new_state
== IEEE80211_STA_AUTH
&&
5309 (vif
->type
== NL80211_IFTYPE_AP
||
5310 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5314 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
5317 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
5319 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
5320 sta
->addr
, arvif
->vdev_id
, ret
);
5323 mutex_unlock(&ar
->conf_mutex
);
5327 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
5328 u16 ac
, bool enable
)
5330 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5331 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
5332 u32 prio
= 0, acc
= 0;
5336 lockdep_assert_held(&ar
->conf_mutex
);
5338 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
5342 case IEEE80211_AC_VO
:
5343 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
5344 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
5348 case IEEE80211_AC_VI
:
5349 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
5350 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
5354 case IEEE80211_AC_BE
:
5355 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
5356 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
5360 case IEEE80211_AC_BK
:
5361 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
5362 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
5369 arvif
->u
.sta
.uapsd
|= value
;
5371 arvif
->u
.sta
.uapsd
&= ~value
;
5373 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5374 WMI_STA_PS_PARAM_UAPSD
,
5375 arvif
->u
.sta
.uapsd
);
5377 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
5381 if (arvif
->u
.sta
.uapsd
)
5382 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
5384 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5386 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5387 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
5390 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
5392 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5394 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5395 arvif
->vdev_id
, ret
);
5399 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5401 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5402 arvif
->vdev_id
, ret
);
5406 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
5407 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
5408 /* Only userspace can make an educated decision when to send
5409 * trigger frame. The following effectively disables u-UAPSD
5410 * autotrigger in firmware (which is enabled by default
5411 * provided the autotrigger service is available).
5415 arg
.user_priority
= prio
;
5416 arg
.service_interval
= 0;
5417 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5418 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5420 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
5421 arvif
->bssid
, &arg
, 1);
5423 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
5433 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
5434 struct ieee80211_vif
*vif
, u16 ac
,
5435 const struct ieee80211_tx_queue_params
*params
)
5437 struct ath10k
*ar
= hw
->priv
;
5438 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5439 struct wmi_wmm_params_arg
*p
= NULL
;
5442 mutex_lock(&ar
->conf_mutex
);
5445 case IEEE80211_AC_VO
:
5446 p
= &arvif
->wmm_params
.ac_vo
;
5448 case IEEE80211_AC_VI
:
5449 p
= &arvif
->wmm_params
.ac_vi
;
5451 case IEEE80211_AC_BE
:
5452 p
= &arvif
->wmm_params
.ac_be
;
5454 case IEEE80211_AC_BK
:
5455 p
= &arvif
->wmm_params
.ac_bk
;
5464 p
->cwmin
= params
->cw_min
;
5465 p
->cwmax
= params
->cw_max
;
5466 p
->aifs
= params
->aifs
;
5469 * The channel time duration programmed in the HW is in absolute
5470 * microseconds, while mac80211 gives the txop in units of
5473 p
->txop
= params
->txop
* 32;
5475 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
5476 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
5477 &arvif
->wmm_params
);
5479 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
5480 arvif
->vdev_id
, ret
);
5484 /* This won't work well with multi-interface cases but it's
5485 * better than nothing.
5487 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
5489 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
5494 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
5496 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
5499 mutex_unlock(&ar
->conf_mutex
);
5503 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5505 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
5506 struct ieee80211_vif
*vif
,
5507 struct ieee80211_channel
*chan
,
5509 enum ieee80211_roc_type type
)
5511 struct ath10k
*ar
= hw
->priv
;
5512 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5513 struct wmi_start_scan_arg arg
;
5517 mutex_lock(&ar
->conf_mutex
);
5519 spin_lock_bh(&ar
->data_lock
);
5520 switch (ar
->scan
.state
) {
5521 case ATH10K_SCAN_IDLE
:
5522 reinit_completion(&ar
->scan
.started
);
5523 reinit_completion(&ar
->scan
.completed
);
5524 reinit_completion(&ar
->scan
.on_channel
);
5525 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
5526 ar
->scan
.is_roc
= true;
5527 ar
->scan
.vdev_id
= arvif
->vdev_id
;
5528 ar
->scan
.roc_freq
= chan
->center_freq
;
5529 ar
->scan
.roc_notify
= true;
5532 case ATH10K_SCAN_STARTING
:
5533 case ATH10K_SCAN_RUNNING
:
5534 case ATH10K_SCAN_ABORTING
:
5538 spin_unlock_bh(&ar
->data_lock
);
5543 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
5545 memset(&arg
, 0, sizeof(arg
));
5546 ath10k_wmi_start_scan_init(ar
, &arg
);
5547 arg
.vdev_id
= arvif
->vdev_id
;
5548 arg
.scan_id
= ATH10K_SCAN_ID
;
5550 arg
.channels
[0] = chan
->center_freq
;
5551 arg
.dwell_time_active
= scan_time_msec
;
5552 arg
.dwell_time_passive
= scan_time_msec
;
5553 arg
.max_scan_time
= scan_time_msec
;
5554 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
5555 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
5556 arg
.burst_duration_ms
= duration
;
5558 ret
= ath10k_start_scan(ar
, &arg
);
5560 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
5561 spin_lock_bh(&ar
->data_lock
);
5562 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
5563 spin_unlock_bh(&ar
->data_lock
);
5567 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
5569 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
5571 ret
= ath10k_scan_stop(ar
);
5573 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
5579 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
5580 msecs_to_jiffies(duration
));
5584 mutex_unlock(&ar
->conf_mutex
);
5588 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
5590 struct ath10k
*ar
= hw
->priv
;
5592 mutex_lock(&ar
->conf_mutex
);
5594 spin_lock_bh(&ar
->data_lock
);
5595 ar
->scan
.roc_notify
= false;
5596 spin_unlock_bh(&ar
->data_lock
);
5598 ath10k_scan_abort(ar
);
5600 mutex_unlock(&ar
->conf_mutex
);
5602 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5608 * Both RTS and Fragmentation threshold are interface-specific
5609 * in ath10k, but device-specific in mac80211.
5612 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5614 struct ath10k
*ar
= hw
->priv
;
5615 struct ath10k_vif
*arvif
;
5618 mutex_lock(&ar
->conf_mutex
);
5619 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5620 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
5621 arvif
->vdev_id
, value
);
5623 ret
= ath10k_mac_set_rts(arvif
, value
);
5625 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5626 arvif
->vdev_id
, ret
);
5630 mutex_unlock(&ar
->conf_mutex
);
5635 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
5637 /* Even though there's a WMI enum for fragmentation threshold no known
5638 * firmware actually implements it. Moreover it is not possible to rely
5639 * frame fragmentation to mac80211 because firmware clears the "more
5640 * fragments" bit in frame control making it impossible for remote
5641 * devices to reassemble frames.
5643 * Hence implement a dummy callback just to say fragmentation isn't
5644 * supported. This effectively prevents mac80211 from doing frame
5645 * fragmentation in software.
5650 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5651 u32 queues
, bool drop
)
5653 struct ath10k
*ar
= hw
->priv
;
5657 /* mac80211 doesn't care if we really xmit queued frames or not
5658 * we'll collect those frames either way if we stop/delete vdevs */
5662 mutex_lock(&ar
->conf_mutex
);
5664 if (ar
->state
== ATH10K_STATE_WEDGED
)
5667 time_left
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
5670 spin_lock_bh(&ar
->htt
.tx_lock
);
5671 empty
= (ar
->htt
.num_pending_tx
== 0);
5672 spin_unlock_bh(&ar
->htt
.tx_lock
);
5674 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
5675 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
5679 }), ATH10K_FLUSH_TIMEOUT_HZ
);
5681 if (time_left
== 0 || skip
)
5682 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5683 skip
, ar
->state
, time_left
);
5686 mutex_unlock(&ar
->conf_mutex
);
5689 /* TODO: Implement this function properly
5690 * For now it is needed to reply to Probe Requests in IBSS mode.
5691 * Propably we need this information from FW.
5693 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
5698 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
5699 enum ieee80211_reconfig_type reconfig_type
)
5701 struct ath10k
*ar
= hw
->priv
;
5703 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
5706 mutex_lock(&ar
->conf_mutex
);
5708 /* If device failed to restart it will be in a different state, e.g.
5709 * ATH10K_STATE_WEDGED */
5710 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
5711 ath10k_info(ar
, "device successfully recovered\n");
5712 ar
->state
= ATH10K_STATE_ON
;
5713 ieee80211_wake_queues(ar
->hw
);
5716 mutex_unlock(&ar
->conf_mutex
);
5719 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5720 struct survey_info
*survey
)
5722 struct ath10k
*ar
= hw
->priv
;
5723 struct ieee80211_supported_band
*sband
;
5724 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
5727 mutex_lock(&ar
->conf_mutex
);
5729 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5730 if (sband
&& idx
>= sband
->n_channels
) {
5731 idx
-= sband
->n_channels
;
5736 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5738 if (!sband
|| idx
>= sband
->n_channels
) {
5743 spin_lock_bh(&ar
->data_lock
);
5744 memcpy(survey
, ar_survey
, sizeof(*survey
));
5745 spin_unlock_bh(&ar
->data_lock
);
5747 survey
->channel
= &sband
->channels
[idx
];
5749 if (ar
->rx_channel
== survey
->channel
)
5750 survey
->filled
|= SURVEY_INFO_IN_USE
;
5753 mutex_unlock(&ar
->conf_mutex
);
5758 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
5759 enum ieee80211_band band
,
5760 const struct cfg80211_bitrate_mask
*mask
)
5765 num_rates
+= hweight32(mask
->control
[band
].legacy
);
5767 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
5768 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
5770 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++)
5771 num_rates
+= hweight16(mask
->control
[band
].vht_mcs
[i
]);
5773 return num_rates
== 1;
5777 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
5778 enum ieee80211_band band
,
5779 const struct cfg80211_bitrate_mask
*mask
,
5782 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
5783 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
5785 u8 vht_nss_mask
= 0;
5788 if (mask
->control
[band
].legacy
)
5791 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
5792 if (mask
->control
[band
].ht_mcs
[i
] == 0)
5794 else if (mask
->control
[band
].ht_mcs
[i
] ==
5795 sband
->ht_cap
.mcs
.rx_mask
[i
])
5796 ht_nss_mask
|= BIT(i
);
5801 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
5802 if (mask
->control
[band
].vht_mcs
[i
] == 0)
5804 else if (mask
->control
[band
].vht_mcs
[i
] ==
5805 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
5806 vht_nss_mask
|= BIT(i
);
5811 if (ht_nss_mask
!= vht_nss_mask
)
5814 if (ht_nss_mask
== 0)
5817 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
5820 *nss
= fls(ht_nss_mask
);
5826 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
5827 enum ieee80211_band band
,
5828 const struct cfg80211_bitrate_mask
*mask
,
5831 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
5838 if (hweight32(mask
->control
[band
].legacy
) == 1) {
5839 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
5841 hw_rate
= sband
->bitrates
[rate_idx
].hw_value
;
5842 bitrate
= sband
->bitrates
[rate_idx
].bitrate
;
5844 if (ath10k_mac_bitrate_is_cck(bitrate
))
5845 preamble
= WMI_RATE_PREAMBLE_CCK
;
5847 preamble
= WMI_RATE_PREAMBLE_OFDM
;
5850 *rate
= preamble
<< 6 |
5857 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
5858 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
5860 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
5862 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
5868 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
5869 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
5871 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
5873 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
5882 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
5883 u8 rate
, u8 nss
, u8 sgi
)
5885 struct ath10k
*ar
= arvif
->ar
;
5889 lockdep_assert_held(&ar
->conf_mutex
);
5891 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5892 arvif
->vdev_id
, rate
, nss
, sgi
);
5894 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
5895 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
5897 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
5902 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5903 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
5905 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
5909 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
5910 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
5912 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
5920 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
5921 enum ieee80211_band band
,
5922 const struct cfg80211_bitrate_mask
*mask
)
5927 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5928 * to express all VHT MCS rate masks. Effectively only the following
5929 * ranges can be used: none, 0-7, 0-8 and 0-9.
5931 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
5932 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
5941 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5949 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
5950 struct ieee80211_sta
*sta
)
5952 struct ath10k_vif
*arvif
= data
;
5953 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5954 struct ath10k
*ar
= arvif
->ar
;
5956 if (arsta
->arvif
!= arvif
)
5959 spin_lock_bh(&ar
->data_lock
);
5960 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
5961 spin_unlock_bh(&ar
->data_lock
);
5963 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
5966 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
5967 struct ieee80211_vif
*vif
,
5968 const struct cfg80211_bitrate_mask
*mask
)
5970 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5971 struct cfg80211_chan_def def
;
5972 struct ath10k
*ar
= arvif
->ar
;
5973 enum ieee80211_band band
;
5974 const u8
*ht_mcs_mask
;
5975 const u16
*vht_mcs_mask
;
5982 if (ath10k_mac_vif_chan(vif
, &def
))
5985 band
= def
.chan
->band
;
5986 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
5987 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
5989 sgi
= mask
->control
[band
].gi
;
5990 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
5993 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
)) {
5994 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
5997 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
5998 arvif
->vdev_id
, ret
);
6001 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
6003 rate
= WMI_FIXED_RATE_NONE
;
6006 rate
= WMI_FIXED_RATE_NONE
;
6007 nss
= min(ar
->num_rf_chains
,
6008 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6009 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6011 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
))
6014 mutex_lock(&ar
->conf_mutex
);
6016 arvif
->bitrate_mask
= *mask
;
6017 ieee80211_iterate_stations_atomic(ar
->hw
,
6018 ath10k_mac_set_bitrate_mask_iter
,
6021 mutex_unlock(&ar
->conf_mutex
);
6024 mutex_lock(&ar
->conf_mutex
);
6026 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
);
6028 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
6029 arvif
->vdev_id
, ret
);
6034 mutex_unlock(&ar
->conf_mutex
);
6039 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
6040 struct ieee80211_vif
*vif
,
6041 struct ieee80211_sta
*sta
,
6044 struct ath10k
*ar
= hw
->priv
;
6045 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6048 spin_lock_bh(&ar
->data_lock
);
6050 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6051 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6052 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
6055 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6056 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6058 switch (sta
->bandwidth
) {
6059 case IEEE80211_STA_RX_BW_20
:
6060 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6062 case IEEE80211_STA_RX_BW_40
:
6063 bw
= WMI_PEER_CHWIDTH_40MHZ
;
6065 case IEEE80211_STA_RX_BW_80
:
6066 bw
= WMI_PEER_CHWIDTH_80MHZ
;
6068 case IEEE80211_STA_RX_BW_160
:
6069 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
6070 sta
->bandwidth
, sta
->addr
);
6071 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6078 if (changed
& IEEE80211_RC_NSS_CHANGED
)
6079 arsta
->nss
= sta
->rx_nss
;
6081 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6082 smps
= WMI_PEER_SMPS_PS_NONE
;
6084 switch (sta
->smps_mode
) {
6085 case IEEE80211_SMPS_AUTOMATIC
:
6086 case IEEE80211_SMPS_OFF
:
6087 smps
= WMI_PEER_SMPS_PS_NONE
;
6089 case IEEE80211_SMPS_STATIC
:
6090 smps
= WMI_PEER_SMPS_STATIC
;
6092 case IEEE80211_SMPS_DYNAMIC
:
6093 smps
= WMI_PEER_SMPS_DYNAMIC
;
6095 case IEEE80211_SMPS_NUM_MODES
:
6096 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
6097 sta
->smps_mode
, sta
->addr
);
6098 smps
= WMI_PEER_SMPS_PS_NONE
;
6105 arsta
->changed
|= changed
;
6107 spin_unlock_bh(&ar
->data_lock
);
6109 ieee80211_queue_work(hw
, &arsta
->update_wk
);
6112 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
6115 * FIXME: Return 0 for time being. Need to figure out whether FW
6116 * has the API to fetch 64-bit local TSF
6122 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
6123 struct ieee80211_vif
*vif
,
6124 enum ieee80211_ampdu_mlme_action action
,
6125 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
6128 struct ath10k
*ar
= hw
->priv
;
6129 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6131 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6132 arvif
->vdev_id
, sta
->addr
, tid
, action
);
6135 case IEEE80211_AMPDU_RX_START
:
6136 case IEEE80211_AMPDU_RX_STOP
:
6137 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6138 * creation/removal. Do we need to verify this?
6141 case IEEE80211_AMPDU_TX_START
:
6142 case IEEE80211_AMPDU_TX_STOP_CONT
:
6143 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
6144 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
6145 case IEEE80211_AMPDU_TX_OPERATIONAL
:
6146 /* Firmware offloads Tx aggregation entirely so deny mac80211
6147 * Tx aggregation requests.
6156 ath10k_mac_update_rx_channel(struct ath10k
*ar
,
6157 struct ieee80211_chanctx_conf
*ctx
,
6158 struct ieee80211_vif_chanctx_switch
*vifs
,
6161 struct cfg80211_chan_def
*def
= NULL
;
6163 /* Both locks are required because ar->rx_channel is modified. This
6164 * allows readers to hold either lock.
6166 lockdep_assert_held(&ar
->conf_mutex
);
6167 lockdep_assert_held(&ar
->data_lock
);
6169 WARN_ON(ctx
&& vifs
);
6170 WARN_ON(vifs
&& n_vifs
!= 1);
6172 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6173 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6174 * ppdu on Rx may reduce performance on low-end systems. It should be
6175 * possible to make tables/hashmaps to speed the lookup up (be vary of
6176 * cpu data cache lines though regarding sizes) but to keep the initial
6177 * implementation simple and less intrusive fallback to the slow lookup
6178 * only for multi-channel cases. Single-channel cases will remain to
6179 * use the old channel derival and thus performance should not be
6183 if (!ctx
&& ath10k_mac_num_chanctxs(ar
) == 1) {
6184 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
6185 ath10k_mac_get_any_chandef_iter
,
6189 def
= &vifs
[0].new_ctx
->def
;
6191 ar
->rx_channel
= def
->chan
;
6192 } else if (ctx
&& ath10k_mac_num_chanctxs(ar
) == 0) {
6193 ar
->rx_channel
= ctx
->def
.chan
;
6195 ar
->rx_channel
= NULL
;
6201 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
6202 struct ieee80211_chanctx_conf
*ctx
)
6204 struct ath10k
*ar
= hw
->priv
;
6206 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6207 "mac chanctx add freq %hu width %d ptr %p\n",
6208 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6210 mutex_lock(&ar
->conf_mutex
);
6212 spin_lock_bh(&ar
->data_lock
);
6213 ath10k_mac_update_rx_channel(ar
, ctx
, NULL
, 0);
6214 spin_unlock_bh(&ar
->data_lock
);
6216 ath10k_recalc_radar_detection(ar
);
6217 ath10k_monitor_recalc(ar
);
6219 mutex_unlock(&ar
->conf_mutex
);
6225 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
6226 struct ieee80211_chanctx_conf
*ctx
)
6228 struct ath10k
*ar
= hw
->priv
;
6230 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6231 "mac chanctx remove freq %hu width %d ptr %p\n",
6232 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6234 mutex_lock(&ar
->conf_mutex
);
6236 spin_lock_bh(&ar
->data_lock
);
6237 ath10k_mac_update_rx_channel(ar
, NULL
, NULL
, 0);
6238 spin_unlock_bh(&ar
->data_lock
);
6240 ath10k_recalc_radar_detection(ar
);
6241 ath10k_monitor_recalc(ar
);
6243 mutex_unlock(&ar
->conf_mutex
);
6247 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
6248 struct ieee80211_chanctx_conf
*ctx
,
6251 struct ath10k
*ar
= hw
->priv
;
6253 mutex_lock(&ar
->conf_mutex
);
6255 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6256 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6257 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
, changed
);
6259 /* This shouldn't really happen because channel switching should use
6260 * switch_vif_chanctx().
6262 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
6265 ath10k_recalc_radar_detection(ar
);
6267 /* FIXME: How to configure Rx chains properly? */
6269 /* No other actions are actually necessary. Firmware maintains channel
6270 * definitions per vdev internally and there's no host-side channel
6271 * context abstraction to configure, e.g. channel width.
6275 mutex_unlock(&ar
->conf_mutex
);
6279 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
6280 struct ieee80211_vif
*vif
,
6281 struct ieee80211_chanctx_conf
*ctx
)
6283 struct ath10k
*ar
= hw
->priv
;
6284 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6287 mutex_lock(&ar
->conf_mutex
);
6289 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6290 "mac chanctx assign ptr %p vdev_id %i\n",
6291 ctx
, arvif
->vdev_id
);
6293 if (WARN_ON(arvif
->is_started
)) {
6294 mutex_unlock(&ar
->conf_mutex
);
6298 ret
= ath10k_vdev_start(arvif
, &ctx
->def
);
6300 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
6301 arvif
->vdev_id
, vif
->addr
,
6302 ctx
->def
.chan
->center_freq
, ret
);
6306 arvif
->is_started
= true;
6308 ret
= ath10k_mac_vif_setup_ps(arvif
);
6310 ath10k_warn(ar
, "failed to update vdev %i ps: %d\n",
6311 arvif
->vdev_id
, ret
);
6315 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6316 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
6318 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
6319 arvif
->vdev_id
, ret
);
6323 arvif
->is_up
= true;
6326 mutex_unlock(&ar
->conf_mutex
);
6330 ath10k_vdev_stop(arvif
);
6331 arvif
->is_started
= false;
6332 ath10k_mac_vif_setup_ps(arvif
);
6335 mutex_unlock(&ar
->conf_mutex
);
6340 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
6341 struct ieee80211_vif
*vif
,
6342 struct ieee80211_chanctx_conf
*ctx
)
6344 struct ath10k
*ar
= hw
->priv
;
6345 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6348 mutex_lock(&ar
->conf_mutex
);
6350 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6351 "mac chanctx unassign ptr %p vdev_id %i\n",
6352 ctx
, arvif
->vdev_id
);
6354 WARN_ON(!arvif
->is_started
);
6356 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6357 WARN_ON(!arvif
->is_up
);
6359 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
6361 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
6362 arvif
->vdev_id
, ret
);
6364 arvif
->is_up
= false;
6367 ret
= ath10k_vdev_stop(arvif
);
6369 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
6370 arvif
->vdev_id
, ret
);
6372 arvif
->is_started
= false;
6374 mutex_unlock(&ar
->conf_mutex
);
6378 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
6379 struct ieee80211_vif_chanctx_switch
*vifs
,
6381 enum ieee80211_chanctx_switch_mode mode
)
6383 struct ath10k
*ar
= hw
->priv
;
6384 struct ath10k_vif
*arvif
;
6388 mutex_lock(&ar
->conf_mutex
);
6390 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6391 "mac chanctx switch n_vifs %d mode %d\n",
6394 /* First stop monitor interface. Some FW versions crash if there's a
6395 * lone monitor interface.
6397 if (ar
->monitor_started
)
6398 ath10k_monitor_stop(ar
);
6400 for (i
= 0; i
< n_vifs
; i
++) {
6401 arvif
= ath10k_vif_to_arvif(vifs
[i
].vif
);
6403 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6404 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6406 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
6407 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
6408 vifs
[i
].old_ctx
->def
.width
,
6409 vifs
[i
].new_ctx
->def
.width
);
6411 if (WARN_ON(!arvif
->is_started
))
6414 if (WARN_ON(!arvif
->is_up
))
6417 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
6419 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
6420 arvif
->vdev_id
, ret
);
6425 /* All relevant vdevs are downed and associated channel resources
6426 * should be available for the channel switch now.
6429 spin_lock_bh(&ar
->data_lock
);
6430 ath10k_mac_update_rx_channel(ar
, NULL
, vifs
, n_vifs
);
6431 spin_unlock_bh(&ar
->data_lock
);
6433 for (i
= 0; i
< n_vifs
; i
++) {
6434 arvif
= ath10k_vif_to_arvif(vifs
[i
].vif
);
6436 if (WARN_ON(!arvif
->is_started
))
6439 if (WARN_ON(!arvif
->is_up
))
6442 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
6444 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
6447 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
6449 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
6452 ret
= ath10k_vdev_restart(arvif
, &vifs
[i
].new_ctx
->def
);
6454 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
6455 arvif
->vdev_id
, ret
);
6459 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
6462 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
6463 arvif
->vdev_id
, ret
);
6468 ath10k_monitor_recalc(ar
);
6470 mutex_unlock(&ar
->conf_mutex
);
6474 static const struct ieee80211_ops ath10k_ops
= {
6476 .start
= ath10k_start
,
6477 .stop
= ath10k_stop
,
6478 .config
= ath10k_config
,
6479 .add_interface
= ath10k_add_interface
,
6480 .remove_interface
= ath10k_remove_interface
,
6481 .configure_filter
= ath10k_configure_filter
,
6482 .bss_info_changed
= ath10k_bss_info_changed
,
6483 .hw_scan
= ath10k_hw_scan
,
6484 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
6485 .set_key
= ath10k_set_key
,
6486 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
6487 .sta_state
= ath10k_sta_state
,
6488 .conf_tx
= ath10k_conf_tx
,
6489 .remain_on_channel
= ath10k_remain_on_channel
,
6490 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
6491 .set_rts_threshold
= ath10k_set_rts_threshold
,
6492 .set_frag_threshold
= ath10k_mac_op_set_frag_threshold
,
6493 .flush
= ath10k_flush
,
6494 .tx_last_beacon
= ath10k_tx_last_beacon
,
6495 .set_antenna
= ath10k_set_antenna
,
6496 .get_antenna
= ath10k_get_antenna
,
6497 .reconfig_complete
= ath10k_reconfig_complete
,
6498 .get_survey
= ath10k_get_survey
,
6499 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
6500 .sta_rc_update
= ath10k_sta_rc_update
,
6501 .get_tsf
= ath10k_get_tsf
,
6502 .ampdu_action
= ath10k_ampdu_action
,
6503 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
6504 .get_et_stats
= ath10k_debug_get_et_stats
,
6505 .get_et_strings
= ath10k_debug_get_et_strings
,
6506 .add_chanctx
= ath10k_mac_op_add_chanctx
,
6507 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
6508 .change_chanctx
= ath10k_mac_op_change_chanctx
,
6509 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
6510 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
6511 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
6513 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
6516 .suspend
= ath10k_wow_op_suspend
,
6517 .resume
= ath10k_wow_op_resume
,
6519 #ifdef CONFIG_MAC80211_DEBUGFS
6520 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
6524 #define CHAN2G(_channel, _freq, _flags) { \
6525 .band = IEEE80211_BAND_2GHZ, \
6526 .hw_value = (_channel), \
6527 .center_freq = (_freq), \
6528 .flags = (_flags), \
6529 .max_antenna_gain = 0, \
6533 #define CHAN5G(_channel, _freq, _flags) { \
6534 .band = IEEE80211_BAND_5GHZ, \
6535 .hw_value = (_channel), \
6536 .center_freq = (_freq), \
6537 .flags = (_flags), \
6538 .max_antenna_gain = 0, \
6542 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
6552 CHAN2G(10, 2457, 0),
6553 CHAN2G(11, 2462, 0),
6554 CHAN2G(12, 2467, 0),
6555 CHAN2G(13, 2472, 0),
6556 CHAN2G(14, 2484, 0),
6559 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
6560 CHAN5G(36, 5180, 0),
6561 CHAN5G(40, 5200, 0),
6562 CHAN5G(44, 5220, 0),
6563 CHAN5G(48, 5240, 0),
6564 CHAN5G(52, 5260, 0),
6565 CHAN5G(56, 5280, 0),
6566 CHAN5G(60, 5300, 0),
6567 CHAN5G(64, 5320, 0),
6568 CHAN5G(100, 5500, 0),
6569 CHAN5G(104, 5520, 0),
6570 CHAN5G(108, 5540, 0),
6571 CHAN5G(112, 5560, 0),
6572 CHAN5G(116, 5580, 0),
6573 CHAN5G(120, 5600, 0),
6574 CHAN5G(124, 5620, 0),
6575 CHAN5G(128, 5640, 0),
6576 CHAN5G(132, 5660, 0),
6577 CHAN5G(136, 5680, 0),
6578 CHAN5G(140, 5700, 0),
6579 CHAN5G(144, 5720, 0),
6580 CHAN5G(149, 5745, 0),
6581 CHAN5G(153, 5765, 0),
6582 CHAN5G(157, 5785, 0),
6583 CHAN5G(161, 5805, 0),
6584 CHAN5G(165, 5825, 0),
6587 struct ath10k
*ath10k_mac_create(size_t priv_size
)
6589 struct ieee80211_hw
*hw
;
6592 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
6602 void ath10k_mac_destroy(struct ath10k
*ar
)
6604 ieee80211_free_hw(ar
->hw
);
6607 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
6610 .types
= BIT(NL80211_IFTYPE_STATION
)
6611 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
6615 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
6619 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
6623 .types
= BIT(NL80211_IFTYPE_AP
)
6627 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
6630 .types
= BIT(NL80211_IFTYPE_AP
)
6634 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
6636 .limits
= ath10k_if_limits
,
6637 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
6638 .max_interfaces
= 8,
6639 .num_different_channels
= 1,
6640 .beacon_int_infra_match
= true,
6644 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
6646 .limits
= ath10k_10x_if_limits
,
6647 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
6648 .max_interfaces
= 8,
6649 .num_different_channels
= 1,
6650 .beacon_int_infra_match
= true,
6651 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6652 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
6653 BIT(NL80211_CHAN_WIDTH_20
) |
6654 BIT(NL80211_CHAN_WIDTH_40
) |
6655 BIT(NL80211_CHAN_WIDTH_80
),
6660 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
6663 .types
= BIT(NL80211_IFTYPE_STATION
),
6667 .types
= BIT(NL80211_IFTYPE_AP
) |
6668 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6669 BIT(NL80211_IFTYPE_P2P_GO
),
6673 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
6677 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit
[] = {
6680 .types
= BIT(NL80211_IFTYPE_STATION
),
6684 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
),
6688 .types
= BIT(NL80211_IFTYPE_AP
) |
6689 BIT(NL80211_IFTYPE_P2P_GO
),
6693 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
6697 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
6700 .types
= BIT(NL80211_IFTYPE_STATION
),
6704 .types
= BIT(NL80211_IFTYPE_ADHOC
),
6708 /* FIXME: This is not thouroughly tested. These combinations may over- or
6709 * underestimate hw/fw capabilities.
6711 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
6713 .limits
= ath10k_tlv_if_limit
,
6714 .num_different_channels
= 1,
6715 .max_interfaces
= 4,
6716 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
6719 .limits
= ath10k_tlv_if_limit_ibss
,
6720 .num_different_channels
= 1,
6721 .max_interfaces
= 2,
6722 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
6726 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
6728 .limits
= ath10k_tlv_if_limit
,
6729 .num_different_channels
= 1,
6730 .max_interfaces
= 4,
6731 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
6734 .limits
= ath10k_tlv_qcs_if_limit
,
6735 .num_different_channels
= 2,
6736 .max_interfaces
= 4,
6737 .n_limits
= ARRAY_SIZE(ath10k_tlv_qcs_if_limit
),
6740 .limits
= ath10k_tlv_if_limit_ibss
,
6741 .num_different_channels
= 1,
6742 .max_interfaces
= 2,
6743 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
6747 static const struct ieee80211_iface_limit ath10k_10_4_if_limits
[] = {
6750 .types
= BIT(NL80211_IFTYPE_STATION
),
6754 .types
= BIT(NL80211_IFTYPE_AP
)
6758 static const struct ieee80211_iface_combination ath10k_10_4_if_comb
[] = {
6760 .limits
= ath10k_10_4_if_limits
,
6761 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
6762 .max_interfaces
= 16,
6763 .num_different_channels
= 1,
6764 .beacon_int_infra_match
= true,
6765 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6766 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
6767 BIT(NL80211_CHAN_WIDTH_20
) |
6768 BIT(NL80211_CHAN_WIDTH_40
) |
6769 BIT(NL80211_CHAN_WIDTH_80
),
6774 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
6776 struct ieee80211_sta_vht_cap vht_cap
= {0};
6781 vht_cap
.vht_supported
= 1;
6782 vht_cap
.cap
= ar
->vht_cap_info
;
6784 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
6785 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
6786 val
= ar
->num_rf_chains
- 1;
6787 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
6788 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
6793 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
6794 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
6795 val
= ar
->num_rf_chains
- 1;
6796 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
6797 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
6803 for (i
= 0; i
< 8; i
++) {
6804 if (i
< ar
->num_rf_chains
)
6805 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
6807 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
6810 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
6811 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
6816 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
6819 struct ieee80211_sta_ht_cap ht_cap
= {0};
6821 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
6824 ht_cap
.ht_supported
= 1;
6825 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
6826 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
6827 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
6828 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
6829 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
6831 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
6832 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
6834 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
6835 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
6837 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
6840 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
6841 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
6846 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
6847 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
6849 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
6852 stbc
= ar
->ht_cap_info
;
6853 stbc
&= WMI_HT_CAP_RX_STBC
;
6854 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
6855 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
6856 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
6861 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
6862 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
6864 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
6865 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
6867 /* max AMSDU is implicitly taken from vht_cap_info */
6868 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
6869 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
6871 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
6872 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
6874 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
6879 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
6880 struct ieee80211_vif
*vif
)
6882 struct ath10k_vif_iter
*arvif_iter
= data
;
6883 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6885 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
6886 arvif_iter
->arvif
= arvif
;
6889 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
6891 struct ath10k_vif_iter arvif_iter
;
6894 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
6895 arvif_iter
.vdev_id
= vdev_id
;
6897 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
6898 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
6900 ath10k_get_arvif_iter
,
6902 if (!arvif_iter
.arvif
) {
6903 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
6907 return arvif_iter
.arvif
;
6910 int ath10k_mac_register(struct ath10k
*ar
)
6912 static const u32 cipher_suites
[] = {
6913 WLAN_CIPHER_SUITE_WEP40
,
6914 WLAN_CIPHER_SUITE_WEP104
,
6915 WLAN_CIPHER_SUITE_TKIP
,
6916 WLAN_CIPHER_SUITE_CCMP
,
6917 WLAN_CIPHER_SUITE_AES_CMAC
,
6919 struct ieee80211_supported_band
*band
;
6920 struct ieee80211_sta_vht_cap vht_cap
;
6921 struct ieee80211_sta_ht_cap ht_cap
;
6925 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
6927 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
6929 ht_cap
= ath10k_get_ht_cap(ar
);
6930 vht_cap
= ath10k_create_vht_cap(ar
);
6932 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
6933 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
6936 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
6937 channels
= kmemdup(ath10k_2ghz_channels
,
6938 sizeof(ath10k_2ghz_channels
),
6945 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
6946 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
6947 band
->channels
= channels
;
6948 band
->n_bitrates
= ath10k_g_rates_size
;
6949 band
->bitrates
= ath10k_g_rates
;
6950 band
->ht_cap
= ht_cap
;
6952 /* Enable the VHT support at 2.4 GHz */
6953 band
->vht_cap
= vht_cap
;
6955 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
6958 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
6959 channels
= kmemdup(ath10k_5ghz_channels
,
6960 sizeof(ath10k_5ghz_channels
),
6967 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
6968 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
6969 band
->channels
= channels
;
6970 band
->n_bitrates
= ath10k_a_rates_size
;
6971 band
->bitrates
= ath10k_a_rates
;
6972 band
->ht_cap
= ht_cap
;
6973 band
->vht_cap
= vht_cap
;
6974 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
6977 ar
->hw
->wiphy
->interface_modes
=
6978 BIT(NL80211_IFTYPE_STATION
) |
6979 BIT(NL80211_IFTYPE_AP
);
6981 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
6982 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
6984 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
6985 ar
->hw
->wiphy
->interface_modes
|=
6986 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
6987 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6988 BIT(NL80211_IFTYPE_P2P_GO
);
6990 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
6991 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
6992 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
6993 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
6994 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
6995 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
6996 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
6997 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
6998 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
6999 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
7000 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
7001 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
7002 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
7003 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
7005 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
7006 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
7008 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
7009 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
7011 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
7012 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
7014 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
7015 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
7016 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
7019 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
7020 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
7022 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
7023 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
7025 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
7027 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
7028 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
7030 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7031 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7032 * correct Probe Responses. This is more of a hack advert..
7034 ar
->hw
->wiphy
->probe_resp_offload
|=
7035 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
7036 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
7037 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
7040 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
))
7041 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
7043 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
7044 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
7045 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
7047 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
7048 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
7050 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
7052 ret
= ath10k_wow_init(ar
);
7054 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
7058 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
7061 * on LL hardware queues are managed entirely by the FW
7062 * so we only advertise to mac we can do the queues thing
7064 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
7066 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7067 * something that vdev_ids can't reach so that we don't stop the queue
7070 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
7072 switch (ar
->wmi
.op_version
) {
7073 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
7074 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
7075 ar
->hw
->wiphy
->n_iface_combinations
=
7076 ARRAY_SIZE(ath10k_if_comb
);
7077 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
7079 case ATH10K_FW_WMI_OP_VERSION_TLV
:
7080 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
7081 ar
->hw
->wiphy
->iface_combinations
=
7082 ath10k_tlv_qcs_if_comb
;
7083 ar
->hw
->wiphy
->n_iface_combinations
=
7084 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
7086 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
7087 ar
->hw
->wiphy
->n_iface_combinations
=
7088 ARRAY_SIZE(ath10k_tlv_if_comb
);
7090 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
7092 case ATH10K_FW_WMI_OP_VERSION_10_1
:
7093 case ATH10K_FW_WMI_OP_VERSION_10_2
:
7094 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
7095 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
7096 ar
->hw
->wiphy
->n_iface_combinations
=
7097 ARRAY_SIZE(ath10k_10x_if_comb
);
7099 case ATH10K_FW_WMI_OP_VERSION_10_4
:
7100 ar
->hw
->wiphy
->iface_combinations
= ath10k_10_4_if_comb
;
7101 ar
->hw
->wiphy
->n_iface_combinations
=
7102 ARRAY_SIZE(ath10k_10_4_if_comb
);
7104 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
7105 case ATH10K_FW_WMI_OP_VERSION_MAX
:
7111 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
7112 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
7114 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
7115 /* Init ath dfs pattern detector */
7116 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
7117 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
7120 if (!ar
->dfs_detector
)
7121 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
7124 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
7125 ath10k_reg_notifier
);
7127 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
7131 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
7132 ar
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
7134 ret
= ieee80211_register_hw(ar
->hw
);
7136 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
7140 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
7141 ret
= regulatory_hint(ar
->hw
->wiphy
,
7142 ar
->ath_common
.regulatory
.alpha2
);
7144 goto err_unregister
;
7150 ieee80211_unregister_hw(ar
->hw
);
7152 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
7153 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
7158 void ath10k_mac_unregister(struct ath10k
*ar
)
7160 ieee80211_unregister_hw(ar
->hw
);
7162 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
7163 ar
->dfs_detector
->exit(ar
->dfs_detector
);
7165 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
7166 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
7168 SET_IEEE80211_DEV(ar
->hw
, NULL
);