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 (cmd
== DISABLE_KEY
) {
201 arg
.key_cipher
= WMI_CIPHER_NONE
;
205 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
208 static int ath10k_install_key(struct ath10k_vif
*arvif
,
209 struct ieee80211_key_conf
*key
,
210 enum set_key_cmd cmd
,
211 const u8
*macaddr
, u32 flags
)
213 struct ath10k
*ar
= arvif
->ar
;
215 unsigned long time_left
;
217 lockdep_assert_held(&ar
->conf_mutex
);
219 reinit_completion(&ar
->install_key_done
);
221 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
225 time_left
= wait_for_completion_timeout(&ar
->install_key_done
, 3 * HZ
);
232 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
235 struct ath10k
*ar
= arvif
->ar
;
236 struct ath10k_peer
*peer
;
241 lockdep_assert_held(&ar
->conf_mutex
);
243 spin_lock_bh(&ar
->data_lock
);
244 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
245 spin_unlock_bh(&ar
->data_lock
);
250 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
251 if (arvif
->wep_keys
[i
] == NULL
)
255 flags
|= WMI_KEY_PAIRWISE
;
257 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
263 flags
|= WMI_KEY_GROUP
;
265 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
270 spin_lock_bh(&ar
->data_lock
);
271 peer
->keys
[i
] = arvif
->wep_keys
[i
];
272 spin_unlock_bh(&ar
->data_lock
);
275 /* In some cases (notably with static WEP IBSS with multiple keys)
276 * multicast Tx becomes broken. Both pairwise and groupwise keys are
277 * installed already. Using WMI_KEY_TX_USAGE in different combinations
278 * didn't seem help. Using def_keyid vdev parameter seems to be
279 * effective so use that.
281 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
283 if (arvif
->def_wep_key_idx
== -1)
286 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
288 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
289 arvif
->def_wep_key_idx
);
291 ath10k_warn(ar
, "failed to re-set def wpa key idxon vdev %i: %d\n",
292 arvif
->vdev_id
, ret
);
299 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
302 struct ath10k
*ar
= arvif
->ar
;
303 struct ath10k_peer
*peer
;
309 lockdep_assert_held(&ar
->conf_mutex
);
311 spin_lock_bh(&ar
->data_lock
);
312 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
313 spin_unlock_bh(&ar
->data_lock
);
318 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
319 if (peer
->keys
[i
] == NULL
)
322 /* key flags are not required to delete the key */
323 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
324 DISABLE_KEY
, addr
, flags
);
325 if (ret
&& first_errno
== 0)
329 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
332 spin_lock_bh(&ar
->data_lock
);
333 peer
->keys
[i
] = NULL
;
334 spin_unlock_bh(&ar
->data_lock
);
340 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
343 struct ath10k_peer
*peer
;
346 lockdep_assert_held(&ar
->data_lock
);
348 /* We don't know which vdev this peer belongs to,
349 * since WMI doesn't give us that information.
351 * FIXME: multi-bss needs to be handled.
353 peer
= ath10k_peer_find(ar
, 0, addr
);
357 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
358 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
365 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
366 struct ieee80211_key_conf
*key
)
368 struct ath10k
*ar
= arvif
->ar
;
369 struct ath10k_peer
*peer
;
376 lockdep_assert_held(&ar
->conf_mutex
);
379 /* since ath10k_install_key we can't hold data_lock all the
380 * time, so we try to remove the keys incrementally */
381 spin_lock_bh(&ar
->data_lock
);
383 list_for_each_entry(peer
, &ar
->peers
, list
) {
384 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
385 if (peer
->keys
[i
] == key
) {
386 ether_addr_copy(addr
, peer
->addr
);
387 peer
->keys
[i
] = NULL
;
392 if (i
< ARRAY_SIZE(peer
->keys
))
395 spin_unlock_bh(&ar
->data_lock
);
397 if (i
== ARRAY_SIZE(peer
->keys
))
399 /* key flags are not required to delete the key */
400 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
401 if (ret
&& first_errno
== 0)
405 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
412 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
413 struct ieee80211_key_conf
*key
)
415 struct ath10k
*ar
= arvif
->ar
;
416 struct ath10k_peer
*peer
;
419 lockdep_assert_held(&ar
->conf_mutex
);
421 list_for_each_entry(peer
, &ar
->peers
, list
) {
422 if (!memcmp(peer
->addr
, arvif
->vif
->addr
, ETH_ALEN
))
425 if (!memcmp(peer
->addr
, arvif
->bssid
, ETH_ALEN
))
428 if (peer
->keys
[key
->keyidx
] == key
)
431 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
432 arvif
->vdev_id
, key
->keyidx
);
434 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
436 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
437 arvif
->vdev_id
, peer
->addr
, ret
);
445 /*********************/
446 /* General utilities */
447 /*********************/
449 static inline enum wmi_phy_mode
450 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
452 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
454 switch (chandef
->chan
->band
) {
455 case IEEE80211_BAND_2GHZ
:
456 switch (chandef
->width
) {
457 case NL80211_CHAN_WIDTH_20_NOHT
:
458 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
463 case NL80211_CHAN_WIDTH_20
:
464 phymode
= MODE_11NG_HT20
;
466 case NL80211_CHAN_WIDTH_40
:
467 phymode
= MODE_11NG_HT40
;
469 case NL80211_CHAN_WIDTH_5
:
470 case NL80211_CHAN_WIDTH_10
:
471 case NL80211_CHAN_WIDTH_80
:
472 case NL80211_CHAN_WIDTH_80P80
:
473 case NL80211_CHAN_WIDTH_160
:
474 phymode
= MODE_UNKNOWN
;
478 case IEEE80211_BAND_5GHZ
:
479 switch (chandef
->width
) {
480 case NL80211_CHAN_WIDTH_20_NOHT
:
483 case NL80211_CHAN_WIDTH_20
:
484 phymode
= MODE_11NA_HT20
;
486 case NL80211_CHAN_WIDTH_40
:
487 phymode
= MODE_11NA_HT40
;
489 case NL80211_CHAN_WIDTH_80
:
490 phymode
= MODE_11AC_VHT80
;
492 case NL80211_CHAN_WIDTH_5
:
493 case NL80211_CHAN_WIDTH_10
:
494 case NL80211_CHAN_WIDTH_80P80
:
495 case NL80211_CHAN_WIDTH_160
:
496 phymode
= MODE_UNKNOWN
;
504 WARN_ON(phymode
== MODE_UNKNOWN
);
508 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
511 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
512 * 0 for no restriction
521 switch (mpdudensity
) {
527 /* Our lower layer calculations limit our precision to
543 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
544 struct cfg80211_chan_def
*def
)
546 struct ieee80211_chanctx_conf
*conf
;
549 conf
= rcu_dereference(vif
->chanctx_conf
);
561 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
562 struct ieee80211_chanctx_conf
*conf
,
570 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
574 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
575 ath10k_mac_num_chanctxs_iter
,
582 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
583 struct ieee80211_chanctx_conf
*conf
,
586 struct cfg80211_chan_def
**def
= data
;
591 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
,
592 enum wmi_peer_type peer_type
)
596 lockdep_assert_held(&ar
->conf_mutex
);
598 if (ar
->num_peers
>= ar
->max_num_peers
)
601 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
603 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
608 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
610 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
620 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
622 struct ath10k
*ar
= arvif
->ar
;
626 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
627 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
628 ATH10K_KICKOUT_THRESHOLD
);
630 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
631 arvif
->vdev_id
, ret
);
635 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
636 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
637 ATH10K_KEEPALIVE_MIN_IDLE
);
639 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
640 arvif
->vdev_id
, ret
);
644 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
645 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
646 ATH10K_KEEPALIVE_MAX_IDLE
);
648 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
649 arvif
->vdev_id
, ret
);
653 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
654 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
655 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
657 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
658 arvif
->vdev_id
, ret
);
665 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
667 struct ath10k
*ar
= arvif
->ar
;
670 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
671 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
674 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
676 struct ath10k
*ar
= arvif
->ar
;
679 if (value
!= 0xFFFFFFFF)
680 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
681 ATH10K_FRAGMT_THRESHOLD_MIN
,
682 ATH10K_FRAGMT_THRESHOLD_MAX
);
684 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
685 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
688 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
692 lockdep_assert_held(&ar
->conf_mutex
);
694 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
698 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
707 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
709 struct ath10k_peer
*peer
, *tmp
;
711 lockdep_assert_held(&ar
->conf_mutex
);
713 spin_lock_bh(&ar
->data_lock
);
714 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
715 if (peer
->vdev_id
!= vdev_id
)
718 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
719 peer
->addr
, vdev_id
);
721 list_del(&peer
->list
);
725 spin_unlock_bh(&ar
->data_lock
);
728 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
730 struct ath10k_peer
*peer
, *tmp
;
732 lockdep_assert_held(&ar
->conf_mutex
);
734 spin_lock_bh(&ar
->data_lock
);
735 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
736 list_del(&peer
->list
);
739 spin_unlock_bh(&ar
->data_lock
);
742 ar
->num_stations
= 0;
745 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
746 struct ieee80211_sta
*sta
,
747 enum wmi_tdls_peer_state state
)
750 struct wmi_tdls_peer_update_cmd_arg arg
= {};
751 struct wmi_tdls_peer_capab_arg cap
= {};
752 struct wmi_channel_arg chan_arg
= {};
754 lockdep_assert_held(&ar
->conf_mutex
);
756 arg
.vdev_id
= vdev_id
;
757 arg
.peer_state
= state
;
758 ether_addr_copy(arg
.addr
, sta
->addr
);
760 cap
.peer_max_sp
= sta
->max_sp
;
761 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
763 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
764 !sta
->tdls_initiator
)
765 cap
.is_peer_responder
= 1;
767 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
769 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
770 arg
.addr
, vdev_id
, ret
);
777 /************************/
778 /* Interface management */
779 /************************/
781 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
783 struct ath10k
*ar
= arvif
->ar
;
785 lockdep_assert_held(&ar
->data_lock
);
790 if (!arvif
->beacon_buf
)
791 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
792 arvif
->beacon
->len
, DMA_TO_DEVICE
);
794 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
795 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
798 dev_kfree_skb_any(arvif
->beacon
);
800 arvif
->beacon
= NULL
;
801 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
804 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
806 struct ath10k
*ar
= arvif
->ar
;
808 lockdep_assert_held(&ar
->data_lock
);
810 ath10k_mac_vif_beacon_free(arvif
);
812 if (arvif
->beacon_buf
) {
813 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
814 arvif
->beacon_buf
, arvif
->beacon_paddr
);
815 arvif
->beacon_buf
= NULL
;
819 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
821 unsigned long time_left
;
823 lockdep_assert_held(&ar
->conf_mutex
);
825 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
828 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
829 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
836 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
838 struct cfg80211_chan_def
*chandef
= NULL
;
839 struct ieee80211_channel
*channel
= chandef
->chan
;
840 struct wmi_vdev_start_request_arg arg
= {};
843 lockdep_assert_held(&ar
->conf_mutex
);
845 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
846 ath10k_mac_get_any_chandef_iter
,
848 if (WARN_ON_ONCE(!chandef
))
851 channel
= chandef
->chan
;
853 arg
.vdev_id
= vdev_id
;
854 arg
.channel
.freq
= channel
->center_freq
;
855 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
857 /* TODO setup this dynamically, what in case we
858 don't have any vifs? */
859 arg
.channel
.mode
= chan_to_phymode(chandef
);
860 arg
.channel
.chan_radar
=
861 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
863 arg
.channel
.min_power
= 0;
864 arg
.channel
.max_power
= channel
->max_power
* 2;
865 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
866 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
868 reinit_completion(&ar
->vdev_setup_done
);
870 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
872 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
877 ret
= ath10k_vdev_setup_sync(ar
);
879 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
884 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
886 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
891 ar
->monitor_vdev_id
= vdev_id
;
893 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
894 ar
->monitor_vdev_id
);
898 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
900 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
901 ar
->monitor_vdev_id
, ret
);
906 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
910 lockdep_assert_held(&ar
->conf_mutex
);
912 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
914 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
915 ar
->monitor_vdev_id
, ret
);
917 reinit_completion(&ar
->vdev_setup_done
);
919 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
921 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
922 ar
->monitor_vdev_id
, ret
);
924 ret
= ath10k_vdev_setup_sync(ar
);
926 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
927 ar
->monitor_vdev_id
, ret
);
929 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
930 ar
->monitor_vdev_id
);
934 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
938 lockdep_assert_held(&ar
->conf_mutex
);
940 if (ar
->free_vdev_map
== 0) {
941 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
945 bit
= __ffs64(ar
->free_vdev_map
);
947 ar
->monitor_vdev_id
= bit
;
949 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
950 WMI_VDEV_TYPE_MONITOR
,
953 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
954 ar
->monitor_vdev_id
, ret
);
958 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
959 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
960 ar
->monitor_vdev_id
);
965 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
969 lockdep_assert_held(&ar
->conf_mutex
);
971 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
973 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
974 ar
->monitor_vdev_id
, ret
);
978 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
980 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
981 ar
->monitor_vdev_id
);
985 static int ath10k_monitor_start(struct ath10k
*ar
)
989 lockdep_assert_held(&ar
->conf_mutex
);
991 ret
= ath10k_monitor_vdev_create(ar
);
993 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
997 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
999 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
1000 ath10k_monitor_vdev_delete(ar
);
1004 ar
->monitor_started
= true;
1005 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
1010 static int ath10k_monitor_stop(struct ath10k
*ar
)
1014 lockdep_assert_held(&ar
->conf_mutex
);
1016 ret
= ath10k_monitor_vdev_stop(ar
);
1018 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1022 ret
= ath10k_monitor_vdev_delete(ar
);
1024 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1028 ar
->monitor_started
= false;
1029 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1034 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1038 /* At least one chanctx is required to derive a channel to start
1041 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1045 /* If there's already an existing special monitor interface then don't
1046 * bother creating another monitor vdev.
1048 if (ar
->monitor_arvif
)
1051 return ar
->monitor
||
1052 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1055 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1059 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1061 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1062 * shouldn't allow this but make sure to prevent handling the following
1063 * case anyway since multi-channel DFS hasn't been tested at all.
1065 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1071 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1077 lockdep_assert_held(&ar
->conf_mutex
);
1079 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1080 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1082 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1083 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1084 ar
->monitor_started
, needed
, allowed
);
1086 if (WARN_ON(needed
&& !allowed
)) {
1087 if (ar
->monitor_started
) {
1088 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1090 ret
= ath10k_monitor_stop(ar
);
1092 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n", ret
);
1099 if (needed
== ar
->monitor_started
)
1103 return ath10k_monitor_start(ar
);
1105 return ath10k_monitor_stop(ar
);
1108 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1110 struct ath10k
*ar
= arvif
->ar
;
1111 u32 vdev_param
, rts_cts
= 0;
1113 lockdep_assert_held(&ar
->conf_mutex
);
1115 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1117 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1119 if (arvif
->num_legacy_stations
> 0)
1120 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1121 WMI_RTSCTS_PROFILE
);
1123 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1124 WMI_RTSCTS_PROFILE
);
1126 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1130 static int ath10k_start_cac(struct ath10k
*ar
)
1134 lockdep_assert_held(&ar
->conf_mutex
);
1136 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1138 ret
= ath10k_monitor_recalc(ar
);
1140 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1141 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1145 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1146 ar
->monitor_vdev_id
);
1151 static int ath10k_stop_cac(struct ath10k
*ar
)
1153 lockdep_assert_held(&ar
->conf_mutex
);
1155 /* CAC is not running - do nothing */
1156 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1159 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1160 ath10k_monitor_stop(ar
);
1162 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1167 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1168 struct ieee80211_chanctx_conf
*conf
,
1173 if (!*ret
&& conf
->radar_enabled
)
1177 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1179 bool has_radar
= false;
1181 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1182 ath10k_mac_has_radar_iter
,
1188 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1192 lockdep_assert_held(&ar
->conf_mutex
);
1194 ath10k_stop_cac(ar
);
1196 if (!ath10k_mac_has_radar_enabled(ar
))
1199 if (ar
->num_started_vdevs
> 0)
1202 ret
= ath10k_start_cac(ar
);
1205 * Not possible to start CAC on current channel so starting
1206 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1207 * by indicating that radar was detected.
1209 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1210 ieee80211_radar_detected(ar
->hw
);
1214 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1216 struct ath10k
*ar
= arvif
->ar
;
1219 lockdep_assert_held(&ar
->conf_mutex
);
1221 reinit_completion(&ar
->vdev_setup_done
);
1223 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1225 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1226 arvif
->vdev_id
, ret
);
1230 ret
= ath10k_vdev_setup_sync(ar
);
1232 ath10k_warn(ar
, "failed to syncronise setup for vdev %i: %d\n",
1233 arvif
->vdev_id
, ret
);
1237 WARN_ON(ar
->num_started_vdevs
== 0);
1239 if (ar
->num_started_vdevs
!= 0) {
1240 ar
->num_started_vdevs
--;
1241 ath10k_recalc_radar_detection(ar
);
1247 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1248 const struct cfg80211_chan_def
*chandef
,
1251 struct ath10k
*ar
= arvif
->ar
;
1252 struct wmi_vdev_start_request_arg arg
= {};
1255 lockdep_assert_held(&ar
->conf_mutex
);
1257 reinit_completion(&ar
->vdev_setup_done
);
1259 arg
.vdev_id
= arvif
->vdev_id
;
1260 arg
.dtim_period
= arvif
->dtim_period
;
1261 arg
.bcn_intval
= arvif
->beacon_interval
;
1263 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1264 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1265 arg
.channel
.mode
= chan_to_phymode(chandef
);
1267 arg
.channel
.min_power
= 0;
1268 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1269 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1270 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1272 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1273 arg
.ssid
= arvif
->u
.ap
.ssid
;
1274 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1275 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1277 /* For now allow DFS for AP mode */
1278 arg
.channel
.chan_radar
=
1279 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1280 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1281 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1282 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1285 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1286 "mac vdev %d start center_freq %d phymode %s\n",
1287 arg
.vdev_id
, arg
.channel
.freq
,
1288 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1291 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1293 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1296 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1301 ret
= ath10k_vdev_setup_sync(ar
);
1304 "failed to synchronize setup for vdev %i restart %d: %d\n",
1305 arg
.vdev_id
, restart
, ret
);
1309 ar
->num_started_vdevs
++;
1310 ath10k_recalc_radar_detection(ar
);
1315 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1316 const struct cfg80211_chan_def
*def
)
1318 return ath10k_vdev_start_restart(arvif
, def
, false);
1321 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1322 const struct cfg80211_chan_def
*def
)
1324 return ath10k_vdev_start_restart(arvif
, def
, true);
1327 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1328 struct sk_buff
*bcn
)
1330 struct ath10k
*ar
= arvif
->ar
;
1331 struct ieee80211_mgmt
*mgmt
;
1335 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1338 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1341 mgmt
= (void *)bcn
->data
;
1342 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1343 mgmt
->u
.beacon
.variable
,
1344 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1349 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1351 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1352 arvif
->vdev_id
, ret
);
1359 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1360 u8 oui_type
, size_t ie_offset
)
1367 if (WARN_ON(skb
->len
< ie_offset
))
1370 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1371 skb
->data
+ ie_offset
,
1372 skb
->len
- ie_offset
);
1377 end
= skb
->data
+ skb
->len
;
1380 if (WARN_ON(next
> end
))
1383 memmove(ie
, next
, end
- next
);
1384 skb_trim(skb
, skb
->len
- len
);
1389 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1391 struct ath10k
*ar
= arvif
->ar
;
1392 struct ieee80211_hw
*hw
= ar
->hw
;
1393 struct ieee80211_vif
*vif
= arvif
->vif
;
1394 struct ieee80211_mutable_offsets offs
= {};
1395 struct sk_buff
*bcn
;
1398 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1401 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1402 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1405 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1407 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1411 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1413 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1418 /* P2P IE is inserted by firmware automatically (as configured above)
1419 * so remove it from the base beacon template to avoid duplicate P2P
1420 * IEs in beacon frames.
1422 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1423 offsetof(struct ieee80211_mgmt
,
1424 u
.beacon
.variable
));
1426 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1431 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1439 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1441 struct ath10k
*ar
= arvif
->ar
;
1442 struct ieee80211_hw
*hw
= ar
->hw
;
1443 struct ieee80211_vif
*vif
= arvif
->vif
;
1444 struct sk_buff
*prb
;
1447 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1450 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1453 prb
= ieee80211_proberesp_get(hw
, vif
);
1455 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1459 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1463 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1471 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1473 struct ath10k
*ar
= arvif
->ar
;
1474 struct cfg80211_chan_def def
;
1477 /* When originally vdev is started during assign_vif_chanctx() some
1478 * information is missing, notably SSID. Firmware revisions with beacon
1479 * offloading require the SSID to be provided during vdev (re)start to
1480 * handle hidden SSID properly.
1482 * Vdev restart must be done after vdev has been both started and
1483 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1484 * deliver vdev restart response event causing timeouts during vdev
1485 * syncing in ath10k.
1487 * Note: The vdev down/up and template reinstallation could be skipped
1488 * since only wmi-tlv firmware are known to have beacon offload and
1489 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1490 * response delivery. It's probably more robust to keep it as is.
1492 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1495 if (WARN_ON(!arvif
->is_started
))
1498 if (WARN_ON(!arvif
->is_up
))
1501 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1504 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1506 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1507 arvif
->vdev_id
, ret
);
1511 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1512 * firmware will crash upon vdev up.
1515 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1517 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1521 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1523 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1527 ret
= ath10k_vdev_restart(arvif
, &def
);
1529 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1530 arvif
->vdev_id
, ret
);
1534 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1537 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1538 arvif
->vdev_id
, ret
);
1545 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1546 struct ieee80211_bss_conf
*info
)
1548 struct ath10k
*ar
= arvif
->ar
;
1551 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1553 if (!info
->enable_beacon
) {
1554 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1556 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1557 arvif
->vdev_id
, ret
);
1559 arvif
->is_up
= false;
1561 spin_lock_bh(&arvif
->ar
->data_lock
);
1562 ath10k_mac_vif_beacon_free(arvif
);
1563 spin_unlock_bh(&arvif
->ar
->data_lock
);
1568 arvif
->tx_seq_no
= 0x1000;
1571 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1573 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1576 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1577 arvif
->vdev_id
, ret
);
1581 arvif
->is_up
= true;
1583 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1585 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1586 arvif
->vdev_id
, ret
);
1590 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1593 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1594 struct ieee80211_bss_conf
*info
,
1595 const u8 self_peer
[ETH_ALEN
])
1597 struct ath10k
*ar
= arvif
->ar
;
1601 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1603 if (!info
->ibss_joined
) {
1604 if (is_zero_ether_addr(arvif
->bssid
))
1607 eth_zero_addr(arvif
->bssid
);
1612 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1613 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1614 ATH10K_DEFAULT_ATIM
);
1616 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1617 arvif
->vdev_id
, ret
);
1620 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1622 struct ath10k
*ar
= arvif
->ar
;
1627 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1629 if (arvif
->u
.sta
.uapsd
)
1630 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1632 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1634 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1635 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1637 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1638 value
, arvif
->vdev_id
, ret
);
1645 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1647 struct ath10k
*ar
= arvif
->ar
;
1652 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1654 if (arvif
->u
.sta
.uapsd
)
1655 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1657 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1659 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1660 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1663 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1664 value
, arvif
->vdev_id
, ret
);
1671 static int ath10k_mac_ps_vif_count(struct ath10k
*ar
)
1673 struct ath10k_vif
*arvif
;
1676 lockdep_assert_held(&ar
->conf_mutex
);
1678 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1685 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1687 struct ath10k
*ar
= arvif
->ar
;
1688 struct ieee80211_vif
*vif
= arvif
->vif
;
1689 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1690 enum wmi_sta_powersave_param param
;
1691 enum wmi_sta_ps_mode psmode
;
1696 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1698 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1701 enable_ps
= arvif
->ps
;
1703 if (enable_ps
&& ath10k_mac_ps_vif_count(ar
) > 1 &&
1704 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1706 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1711 if (!arvif
->is_started
) {
1712 /* mac80211 can update vif powersave state while disconnected.
1713 * Firmware doesn't behave nicely and consumes more power than
1714 * necessary if PS is disabled on a non-started vdev. Hence
1715 * force-enable PS for non-running vdevs.
1717 psmode
= WMI_STA_PS_MODE_ENABLED
;
1718 } else if (enable_ps
) {
1719 psmode
= WMI_STA_PS_MODE_ENABLED
;
1720 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1722 ps_timeout
= conf
->dynamic_ps_timeout
;
1723 if (ps_timeout
== 0) {
1724 /* Firmware doesn't like 0 */
1725 ps_timeout
= ieee80211_tu_to_usec(
1726 vif
->bss_conf
.beacon_int
) / 1000;
1729 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1732 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1733 arvif
->vdev_id
, ret
);
1737 psmode
= WMI_STA_PS_MODE_DISABLED
;
1740 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1741 arvif
->vdev_id
, psmode
? "enable" : "disable");
1743 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1745 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1746 psmode
, arvif
->vdev_id
, ret
);
1753 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1755 struct ath10k
*ar
= arvif
->ar
;
1756 struct wmi_sta_keepalive_arg arg
= {};
1759 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1761 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1764 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1767 /* Some firmware revisions have a bug and ignore the `enabled` field.
1768 * Instead use the interval to disable the keepalive.
1770 arg
.vdev_id
= arvif
->vdev_id
;
1772 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1773 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1775 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1777 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1778 arvif
->vdev_id
, ret
);
1785 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
1787 struct ath10k
*ar
= arvif
->ar
;
1788 struct ieee80211_vif
*vif
= arvif
->vif
;
1791 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1793 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
1796 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1799 if (!vif
->csa_active
)
1805 if (!ieee80211_csa_is_complete(vif
)) {
1806 ieee80211_csa_update_counter(vif
);
1808 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1810 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
1813 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1815 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
1818 ieee80211_csa_finish(vif
);
1822 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
1824 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1826 struct ath10k
*ar
= arvif
->ar
;
1828 mutex_lock(&ar
->conf_mutex
);
1829 ath10k_mac_vif_ap_csa_count_down(arvif
);
1830 mutex_unlock(&ar
->conf_mutex
);
1833 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
1834 struct ieee80211_vif
*vif
)
1836 struct sk_buff
*skb
= data
;
1837 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1838 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1840 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1843 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
1846 cancel_delayed_work(&arvif
->connection_loss_work
);
1849 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
1851 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1852 IEEE80211_IFACE_ITER_NORMAL
,
1853 ath10k_mac_handle_beacon_iter
,
1857 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
1858 struct ieee80211_vif
*vif
)
1860 u32
*vdev_id
= data
;
1861 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1862 struct ath10k
*ar
= arvif
->ar
;
1863 struct ieee80211_hw
*hw
= ar
->hw
;
1865 if (arvif
->vdev_id
!= *vdev_id
)
1871 ieee80211_beacon_loss(vif
);
1873 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1874 * (done by mac80211) succeeds but beacons do not resume then it
1875 * doesn't make sense to continue operation. Queue connection loss work
1876 * which can be cancelled when beacon is received.
1878 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
1879 ATH10K_CONNECTION_LOSS_HZ
);
1882 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
1884 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1885 IEEE80211_IFACE_ITER_NORMAL
,
1886 ath10k_mac_handle_beacon_miss_iter
,
1890 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
1892 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1893 connection_loss_work
.work
);
1894 struct ieee80211_vif
*vif
= arvif
->vif
;
1899 ieee80211_connection_loss(vif
);
1902 /**********************/
1903 /* Station management */
1904 /**********************/
1906 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1907 struct ieee80211_vif
*vif
)
1909 /* Some firmware revisions have unstable STA powersave when listen
1910 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1911 * generate NullFunc frames properly even if buffered frames have been
1912 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1913 * buffered frames. Often pinging the device from AP would simply fail.
1915 * As a workaround set it to 1.
1917 if (vif
->type
== NL80211_IFTYPE_STATION
)
1920 return ar
->hw
->conf
.listen_interval
;
1923 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1924 struct ieee80211_vif
*vif
,
1925 struct ieee80211_sta
*sta
,
1926 struct wmi_peer_assoc_complete_arg
*arg
)
1928 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1931 lockdep_assert_held(&ar
->conf_mutex
);
1933 if (vif
->type
== NL80211_IFTYPE_STATION
)
1934 aid
= vif
->bss_conf
.aid
;
1938 ether_addr_copy(arg
->addr
, sta
->addr
);
1939 arg
->vdev_id
= arvif
->vdev_id
;
1940 arg
->peer_aid
= aid
;
1941 arg
->peer_flags
|= WMI_PEER_AUTH
;
1942 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1943 arg
->peer_num_spatial_streams
= 1;
1944 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1947 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1948 struct ieee80211_vif
*vif
,
1949 struct wmi_peer_assoc_complete_arg
*arg
)
1951 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1952 struct cfg80211_chan_def def
;
1953 struct cfg80211_bss
*bss
;
1954 const u8
*rsnie
= NULL
;
1955 const u8
*wpaie
= NULL
;
1957 lockdep_assert_held(&ar
->conf_mutex
);
1959 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
1962 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
, NULL
, 0,
1963 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
1965 const struct cfg80211_bss_ies
*ies
;
1968 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1970 ies
= rcu_dereference(bss
->ies
);
1972 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1973 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1977 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1980 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1981 if (rsnie
|| wpaie
) {
1982 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1983 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1987 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1988 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1992 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1993 struct ieee80211_vif
*vif
,
1994 struct ieee80211_sta
*sta
,
1995 struct wmi_peer_assoc_complete_arg
*arg
)
1997 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1998 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
1999 struct cfg80211_chan_def def
;
2000 const struct ieee80211_supported_band
*sband
;
2001 const struct ieee80211_rate
*rates
;
2002 enum ieee80211_band band
;
2007 lockdep_assert_held(&ar
->conf_mutex
);
2009 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2012 band
= def
.chan
->band
;
2013 sband
= ar
->hw
->wiphy
->bands
[band
];
2014 ratemask
= sta
->supp_rates
[band
];
2015 ratemask
&= arvif
->bitrate_mask
.control
[band
].legacy
;
2016 rates
= sband
->bitrates
;
2018 rateset
->num_rates
= 0;
2020 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2021 if (!(ratemask
& 1))
2024 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2025 rateset
->rates
[rateset
->num_rates
] = rate
;
2026 rateset
->num_rates
++;
2031 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
2035 for (nss
= 0; nss
< IEEE80211_HT_MCS_MASK_LEN
; nss
++)
2036 if (ht_mcs_mask
[nss
])
2043 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
2047 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++)
2048 if (vht_mcs_mask
[nss
])
2054 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2055 struct ieee80211_vif
*vif
,
2056 struct ieee80211_sta
*sta
,
2057 struct wmi_peer_assoc_complete_arg
*arg
)
2059 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2060 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2061 struct cfg80211_chan_def def
;
2062 enum ieee80211_band band
;
2063 const u8
*ht_mcs_mask
;
2064 const u16
*vht_mcs_mask
;
2068 lockdep_assert_held(&ar
->conf_mutex
);
2070 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2073 if (!ht_cap
->ht_supported
)
2076 band
= def
.chan
->band
;
2077 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2078 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2080 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
) &&
2081 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2084 arg
->peer_flags
|= WMI_PEER_HT
;
2085 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2086 ht_cap
->ampdu_factor
)) - 1;
2088 arg
->peer_mpdu_density
=
2089 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2091 arg
->peer_ht_caps
= ht_cap
->cap
;
2092 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2094 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2095 arg
->peer_flags
|= WMI_PEER_LDPC
;
2097 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2098 arg
->peer_flags
|= WMI_PEER_40MHZ
;
2099 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2102 if (arvif
->bitrate_mask
.control
[band
].gi
!= NL80211_TXRATE_FORCE_LGI
) {
2103 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2104 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2106 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2107 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2110 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2111 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2112 arg
->peer_flags
|= WMI_PEER_STBC
;
2115 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2116 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2117 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2118 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2119 arg
->peer_rate_caps
|= stbc
;
2120 arg
->peer_flags
|= WMI_PEER_STBC
;
2123 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2124 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2125 else if (ht_cap
->mcs
.rx_mask
[1])
2126 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2128 for (i
= 0, n
= 0, max_nss
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
* 8; i
++)
2129 if ((ht_cap
->mcs
.rx_mask
[i
/ 8] & BIT(i
% 8)) &&
2130 (ht_mcs_mask
[i
/ 8] & BIT(i
% 8))) {
2131 max_nss
= (i
/ 8) + 1;
2132 arg
->peer_ht_rates
.rates
[n
++] = i
;
2136 * This is a workaround for HT-enabled STAs which break the spec
2137 * and have no HT capabilities RX mask (no HT RX MCS map).
2139 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2140 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2142 * Firmware asserts if such situation occurs.
2145 arg
->peer_ht_rates
.num_rates
= 8;
2146 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2147 arg
->peer_ht_rates
.rates
[i
] = i
;
2149 arg
->peer_ht_rates
.num_rates
= n
;
2150 arg
->peer_num_spatial_streams
= max_nss
;
2153 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2155 arg
->peer_ht_rates
.num_rates
,
2156 arg
->peer_num_spatial_streams
);
2159 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2160 struct ath10k_vif
*arvif
,
2161 struct ieee80211_sta
*sta
)
2167 lockdep_assert_held(&ar
->conf_mutex
);
2169 if (sta
->wme
&& sta
->uapsd_queues
) {
2170 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2171 sta
->uapsd_queues
, sta
->max_sp
);
2173 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2174 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2175 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2176 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2177 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2178 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2179 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2180 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2181 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2182 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2183 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2184 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2186 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2187 max_sp
= sta
->max_sp
;
2189 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2191 WMI_AP_PS_PEER_PARAM_UAPSD
,
2194 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2195 arvif
->vdev_id
, ret
);
2199 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2201 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2204 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2205 arvif
->vdev_id
, ret
);
2209 /* TODO setup this based on STA listen interval and
2210 beacon interval. Currently we don't know
2211 sta->listen_interval - mac80211 patch required.
2212 Currently use 10 seconds */
2213 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2214 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2217 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2218 arvif
->vdev_id
, ret
);
2227 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set
,
2228 const u16 vht_mcs_limit
[NL80211_VHT_NSS_MAX
])
2235 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
2236 mcs_map
= ath10k_mac_get_max_vht_mcs_map(tx_mcs_set
, nss
) &
2240 idx_limit
= fls(mcs_map
) - 1;
2244 switch (idx_limit
) {
2245 case 0: /* fall through */
2246 case 1: /* fall through */
2247 case 2: /* fall through */
2248 case 3: /* fall through */
2249 case 4: /* fall through */
2250 case 5: /* fall through */
2251 case 6: /* fall through */
2253 /* see ath10k_mac_can_set_bitrate_mask() */
2257 mcs
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
2260 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_7
;
2263 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_8
;
2266 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_9
;
2270 tx_mcs_set
&= ~(0x3 << (nss
* 2));
2271 tx_mcs_set
|= mcs
<< (nss
* 2);
2277 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2278 struct ieee80211_vif
*vif
,
2279 struct ieee80211_sta
*sta
,
2280 struct wmi_peer_assoc_complete_arg
*arg
)
2282 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
2283 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2284 struct cfg80211_chan_def def
;
2285 enum ieee80211_band band
;
2286 const u16
*vht_mcs_mask
;
2289 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2292 if (!vht_cap
->vht_supported
)
2295 band
= def
.chan
->band
;
2296 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2298 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2301 arg
->peer_flags
|= WMI_PEER_VHT
;
2303 if (def
.chan
->band
== IEEE80211_BAND_2GHZ
)
2304 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
2306 arg
->peer_vht_caps
= vht_cap
->cap
;
2308 ampdu_factor
= (vht_cap
->cap
&
2309 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2310 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2312 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2313 * zero in VHT IE. Using it would result in degraded throughput.
2314 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2315 * it if VHT max_mpdu is smaller. */
2316 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2317 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2318 ampdu_factor
)) - 1);
2320 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2321 arg
->peer_flags
|= WMI_PEER_80MHZ
;
2323 arg
->peer_vht_rates
.rx_max_rate
=
2324 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2325 arg
->peer_vht_rates
.rx_mcs_set
=
2326 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2327 arg
->peer_vht_rates
.tx_max_rate
=
2328 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2329 arg
->peer_vht_rates
.tx_mcs_set
= ath10k_peer_assoc_h_vht_limit(
2330 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
), vht_mcs_mask
);
2332 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2333 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
2336 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2337 struct ieee80211_vif
*vif
,
2338 struct ieee80211_sta
*sta
,
2339 struct wmi_peer_assoc_complete_arg
*arg
)
2341 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2343 switch (arvif
->vdev_type
) {
2344 case WMI_VDEV_TYPE_AP
:
2346 arg
->peer_flags
|= WMI_PEER_QOS
;
2348 if (sta
->wme
&& sta
->uapsd_queues
) {
2349 arg
->peer_flags
|= WMI_PEER_APSD
;
2350 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2353 case WMI_VDEV_TYPE_STA
:
2354 if (vif
->bss_conf
.qos
)
2355 arg
->peer_flags
|= WMI_PEER_QOS
;
2357 case WMI_VDEV_TYPE_IBSS
:
2359 arg
->peer_flags
|= WMI_PEER_QOS
;
2365 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2366 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
2369 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2371 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >>
2372 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2375 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2376 struct ieee80211_vif
*vif
,
2377 struct ieee80211_sta
*sta
,
2378 struct wmi_peer_assoc_complete_arg
*arg
)
2380 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2381 struct cfg80211_chan_def def
;
2382 enum ieee80211_band band
;
2383 const u8
*ht_mcs_mask
;
2384 const u16
*vht_mcs_mask
;
2385 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2387 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2390 band
= def
.chan
->band
;
2391 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2392 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2395 case IEEE80211_BAND_2GHZ
:
2396 if (sta
->vht_cap
.vht_supported
&&
2397 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2398 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2399 phymode
= MODE_11AC_VHT40
;
2401 phymode
= MODE_11AC_VHT20
;
2402 } else if (sta
->ht_cap
.ht_supported
&&
2403 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2404 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2405 phymode
= MODE_11NG_HT40
;
2407 phymode
= MODE_11NG_HT20
;
2408 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2415 case IEEE80211_BAND_5GHZ
:
2419 if (sta
->vht_cap
.vht_supported
&&
2420 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2421 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2422 phymode
= MODE_11AC_VHT80
;
2423 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2424 phymode
= MODE_11AC_VHT40
;
2425 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2426 phymode
= MODE_11AC_VHT20
;
2427 } else if (sta
->ht_cap
.ht_supported
&&
2428 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2429 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
)
2430 phymode
= MODE_11NA_HT40
;
2432 phymode
= MODE_11NA_HT20
;
2442 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2443 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2445 arg
->peer_phymode
= phymode
;
2446 WARN_ON(phymode
== MODE_UNKNOWN
);
2449 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2450 struct ieee80211_vif
*vif
,
2451 struct ieee80211_sta
*sta
,
2452 struct wmi_peer_assoc_complete_arg
*arg
)
2454 lockdep_assert_held(&ar
->conf_mutex
);
2456 memset(arg
, 0, sizeof(*arg
));
2458 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2459 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
2460 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2461 ath10k_peer_assoc_h_ht(ar
, vif
, sta
, arg
);
2462 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2463 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2464 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2469 static const u32 ath10k_smps_map
[] = {
2470 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2471 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2472 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2473 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2476 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2478 const struct ieee80211_sta_ht_cap
*ht_cap
)
2482 if (!ht_cap
->ht_supported
)
2485 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2486 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2488 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2491 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2492 WMI_PEER_SMPS_STATE
,
2493 ath10k_smps_map
[smps
]);
2496 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2497 struct ieee80211_vif
*vif
,
2498 struct ieee80211_sta_vht_cap vht_cap
)
2500 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2505 if (!(ar
->vht_cap_info
&
2506 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2507 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2508 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2509 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2512 param
= ar
->wmi
.vdev_param
->txbf
;
2515 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2518 /* The following logic is correct. If a remote STA advertises support
2519 * for being a beamformer then we should enable us being a beamformee.
2522 if (ar
->vht_cap_info
&
2523 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2524 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2525 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2526 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2528 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2529 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2532 if (ar
->vht_cap_info
&
2533 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2534 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2535 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2536 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2538 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2539 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2542 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2543 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2545 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2546 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2548 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2550 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2558 /* can be called only in mac80211 callbacks due to `key_count` usage */
2559 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2560 struct ieee80211_vif
*vif
,
2561 struct ieee80211_bss_conf
*bss_conf
)
2563 struct ath10k
*ar
= hw
->priv
;
2564 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2565 struct ieee80211_sta_ht_cap ht_cap
;
2566 struct ieee80211_sta_vht_cap vht_cap
;
2567 struct wmi_peer_assoc_complete_arg peer_arg
;
2568 struct ieee80211_sta
*ap_sta
;
2571 lockdep_assert_held(&ar
->conf_mutex
);
2573 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2574 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2578 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2580 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2581 bss_conf
->bssid
, arvif
->vdev_id
);
2586 /* ap_sta must be accessed only within rcu section which must be left
2587 * before calling ath10k_setup_peer_smps() which might sleep. */
2588 ht_cap
= ap_sta
->ht_cap
;
2589 vht_cap
= ap_sta
->vht_cap
;
2591 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2593 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2594 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2601 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2603 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2604 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2608 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2610 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2611 arvif
->vdev_id
, ret
);
2615 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2617 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2618 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2622 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2623 "mac vdev %d up (associated) bssid %pM aid %d\n",
2624 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2626 WARN_ON(arvif
->is_up
);
2628 arvif
->aid
= bss_conf
->aid
;
2629 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2631 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2633 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2634 arvif
->vdev_id
, ret
);
2638 arvif
->is_up
= true;
2640 /* Workaround: Some firmware revisions (tested with qca6174
2641 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2642 * poked with peer param command.
2644 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2645 WMI_PEER_DUMMY_VAR
, 1);
2647 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2648 arvif
->bssid
, arvif
->vdev_id
, ret
);
2653 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2654 struct ieee80211_vif
*vif
)
2656 struct ath10k
*ar
= hw
->priv
;
2657 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2658 struct ieee80211_sta_vht_cap vht_cap
= {};
2661 lockdep_assert_held(&ar
->conf_mutex
);
2663 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2664 arvif
->vdev_id
, arvif
->bssid
);
2666 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2668 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
2669 arvif
->vdev_id
, ret
);
2671 arvif
->def_wep_key_idx
= -1;
2673 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2675 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2676 arvif
->vdev_id
, ret
);
2680 arvif
->is_up
= false;
2682 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
2685 static int ath10k_station_assoc(struct ath10k
*ar
,
2686 struct ieee80211_vif
*vif
,
2687 struct ieee80211_sta
*sta
,
2690 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2691 struct wmi_peer_assoc_complete_arg peer_arg
;
2694 lockdep_assert_held(&ar
->conf_mutex
);
2696 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2698 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2699 sta
->addr
, arvif
->vdev_id
, ret
);
2703 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2705 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2706 sta
->addr
, arvif
->vdev_id
, ret
);
2710 /* Re-assoc is run only to update supported rates for given station. It
2711 * doesn't make much sense to reconfigure the peer completely.
2714 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2717 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2718 arvif
->vdev_id
, ret
);
2722 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2724 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2725 sta
->addr
, arvif
->vdev_id
, ret
);
2730 arvif
->num_legacy_stations
++;
2731 ret
= ath10k_recalc_rtscts_prot(arvif
);
2733 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2734 arvif
->vdev_id
, ret
);
2739 /* Plumb cached keys only for static WEP */
2740 if (arvif
->def_wep_key_idx
!= -1) {
2741 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2743 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2744 arvif
->vdev_id
, ret
);
2753 static int ath10k_station_disassoc(struct ath10k
*ar
,
2754 struct ieee80211_vif
*vif
,
2755 struct ieee80211_sta
*sta
)
2757 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2760 lockdep_assert_held(&ar
->conf_mutex
);
2763 arvif
->num_legacy_stations
--;
2764 ret
= ath10k_recalc_rtscts_prot(arvif
);
2766 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2767 arvif
->vdev_id
, ret
);
2772 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2774 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2775 arvif
->vdev_id
, ret
);
2786 static int ath10k_update_channel_list(struct ath10k
*ar
)
2788 struct ieee80211_hw
*hw
= ar
->hw
;
2789 struct ieee80211_supported_band
**bands
;
2790 enum ieee80211_band band
;
2791 struct ieee80211_channel
*channel
;
2792 struct wmi_scan_chan_list_arg arg
= {0};
2793 struct wmi_channel_arg
*ch
;
2799 lockdep_assert_held(&ar
->conf_mutex
);
2801 bands
= hw
->wiphy
->bands
;
2802 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2806 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2807 if (bands
[band
]->channels
[i
].flags
&
2808 IEEE80211_CHAN_DISABLED
)
2815 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2816 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2821 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2825 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2826 channel
= &bands
[band
]->channels
[i
];
2828 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2831 ch
->allow_ht
= true;
2833 /* FIXME: when should we really allow VHT? */
2834 ch
->allow_vht
= true;
2837 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2840 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2843 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2845 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2846 ch
->passive
= passive
;
2848 ch
->freq
= channel
->center_freq
;
2849 ch
->band_center_freq1
= channel
->center_freq
;
2851 ch
->max_power
= channel
->max_power
* 2;
2852 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2853 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2854 ch
->reg_class_id
= 0; /* FIXME */
2856 /* FIXME: why use only legacy modes, why not any
2857 * HT/VHT modes? Would that even make any
2859 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2860 ch
->mode
= MODE_11G
;
2862 ch
->mode
= MODE_11A
;
2864 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2867 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2868 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2869 ch
- arg
.channels
, arg
.n_channels
,
2870 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2871 ch
->max_antenna_gain
, ch
->mode
);
2877 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2878 kfree(arg
.channels
);
2883 static enum wmi_dfs_region
2884 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2886 switch (dfs_region
) {
2887 case NL80211_DFS_UNSET
:
2888 return WMI_UNINIT_DFS_DOMAIN
;
2889 case NL80211_DFS_FCC
:
2890 return WMI_FCC_DFS_DOMAIN
;
2891 case NL80211_DFS_ETSI
:
2892 return WMI_ETSI_DFS_DOMAIN
;
2893 case NL80211_DFS_JP
:
2894 return WMI_MKK4_DFS_DOMAIN
;
2896 return WMI_UNINIT_DFS_DOMAIN
;
2899 static void ath10k_regd_update(struct ath10k
*ar
)
2901 struct reg_dmn_pair_mapping
*regpair
;
2903 enum wmi_dfs_region wmi_dfs_reg
;
2904 enum nl80211_dfs_regions nl_dfs_reg
;
2906 lockdep_assert_held(&ar
->conf_mutex
);
2908 ret
= ath10k_update_channel_list(ar
);
2910 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2912 regpair
= ar
->ath_common
.regulatory
.regpair
;
2914 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2915 nl_dfs_reg
= ar
->dfs_detector
->region
;
2916 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2918 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2921 /* Target allows setting up per-band regdomain but ath_common provides
2922 * a combined one only */
2923 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2924 regpair
->reg_domain
,
2925 regpair
->reg_domain
, /* 2ghz */
2926 regpair
->reg_domain
, /* 5ghz */
2927 regpair
->reg_2ghz_ctl
,
2928 regpair
->reg_5ghz_ctl
,
2931 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2934 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2935 struct regulatory_request
*request
)
2937 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2938 struct ath10k
*ar
= hw
->priv
;
2941 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2943 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2944 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
2945 request
->dfs_region
);
2946 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
2947 request
->dfs_region
);
2949 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2950 request
->dfs_region
);
2953 mutex_lock(&ar
->conf_mutex
);
2954 if (ar
->state
== ATH10K_STATE_ON
)
2955 ath10k_regd_update(ar
);
2956 mutex_unlock(&ar
->conf_mutex
);
2963 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
2965 lockdep_assert_held(&ar
->htt
.tx_lock
);
2967 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
2968 ar
->tx_paused
|= BIT(reason
);
2969 ieee80211_stop_queues(ar
->hw
);
2972 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
2973 struct ieee80211_vif
*vif
)
2975 struct ath10k
*ar
= data
;
2976 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2978 if (arvif
->tx_paused
)
2981 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
2984 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
2986 lockdep_assert_held(&ar
->htt
.tx_lock
);
2988 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
2989 ar
->tx_paused
&= ~BIT(reason
);
2994 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2995 IEEE80211_IFACE_ITER_RESUME_ALL
,
2996 ath10k_mac_tx_unlock_iter
,
3000 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
3002 struct ath10k
*ar
= arvif
->ar
;
3004 lockdep_assert_held(&ar
->htt
.tx_lock
);
3006 WARN_ON(reason
>= BITS_PER_LONG
);
3007 arvif
->tx_paused
|= BIT(reason
);
3008 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
3011 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
3013 struct ath10k
*ar
= arvif
->ar
;
3015 lockdep_assert_held(&ar
->htt
.tx_lock
);
3017 WARN_ON(reason
>= BITS_PER_LONG
);
3018 arvif
->tx_paused
&= ~BIT(reason
);
3023 if (arvif
->tx_paused
)
3026 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3029 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
3030 enum wmi_tlv_tx_pause_id pause_id
,
3031 enum wmi_tlv_tx_pause_action action
)
3033 struct ath10k
*ar
= arvif
->ar
;
3035 lockdep_assert_held(&ar
->htt
.tx_lock
);
3038 case WMI_TLV_TX_PAUSE_ID_MCC
:
3039 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA
:
3040 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS
:
3041 case WMI_TLV_TX_PAUSE_ID_AP_PS
:
3042 case WMI_TLV_TX_PAUSE_ID_IBSS_PS
:
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
);
3056 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS
:
3057 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD
:
3058 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA
:
3059 case WMI_TLV_TX_PAUSE_ID_HOST
:
3061 /* FIXME: Some pause_ids aren't vdev specific. Instead they
3062 * target peer_id and tid. Implementing these could improve
3063 * traffic scheduling fairness across multiple connected
3064 * stations in AP/IBSS modes.
3066 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3067 "mac ignoring unsupported tx pause vdev %i id %d\n",
3068 arvif
->vdev_id
, pause_id
);
3073 struct ath10k_mac_tx_pause
{
3075 enum wmi_tlv_tx_pause_id pause_id
;
3076 enum wmi_tlv_tx_pause_action action
;
3079 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
3080 struct ieee80211_vif
*vif
)
3082 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3083 struct ath10k_mac_tx_pause
*arg
= data
;
3085 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
3088 void ath10k_mac_handle_tx_pause(struct ath10k
*ar
, u32 vdev_id
,
3089 enum wmi_tlv_tx_pause_id pause_id
,
3090 enum wmi_tlv_tx_pause_action action
)
3092 struct ath10k_mac_tx_pause arg
= {
3094 .pause_id
= pause_id
,
3098 spin_lock_bh(&ar
->htt
.tx_lock
);
3099 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3100 IEEE80211_IFACE_ITER_RESUME_ALL
,
3101 ath10k_mac_handle_tx_pause_iter
,
3103 spin_unlock_bh(&ar
->htt
.tx_lock
);
3106 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
3108 if (ieee80211_is_mgmt(hdr
->frame_control
))
3109 return HTT_DATA_TX_EXT_TID_MGMT
;
3111 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3112 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3114 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
3115 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3117 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
3120 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
3123 return ath10k_vif_to_arvif(vif
)->vdev_id
;
3125 if (ar
->monitor_started
)
3126 return ar
->monitor_vdev_id
;
3128 ath10k_warn(ar
, "failed to resolve vdev id\n");
3132 static enum ath10k_hw_txrx_mode
3133 ath10k_tx_h_get_txmode(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
3134 struct ieee80211_sta
*sta
, struct sk_buff
*skb
)
3136 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3137 __le16 fc
= hdr
->frame_control
;
3139 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3140 return ATH10K_HW_TXRX_RAW
;
3142 if (ieee80211_is_mgmt(fc
))
3143 return ATH10K_HW_TXRX_MGMT
;
3147 * NullFunc frames are mostly used to ping if a client or AP are still
3148 * reachable and responsive. This implies tx status reports must be
3149 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3150 * come to a conclusion that the other end disappeared and tear down
3151 * BSS connection or it can never disconnect from BSS/client (which is
3154 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3155 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3156 * which seems to deliver correct tx reports for NullFunc frames. The
3157 * downside of using it is it ignores client powersave state so it can
3158 * end up disconnecting sleeping clients in AP mode. It should fix STA
3159 * mode though because AP don't sleep.
3161 if (ar
->htt
.target_version_major
< 3 &&
3162 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3163 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
, ar
->fw_features
))
3164 return ATH10K_HW_TXRX_MGMT
;
3168 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3169 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3170 * to work with Ethernet txmode so use it.
3172 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3173 return ATH10K_HW_TXRX_ETHERNET
;
3175 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3178 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3179 * Control in the header.
3181 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3183 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3184 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3187 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3190 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3191 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3192 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3193 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3195 /* Some firmware revisions don't handle sending QoS NullFunc well.
3196 * These frames are mainly used for CQM purposes so it doesn't really
3197 * matter whether QoS NullFunc or NullFunc are sent.
3199 hdr
= (void *)skb
->data
;
3200 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3201 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3203 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3206 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3208 struct ieee80211_hdr
*hdr
;
3209 struct rfc1042_hdr
*rfc1042
;
3216 hdr
= (void *)skb
->data
;
3217 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3218 rfc1042
= (void *)skb
->data
+ hdrlen
;
3220 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3221 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3222 type
= rfc1042
->snap_type
;
3224 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3225 skb_push(skb
, sizeof(*eth
));
3227 eth
= (void *)skb
->data
;
3228 ether_addr_copy(eth
->h_dest
, da
);
3229 ether_addr_copy(eth
->h_source
, sa
);
3230 eth
->h_proto
= type
;
3233 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3234 struct ieee80211_vif
*vif
,
3235 struct sk_buff
*skb
)
3237 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3238 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3240 /* This is case only for P2P_GO */
3241 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
3242 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
3245 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3246 spin_lock_bh(&ar
->data_lock
);
3247 if (arvif
->u
.ap
.noa_data
)
3248 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3250 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
3251 arvif
->u
.ap
.noa_data
,
3252 arvif
->u
.ap
.noa_len
);
3253 spin_unlock_bh(&ar
->data_lock
);
3257 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
3259 /* FIXME: Not really sure since when the behaviour changed. At some
3260 * point new firmware stopped requiring creation of peer entries for
3261 * offchannel tx (and actually creating them causes issues with wmi-htc
3262 * tx credit replenishment and reliability). Assuming it's at least 3.4
3263 * because that's when the `freq` was introduced to TX_FRM HTT command.
3265 return !(ar
->htt
.target_version_major
>= 3 &&
3266 ar
->htt
.target_version_minor
>= 4);
3269 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3271 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3274 spin_lock_bh(&ar
->data_lock
);
3276 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
3277 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3282 __skb_queue_tail(q
, skb
);
3283 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3286 spin_unlock_bh(&ar
->data_lock
);
3291 static void ath10k_mac_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
3293 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3294 struct ath10k_htt
*htt
= &ar
->htt
;
3297 switch (cb
->txmode
) {
3298 case ATH10K_HW_TXRX_RAW
:
3299 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3300 case ATH10K_HW_TXRX_ETHERNET
:
3301 ret
= ath10k_htt_tx(htt
, skb
);
3303 case ATH10K_HW_TXRX_MGMT
:
3304 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3306 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
3307 else if (ar
->htt
.target_version_major
>= 3)
3308 ret
= ath10k_htt_tx(htt
, skb
);
3310 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
3315 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
3317 ieee80211_free_txskb(ar
->hw
, skb
);
3321 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
3323 struct sk_buff
*skb
;
3326 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3330 ieee80211_free_txskb(ar
->hw
, skb
);
3334 void ath10k_offchan_tx_work(struct work_struct
*work
)
3336 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
3337 struct ath10k_peer
*peer
;
3338 struct ieee80211_hdr
*hdr
;
3339 struct sk_buff
*skb
;
3340 const u8
*peer_addr
;
3343 unsigned long time_left
;
3345 /* FW requirement: We must create a peer before FW will send out
3346 * an offchannel frame. Otherwise the frame will be stuck and
3347 * never transmitted. We delete the peer upon tx completion.
3348 * It is unlikely that a peer for offchannel tx will already be
3349 * present. However it may be in some rare cases so account for that.
3350 * Otherwise we might remove a legitimate peer and break stuff. */
3353 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3357 mutex_lock(&ar
->conf_mutex
);
3359 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
3362 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3363 peer_addr
= ieee80211_get_DA(hdr
);
3364 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
3366 spin_lock_bh(&ar
->data_lock
);
3367 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
3368 spin_unlock_bh(&ar
->data_lock
);
3371 /* FIXME: should this use ath10k_warn()? */
3372 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
3373 peer_addr
, vdev_id
);
3376 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
,
3377 WMI_PEER_TYPE_DEFAULT
);
3379 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
3380 peer_addr
, vdev_id
, ret
);
3383 spin_lock_bh(&ar
->data_lock
);
3384 reinit_completion(&ar
->offchan_tx_completed
);
3385 ar
->offchan_tx_skb
= skb
;
3386 spin_unlock_bh(&ar
->data_lock
);
3388 ath10k_mac_tx(ar
, skb
);
3391 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
3393 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
3397 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
3399 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
3400 peer_addr
, vdev_id
, ret
);
3403 mutex_unlock(&ar
->conf_mutex
);
3407 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
3409 struct sk_buff
*skb
;
3412 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3416 ieee80211_free_txskb(ar
->hw
, skb
);
3420 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
3422 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
3423 struct sk_buff
*skb
;
3427 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3431 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
3433 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
3435 ieee80211_free_txskb(ar
->hw
, skb
);
3444 void __ath10k_scan_finish(struct ath10k
*ar
)
3446 lockdep_assert_held(&ar
->data_lock
);
3448 switch (ar
->scan
.state
) {
3449 case ATH10K_SCAN_IDLE
:
3451 case ATH10K_SCAN_RUNNING
:
3452 if (ar
->scan
.is_roc
)
3453 ieee80211_remain_on_channel_expired(ar
->hw
);
3455 case ATH10K_SCAN_ABORTING
:
3456 if (!ar
->scan
.is_roc
)
3457 ieee80211_scan_completed(ar
->hw
,
3459 ATH10K_SCAN_ABORTING
));
3461 case ATH10K_SCAN_STARTING
:
3462 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3463 ar
->scan_channel
= NULL
;
3464 ath10k_offchan_tx_purge(ar
);
3465 cancel_delayed_work(&ar
->scan
.timeout
);
3466 complete_all(&ar
->scan
.completed
);
3471 void ath10k_scan_finish(struct ath10k
*ar
)
3473 spin_lock_bh(&ar
->data_lock
);
3474 __ath10k_scan_finish(ar
);
3475 spin_unlock_bh(&ar
->data_lock
);
3478 static int ath10k_scan_stop(struct ath10k
*ar
)
3480 struct wmi_stop_scan_arg arg
= {
3481 .req_id
= 1, /* FIXME */
3482 .req_type
= WMI_SCAN_STOP_ONE
,
3483 .u
.scan_id
= ATH10K_SCAN_ID
,
3487 lockdep_assert_held(&ar
->conf_mutex
);
3489 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
3491 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
3495 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
3497 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
3499 } else if (ret
> 0) {
3504 /* Scan state should be updated upon scan completion but in case
3505 * firmware fails to deliver the event (for whatever reason) it is
3506 * desired to clean up scan state anyway. Firmware may have just
3507 * dropped the scan completion event delivery due to transport pipe
3508 * being overflown with data and/or it can recover on its own before
3509 * next scan request is submitted.
3511 spin_lock_bh(&ar
->data_lock
);
3512 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
3513 __ath10k_scan_finish(ar
);
3514 spin_unlock_bh(&ar
->data_lock
);
3519 static void ath10k_scan_abort(struct ath10k
*ar
)
3523 lockdep_assert_held(&ar
->conf_mutex
);
3525 spin_lock_bh(&ar
->data_lock
);
3527 switch (ar
->scan
.state
) {
3528 case ATH10K_SCAN_IDLE
:
3529 /* This can happen if timeout worker kicked in and called
3530 * abortion while scan completion was being processed.
3533 case ATH10K_SCAN_STARTING
:
3534 case ATH10K_SCAN_ABORTING
:
3535 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3536 ath10k_scan_state_str(ar
->scan
.state
),
3539 case ATH10K_SCAN_RUNNING
:
3540 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
3541 spin_unlock_bh(&ar
->data_lock
);
3543 ret
= ath10k_scan_stop(ar
);
3545 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
3547 spin_lock_bh(&ar
->data_lock
);
3551 spin_unlock_bh(&ar
->data_lock
);
3554 void ath10k_scan_timeout_work(struct work_struct
*work
)
3556 struct ath10k
*ar
= container_of(work
, struct ath10k
,
3559 mutex_lock(&ar
->conf_mutex
);
3560 ath10k_scan_abort(ar
);
3561 mutex_unlock(&ar
->conf_mutex
);
3564 static int ath10k_start_scan(struct ath10k
*ar
,
3565 const struct wmi_start_scan_arg
*arg
)
3569 lockdep_assert_held(&ar
->conf_mutex
);
3571 ret
= ath10k_wmi_start_scan(ar
, arg
);
3575 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
3577 ret
= ath10k_scan_stop(ar
);
3579 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
3584 /* If we failed to start the scan, return error code at
3585 * this point. This is probably due to some issue in the
3586 * firmware, but no need to wedge the driver due to that...
3588 spin_lock_bh(&ar
->data_lock
);
3589 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
3590 spin_unlock_bh(&ar
->data_lock
);
3593 spin_unlock_bh(&ar
->data_lock
);
3595 /* Add a 200ms margin to account for event/command processing */
3596 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
3597 msecs_to_jiffies(arg
->max_scan_time
+200));
3601 /**********************/
3602 /* mac80211 callbacks */
3603 /**********************/
3605 static void ath10k_tx(struct ieee80211_hw
*hw
,
3606 struct ieee80211_tx_control
*control
,
3607 struct sk_buff
*skb
)
3609 struct ath10k
*ar
= hw
->priv
;
3610 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3611 struct ieee80211_vif
*vif
= info
->control
.vif
;
3612 struct ieee80211_sta
*sta
= control
->sta
;
3613 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3614 __le16 fc
= hdr
->frame_control
;
3616 /* We should disable CCK RATE due to P2P */
3617 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3618 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3620 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
3621 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3622 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
3623 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
3624 ATH10K_SKB_CB(skb
)->txmode
= ath10k_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3625 ATH10K_SKB_CB(skb
)->is_protected
= ieee80211_has_protected(fc
);
3627 switch (ATH10K_SKB_CB(skb
)->txmode
) {
3628 case ATH10K_HW_TXRX_MGMT
:
3629 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3630 ath10k_tx_h_nwifi(hw
, skb
);
3631 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3632 ath10k_tx_h_seq_no(vif
, skb
);
3634 case ATH10K_HW_TXRX_ETHERNET
:
3635 ath10k_tx_h_8023(skb
);
3637 case ATH10K_HW_TXRX_RAW
:
3638 /* FIXME: Packet injection isn't implemented. It should be
3639 * doable with firmware 10.2 on qca988x.
3642 ieee80211_free_txskb(hw
, skb
);
3646 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3647 spin_lock_bh(&ar
->data_lock
);
3648 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
3649 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
3650 spin_unlock_bh(&ar
->data_lock
);
3652 if (ath10k_mac_need_offchan_tx_work(ar
)) {
3653 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3654 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
3656 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
3659 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3660 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3665 ath10k_mac_tx(ar
, skb
);
3668 /* Must not be called with conf_mutex held as workers can use that also. */
3669 void ath10k_drain_tx(struct ath10k
*ar
)
3671 /* make sure rcu-protected mac80211 tx path itself is drained */
3674 ath10k_offchan_tx_purge(ar
);
3675 ath10k_mgmt_over_wmi_tx_purge(ar
);
3677 cancel_work_sync(&ar
->offchan_tx_work
);
3678 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
3681 void ath10k_halt(struct ath10k
*ar
)
3683 struct ath10k_vif
*arvif
;
3685 lockdep_assert_held(&ar
->conf_mutex
);
3687 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
3688 ar
->filter_flags
= 0;
3689 ar
->monitor
= false;
3690 ar
->monitor_arvif
= NULL
;
3692 if (ar
->monitor_started
)
3693 ath10k_monitor_stop(ar
);
3695 ar
->monitor_started
= false;
3698 ath10k_scan_finish(ar
);
3699 ath10k_peer_cleanup_all(ar
);
3700 ath10k_core_stop(ar
);
3701 ath10k_hif_power_down(ar
);
3703 spin_lock_bh(&ar
->data_lock
);
3704 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
3705 ath10k_mac_vif_beacon_cleanup(arvif
);
3706 spin_unlock_bh(&ar
->data_lock
);
3709 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
3711 struct ath10k
*ar
= hw
->priv
;
3713 mutex_lock(&ar
->conf_mutex
);
3715 if (ar
->cfg_tx_chainmask
) {
3716 *tx_ant
= ar
->cfg_tx_chainmask
;
3717 *rx_ant
= ar
->cfg_rx_chainmask
;
3719 *tx_ant
= ar
->supp_tx_chainmask
;
3720 *rx_ant
= ar
->supp_rx_chainmask
;
3723 mutex_unlock(&ar
->conf_mutex
);
3728 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
3730 /* It is not clear that allowing gaps in chainmask
3731 * is helpful. Probably it will not do what user
3732 * is hoping for, so warn in that case.
3734 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
3737 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3741 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
3745 lockdep_assert_held(&ar
->conf_mutex
);
3747 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
3748 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
3750 ar
->cfg_tx_chainmask
= tx_ant
;
3751 ar
->cfg_rx_chainmask
= rx_ant
;
3753 if ((ar
->state
!= ATH10K_STATE_ON
) &&
3754 (ar
->state
!= ATH10K_STATE_RESTARTED
))
3757 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
3760 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
3765 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
3768 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
3776 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
3778 struct ath10k
*ar
= hw
->priv
;
3781 mutex_lock(&ar
->conf_mutex
);
3782 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
3783 mutex_unlock(&ar
->conf_mutex
);
3787 static int ath10k_start(struct ieee80211_hw
*hw
)
3789 struct ath10k
*ar
= hw
->priv
;
3794 * This makes sense only when restarting hw. It is harmless to call
3795 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3796 * commands will be submitted while restarting.
3798 ath10k_drain_tx(ar
);
3800 mutex_lock(&ar
->conf_mutex
);
3802 switch (ar
->state
) {
3803 case ATH10K_STATE_OFF
:
3804 ar
->state
= ATH10K_STATE_ON
;
3806 case ATH10K_STATE_RESTARTING
:
3808 ar
->state
= ATH10K_STATE_RESTARTED
;
3810 case ATH10K_STATE_ON
:
3811 case ATH10K_STATE_RESTARTED
:
3812 case ATH10K_STATE_WEDGED
:
3816 case ATH10K_STATE_UTF
:
3821 ret
= ath10k_hif_power_up(ar
);
3823 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
3827 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
3829 ath10k_err(ar
, "Could not init core: %d\n", ret
);
3830 goto err_power_down
;
3833 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
3835 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
3839 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
3841 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
3845 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
3846 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
3848 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
3854 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
3855 burst_enable
= ar
->wmi
.pdev_param
->burst_enable
;
3856 ret
= ath10k_wmi_pdev_set_param(ar
, burst_enable
, 0);
3858 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
3863 if (ar
->cfg_tx_chainmask
)
3864 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
3865 ar
->cfg_rx_chainmask
);
3868 * By default FW set ARP frames ac to voice (6). In that case ARP
3869 * exchange is not working properly for UAPSD enabled AP. ARP requests
3870 * which arrives with access category 0 are processed by network stack
3871 * and send back with access category 0, but FW changes access category
3872 * to 6. Set ARP frames access category to best effort (0) solves
3876 ret
= ath10k_wmi_pdev_set_param(ar
,
3877 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
3879 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
3884 ret
= ath10k_wmi_pdev_set_param(ar
,
3885 ar
->wmi
.pdev_param
->ani_enable
, 1);
3887 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
3892 ar
->ani_enabled
= true;
3894 ar
->num_started_vdevs
= 0;
3895 ath10k_regd_update(ar
);
3897 ath10k_spectral_start(ar
);
3898 ath10k_thermal_set_throttling(ar
);
3900 mutex_unlock(&ar
->conf_mutex
);
3904 ath10k_core_stop(ar
);
3907 ath10k_hif_power_down(ar
);
3910 ar
->state
= ATH10K_STATE_OFF
;
3913 mutex_unlock(&ar
->conf_mutex
);
3917 static void ath10k_stop(struct ieee80211_hw
*hw
)
3919 struct ath10k
*ar
= hw
->priv
;
3921 ath10k_drain_tx(ar
);
3923 mutex_lock(&ar
->conf_mutex
);
3924 if (ar
->state
!= ATH10K_STATE_OFF
) {
3926 ar
->state
= ATH10K_STATE_OFF
;
3928 mutex_unlock(&ar
->conf_mutex
);
3930 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3931 cancel_work_sync(&ar
->restart_work
);
3934 static int ath10k_config_ps(struct ath10k
*ar
)
3936 struct ath10k_vif
*arvif
;
3939 lockdep_assert_held(&ar
->conf_mutex
);
3941 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3942 ret
= ath10k_mac_vif_setup_ps(arvif
);
3944 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
3952 static void ath10k_mac_chan_reconfigure(struct ath10k
*ar
)
3954 struct ath10k_vif
*arvif
;
3955 struct cfg80211_chan_def def
;
3958 lockdep_assert_held(&ar
->conf_mutex
);
3960 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac chan reconfigure\n");
3962 /* First stop monitor interface. Some FW versions crash if there's a
3963 * lone monitor interface. */
3964 if (ar
->monitor_started
)
3965 ath10k_monitor_stop(ar
);
3967 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3968 if (!arvif
->is_started
)
3974 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3977 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
3979 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
3980 arvif
->vdev_id
, ret
);
3985 /* all vdevs are downed now - attempt to restart and re-up them */
3987 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3988 if (!arvif
->is_started
)
3991 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
3994 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
3996 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
3999 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
4001 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
4004 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
4007 ret
= ath10k_vdev_restart(arvif
, &def
);
4009 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
4010 arvif
->vdev_id
, ret
);
4017 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
4020 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
4021 arvif
->vdev_id
, ret
);
4026 ath10k_monitor_recalc(ar
);
4029 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
4034 lockdep_assert_held(&ar
->conf_mutex
);
4036 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
4038 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
4039 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
4041 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
4046 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
4047 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
4049 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
4057 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
4059 struct ath10k_vif
*arvif
;
4060 int ret
, txpower
= -1;
4062 lockdep_assert_held(&ar
->conf_mutex
);
4064 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
4065 WARN_ON(arvif
->txpower
< 0);
4068 txpower
= arvif
->txpower
;
4070 txpower
= min(txpower
, arvif
->txpower
);
4073 if (WARN_ON(txpower
== -1))
4076 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
4078 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
4086 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
4088 struct ath10k
*ar
= hw
->priv
;
4089 struct ieee80211_conf
*conf
= &hw
->conf
;
4092 mutex_lock(&ar
->conf_mutex
);
4094 if (changed
& IEEE80211_CONF_CHANGE_PS
)
4095 ath10k_config_ps(ar
);
4097 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
4098 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
4099 ret
= ath10k_monitor_recalc(ar
);
4101 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4104 mutex_unlock(&ar
->conf_mutex
);
4108 static u32
get_nss_from_chainmask(u16 chain_mask
)
4110 if ((chain_mask
& 0x15) == 0x15)
4112 else if ((chain_mask
& 0x7) == 0x7)
4114 else if ((chain_mask
& 0x3) == 0x3)
4121 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4122 * because we will send mgmt frames without CCK. This requirement
4123 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4126 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
4127 struct ieee80211_vif
*vif
)
4129 struct ath10k
*ar
= hw
->priv
;
4130 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4131 enum wmi_sta_powersave_param param
;
4138 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
4140 mutex_lock(&ar
->conf_mutex
);
4142 memset(arvif
, 0, sizeof(*arvif
));
4147 INIT_LIST_HEAD(&arvif
->list
);
4148 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
4149 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
4150 ath10k_mac_vif_sta_connection_loss_work
);
4152 for (i
= 0; i
< ARRAY_SIZE(arvif
->bitrate_mask
.control
); i
++) {
4153 arvif
->bitrate_mask
.control
[i
].legacy
= 0xffffffff;
4154 memset(arvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
4155 sizeof(arvif
->bitrate_mask
.control
[i
].ht_mcs
));
4156 memset(arvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
4157 sizeof(arvif
->bitrate_mask
.control
[i
].vht_mcs
));
4160 if (ar
->free_vdev_map
== 0) {
4161 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
4165 bit
= __ffs64(ar
->free_vdev_map
);
4167 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
4168 bit
, ar
->free_vdev_map
);
4170 arvif
->vdev_id
= bit
;
4171 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
4173 switch (vif
->type
) {
4174 case NL80211_IFTYPE_P2P_DEVICE
:
4175 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4176 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
4178 case NL80211_IFTYPE_UNSPECIFIED
:
4179 case NL80211_IFTYPE_STATION
:
4180 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4182 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
4184 case NL80211_IFTYPE_ADHOC
:
4185 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
4187 case NL80211_IFTYPE_AP
:
4188 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
4191 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
4193 case NL80211_IFTYPE_MONITOR
:
4194 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
4201 /* Using vdev_id as queue number will make it very easy to do per-vif
4202 * tx queue locking. This shouldn't wrap due to interface combinations
4203 * but do a modulo for correctness sake and prevent using offchannel tx
4204 * queues for regular vif tx.
4206 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4207 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
4208 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4210 /* Some firmware revisions don't wait for beacon tx completion before
4211 * sending another SWBA event. This could lead to hardware using old
4212 * (freed) beacon data in some cases, e.g. tx credit starvation
4213 * combined with missed TBTT. This is very very rare.
4215 * On non-IOMMU-enabled hosts this could be a possible security issue
4216 * because hw could beacon some random data on the air. On
4217 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4218 * device would crash.
4220 * Since there are no beacon tx completions (implicit nor explicit)
4221 * propagated to host the only workaround for this is to allocate a
4222 * DMA-coherent buffer for a lifetime of a vif and use it for all
4223 * beacon tx commands. Worst case for this approach is some beacons may
4224 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4226 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
4227 vif
->type
== NL80211_IFTYPE_AP
) {
4228 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
4229 IEEE80211_MAX_FRAME_LEN
,
4230 &arvif
->beacon_paddr
,
4232 if (!arvif
->beacon_buf
) {
4234 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
4240 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4241 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
4242 arvif
->beacon_buf
? "single-buf" : "per-skb");
4244 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
4245 arvif
->vdev_subtype
, vif
->addr
);
4247 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
4248 arvif
->vdev_id
, ret
);
4252 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
4253 list_add(&arvif
->list
, &ar
->arvifs
);
4255 /* It makes no sense to have firmware do keepalives. mac80211 already
4256 * takes care of this with idle connection polling.
4258 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
4260 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
4261 arvif
->vdev_id
, ret
);
4262 goto err_vdev_delete
;
4265 arvif
->def_wep_key_idx
= -1;
4267 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
4268 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4269 ATH10K_HW_TXRX_NATIVE_WIFI
);
4270 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4271 if (ret
&& ret
!= -EOPNOTSUPP
) {
4272 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
4273 arvif
->vdev_id
, ret
);
4274 goto err_vdev_delete
;
4277 if (ar
->cfg_tx_chainmask
) {
4278 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4280 vdev_param
= ar
->wmi
.vdev_param
->nss
;
4281 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4284 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4285 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
4287 goto err_vdev_delete
;
4291 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4292 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4293 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
,
4294 WMI_PEER_TYPE_DEFAULT
);
4296 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
4297 arvif
->vdev_id
, ret
);
4298 goto err_vdev_delete
;
4302 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
4303 ret
= ath10k_mac_set_kickout(arvif
);
4305 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
4306 arvif
->vdev_id
, ret
);
4307 goto err_peer_delete
;
4311 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
4312 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
4313 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4314 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4317 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
4318 arvif
->vdev_id
, ret
);
4319 goto err_peer_delete
;
4322 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4324 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4325 arvif
->vdev_id
, ret
);
4326 goto err_peer_delete
;
4329 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4331 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4332 arvif
->vdev_id
, ret
);
4333 goto err_peer_delete
;
4337 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
4339 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
4340 arvif
->vdev_id
, ret
);
4341 goto err_peer_delete
;
4344 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
4346 ath10k_warn(ar
, "failed to set frag threshold for vdev %d: %d\n",
4347 arvif
->vdev_id
, ret
);
4348 goto err_peer_delete
;
4351 arvif
->txpower
= vif
->bss_conf
.txpower
;
4352 ret
= ath10k_mac_txpower_recalc(ar
);
4354 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4355 goto err_peer_delete
;
4358 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4359 ar
->monitor_arvif
= arvif
;
4360 ret
= ath10k_monitor_recalc(ar
);
4362 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4363 goto err_peer_delete
;
4367 mutex_unlock(&ar
->conf_mutex
);
4371 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4372 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
)
4373 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
4376 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4377 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4378 list_del(&arvif
->list
);
4381 if (arvif
->beacon_buf
) {
4382 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
4383 arvif
->beacon_buf
, arvif
->beacon_paddr
);
4384 arvif
->beacon_buf
= NULL
;
4387 mutex_unlock(&ar
->conf_mutex
);
4392 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
4396 for (i
= 0; i
< BITS_PER_LONG
; i
++)
4397 ath10k_mac_vif_tx_unlock(arvif
, i
);
4400 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
4401 struct ieee80211_vif
*vif
)
4403 struct ath10k
*ar
= hw
->priv
;
4404 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4407 cancel_work_sync(&arvif
->ap_csa_work
);
4408 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
4410 mutex_lock(&ar
->conf_mutex
);
4412 spin_lock_bh(&ar
->data_lock
);
4413 ath10k_mac_vif_beacon_cleanup(arvif
);
4414 spin_unlock_bh(&ar
->data_lock
);
4416 ret
= ath10k_spectral_vif_stop(arvif
);
4418 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
4419 arvif
->vdev_id
, ret
);
4421 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4422 list_del(&arvif
->list
);
4424 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4425 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4426 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
4429 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4430 arvif
->vdev_id
, ret
);
4432 kfree(arvif
->u
.ap
.noa_data
);
4435 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
4438 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4440 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
4441 arvif
->vdev_id
, ret
);
4443 /* Some firmware revisions don't notify host about self-peer removal
4444 * until after associated vdev is deleted.
4446 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4447 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4448 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
4451 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
4452 arvif
->vdev_id
, ret
);
4454 spin_lock_bh(&ar
->data_lock
);
4456 spin_unlock_bh(&ar
->data_lock
);
4459 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
4461 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4462 ar
->monitor_arvif
= NULL
;
4463 ret
= ath10k_monitor_recalc(ar
);
4465 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4468 spin_lock_bh(&ar
->htt
.tx_lock
);
4469 ath10k_mac_vif_tx_unlock_all(arvif
);
4470 spin_unlock_bh(&ar
->htt
.tx_lock
);
4472 mutex_unlock(&ar
->conf_mutex
);
4476 * FIXME: Has to be verified.
4478 #define SUPPORTED_FILTERS \
4483 FIF_BCN_PRBRESP_PROMISC | \
4487 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
4488 unsigned int changed_flags
,
4489 unsigned int *total_flags
,
4492 struct ath10k
*ar
= hw
->priv
;
4495 mutex_lock(&ar
->conf_mutex
);
4497 changed_flags
&= SUPPORTED_FILTERS
;
4498 *total_flags
&= SUPPORTED_FILTERS
;
4499 ar
->filter_flags
= *total_flags
;
4501 ret
= ath10k_monitor_recalc(ar
);
4503 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
4505 mutex_unlock(&ar
->conf_mutex
);
4508 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
4509 struct ieee80211_vif
*vif
,
4510 struct ieee80211_bss_conf
*info
,
4513 struct ath10k
*ar
= hw
->priv
;
4514 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4516 u32 vdev_param
, pdev_param
, slottime
, preamble
;
4518 mutex_lock(&ar
->conf_mutex
);
4520 if (changed
& BSS_CHANGED_IBSS
)
4521 ath10k_control_ibss(arvif
, info
, vif
->addr
);
4523 if (changed
& BSS_CHANGED_BEACON_INT
) {
4524 arvif
->beacon_interval
= info
->beacon_int
;
4525 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
4526 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4527 arvif
->beacon_interval
);
4528 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4529 "mac vdev %d beacon_interval %d\n",
4530 arvif
->vdev_id
, arvif
->beacon_interval
);
4533 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
4534 arvif
->vdev_id
, ret
);
4537 if (changed
& BSS_CHANGED_BEACON
) {
4538 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4539 "vdev %d set beacon tx mode to staggered\n",
4542 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
4543 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
4544 WMI_BEACON_STAGGERED_MODE
);
4546 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
4547 arvif
->vdev_id
, ret
);
4549 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
4551 ath10k_warn(ar
, "failed to update beacon template: %d\n",
4555 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
4556 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
4558 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
4559 arvif
->vdev_id
, ret
);
4562 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
4563 arvif
->dtim_period
= info
->dtim_period
;
4565 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4566 "mac vdev %d dtim_period %d\n",
4567 arvif
->vdev_id
, arvif
->dtim_period
);
4569 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
4570 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4571 arvif
->dtim_period
);
4573 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
4574 arvif
->vdev_id
, ret
);
4577 if (changed
& BSS_CHANGED_SSID
&&
4578 vif
->type
== NL80211_IFTYPE_AP
) {
4579 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
4581 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
4582 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
4585 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
4586 ether_addr_copy(arvif
->bssid
, info
->bssid
);
4588 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4589 ath10k_control_beaconing(arvif
, info
);
4591 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
4592 arvif
->use_cts_prot
= info
->use_cts_prot
;
4593 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
4594 arvif
->vdev_id
, info
->use_cts_prot
);
4596 ret
= ath10k_recalc_rtscts_prot(arvif
);
4598 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4599 arvif
->vdev_id
, ret
);
4601 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
4602 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4603 info
->use_cts_prot
? 1 : 0);
4605 ath10k_warn(ar
, "failed to set protection mode %d on vdev %i: %d\n",
4606 info
->use_cts_prot
, arvif
->vdev_id
, ret
);
4609 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4610 if (info
->use_short_slot
)
4611 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
4614 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
4616 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
4617 arvif
->vdev_id
, slottime
);
4619 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
4620 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4623 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
4624 arvif
->vdev_id
, ret
);
4627 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4628 if (info
->use_short_preamble
)
4629 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
4631 preamble
= WMI_VDEV_PREAMBLE_LONG
;
4633 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4634 "mac vdev %d preamble %dn",
4635 arvif
->vdev_id
, preamble
);
4637 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
4638 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4641 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
4642 arvif
->vdev_id
, ret
);
4645 if (changed
& BSS_CHANGED_ASSOC
) {
4647 /* Workaround: Make sure monitor vdev is not running
4648 * when associating to prevent some firmware revisions
4649 * (e.g. 10.1 and 10.2) from crashing.
4651 if (ar
->monitor_started
)
4652 ath10k_monitor_stop(ar
);
4653 ath10k_bss_assoc(hw
, vif
, info
);
4654 ath10k_monitor_recalc(ar
);
4656 ath10k_bss_disassoc(hw
, vif
);
4660 if (changed
& BSS_CHANGED_TXPOWER
) {
4661 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
4662 arvif
->vdev_id
, info
->txpower
);
4664 arvif
->txpower
= info
->txpower
;
4665 ret
= ath10k_mac_txpower_recalc(ar
);
4667 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4670 if (changed
& BSS_CHANGED_PS
) {
4671 arvif
->ps
= vif
->bss_conf
.ps
;
4673 ret
= ath10k_config_ps(ar
);
4675 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
4676 arvif
->vdev_id
, ret
);
4679 mutex_unlock(&ar
->conf_mutex
);
4682 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
4683 struct ieee80211_vif
*vif
,
4684 struct ieee80211_scan_request
*hw_req
)
4686 struct ath10k
*ar
= hw
->priv
;
4687 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4688 struct cfg80211_scan_request
*req
= &hw_req
->req
;
4689 struct wmi_start_scan_arg arg
;
4693 mutex_lock(&ar
->conf_mutex
);
4695 spin_lock_bh(&ar
->data_lock
);
4696 switch (ar
->scan
.state
) {
4697 case ATH10K_SCAN_IDLE
:
4698 reinit_completion(&ar
->scan
.started
);
4699 reinit_completion(&ar
->scan
.completed
);
4700 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4701 ar
->scan
.is_roc
= false;
4702 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4705 case ATH10K_SCAN_STARTING
:
4706 case ATH10K_SCAN_RUNNING
:
4707 case ATH10K_SCAN_ABORTING
:
4711 spin_unlock_bh(&ar
->data_lock
);
4716 memset(&arg
, 0, sizeof(arg
));
4717 ath10k_wmi_start_scan_init(ar
, &arg
);
4718 arg
.vdev_id
= arvif
->vdev_id
;
4719 arg
.scan_id
= ATH10K_SCAN_ID
;
4722 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
4725 arg
.ie_len
= req
->ie_len
;
4726 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
4730 arg
.n_ssids
= req
->n_ssids
;
4731 for (i
= 0; i
< arg
.n_ssids
; i
++) {
4732 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
4733 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
4736 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4739 if (req
->n_channels
) {
4740 arg
.n_channels
= req
->n_channels
;
4741 for (i
= 0; i
< arg
.n_channels
; i
++)
4742 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
4745 ret
= ath10k_start_scan(ar
, &arg
);
4747 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
4748 spin_lock_bh(&ar
->data_lock
);
4749 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4750 spin_unlock_bh(&ar
->data_lock
);
4754 mutex_unlock(&ar
->conf_mutex
);
4758 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
4759 struct ieee80211_vif
*vif
)
4761 struct ath10k
*ar
= hw
->priv
;
4763 mutex_lock(&ar
->conf_mutex
);
4764 ath10k_scan_abort(ar
);
4765 mutex_unlock(&ar
->conf_mutex
);
4767 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4770 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
4771 struct ath10k_vif
*arvif
,
4772 enum set_key_cmd cmd
,
4773 struct ieee80211_key_conf
*key
)
4775 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
4778 /* 10.1 firmware branch requires default key index to be set to group
4779 * key index after installing it. Otherwise FW/HW Txes corrupted
4780 * frames with multi-vif APs. This is not required for main firmware
4781 * branch (e.g. 636).
4783 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4785 * FIXME: It remains unknown if this is required for multi-vif STA
4786 * interfaces on 10.1.
4789 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
4790 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
4793 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
4796 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
4799 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4805 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4808 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
4809 arvif
->vdev_id
, ret
);
4812 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
4813 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
4814 struct ieee80211_key_conf
*key
)
4816 struct ath10k
*ar
= hw
->priv
;
4817 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4818 struct ath10k_peer
*peer
;
4819 const u8
*peer_addr
;
4820 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
4821 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
4827 /* this one needs to be done in software */
4828 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
4831 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
4834 mutex_lock(&ar
->conf_mutex
);
4837 peer_addr
= sta
->addr
;
4838 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
4839 peer_addr
= vif
->bss_conf
.bssid
;
4841 peer_addr
= vif
->addr
;
4843 key
->hw_key_idx
= key
->keyidx
;
4847 arvif
->wep_keys
[key
->keyidx
] = key
;
4849 arvif
->wep_keys
[key
->keyidx
] = NULL
;
4852 /* the peer should not disappear in mid-way (unless FW goes awry) since
4853 * we already hold conf_mutex. we just make sure its there now. */
4854 spin_lock_bh(&ar
->data_lock
);
4855 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4856 spin_unlock_bh(&ar
->data_lock
);
4859 if (cmd
== SET_KEY
) {
4860 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
4865 /* if the peer doesn't exist there is no key to disable
4871 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
4872 flags
|= WMI_KEY_PAIRWISE
;
4874 flags
|= WMI_KEY_GROUP
;
4877 if (cmd
== DISABLE_KEY
)
4878 ath10k_clear_vdev_key(arvif
, key
);
4880 /* When WEP keys are uploaded it's possible that there are
4881 * stations associated already (e.g. when merging) without any
4882 * keys. Static WEP needs an explicit per-peer key upload.
4884 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
4886 ath10k_mac_vif_update_wep_key(arvif
, key
);
4888 /* 802.1x never sets the def_wep_key_idx so each set_key()
4889 * call changes default tx key.
4891 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4892 * after first set_key().
4894 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
4895 flags
|= WMI_KEY_TX_USAGE
;
4898 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
4900 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
4901 arvif
->vdev_id
, peer_addr
, ret
);
4905 /* mac80211 sets static WEP keys as groupwise while firmware requires
4906 * them to be installed twice as both pairwise and groupwise.
4908 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
4910 flags2
&= ~WMI_KEY_GROUP
;
4911 flags2
|= WMI_KEY_PAIRWISE
;
4913 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
4915 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4916 arvif
->vdev_id
, peer_addr
, ret
);
4917 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
4920 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4921 arvif
->vdev_id
, peer_addr
, ret2
);
4926 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
4928 spin_lock_bh(&ar
->data_lock
);
4929 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
4930 if (peer
&& cmd
== SET_KEY
)
4931 peer
->keys
[key
->keyidx
] = key
;
4932 else if (peer
&& cmd
== DISABLE_KEY
)
4933 peer
->keys
[key
->keyidx
] = NULL
;
4934 else if (peer
== NULL
)
4935 /* impossible unless FW goes crazy */
4936 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
4937 spin_unlock_bh(&ar
->data_lock
);
4940 mutex_unlock(&ar
->conf_mutex
);
4944 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
4945 struct ieee80211_vif
*vif
,
4948 struct ath10k
*ar
= hw
->priv
;
4949 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4952 mutex_lock(&arvif
->ar
->conf_mutex
);
4954 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
4957 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
4958 arvif
->vdev_id
, keyidx
);
4960 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
4962 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
4966 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
4972 arvif
->def_wep_key_idx
= keyidx
;
4975 mutex_unlock(&arvif
->ar
->conf_mutex
);
4978 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
4981 struct ath10k_vif
*arvif
;
4982 struct ath10k_sta
*arsta
;
4983 struct ieee80211_sta
*sta
;
4984 struct cfg80211_chan_def def
;
4985 enum ieee80211_band band
;
4986 const u8
*ht_mcs_mask
;
4987 const u16
*vht_mcs_mask
;
4988 u32 changed
, bw
, nss
, smps
;
4991 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
4992 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
4993 arvif
= arsta
->arvif
;
4996 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
4999 band
= def
.chan
->band
;
5000 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
5001 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
5003 spin_lock_bh(&ar
->data_lock
);
5005 changed
= arsta
->changed
;
5012 spin_unlock_bh(&ar
->data_lock
);
5014 mutex_lock(&ar
->conf_mutex
);
5016 nss
= max_t(u32
, 1, nss
);
5017 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
5018 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
5020 if (changed
& IEEE80211_RC_BW_CHANGED
) {
5021 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
5024 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5025 WMI_PEER_CHAN_WIDTH
, bw
);
5027 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
5028 sta
->addr
, bw
, err
);
5031 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
5032 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
5035 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5038 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
5039 sta
->addr
, nss
, err
);
5042 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5043 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
5046 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5047 WMI_PEER_SMPS_STATE
, smps
);
5049 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
5050 sta
->addr
, smps
, err
);
5053 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
||
5054 changed
& IEEE80211_RC_NSS_CHANGED
) {
5055 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates/nss\n",
5058 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
5060 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
5064 mutex_unlock(&ar
->conf_mutex
);
5067 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
5068 struct ieee80211_sta
*sta
)
5070 struct ath10k
*ar
= arvif
->ar
;
5072 lockdep_assert_held(&ar
->conf_mutex
);
5074 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
5077 if (ar
->num_stations
>= ar
->max_num_stations
)
5085 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
5086 struct ieee80211_sta
*sta
)
5088 struct ath10k
*ar
= arvif
->ar
;
5090 lockdep_assert_held(&ar
->conf_mutex
);
5092 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
5098 struct ath10k_mac_tdls_iter_data
{
5099 u32 num_tdls_stations
;
5100 struct ieee80211_vif
*curr_vif
;
5103 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
5104 struct ieee80211_sta
*sta
)
5106 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
5107 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5108 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
5110 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
5111 iter_data
->num_tdls_stations
++;
5114 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
5115 struct ieee80211_vif
*vif
)
5117 struct ath10k_mac_tdls_iter_data data
= {};
5119 data
.curr_vif
= vif
;
5121 ieee80211_iterate_stations_atomic(hw
,
5122 ath10k_mac_tdls_vif_stations_count_iter
,
5124 return data
.num_tdls_stations
;
5127 static void ath10k_mac_tdls_vifs_count_iter(void *data
, u8
*mac
,
5128 struct ieee80211_vif
*vif
)
5130 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5131 int *num_tdls_vifs
= data
;
5133 if (vif
->type
!= NL80211_IFTYPE_STATION
)
5136 if (ath10k_mac_tdls_vif_stations_count(arvif
->ar
->hw
, vif
) > 0)
5140 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw
*hw
)
5142 int num_tdls_vifs
= 0;
5144 ieee80211_iterate_active_interfaces_atomic(hw
,
5145 IEEE80211_IFACE_ITER_NORMAL
,
5146 ath10k_mac_tdls_vifs_count_iter
,
5148 return num_tdls_vifs
;
5151 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
5152 struct ieee80211_vif
*vif
,
5153 struct ieee80211_sta
*sta
,
5154 enum ieee80211_sta_state old_state
,
5155 enum ieee80211_sta_state new_state
)
5157 struct ath10k
*ar
= hw
->priv
;
5158 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5159 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5162 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5163 new_state
== IEEE80211_STA_NONE
) {
5164 memset(arsta
, 0, sizeof(*arsta
));
5165 arsta
->arvif
= arvif
;
5166 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
5169 /* cancel must be done outside the mutex to avoid deadlock */
5170 if ((old_state
== IEEE80211_STA_NONE
&&
5171 new_state
== IEEE80211_STA_NOTEXIST
))
5172 cancel_work_sync(&arsta
->update_wk
);
5174 mutex_lock(&ar
->conf_mutex
);
5176 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5177 new_state
== IEEE80211_STA_NONE
) {
5179 * New station addition.
5181 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
5182 u32 num_tdls_stations
;
5185 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5186 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5187 arvif
->vdev_id
, sta
->addr
,
5188 ar
->num_stations
+ 1, ar
->max_num_stations
,
5189 ar
->num_peers
+ 1, ar
->max_num_peers
);
5191 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
5193 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
5194 ar
->max_num_stations
);
5199 peer_type
= WMI_PEER_TYPE_TDLS
;
5201 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
,
5204 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5205 sta
->addr
, arvif
->vdev_id
, ret
);
5206 ath10k_mac_dec_num_stations(arvif
, sta
);
5213 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
5214 num_tdls_vifs
= ath10k_mac_tdls_vifs_count(hw
);
5216 if (num_tdls_vifs
>= ar
->max_num_tdls_vdevs
&&
5217 num_tdls_stations
== 0) {
5218 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5219 arvif
->vdev_id
, ar
->max_num_tdls_vdevs
);
5220 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5221 ath10k_mac_dec_num_stations(arvif
, sta
);
5226 if (num_tdls_stations
== 0) {
5227 /* This is the first tdls peer in current vif */
5228 enum wmi_tdls_state state
= WMI_TDLS_ENABLE_ACTIVE
;
5230 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5233 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5234 arvif
->vdev_id
, ret
);
5235 ath10k_peer_delete(ar
, arvif
->vdev_id
,
5237 ath10k_mac_dec_num_stations(arvif
, sta
);
5242 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5243 WMI_TDLS_PEER_STATE_PEERING
);
5246 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5247 sta
->addr
, arvif
->vdev_id
, ret
);
5248 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5249 ath10k_mac_dec_num_stations(arvif
, sta
);
5251 if (num_tdls_stations
!= 0)
5253 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5256 } else if ((old_state
== IEEE80211_STA_NONE
&&
5257 new_state
== IEEE80211_STA_NOTEXIST
)) {
5259 * Existing station deletion.
5261 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5262 "mac vdev %d peer delete %pM (sta gone)\n",
5263 arvif
->vdev_id
, sta
->addr
);
5265 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5267 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
5268 sta
->addr
, arvif
->vdev_id
, ret
);
5270 ath10k_mac_dec_num_stations(arvif
, sta
);
5275 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
5278 /* This was the last tdls peer in current vif */
5279 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5282 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5283 arvif
->vdev_id
, ret
);
5285 } else if (old_state
== IEEE80211_STA_AUTH
&&
5286 new_state
== IEEE80211_STA_ASSOC
&&
5287 (vif
->type
== NL80211_IFTYPE_AP
||
5288 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5292 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
5295 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5297 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
5298 sta
->addr
, arvif
->vdev_id
, ret
);
5299 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5300 new_state
== IEEE80211_STA_AUTHORIZED
&&
5303 * Tdls station authorized.
5305 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
5308 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5310 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
5311 sta
->addr
, arvif
->vdev_id
, ret
);
5315 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5316 WMI_TDLS_PEER_STATE_CONNECTED
);
5318 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
5319 sta
->addr
, arvif
->vdev_id
, ret
);
5320 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5321 new_state
== IEEE80211_STA_AUTH
&&
5322 (vif
->type
== NL80211_IFTYPE_AP
||
5323 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5327 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
5330 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
5332 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
5333 sta
->addr
, arvif
->vdev_id
, ret
);
5336 mutex_unlock(&ar
->conf_mutex
);
5340 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
5341 u16 ac
, bool enable
)
5343 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5344 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
5345 u32 prio
= 0, acc
= 0;
5349 lockdep_assert_held(&ar
->conf_mutex
);
5351 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
5355 case IEEE80211_AC_VO
:
5356 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
5357 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
5361 case IEEE80211_AC_VI
:
5362 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
5363 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
5367 case IEEE80211_AC_BE
:
5368 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
5369 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
5373 case IEEE80211_AC_BK
:
5374 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
5375 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
5382 arvif
->u
.sta
.uapsd
|= value
;
5384 arvif
->u
.sta
.uapsd
&= ~value
;
5386 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5387 WMI_STA_PS_PARAM_UAPSD
,
5388 arvif
->u
.sta
.uapsd
);
5390 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
5394 if (arvif
->u
.sta
.uapsd
)
5395 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
5397 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5399 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5400 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
5403 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
5405 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5407 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5408 arvif
->vdev_id
, ret
);
5412 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5414 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5415 arvif
->vdev_id
, ret
);
5419 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
5420 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
5421 /* Only userspace can make an educated decision when to send
5422 * trigger frame. The following effectively disables u-UAPSD
5423 * autotrigger in firmware (which is enabled by default
5424 * provided the autotrigger service is available).
5428 arg
.user_priority
= prio
;
5429 arg
.service_interval
= 0;
5430 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5431 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5433 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
5434 arvif
->bssid
, &arg
, 1);
5436 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
5446 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
5447 struct ieee80211_vif
*vif
, u16 ac
,
5448 const struct ieee80211_tx_queue_params
*params
)
5450 struct ath10k
*ar
= hw
->priv
;
5451 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5452 struct wmi_wmm_params_arg
*p
= NULL
;
5455 mutex_lock(&ar
->conf_mutex
);
5458 case IEEE80211_AC_VO
:
5459 p
= &arvif
->wmm_params
.ac_vo
;
5461 case IEEE80211_AC_VI
:
5462 p
= &arvif
->wmm_params
.ac_vi
;
5464 case IEEE80211_AC_BE
:
5465 p
= &arvif
->wmm_params
.ac_be
;
5467 case IEEE80211_AC_BK
:
5468 p
= &arvif
->wmm_params
.ac_bk
;
5477 p
->cwmin
= params
->cw_min
;
5478 p
->cwmax
= params
->cw_max
;
5479 p
->aifs
= params
->aifs
;
5482 * The channel time duration programmed in the HW is in absolute
5483 * microseconds, while mac80211 gives the txop in units of
5486 p
->txop
= params
->txop
* 32;
5488 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
5489 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
5490 &arvif
->wmm_params
);
5492 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
5493 arvif
->vdev_id
, ret
);
5497 /* This won't work well with multi-interface cases but it's
5498 * better than nothing.
5500 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
5502 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
5507 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
5509 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
5512 mutex_unlock(&ar
->conf_mutex
);
5516 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5518 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
5519 struct ieee80211_vif
*vif
,
5520 struct ieee80211_channel
*chan
,
5522 enum ieee80211_roc_type type
)
5524 struct ath10k
*ar
= hw
->priv
;
5525 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5526 struct wmi_start_scan_arg arg
;
5530 mutex_lock(&ar
->conf_mutex
);
5532 spin_lock_bh(&ar
->data_lock
);
5533 switch (ar
->scan
.state
) {
5534 case ATH10K_SCAN_IDLE
:
5535 reinit_completion(&ar
->scan
.started
);
5536 reinit_completion(&ar
->scan
.completed
);
5537 reinit_completion(&ar
->scan
.on_channel
);
5538 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
5539 ar
->scan
.is_roc
= true;
5540 ar
->scan
.vdev_id
= arvif
->vdev_id
;
5541 ar
->scan
.roc_freq
= chan
->center_freq
;
5544 case ATH10K_SCAN_STARTING
:
5545 case ATH10K_SCAN_RUNNING
:
5546 case ATH10K_SCAN_ABORTING
:
5550 spin_unlock_bh(&ar
->data_lock
);
5555 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
5557 memset(&arg
, 0, sizeof(arg
));
5558 ath10k_wmi_start_scan_init(ar
, &arg
);
5559 arg
.vdev_id
= arvif
->vdev_id
;
5560 arg
.scan_id
= ATH10K_SCAN_ID
;
5562 arg
.channels
[0] = chan
->center_freq
;
5563 arg
.dwell_time_active
= scan_time_msec
;
5564 arg
.dwell_time_passive
= scan_time_msec
;
5565 arg
.max_scan_time
= scan_time_msec
;
5566 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
5567 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
5568 arg
.burst_duration_ms
= duration
;
5570 ret
= ath10k_start_scan(ar
, &arg
);
5572 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
5573 spin_lock_bh(&ar
->data_lock
);
5574 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
5575 spin_unlock_bh(&ar
->data_lock
);
5579 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
5581 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
5583 ret
= ath10k_scan_stop(ar
);
5585 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
5591 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
5592 msecs_to_jiffies(duration
));
5596 mutex_unlock(&ar
->conf_mutex
);
5600 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
5602 struct ath10k
*ar
= hw
->priv
;
5604 mutex_lock(&ar
->conf_mutex
);
5605 ath10k_scan_abort(ar
);
5606 mutex_unlock(&ar
->conf_mutex
);
5608 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5614 * Both RTS and Fragmentation threshold are interface-specific
5615 * in ath10k, but device-specific in mac80211.
5618 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5620 struct ath10k
*ar
= hw
->priv
;
5621 struct ath10k_vif
*arvif
;
5624 mutex_lock(&ar
->conf_mutex
);
5625 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5626 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
5627 arvif
->vdev_id
, value
);
5629 ret
= ath10k_mac_set_rts(arvif
, value
);
5631 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5632 arvif
->vdev_id
, ret
);
5636 mutex_unlock(&ar
->conf_mutex
);
5641 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5642 u32 queues
, bool drop
)
5644 struct ath10k
*ar
= hw
->priv
;
5648 /* mac80211 doesn't care if we really xmit queued frames or not
5649 * we'll collect those frames either way if we stop/delete vdevs */
5653 mutex_lock(&ar
->conf_mutex
);
5655 if (ar
->state
== ATH10K_STATE_WEDGED
)
5658 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
5661 spin_lock_bh(&ar
->htt
.tx_lock
);
5662 empty
= (ar
->htt
.num_pending_tx
== 0);
5663 spin_unlock_bh(&ar
->htt
.tx_lock
);
5665 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
5666 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
5670 }), ATH10K_FLUSH_TIMEOUT_HZ
);
5672 if (ret
<= 0 || skip
)
5673 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
5674 skip
, ar
->state
, ret
);
5677 mutex_unlock(&ar
->conf_mutex
);
5680 /* TODO: Implement this function properly
5681 * For now it is needed to reply to Probe Requests in IBSS mode.
5682 * Propably we need this information from FW.
5684 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
5689 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
5690 enum ieee80211_reconfig_type reconfig_type
)
5692 struct ath10k
*ar
= hw
->priv
;
5694 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
5697 mutex_lock(&ar
->conf_mutex
);
5699 /* If device failed to restart it will be in a different state, e.g.
5700 * ATH10K_STATE_WEDGED */
5701 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
5702 ath10k_info(ar
, "device successfully recovered\n");
5703 ar
->state
= ATH10K_STATE_ON
;
5704 ieee80211_wake_queues(ar
->hw
);
5707 mutex_unlock(&ar
->conf_mutex
);
5710 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5711 struct survey_info
*survey
)
5713 struct ath10k
*ar
= hw
->priv
;
5714 struct ieee80211_supported_band
*sband
;
5715 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
5718 mutex_lock(&ar
->conf_mutex
);
5720 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5721 if (sband
&& idx
>= sband
->n_channels
) {
5722 idx
-= sband
->n_channels
;
5727 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5729 if (!sband
|| idx
>= sband
->n_channels
) {
5734 spin_lock_bh(&ar
->data_lock
);
5735 memcpy(survey
, ar_survey
, sizeof(*survey
));
5736 spin_unlock_bh(&ar
->data_lock
);
5738 survey
->channel
= &sband
->channels
[idx
];
5740 if (ar
->rx_channel
== survey
->channel
)
5741 survey
->filled
|= SURVEY_INFO_IN_USE
;
5744 mutex_unlock(&ar
->conf_mutex
);
5749 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
5750 enum ieee80211_band band
,
5751 const struct cfg80211_bitrate_mask
*mask
)
5756 num_rates
+= hweight32(mask
->control
[band
].legacy
);
5758 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
5759 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
5761 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++)
5762 num_rates
+= hweight16(mask
->control
[band
].vht_mcs
[i
]);
5764 return num_rates
== 1;
5768 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
5769 enum ieee80211_band band
,
5770 const struct cfg80211_bitrate_mask
*mask
,
5773 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
5774 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
5776 u8 vht_nss_mask
= 0;
5779 if (mask
->control
[band
].legacy
)
5782 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
5783 if (mask
->control
[band
].ht_mcs
[i
] == 0)
5785 else if (mask
->control
[band
].ht_mcs
[i
] ==
5786 sband
->ht_cap
.mcs
.rx_mask
[i
])
5787 ht_nss_mask
|= BIT(i
);
5792 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
5793 if (mask
->control
[band
].vht_mcs
[i
] == 0)
5795 else if (mask
->control
[band
].vht_mcs
[i
] ==
5796 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
5797 vht_nss_mask
|= BIT(i
);
5802 if (ht_nss_mask
!= vht_nss_mask
)
5805 if (ht_nss_mask
== 0)
5808 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
5811 *nss
= fls(ht_nss_mask
);
5817 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
5818 enum ieee80211_band band
,
5819 const struct cfg80211_bitrate_mask
*mask
,
5822 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
5829 if (hweight32(mask
->control
[band
].legacy
) == 1) {
5830 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
5832 hw_rate
= sband
->bitrates
[rate_idx
].hw_value
;
5833 bitrate
= sband
->bitrates
[rate_idx
].bitrate
;
5835 if (ath10k_mac_bitrate_is_cck(bitrate
))
5836 preamble
= WMI_RATE_PREAMBLE_CCK
;
5838 preamble
= WMI_RATE_PREAMBLE_OFDM
;
5841 *rate
= preamble
<< 6 |
5848 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
5849 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
5851 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
5853 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
5859 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
5860 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
5862 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
5864 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
5873 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
5874 u8 rate
, u8 nss
, u8 sgi
)
5876 struct ath10k
*ar
= arvif
->ar
;
5880 lockdep_assert_held(&ar
->conf_mutex
);
5882 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5883 arvif
->vdev_id
, rate
, nss
, sgi
);
5885 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
5886 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
5888 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
5893 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5894 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
5896 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
5900 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
5901 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
5903 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
5911 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
5912 enum ieee80211_band band
,
5913 const struct cfg80211_bitrate_mask
*mask
)
5918 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5919 * to express all VHT MCS rate masks. Effectively only the following
5920 * ranges can be used: none, 0-7, 0-8 and 0-9.
5922 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
5923 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
5932 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5940 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
5941 struct ieee80211_sta
*sta
)
5943 struct ath10k_vif
*arvif
= data
;
5944 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5945 struct ath10k
*ar
= arvif
->ar
;
5947 if (arsta
->arvif
!= arvif
)
5950 spin_lock_bh(&ar
->data_lock
);
5951 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
5952 spin_unlock_bh(&ar
->data_lock
);
5954 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
5957 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
5958 struct ieee80211_vif
*vif
,
5959 const struct cfg80211_bitrate_mask
*mask
)
5961 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5962 struct cfg80211_chan_def def
;
5963 struct ath10k
*ar
= arvif
->ar
;
5964 enum ieee80211_band band
;
5965 const u8
*ht_mcs_mask
;
5966 const u16
*vht_mcs_mask
;
5973 if (ath10k_mac_vif_chan(vif
, &def
))
5976 band
= def
.chan
->band
;
5977 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
5978 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
5980 sgi
= mask
->control
[band
].gi
;
5981 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
5984 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
)) {
5985 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
5988 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
5989 arvif
->vdev_id
, ret
);
5992 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
5994 rate
= WMI_FIXED_RATE_NONE
;
5997 rate
= WMI_FIXED_RATE_NONE
;
5998 nss
= min(ar
->num_rf_chains
,
5999 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6000 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6002 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
))
6005 mutex_lock(&ar
->conf_mutex
);
6007 arvif
->bitrate_mask
= *mask
;
6008 ieee80211_iterate_stations_atomic(ar
->hw
,
6009 ath10k_mac_set_bitrate_mask_iter
,
6012 mutex_unlock(&ar
->conf_mutex
);
6015 mutex_lock(&ar
->conf_mutex
);
6017 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
);
6019 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
6020 arvif
->vdev_id
, ret
);
6025 mutex_unlock(&ar
->conf_mutex
);
6030 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
6031 struct ieee80211_vif
*vif
,
6032 struct ieee80211_sta
*sta
,
6035 struct ath10k
*ar
= hw
->priv
;
6036 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6039 spin_lock_bh(&ar
->data_lock
);
6041 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6042 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6043 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
6046 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6047 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6049 switch (sta
->bandwidth
) {
6050 case IEEE80211_STA_RX_BW_20
:
6051 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6053 case IEEE80211_STA_RX_BW_40
:
6054 bw
= WMI_PEER_CHWIDTH_40MHZ
;
6056 case IEEE80211_STA_RX_BW_80
:
6057 bw
= WMI_PEER_CHWIDTH_80MHZ
;
6059 case IEEE80211_STA_RX_BW_160
:
6060 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
6061 sta
->bandwidth
, sta
->addr
);
6062 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6069 if (changed
& IEEE80211_RC_NSS_CHANGED
)
6070 arsta
->nss
= sta
->rx_nss
;
6072 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6073 smps
= WMI_PEER_SMPS_PS_NONE
;
6075 switch (sta
->smps_mode
) {
6076 case IEEE80211_SMPS_AUTOMATIC
:
6077 case IEEE80211_SMPS_OFF
:
6078 smps
= WMI_PEER_SMPS_PS_NONE
;
6080 case IEEE80211_SMPS_STATIC
:
6081 smps
= WMI_PEER_SMPS_STATIC
;
6083 case IEEE80211_SMPS_DYNAMIC
:
6084 smps
= WMI_PEER_SMPS_DYNAMIC
;
6086 case IEEE80211_SMPS_NUM_MODES
:
6087 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
6088 sta
->smps_mode
, sta
->addr
);
6089 smps
= WMI_PEER_SMPS_PS_NONE
;
6096 arsta
->changed
|= changed
;
6098 spin_unlock_bh(&ar
->data_lock
);
6100 ieee80211_queue_work(hw
, &arsta
->update_wk
);
6103 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
6106 * FIXME: Return 0 for time being. Need to figure out whether FW
6107 * has the API to fetch 64-bit local TSF
6113 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
6114 struct ieee80211_vif
*vif
,
6115 enum ieee80211_ampdu_mlme_action action
,
6116 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
6119 struct ath10k
*ar
= hw
->priv
;
6120 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6122 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6123 arvif
->vdev_id
, sta
->addr
, tid
, action
);
6126 case IEEE80211_AMPDU_RX_START
:
6127 case IEEE80211_AMPDU_RX_STOP
:
6128 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6129 * creation/removal. Do we need to verify this?
6132 case IEEE80211_AMPDU_TX_START
:
6133 case IEEE80211_AMPDU_TX_STOP_CONT
:
6134 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
6135 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
6136 case IEEE80211_AMPDU_TX_OPERATIONAL
:
6137 /* Firmware offloads Tx aggregation entirely so deny mac80211
6138 * Tx aggregation requests.
6147 ath10k_mac_update_rx_channel(struct ath10k
*ar
)
6149 struct cfg80211_chan_def
*def
= NULL
;
6151 /* Both locks are required because ar->rx_channel is modified. This
6152 * allows readers to hold either lock.
6154 lockdep_assert_held(&ar
->conf_mutex
);
6155 lockdep_assert_held(&ar
->data_lock
);
6157 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6158 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6159 * ppdu on Rx may reduce performance on low-end systems. It should be
6160 * possible to make tables/hashmaps to speed the lookup up (be vary of
6161 * cpu data cache lines though regarding sizes) but to keep the initial
6162 * implementation simple and less intrusive fallback to the slow lookup
6163 * only for multi-channel cases. Single-channel cases will remain to
6164 * use the old channel derival and thus performance should not be
6168 if (ath10k_mac_num_chanctxs(ar
) == 1) {
6169 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
6170 ath10k_mac_get_any_chandef_iter
,
6172 ar
->rx_channel
= def
->chan
;
6174 ar
->rx_channel
= NULL
;
6180 ath10k_mac_chan_ctx_init(struct ath10k
*ar
,
6181 struct ath10k_chanctx
*arctx
,
6182 struct ieee80211_chanctx_conf
*conf
)
6184 lockdep_assert_held(&ar
->conf_mutex
);
6185 lockdep_assert_held(&ar
->data_lock
);
6187 memset(arctx
, 0, sizeof(*arctx
));
6189 arctx
->conf
= *conf
;
6193 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
6194 struct ieee80211_chanctx_conf
*ctx
)
6196 struct ath10k
*ar
= hw
->priv
;
6197 struct ath10k_chanctx
*arctx
= (void *)ctx
->drv_priv
;
6199 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6200 "mac chanctx add freq %hu width %d ptr %p\n",
6201 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6203 mutex_lock(&ar
->conf_mutex
);
6205 spin_lock_bh(&ar
->data_lock
);
6206 ath10k_mac_chan_ctx_init(ar
, arctx
, ctx
);
6207 ath10k_mac_update_rx_channel(ar
);
6208 spin_unlock_bh(&ar
->data_lock
);
6210 ath10k_recalc_radar_detection(ar
);
6211 ath10k_monitor_recalc(ar
);
6213 mutex_unlock(&ar
->conf_mutex
);
6219 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
6220 struct ieee80211_chanctx_conf
*ctx
)
6222 struct ath10k
*ar
= hw
->priv
;
6224 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6225 "mac chanctx remove freq %hu width %d ptr %p\n",
6226 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6228 mutex_lock(&ar
->conf_mutex
);
6230 spin_lock_bh(&ar
->data_lock
);
6231 ath10k_mac_update_rx_channel(ar
);
6232 spin_unlock_bh(&ar
->data_lock
);
6234 ath10k_recalc_radar_detection(ar
);
6235 ath10k_monitor_recalc(ar
);
6237 mutex_unlock(&ar
->conf_mutex
);
6241 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
6242 struct ieee80211_chanctx_conf
*ctx
,
6245 struct ath10k
*ar
= hw
->priv
;
6246 struct ath10k_chanctx
*arctx
= (void *)ctx
->drv_priv
;
6248 mutex_lock(&ar
->conf_mutex
);
6250 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6251 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6252 arctx
->conf
.def
.chan
->center_freq
,
6253 ctx
->def
.chan
->center_freq
,
6254 arctx
->conf
.def
.width
, ctx
->def
.width
,
6257 /* This shouldn't really happen because channel switching should use
6258 * switch_vif_chanctx().
6260 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
6263 spin_lock_bh(&ar
->data_lock
);
6265 spin_unlock_bh(&ar
->data_lock
);
6267 ath10k_recalc_radar_detection(ar
);
6269 /* FIXME: How to configure Rx chains properly? */
6271 /* No other actions are actually necessary. Firmware maintains channel
6272 * definitions per vdev internally and there's no host-side channel
6273 * context abstraction to configure, e.g. channel width.
6277 mutex_unlock(&ar
->conf_mutex
);
6281 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
6282 struct ieee80211_vif
*vif
,
6283 struct ieee80211_chanctx_conf
*ctx
)
6285 struct ath10k
*ar
= hw
->priv
;
6286 struct ath10k_chanctx
*arctx
= (void *)ctx
->drv_priv
;
6287 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6290 mutex_lock(&ar
->conf_mutex
);
6292 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6293 "mac chanctx assign ptr %p vdev_id %i\n",
6294 ctx
, arvif
->vdev_id
);
6296 if (WARN_ON(arvif
->is_started
)) {
6297 mutex_unlock(&ar
->conf_mutex
);
6301 ret
= ath10k_vdev_start(arvif
, &arctx
->conf
.def
);
6303 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
6304 arvif
->vdev_id
, vif
->addr
,
6305 arctx
->conf
.def
.chan
->center_freq
, ret
);
6309 arvif
->is_started
= true;
6311 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6312 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
6314 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
6315 arvif
->vdev_id
, ret
);
6319 arvif
->is_up
= true;
6322 mutex_unlock(&ar
->conf_mutex
);
6326 ath10k_vdev_stop(arvif
);
6327 arvif
->is_started
= false;
6330 mutex_unlock(&ar
->conf_mutex
);
6335 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
6336 struct ieee80211_vif
*vif
,
6337 struct ieee80211_chanctx_conf
*ctx
)
6339 struct ath10k
*ar
= hw
->priv
;
6340 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6343 mutex_lock(&ar
->conf_mutex
);
6345 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6346 "mac chanctx unassign ptr %p vdev_id %i\n",
6347 ctx
, arvif
->vdev_id
);
6349 WARN_ON(!arvif
->is_started
);
6351 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6352 WARN_ON(!arvif
->is_up
);
6354 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
6356 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
6357 arvif
->vdev_id
, ret
);
6359 arvif
->is_up
= false;
6362 ret
= ath10k_vdev_stop(arvif
);
6364 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
6365 arvif
->vdev_id
, ret
);
6367 arvif
->is_started
= false;
6369 mutex_unlock(&ar
->conf_mutex
);
6373 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
6374 struct ieee80211_vif_chanctx_switch
*vifs
,
6376 enum ieee80211_chanctx_switch_mode mode
)
6378 struct ath10k
*ar
= hw
->priv
;
6379 struct ath10k_vif
*arvif
;
6380 struct ath10k_chanctx
*arctx_new
, *arctx_old
;
6383 mutex_lock(&ar
->conf_mutex
);
6385 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6386 "mac chanctx switch n_vifs %d mode %d\n",
6389 spin_lock_bh(&ar
->data_lock
);
6390 for (i
= 0; i
< n_vifs
; i
++) {
6391 arvif
= ath10k_vif_to_arvif(vifs
[i
].vif
);
6392 arctx_new
= (void *)vifs
[i
].new_ctx
->drv_priv
;
6393 arctx_old
= (void *)vifs
[i
].old_ctx
->drv_priv
;
6395 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6396 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6398 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
6399 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
6400 vifs
[i
].old_ctx
->def
.width
,
6401 vifs
[i
].new_ctx
->def
.width
,
6402 arctx_old
, arctx_new
);
6404 if (mode
== CHANCTX_SWMODE_SWAP_CONTEXTS
) {
6405 ath10k_mac_chan_ctx_init(ar
, arctx_new
,
6409 arctx_new
->conf
= *vifs
[i
].new_ctx
;
6411 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6412 * yet updated chanctx_conf pointer.
6414 arctx_old
->conf
= *vifs
[i
].new_ctx
;
6416 ath10k_mac_update_rx_channel(ar
);
6417 spin_unlock_bh(&ar
->data_lock
);
6419 /* FIXME: Reconfigure only affected vifs */
6420 ath10k_mac_chan_reconfigure(ar
);
6422 mutex_unlock(&ar
->conf_mutex
);
6426 static const struct ieee80211_ops ath10k_ops
= {
6428 .start
= ath10k_start
,
6429 .stop
= ath10k_stop
,
6430 .config
= ath10k_config
,
6431 .add_interface
= ath10k_add_interface
,
6432 .remove_interface
= ath10k_remove_interface
,
6433 .configure_filter
= ath10k_configure_filter
,
6434 .bss_info_changed
= ath10k_bss_info_changed
,
6435 .hw_scan
= ath10k_hw_scan
,
6436 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
6437 .set_key
= ath10k_set_key
,
6438 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
6439 .sta_state
= ath10k_sta_state
,
6440 .conf_tx
= ath10k_conf_tx
,
6441 .remain_on_channel
= ath10k_remain_on_channel
,
6442 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
6443 .set_rts_threshold
= ath10k_set_rts_threshold
,
6444 .flush
= ath10k_flush
,
6445 .tx_last_beacon
= ath10k_tx_last_beacon
,
6446 .set_antenna
= ath10k_set_antenna
,
6447 .get_antenna
= ath10k_get_antenna
,
6448 .reconfig_complete
= ath10k_reconfig_complete
,
6449 .get_survey
= ath10k_get_survey
,
6450 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
6451 .sta_rc_update
= ath10k_sta_rc_update
,
6452 .get_tsf
= ath10k_get_tsf
,
6453 .ampdu_action
= ath10k_ampdu_action
,
6454 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
6455 .get_et_stats
= ath10k_debug_get_et_stats
,
6456 .get_et_strings
= ath10k_debug_get_et_strings
,
6457 .add_chanctx
= ath10k_mac_op_add_chanctx
,
6458 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
6459 .change_chanctx
= ath10k_mac_op_change_chanctx
,
6460 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
6461 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
6462 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
6464 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
6467 .suspend
= ath10k_wow_op_suspend
,
6468 .resume
= ath10k_wow_op_resume
,
6470 #ifdef CONFIG_MAC80211_DEBUGFS
6471 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
6475 #define CHAN2G(_channel, _freq, _flags) { \
6476 .band = IEEE80211_BAND_2GHZ, \
6477 .hw_value = (_channel), \
6478 .center_freq = (_freq), \
6479 .flags = (_flags), \
6480 .max_antenna_gain = 0, \
6484 #define CHAN5G(_channel, _freq, _flags) { \
6485 .band = IEEE80211_BAND_5GHZ, \
6486 .hw_value = (_channel), \
6487 .center_freq = (_freq), \
6488 .flags = (_flags), \
6489 .max_antenna_gain = 0, \
6493 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
6503 CHAN2G(10, 2457, 0),
6504 CHAN2G(11, 2462, 0),
6505 CHAN2G(12, 2467, 0),
6506 CHAN2G(13, 2472, 0),
6507 CHAN2G(14, 2484, 0),
6510 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
6511 CHAN5G(36, 5180, 0),
6512 CHAN5G(40, 5200, 0),
6513 CHAN5G(44, 5220, 0),
6514 CHAN5G(48, 5240, 0),
6515 CHAN5G(52, 5260, 0),
6516 CHAN5G(56, 5280, 0),
6517 CHAN5G(60, 5300, 0),
6518 CHAN5G(64, 5320, 0),
6519 CHAN5G(100, 5500, 0),
6520 CHAN5G(104, 5520, 0),
6521 CHAN5G(108, 5540, 0),
6522 CHAN5G(112, 5560, 0),
6523 CHAN5G(116, 5580, 0),
6524 CHAN5G(120, 5600, 0),
6525 CHAN5G(124, 5620, 0),
6526 CHAN5G(128, 5640, 0),
6527 CHAN5G(132, 5660, 0),
6528 CHAN5G(136, 5680, 0),
6529 CHAN5G(140, 5700, 0),
6530 CHAN5G(144, 5720, 0),
6531 CHAN5G(149, 5745, 0),
6532 CHAN5G(153, 5765, 0),
6533 CHAN5G(157, 5785, 0),
6534 CHAN5G(161, 5805, 0),
6535 CHAN5G(165, 5825, 0),
6538 struct ath10k
*ath10k_mac_create(size_t priv_size
)
6540 struct ieee80211_hw
*hw
;
6543 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
6553 void ath10k_mac_destroy(struct ath10k
*ar
)
6555 ieee80211_free_hw(ar
->hw
);
6558 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
6561 .types
= BIT(NL80211_IFTYPE_STATION
)
6562 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
6566 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
6570 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
6574 .types
= BIT(NL80211_IFTYPE_AP
)
6578 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
6581 .types
= BIT(NL80211_IFTYPE_AP
)
6585 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
6587 .limits
= ath10k_if_limits
,
6588 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
6589 .max_interfaces
= 8,
6590 .num_different_channels
= 1,
6591 .beacon_int_infra_match
= true,
6595 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
6597 .limits
= ath10k_10x_if_limits
,
6598 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
6599 .max_interfaces
= 8,
6600 .num_different_channels
= 1,
6601 .beacon_int_infra_match
= true,
6602 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6603 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
6604 BIT(NL80211_CHAN_WIDTH_20
) |
6605 BIT(NL80211_CHAN_WIDTH_40
) |
6606 BIT(NL80211_CHAN_WIDTH_80
),
6611 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
6614 .types
= BIT(NL80211_IFTYPE_STATION
) |
6615 BIT(NL80211_IFTYPE_AP
) |
6616 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6617 BIT(NL80211_IFTYPE_P2P_GO
),
6621 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
6625 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
6628 .types
= BIT(NL80211_IFTYPE_STATION
),
6632 .types
= BIT(NL80211_IFTYPE_ADHOC
),
6636 /* FIXME: This is not thouroughly tested. These combinations may over- or
6637 * underestimate hw/fw capabilities.
6639 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
6641 .limits
= ath10k_tlv_if_limit
,
6642 .num_different_channels
= 1,
6643 .max_interfaces
= 3,
6644 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
6647 .limits
= ath10k_tlv_if_limit_ibss
,
6648 .num_different_channels
= 1,
6649 .max_interfaces
= 2,
6650 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
6654 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
6656 .limits
= ath10k_tlv_if_limit
,
6657 .num_different_channels
= 2,
6658 .max_interfaces
= 3,
6659 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
6662 .limits
= ath10k_tlv_if_limit_ibss
,
6663 .num_different_channels
= 1,
6664 .max_interfaces
= 2,
6665 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
6669 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
6671 struct ieee80211_sta_vht_cap vht_cap
= {0};
6676 vht_cap
.vht_supported
= 1;
6677 vht_cap
.cap
= ar
->vht_cap_info
;
6679 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
6680 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
6681 val
= ar
->num_rf_chains
- 1;
6682 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
6683 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
6688 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
6689 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
6690 val
= ar
->num_rf_chains
- 1;
6691 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
6692 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
6698 for (i
= 0; i
< 8; i
++) {
6699 if (i
< ar
->num_rf_chains
)
6700 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
6702 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
6705 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
6706 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
6711 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
6714 struct ieee80211_sta_ht_cap ht_cap
= {0};
6716 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
6719 ht_cap
.ht_supported
= 1;
6720 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
6721 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
6722 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
6723 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
6724 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
6726 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
6727 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
6729 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
6730 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
6732 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
6735 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
6736 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
6741 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
6742 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
6744 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
6747 stbc
= ar
->ht_cap_info
;
6748 stbc
&= WMI_HT_CAP_RX_STBC
;
6749 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
6750 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
6751 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
6756 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
6757 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
6759 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
6760 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
6762 /* max AMSDU is implicitly taken from vht_cap_info */
6763 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
6764 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
6766 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
6767 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
6769 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
6774 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
6775 struct ieee80211_vif
*vif
)
6777 struct ath10k_vif_iter
*arvif_iter
= data
;
6778 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6780 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
6781 arvif_iter
->arvif
= arvif
;
6784 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
6786 struct ath10k_vif_iter arvif_iter
;
6789 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
6790 arvif_iter
.vdev_id
= vdev_id
;
6792 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
6793 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
6795 ath10k_get_arvif_iter
,
6797 if (!arvif_iter
.arvif
) {
6798 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
6802 return arvif_iter
.arvif
;
6805 int ath10k_mac_register(struct ath10k
*ar
)
6807 static const u32 cipher_suites
[] = {
6808 WLAN_CIPHER_SUITE_WEP40
,
6809 WLAN_CIPHER_SUITE_WEP104
,
6810 WLAN_CIPHER_SUITE_TKIP
,
6811 WLAN_CIPHER_SUITE_CCMP
,
6812 WLAN_CIPHER_SUITE_AES_CMAC
,
6814 struct ieee80211_supported_band
*band
;
6815 struct ieee80211_sta_vht_cap vht_cap
;
6816 struct ieee80211_sta_ht_cap ht_cap
;
6820 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
6822 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
6824 ht_cap
= ath10k_get_ht_cap(ar
);
6825 vht_cap
= ath10k_create_vht_cap(ar
);
6827 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
6828 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
6831 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
6832 channels
= kmemdup(ath10k_2ghz_channels
,
6833 sizeof(ath10k_2ghz_channels
),
6840 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
6841 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
6842 band
->channels
= channels
;
6843 band
->n_bitrates
= ath10k_g_rates_size
;
6844 band
->bitrates
= ath10k_g_rates
;
6845 band
->ht_cap
= ht_cap
;
6847 /* Enable the VHT support at 2.4 GHz */
6848 band
->vht_cap
= vht_cap
;
6850 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
6853 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
6854 channels
= kmemdup(ath10k_5ghz_channels
,
6855 sizeof(ath10k_5ghz_channels
),
6862 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
6863 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
6864 band
->channels
= channels
;
6865 band
->n_bitrates
= ath10k_a_rates_size
;
6866 band
->bitrates
= ath10k_a_rates
;
6867 band
->ht_cap
= ht_cap
;
6868 band
->vht_cap
= vht_cap
;
6869 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
6872 ar
->hw
->wiphy
->interface_modes
=
6873 BIT(NL80211_IFTYPE_STATION
) |
6874 BIT(NL80211_IFTYPE_AP
);
6876 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
6877 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
6879 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
6880 ar
->hw
->wiphy
->interface_modes
|=
6881 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
6882 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
6883 BIT(NL80211_IFTYPE_P2P_GO
);
6885 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
6886 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
6887 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
6888 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
6889 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
6890 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
6891 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
6892 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
6893 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
6894 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
6895 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
6896 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
6897 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
6898 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
6899 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
6901 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
6902 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
6904 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
6905 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
6907 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
6908 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
6909 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
6912 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
6913 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
6915 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
6916 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
6917 ar
->hw
->chanctx_data_size
= sizeof(struct ath10k_chanctx
);
6919 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
6921 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
6922 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
6924 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6925 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6926 * correct Probe Responses. This is more of a hack advert..
6928 ar
->hw
->wiphy
->probe_resp_offload
|=
6929 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
6930 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
6931 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
6934 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
))
6935 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
6937 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
6938 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
6939 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
6941 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
6942 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
6944 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
6946 ret
= ath10k_wow_init(ar
);
6948 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
6953 * on LL hardware queues are managed entirely by the FW
6954 * so we only advertise to mac we can do the queues thing
6956 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
6958 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6959 * something that vdev_ids can't reach so that we don't stop the queue
6962 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
6964 switch (ar
->wmi
.op_version
) {
6965 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
6966 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
6967 ar
->hw
->wiphy
->n_iface_combinations
=
6968 ARRAY_SIZE(ath10k_if_comb
);
6969 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
6971 case ATH10K_FW_WMI_OP_VERSION_TLV
:
6972 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
6973 ar
->hw
->wiphy
->iface_combinations
=
6974 ath10k_tlv_qcs_if_comb
;
6975 ar
->hw
->wiphy
->n_iface_combinations
=
6976 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
6978 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
6979 ar
->hw
->wiphy
->n_iface_combinations
=
6980 ARRAY_SIZE(ath10k_tlv_if_comb
);
6982 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
6984 case ATH10K_FW_WMI_OP_VERSION_10_1
:
6985 case ATH10K_FW_WMI_OP_VERSION_10_2
:
6986 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
6987 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
6988 ar
->hw
->wiphy
->n_iface_combinations
=
6989 ARRAY_SIZE(ath10k_10x_if_comb
);
6991 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
6992 case ATH10K_FW_WMI_OP_VERSION_MAX
:
6998 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
7000 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
7001 /* Init ath dfs pattern detector */
7002 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
7003 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
7006 if (!ar
->dfs_detector
)
7007 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
7010 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
7011 ath10k_reg_notifier
);
7013 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
7017 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
7018 ar
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
7020 ret
= ieee80211_register_hw(ar
->hw
);
7022 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
7026 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
7027 ret
= regulatory_hint(ar
->hw
->wiphy
,
7028 ar
->ath_common
.regulatory
.alpha2
);
7030 goto err_unregister
;
7036 ieee80211_unregister_hw(ar
->hw
);
7038 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
7039 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
7044 void ath10k_mac_unregister(struct ath10k
*ar
)
7046 ieee80211_unregister_hw(ar
->hw
);
7048 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
7049 ar
->dfs_detector
->exit(ar
->dfs_detector
);
7051 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
7052 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
7054 SET_IEEE80211_DEV(ar
->hw
, NULL
);