2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
39 static struct ieee80211_rate ath10k_rates
[] = {
41 .hw_value
= ATH10K_HW_RATE_CCK_LP_1M
},
43 .hw_value
= ATH10K_HW_RATE_CCK_LP_2M
,
44 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_2M
,
45 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
47 .hw_value
= ATH10K_HW_RATE_CCK_LP_5_5M
,
48 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_5_5M
,
49 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
51 .hw_value
= ATH10K_HW_RATE_CCK_LP_11M
,
52 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_11M
,
53 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
55 { .bitrate
= 60, .hw_value
= ATH10K_HW_RATE_OFDM_6M
},
56 { .bitrate
= 90, .hw_value
= ATH10K_HW_RATE_OFDM_9M
},
57 { .bitrate
= 120, .hw_value
= ATH10K_HW_RATE_OFDM_12M
},
58 { .bitrate
= 180, .hw_value
= ATH10K_HW_RATE_OFDM_18M
},
59 { .bitrate
= 240, .hw_value
= ATH10K_HW_RATE_OFDM_24M
},
60 { .bitrate
= 360, .hw_value
= ATH10K_HW_RATE_OFDM_36M
},
61 { .bitrate
= 480, .hw_value
= ATH10K_HW_RATE_OFDM_48M
},
62 { .bitrate
= 540, .hw_value
= ATH10K_HW_RATE_OFDM_54M
},
65 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
67 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
70 #define ath10k_g_rates (ath10k_rates + 0)
71 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
73 static bool ath10k_mac_bitrate_is_cck(int bitrate
)
86 static u8
ath10k_mac_bitrate_to_rate(int bitrate
)
88 return DIV_ROUND_UP(bitrate
, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate
) ? BIT(7) : 0);
92 u8
ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band
*sband
,
95 const struct ieee80211_rate
*rate
;
98 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
99 rate
= &sband
->bitrates
[i
];
101 if (rate
->hw_value
== hw_rate
)
103 else if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
&&
104 rate
->hw_value_short
== hw_rate
)
111 u8
ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band
*sband
,
116 for (i
= 0; i
< sband
->n_bitrates
; i
++)
117 if (sband
->bitrates
[i
].bitrate
== bitrate
)
123 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map
, int nss
)
125 switch ((mcs_map
>> (2 * nss
)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7
: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8
: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9
: return BIT(10) - 1;
134 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
138 for (nss
= IEEE80211_HT_MCS_MASK_LEN
- 1; nss
>= 0; nss
--)
139 if (ht_mcs_mask
[nss
])
146 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
150 for (nss
= NL80211_VHT_NSS_MAX
- 1; nss
>= 0; nss
--)
151 if (vht_mcs_mask
[nss
])
161 static int ath10k_send_key(struct ath10k_vif
*arvif
,
162 struct ieee80211_key_conf
*key
,
163 enum set_key_cmd cmd
,
164 const u8
*macaddr
, u32 flags
)
166 struct ath10k
*ar
= arvif
->ar
;
167 struct wmi_vdev_install_key_arg arg
= {
168 .vdev_id
= arvif
->vdev_id
,
169 .key_idx
= key
->keyidx
,
170 .key_len
= key
->keylen
,
171 .key_data
= key
->key
,
176 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
178 switch (key
->cipher
) {
179 case WLAN_CIPHER_SUITE_CCMP
:
180 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
181 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
183 case WLAN_CIPHER_SUITE_TKIP
:
184 arg
.key_cipher
= WMI_CIPHER_TKIP
;
185 arg
.key_txmic_len
= 8;
186 arg
.key_rxmic_len
= 8;
188 case WLAN_CIPHER_SUITE_WEP40
:
189 case WLAN_CIPHER_SUITE_WEP104
:
190 arg
.key_cipher
= WMI_CIPHER_WEP
;
192 case WLAN_CIPHER_SUITE_AES_CMAC
:
196 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
200 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
201 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
203 if (cmd
== DISABLE_KEY
) {
204 arg
.key_cipher
= WMI_CIPHER_NONE
;
208 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
211 static int ath10k_install_key(struct ath10k_vif
*arvif
,
212 struct ieee80211_key_conf
*key
,
213 enum set_key_cmd cmd
,
214 const u8
*macaddr
, u32 flags
)
216 struct ath10k
*ar
= arvif
->ar
;
218 unsigned long time_left
;
220 lockdep_assert_held(&ar
->conf_mutex
);
222 reinit_completion(&ar
->install_key_done
);
224 if (arvif
->nohwcrypt
)
227 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
231 time_left
= wait_for_completion_timeout(&ar
->install_key_done
, 3 * HZ
);
238 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
241 struct ath10k
*ar
= arvif
->ar
;
242 struct ath10k_peer
*peer
;
247 lockdep_assert_held(&ar
->conf_mutex
);
249 if (WARN_ON(arvif
->vif
->type
!= NL80211_IFTYPE_AP
&&
250 arvif
->vif
->type
!= NL80211_IFTYPE_ADHOC
))
253 spin_lock_bh(&ar
->data_lock
);
254 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
255 spin_unlock_bh(&ar
->data_lock
);
260 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
261 if (arvif
->wep_keys
[i
] == NULL
)
264 switch (arvif
->vif
->type
) {
265 case NL80211_IFTYPE_AP
:
266 flags
= WMI_KEY_PAIRWISE
;
268 if (arvif
->def_wep_key_idx
== i
)
269 flags
|= WMI_KEY_TX_USAGE
;
271 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
272 SET_KEY
, addr
, flags
);
276 case NL80211_IFTYPE_ADHOC
:
277 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
283 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
284 SET_KEY
, addr
, WMI_KEY_GROUP
);
293 spin_lock_bh(&ar
->data_lock
);
294 peer
->keys
[i
] = arvif
->wep_keys
[i
];
295 spin_unlock_bh(&ar
->data_lock
);
298 /* In some cases (notably with static WEP IBSS with multiple keys)
299 * multicast Tx becomes broken. Both pairwise and groupwise keys are
300 * installed already. Using WMI_KEY_TX_USAGE in different combinations
301 * didn't seem help. Using def_keyid vdev parameter seems to be
302 * effective so use that.
304 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
306 if (arvif
->vif
->type
!= NL80211_IFTYPE_ADHOC
)
309 if (arvif
->def_wep_key_idx
== -1)
312 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
314 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
315 arvif
->def_wep_key_idx
);
317 ath10k_warn(ar
, "failed to re-set def wpa key idxon vdev %i: %d\n",
318 arvif
->vdev_id
, ret
);
325 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
328 struct ath10k
*ar
= arvif
->ar
;
329 struct ath10k_peer
*peer
;
335 lockdep_assert_held(&ar
->conf_mutex
);
337 spin_lock_bh(&ar
->data_lock
);
338 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
339 spin_unlock_bh(&ar
->data_lock
);
344 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
345 if (peer
->keys
[i
] == NULL
)
348 /* key flags are not required to delete the key */
349 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
350 DISABLE_KEY
, addr
, flags
);
351 if (ret
< 0 && first_errno
== 0)
355 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
358 spin_lock_bh(&ar
->data_lock
);
359 peer
->keys
[i
] = NULL
;
360 spin_unlock_bh(&ar
->data_lock
);
366 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
369 struct ath10k_peer
*peer
;
372 lockdep_assert_held(&ar
->data_lock
);
374 /* We don't know which vdev this peer belongs to,
375 * since WMI doesn't give us that information.
377 * FIXME: multi-bss needs to be handled.
379 peer
= ath10k_peer_find(ar
, 0, addr
);
383 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
384 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
391 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
392 struct ieee80211_key_conf
*key
)
394 struct ath10k
*ar
= arvif
->ar
;
395 struct ath10k_peer
*peer
;
402 lockdep_assert_held(&ar
->conf_mutex
);
405 /* since ath10k_install_key we can't hold data_lock all the
406 * time, so we try to remove the keys incrementally */
407 spin_lock_bh(&ar
->data_lock
);
409 list_for_each_entry(peer
, &ar
->peers
, list
) {
410 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
411 if (peer
->keys
[i
] == key
) {
412 ether_addr_copy(addr
, peer
->addr
);
413 peer
->keys
[i
] = NULL
;
418 if (i
< ARRAY_SIZE(peer
->keys
))
421 spin_unlock_bh(&ar
->data_lock
);
423 if (i
== ARRAY_SIZE(peer
->keys
))
425 /* key flags are not required to delete the key */
426 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
427 if (ret
< 0 && first_errno
== 0)
431 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
438 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
439 struct ieee80211_key_conf
*key
)
441 struct ath10k
*ar
= arvif
->ar
;
442 struct ath10k_peer
*peer
;
445 lockdep_assert_held(&ar
->conf_mutex
);
447 list_for_each_entry(peer
, &ar
->peers
, list
) {
448 if (!memcmp(peer
->addr
, arvif
->vif
->addr
, ETH_ALEN
))
451 if (!memcmp(peer
->addr
, arvif
->bssid
, ETH_ALEN
))
454 if (peer
->keys
[key
->keyidx
] == key
)
457 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
458 arvif
->vdev_id
, key
->keyidx
);
460 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
462 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
463 arvif
->vdev_id
, peer
->addr
, ret
);
471 /*********************/
472 /* General utilities */
473 /*********************/
475 static inline enum wmi_phy_mode
476 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
478 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
480 switch (chandef
->chan
->band
) {
481 case IEEE80211_BAND_2GHZ
:
482 switch (chandef
->width
) {
483 case NL80211_CHAN_WIDTH_20_NOHT
:
484 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
489 case NL80211_CHAN_WIDTH_20
:
490 phymode
= MODE_11NG_HT20
;
492 case NL80211_CHAN_WIDTH_40
:
493 phymode
= MODE_11NG_HT40
;
495 case NL80211_CHAN_WIDTH_5
:
496 case NL80211_CHAN_WIDTH_10
:
497 case NL80211_CHAN_WIDTH_80
:
498 case NL80211_CHAN_WIDTH_80P80
:
499 case NL80211_CHAN_WIDTH_160
:
500 phymode
= MODE_UNKNOWN
;
504 case IEEE80211_BAND_5GHZ
:
505 switch (chandef
->width
) {
506 case NL80211_CHAN_WIDTH_20_NOHT
:
509 case NL80211_CHAN_WIDTH_20
:
510 phymode
= MODE_11NA_HT20
;
512 case NL80211_CHAN_WIDTH_40
:
513 phymode
= MODE_11NA_HT40
;
515 case NL80211_CHAN_WIDTH_80
:
516 phymode
= MODE_11AC_VHT80
;
518 case NL80211_CHAN_WIDTH_5
:
519 case NL80211_CHAN_WIDTH_10
:
520 case NL80211_CHAN_WIDTH_80P80
:
521 case NL80211_CHAN_WIDTH_160
:
522 phymode
= MODE_UNKNOWN
;
530 WARN_ON(phymode
== MODE_UNKNOWN
);
534 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
537 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
538 * 0 for no restriction
547 switch (mpdudensity
) {
553 /* Our lower layer calculations limit our precision to
569 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
570 struct cfg80211_chan_def
*def
)
572 struct ieee80211_chanctx_conf
*conf
;
575 conf
= rcu_dereference(vif
->chanctx_conf
);
587 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
588 struct ieee80211_chanctx_conf
*conf
,
596 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
600 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
601 ath10k_mac_num_chanctxs_iter
,
608 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
609 struct ieee80211_chanctx_conf
*conf
,
612 struct cfg80211_chan_def
**def
= data
;
617 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
,
618 enum wmi_peer_type peer_type
)
620 struct ath10k_vif
*arvif
;
624 lockdep_assert_held(&ar
->conf_mutex
);
626 num_peers
= ar
->num_peers
;
628 /* Each vdev consumes a peer entry as well */
629 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
632 if (num_peers
>= ar
->max_num_peers
)
635 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
637 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
642 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
644 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
654 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
656 struct ath10k
*ar
= arvif
->ar
;
660 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
661 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
662 ATH10K_KICKOUT_THRESHOLD
);
664 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
665 arvif
->vdev_id
, ret
);
669 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
670 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
671 ATH10K_KEEPALIVE_MIN_IDLE
);
673 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
674 arvif
->vdev_id
, ret
);
678 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
679 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
680 ATH10K_KEEPALIVE_MAX_IDLE
);
682 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
683 arvif
->vdev_id
, ret
);
687 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
688 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
689 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
691 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
692 arvif
->vdev_id
, ret
);
699 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
701 struct ath10k
*ar
= arvif
->ar
;
704 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
705 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
708 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
712 lockdep_assert_held(&ar
->conf_mutex
);
714 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
718 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
727 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
729 struct ath10k_peer
*peer
, *tmp
;
731 lockdep_assert_held(&ar
->conf_mutex
);
733 spin_lock_bh(&ar
->data_lock
);
734 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
735 if (peer
->vdev_id
!= vdev_id
)
738 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
739 peer
->addr
, vdev_id
);
741 list_del(&peer
->list
);
745 spin_unlock_bh(&ar
->data_lock
);
748 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
750 struct ath10k_peer
*peer
, *tmp
;
752 lockdep_assert_held(&ar
->conf_mutex
);
754 spin_lock_bh(&ar
->data_lock
);
755 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
756 list_del(&peer
->list
);
759 spin_unlock_bh(&ar
->data_lock
);
762 ar
->num_stations
= 0;
765 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
766 struct ieee80211_sta
*sta
,
767 enum wmi_tdls_peer_state state
)
770 struct wmi_tdls_peer_update_cmd_arg arg
= {};
771 struct wmi_tdls_peer_capab_arg cap
= {};
772 struct wmi_channel_arg chan_arg
= {};
774 lockdep_assert_held(&ar
->conf_mutex
);
776 arg
.vdev_id
= vdev_id
;
777 arg
.peer_state
= state
;
778 ether_addr_copy(arg
.addr
, sta
->addr
);
780 cap
.peer_max_sp
= sta
->max_sp
;
781 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
783 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
784 !sta
->tdls_initiator
)
785 cap
.is_peer_responder
= 1;
787 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
789 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
790 arg
.addr
, vdev_id
, ret
);
797 /************************/
798 /* Interface management */
799 /************************/
801 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
803 struct ath10k
*ar
= arvif
->ar
;
805 lockdep_assert_held(&ar
->data_lock
);
810 if (!arvif
->beacon_buf
)
811 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
812 arvif
->beacon
->len
, DMA_TO_DEVICE
);
814 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
815 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
818 dev_kfree_skb_any(arvif
->beacon
);
820 arvif
->beacon
= NULL
;
821 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
824 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
826 struct ath10k
*ar
= arvif
->ar
;
828 lockdep_assert_held(&ar
->data_lock
);
830 ath10k_mac_vif_beacon_free(arvif
);
832 if (arvif
->beacon_buf
) {
833 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
834 arvif
->beacon_buf
, arvif
->beacon_paddr
);
835 arvif
->beacon_buf
= NULL
;
839 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
841 unsigned long time_left
;
843 lockdep_assert_held(&ar
->conf_mutex
);
845 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
848 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
849 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
856 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
858 struct cfg80211_chan_def
*chandef
= NULL
;
859 struct ieee80211_channel
*channel
= NULL
;
860 struct wmi_vdev_start_request_arg arg
= {};
863 lockdep_assert_held(&ar
->conf_mutex
);
865 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
866 ath10k_mac_get_any_chandef_iter
,
868 if (WARN_ON_ONCE(!chandef
))
871 channel
= chandef
->chan
;
873 arg
.vdev_id
= vdev_id
;
874 arg
.channel
.freq
= channel
->center_freq
;
875 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
877 /* TODO setup this dynamically, what in case we
878 don't have any vifs? */
879 arg
.channel
.mode
= chan_to_phymode(chandef
);
880 arg
.channel
.chan_radar
=
881 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
883 arg
.channel
.min_power
= 0;
884 arg
.channel
.max_power
= channel
->max_power
* 2;
885 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
886 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
888 reinit_completion(&ar
->vdev_setup_done
);
890 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
892 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
897 ret
= ath10k_vdev_setup_sync(ar
);
899 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
904 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
906 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
911 ar
->monitor_vdev_id
= vdev_id
;
913 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
914 ar
->monitor_vdev_id
);
918 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
920 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
921 ar
->monitor_vdev_id
, ret
);
926 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
930 lockdep_assert_held(&ar
->conf_mutex
);
932 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
934 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
935 ar
->monitor_vdev_id
, ret
);
937 reinit_completion(&ar
->vdev_setup_done
);
939 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
941 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
942 ar
->monitor_vdev_id
, ret
);
944 ret
= ath10k_vdev_setup_sync(ar
);
946 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
947 ar
->monitor_vdev_id
, ret
);
949 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
950 ar
->monitor_vdev_id
);
954 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
958 lockdep_assert_held(&ar
->conf_mutex
);
960 if (ar
->free_vdev_map
== 0) {
961 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
965 bit
= __ffs64(ar
->free_vdev_map
);
967 ar
->monitor_vdev_id
= bit
;
969 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
970 WMI_VDEV_TYPE_MONITOR
,
973 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
974 ar
->monitor_vdev_id
, ret
);
978 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
979 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
980 ar
->monitor_vdev_id
);
985 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
989 lockdep_assert_held(&ar
->conf_mutex
);
991 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
993 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
994 ar
->monitor_vdev_id
, ret
);
998 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
1000 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
1001 ar
->monitor_vdev_id
);
1005 static int ath10k_monitor_start(struct ath10k
*ar
)
1009 lockdep_assert_held(&ar
->conf_mutex
);
1011 ret
= ath10k_monitor_vdev_create(ar
);
1013 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
1017 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
1019 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
1020 ath10k_monitor_vdev_delete(ar
);
1024 ar
->monitor_started
= true;
1025 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
1030 static int ath10k_monitor_stop(struct ath10k
*ar
)
1034 lockdep_assert_held(&ar
->conf_mutex
);
1036 ret
= ath10k_monitor_vdev_stop(ar
);
1038 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1042 ret
= ath10k_monitor_vdev_delete(ar
);
1044 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1048 ar
->monitor_started
= false;
1049 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1054 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1058 /* At least one chanctx is required to derive a channel to start
1061 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1065 /* If there's already an existing special monitor interface then don't
1066 * bother creating another monitor vdev.
1068 if (ar
->monitor_arvif
)
1071 return ar
->monitor
||
1072 ar
->filter_flags
& FIF_OTHER_BSS
||
1073 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1076 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1080 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1082 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1083 * shouldn't allow this but make sure to prevent handling the following
1084 * case anyway since multi-channel DFS hasn't been tested at all.
1086 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1092 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1098 lockdep_assert_held(&ar
->conf_mutex
);
1100 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1101 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1103 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1104 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1105 ar
->monitor_started
, needed
, allowed
);
1107 if (WARN_ON(needed
&& !allowed
)) {
1108 if (ar
->monitor_started
) {
1109 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1111 ret
= ath10k_monitor_stop(ar
);
1113 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n",
1121 if (needed
== ar
->monitor_started
)
1125 return ath10k_monitor_start(ar
);
1127 return ath10k_monitor_stop(ar
);
1130 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif
*arvif
)
1132 struct ath10k
*ar
= arvif
->ar
;
1134 lockdep_assert_held(&ar
->conf_mutex
);
1136 if (!arvif
->is_started
) {
1137 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "defer cts setup, vdev is not ready yet\n");
1144 static int ath10k_mac_set_cts_prot(struct ath10k_vif
*arvif
)
1146 struct ath10k
*ar
= arvif
->ar
;
1149 lockdep_assert_held(&ar
->conf_mutex
);
1151 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
1153 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_protection %d\n",
1154 arvif
->vdev_id
, arvif
->use_cts_prot
);
1156 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1157 arvif
->use_cts_prot
? 1 : 0);
1160 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1162 struct ath10k
*ar
= arvif
->ar
;
1163 u32 vdev_param
, rts_cts
= 0;
1165 lockdep_assert_held(&ar
->conf_mutex
);
1167 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1169 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1171 if (arvif
->num_legacy_stations
> 0)
1172 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1173 WMI_RTSCTS_PROFILE
);
1175 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1176 WMI_RTSCTS_PROFILE
);
1178 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1182 static int ath10k_start_cac(struct ath10k
*ar
)
1186 lockdep_assert_held(&ar
->conf_mutex
);
1188 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1190 ret
= ath10k_monitor_recalc(ar
);
1192 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1193 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1197 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1198 ar
->monitor_vdev_id
);
1203 static int ath10k_stop_cac(struct ath10k
*ar
)
1205 lockdep_assert_held(&ar
->conf_mutex
);
1207 /* CAC is not running - do nothing */
1208 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1211 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1212 ath10k_monitor_stop(ar
);
1214 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1219 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1220 struct ieee80211_chanctx_conf
*conf
,
1225 if (!*ret
&& conf
->radar_enabled
)
1229 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1231 bool has_radar
= false;
1233 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1234 ath10k_mac_has_radar_iter
,
1240 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1244 lockdep_assert_held(&ar
->conf_mutex
);
1246 ath10k_stop_cac(ar
);
1248 if (!ath10k_mac_has_radar_enabled(ar
))
1251 if (ar
->num_started_vdevs
> 0)
1254 ret
= ath10k_start_cac(ar
);
1257 * Not possible to start CAC on current channel so starting
1258 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1259 * by indicating that radar was detected.
1261 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1262 ieee80211_radar_detected(ar
->hw
);
1266 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1268 struct ath10k
*ar
= arvif
->ar
;
1271 lockdep_assert_held(&ar
->conf_mutex
);
1273 reinit_completion(&ar
->vdev_setup_done
);
1275 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1277 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1278 arvif
->vdev_id
, ret
);
1282 ret
= ath10k_vdev_setup_sync(ar
);
1284 ath10k_warn(ar
, "failed to syncronise setup for vdev %i: %d\n",
1285 arvif
->vdev_id
, ret
);
1289 WARN_ON(ar
->num_started_vdevs
== 0);
1291 if (ar
->num_started_vdevs
!= 0) {
1292 ar
->num_started_vdevs
--;
1293 ath10k_recalc_radar_detection(ar
);
1299 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1300 const struct cfg80211_chan_def
*chandef
,
1303 struct ath10k
*ar
= arvif
->ar
;
1304 struct wmi_vdev_start_request_arg arg
= {};
1307 lockdep_assert_held(&ar
->conf_mutex
);
1309 reinit_completion(&ar
->vdev_setup_done
);
1311 arg
.vdev_id
= arvif
->vdev_id
;
1312 arg
.dtim_period
= arvif
->dtim_period
;
1313 arg
.bcn_intval
= arvif
->beacon_interval
;
1315 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1316 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1317 arg
.channel
.mode
= chan_to_phymode(chandef
);
1319 arg
.channel
.min_power
= 0;
1320 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1321 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1322 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1324 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1325 arg
.ssid
= arvif
->u
.ap
.ssid
;
1326 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1327 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1329 /* For now allow DFS for AP mode */
1330 arg
.channel
.chan_radar
=
1331 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1332 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1333 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1334 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1337 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1338 "mac vdev %d start center_freq %d phymode %s\n",
1339 arg
.vdev_id
, arg
.channel
.freq
,
1340 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1343 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1345 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1348 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1353 ret
= ath10k_vdev_setup_sync(ar
);
1356 "failed to synchronize setup for vdev %i restart %d: %d\n",
1357 arg
.vdev_id
, restart
, ret
);
1361 ar
->num_started_vdevs
++;
1362 ath10k_recalc_radar_detection(ar
);
1367 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1368 const struct cfg80211_chan_def
*def
)
1370 return ath10k_vdev_start_restart(arvif
, def
, false);
1373 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1374 const struct cfg80211_chan_def
*def
)
1376 return ath10k_vdev_start_restart(arvif
, def
, true);
1379 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1380 struct sk_buff
*bcn
)
1382 struct ath10k
*ar
= arvif
->ar
;
1383 struct ieee80211_mgmt
*mgmt
;
1387 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1390 if (arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1393 mgmt
= (void *)bcn
->data
;
1394 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1395 mgmt
->u
.beacon
.variable
,
1396 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1401 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1403 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1404 arvif
->vdev_id
, ret
);
1411 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1412 u8 oui_type
, size_t ie_offset
)
1419 if (WARN_ON(skb
->len
< ie_offset
))
1422 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1423 skb
->data
+ ie_offset
,
1424 skb
->len
- ie_offset
);
1429 end
= skb
->data
+ skb
->len
;
1432 if (WARN_ON(next
> end
))
1435 memmove(ie
, next
, end
- next
);
1436 skb_trim(skb
, skb
->len
- len
);
1441 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1443 struct ath10k
*ar
= arvif
->ar
;
1444 struct ieee80211_hw
*hw
= ar
->hw
;
1445 struct ieee80211_vif
*vif
= arvif
->vif
;
1446 struct ieee80211_mutable_offsets offs
= {};
1447 struct sk_buff
*bcn
;
1450 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1453 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1454 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1457 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1459 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1463 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1465 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1470 /* P2P IE is inserted by firmware automatically (as configured above)
1471 * so remove it from the base beacon template to avoid duplicate P2P
1472 * IEs in beacon frames.
1474 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1475 offsetof(struct ieee80211_mgmt
,
1476 u
.beacon
.variable
));
1478 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1483 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1491 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1493 struct ath10k
*ar
= arvif
->ar
;
1494 struct ieee80211_hw
*hw
= ar
->hw
;
1495 struct ieee80211_vif
*vif
= arvif
->vif
;
1496 struct sk_buff
*prb
;
1499 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1502 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1505 prb
= ieee80211_proberesp_get(hw
, vif
);
1507 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1511 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1515 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1523 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1525 struct ath10k
*ar
= arvif
->ar
;
1526 struct cfg80211_chan_def def
;
1529 /* When originally vdev is started during assign_vif_chanctx() some
1530 * information is missing, notably SSID. Firmware revisions with beacon
1531 * offloading require the SSID to be provided during vdev (re)start to
1532 * handle hidden SSID properly.
1534 * Vdev restart must be done after vdev has been both started and
1535 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1536 * deliver vdev restart response event causing timeouts during vdev
1537 * syncing in ath10k.
1539 * Note: The vdev down/up and template reinstallation could be skipped
1540 * since only wmi-tlv firmware are known to have beacon offload and
1541 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1542 * response delivery. It's probably more robust to keep it as is.
1544 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1547 if (WARN_ON(!arvif
->is_started
))
1550 if (WARN_ON(!arvif
->is_up
))
1553 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1556 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1558 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1559 arvif
->vdev_id
, ret
);
1563 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1564 * firmware will crash upon vdev up.
1567 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1569 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1573 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1575 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1579 ret
= ath10k_vdev_restart(arvif
, &def
);
1581 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1582 arvif
->vdev_id
, ret
);
1586 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1589 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1590 arvif
->vdev_id
, ret
);
1597 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1598 struct ieee80211_bss_conf
*info
)
1600 struct ath10k
*ar
= arvif
->ar
;
1603 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1605 if (!info
->enable_beacon
) {
1606 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1608 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1609 arvif
->vdev_id
, ret
);
1611 arvif
->is_up
= false;
1613 spin_lock_bh(&arvif
->ar
->data_lock
);
1614 ath10k_mac_vif_beacon_free(arvif
);
1615 spin_unlock_bh(&arvif
->ar
->data_lock
);
1620 arvif
->tx_seq_no
= 0x1000;
1623 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1625 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1628 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1629 arvif
->vdev_id
, ret
);
1633 arvif
->is_up
= true;
1635 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1637 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1638 arvif
->vdev_id
, ret
);
1642 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1645 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1646 struct ieee80211_bss_conf
*info
,
1647 const u8 self_peer
[ETH_ALEN
])
1649 struct ath10k
*ar
= arvif
->ar
;
1653 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1655 if (!info
->ibss_joined
) {
1656 if (is_zero_ether_addr(arvif
->bssid
))
1659 eth_zero_addr(arvif
->bssid
);
1664 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1665 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1666 ATH10K_DEFAULT_ATIM
);
1668 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1669 arvif
->vdev_id
, ret
);
1672 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1674 struct ath10k
*ar
= arvif
->ar
;
1679 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1681 if (arvif
->u
.sta
.uapsd
)
1682 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1684 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1686 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1687 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1689 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1690 value
, arvif
->vdev_id
, ret
);
1697 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1699 struct ath10k
*ar
= arvif
->ar
;
1704 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1706 if (arvif
->u
.sta
.uapsd
)
1707 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1709 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1711 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1712 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1715 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1716 value
, arvif
->vdev_id
, ret
);
1723 static int ath10k_mac_num_vifs_started(struct ath10k
*ar
)
1725 struct ath10k_vif
*arvif
;
1728 lockdep_assert_held(&ar
->conf_mutex
);
1730 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1731 if (arvif
->is_started
)
1737 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1739 struct ath10k
*ar
= arvif
->ar
;
1740 struct ieee80211_vif
*vif
= arvif
->vif
;
1741 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1742 enum wmi_sta_powersave_param param
;
1743 enum wmi_sta_ps_mode psmode
;
1748 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1750 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1753 enable_ps
= arvif
->ps
;
1755 if (enable_ps
&& ath10k_mac_num_vifs_started(ar
) > 1 &&
1756 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1758 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1763 if (!arvif
->is_started
) {
1764 /* mac80211 can update vif powersave state while disconnected.
1765 * Firmware doesn't behave nicely and consumes more power than
1766 * necessary if PS is disabled on a non-started vdev. Hence
1767 * force-enable PS for non-running vdevs.
1769 psmode
= WMI_STA_PS_MODE_ENABLED
;
1770 } else if (enable_ps
) {
1771 psmode
= WMI_STA_PS_MODE_ENABLED
;
1772 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1774 ps_timeout
= conf
->dynamic_ps_timeout
;
1775 if (ps_timeout
== 0) {
1776 /* Firmware doesn't like 0 */
1777 ps_timeout
= ieee80211_tu_to_usec(
1778 vif
->bss_conf
.beacon_int
) / 1000;
1781 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1784 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1785 arvif
->vdev_id
, ret
);
1789 psmode
= WMI_STA_PS_MODE_DISABLED
;
1792 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1793 arvif
->vdev_id
, psmode
? "enable" : "disable");
1795 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1797 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1798 psmode
, arvif
->vdev_id
, ret
);
1805 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1807 struct ath10k
*ar
= arvif
->ar
;
1808 struct wmi_sta_keepalive_arg arg
= {};
1811 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1813 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1816 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1819 /* Some firmware revisions have a bug and ignore the `enabled` field.
1820 * Instead use the interval to disable the keepalive.
1822 arg
.vdev_id
= arvif
->vdev_id
;
1824 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1825 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1827 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1829 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1830 arvif
->vdev_id
, ret
);
1837 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
1839 struct ath10k
*ar
= arvif
->ar
;
1840 struct ieee80211_vif
*vif
= arvif
->vif
;
1843 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1845 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
1848 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1851 if (!vif
->csa_active
)
1857 if (!ieee80211_csa_is_complete(vif
)) {
1858 ieee80211_csa_update_counter(vif
);
1860 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1862 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
1865 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1867 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
1870 ieee80211_csa_finish(vif
);
1874 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
1876 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1878 struct ath10k
*ar
= arvif
->ar
;
1880 mutex_lock(&ar
->conf_mutex
);
1881 ath10k_mac_vif_ap_csa_count_down(arvif
);
1882 mutex_unlock(&ar
->conf_mutex
);
1885 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
1886 struct ieee80211_vif
*vif
)
1888 struct sk_buff
*skb
= data
;
1889 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1890 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1892 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1895 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
1898 cancel_delayed_work(&arvif
->connection_loss_work
);
1901 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
1903 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1904 IEEE80211_IFACE_ITER_NORMAL
,
1905 ath10k_mac_handle_beacon_iter
,
1909 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
1910 struct ieee80211_vif
*vif
)
1912 u32
*vdev_id
= data
;
1913 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1914 struct ath10k
*ar
= arvif
->ar
;
1915 struct ieee80211_hw
*hw
= ar
->hw
;
1917 if (arvif
->vdev_id
!= *vdev_id
)
1923 ieee80211_beacon_loss(vif
);
1925 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1926 * (done by mac80211) succeeds but beacons do not resume then it
1927 * doesn't make sense to continue operation. Queue connection loss work
1928 * which can be cancelled when beacon is received.
1930 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
1931 ATH10K_CONNECTION_LOSS_HZ
);
1934 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
1936 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
1937 IEEE80211_IFACE_ITER_NORMAL
,
1938 ath10k_mac_handle_beacon_miss_iter
,
1942 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
1944 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1945 connection_loss_work
.work
);
1946 struct ieee80211_vif
*vif
= arvif
->vif
;
1951 ieee80211_connection_loss(vif
);
1954 /**********************/
1955 /* Station management */
1956 /**********************/
1958 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
1959 struct ieee80211_vif
*vif
)
1961 /* Some firmware revisions have unstable STA powersave when listen
1962 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1963 * generate NullFunc frames properly even if buffered frames have been
1964 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1965 * buffered frames. Often pinging the device from AP would simply fail.
1967 * As a workaround set it to 1.
1969 if (vif
->type
== NL80211_IFTYPE_STATION
)
1972 return ar
->hw
->conf
.listen_interval
;
1975 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1976 struct ieee80211_vif
*vif
,
1977 struct ieee80211_sta
*sta
,
1978 struct wmi_peer_assoc_complete_arg
*arg
)
1980 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1983 lockdep_assert_held(&ar
->conf_mutex
);
1985 if (vif
->type
== NL80211_IFTYPE_STATION
)
1986 aid
= vif
->bss_conf
.aid
;
1990 ether_addr_copy(arg
->addr
, sta
->addr
);
1991 arg
->vdev_id
= arvif
->vdev_id
;
1992 arg
->peer_aid
= aid
;
1993 arg
->peer_flags
|= WMI_PEER_AUTH
;
1994 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
1995 arg
->peer_num_spatial_streams
= 1;
1996 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
1999 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
2000 struct ieee80211_vif
*vif
,
2001 struct wmi_peer_assoc_complete_arg
*arg
)
2003 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
2004 struct cfg80211_chan_def def
;
2005 struct cfg80211_bss
*bss
;
2006 const u8
*rsnie
= NULL
;
2007 const u8
*wpaie
= NULL
;
2009 lockdep_assert_held(&ar
->conf_mutex
);
2011 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2014 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
, NULL
, 0,
2015 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
2017 const struct cfg80211_bss_ies
*ies
;
2020 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
2022 ies
= rcu_dereference(bss
->ies
);
2024 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
2025 WLAN_OUI_TYPE_MICROSOFT_WPA
,
2029 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
2032 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2033 if (rsnie
|| wpaie
) {
2034 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
2035 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
2039 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
2040 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
2044 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
2045 struct ieee80211_vif
*vif
,
2046 struct ieee80211_sta
*sta
,
2047 struct wmi_peer_assoc_complete_arg
*arg
)
2049 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2050 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
2051 struct cfg80211_chan_def def
;
2052 const struct ieee80211_supported_band
*sband
;
2053 const struct ieee80211_rate
*rates
;
2054 enum ieee80211_band band
;
2059 lockdep_assert_held(&ar
->conf_mutex
);
2061 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2064 band
= def
.chan
->band
;
2065 sband
= ar
->hw
->wiphy
->bands
[band
];
2066 ratemask
= sta
->supp_rates
[band
];
2067 ratemask
&= arvif
->bitrate_mask
.control
[band
].legacy
;
2068 rates
= sband
->bitrates
;
2070 rateset
->num_rates
= 0;
2072 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2073 if (!(ratemask
& 1))
2076 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2077 rateset
->rates
[rateset
->num_rates
] = rate
;
2078 rateset
->num_rates
++;
2083 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
2087 for (nss
= 0; nss
< IEEE80211_HT_MCS_MASK_LEN
; nss
++)
2088 if (ht_mcs_mask
[nss
])
2095 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
2099 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++)
2100 if (vht_mcs_mask
[nss
])
2106 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2107 struct ieee80211_vif
*vif
,
2108 struct ieee80211_sta
*sta
,
2109 struct wmi_peer_assoc_complete_arg
*arg
)
2111 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2112 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2113 struct cfg80211_chan_def def
;
2114 enum ieee80211_band band
;
2115 const u8
*ht_mcs_mask
;
2116 const u16
*vht_mcs_mask
;
2121 lockdep_assert_held(&ar
->conf_mutex
);
2123 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2126 if (!ht_cap
->ht_supported
)
2129 band
= def
.chan
->band
;
2130 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2131 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2133 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
) &&
2134 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2137 arg
->peer_flags
|= WMI_PEER_HT
;
2138 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2139 ht_cap
->ampdu_factor
)) - 1;
2141 arg
->peer_mpdu_density
=
2142 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2144 arg
->peer_ht_caps
= ht_cap
->cap
;
2145 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2147 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2148 arg
->peer_flags
|= WMI_PEER_LDPC
;
2150 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2151 arg
->peer_flags
|= WMI_PEER_40MHZ
;
2152 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2155 if (arvif
->bitrate_mask
.control
[band
].gi
!= NL80211_TXRATE_FORCE_LGI
) {
2156 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2157 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2159 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2160 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2163 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2164 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2165 arg
->peer_flags
|= WMI_PEER_STBC
;
2168 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2169 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2170 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2171 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2172 arg
->peer_rate_caps
|= stbc
;
2173 arg
->peer_flags
|= WMI_PEER_STBC
;
2176 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2177 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2178 else if (ht_cap
->mcs
.rx_mask
[1])
2179 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2181 for (i
= 0, n
= 0, max_nss
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
* 8; i
++)
2182 if ((ht_cap
->mcs
.rx_mask
[i
/ 8] & BIT(i
% 8)) &&
2183 (ht_mcs_mask
[i
/ 8] & BIT(i
% 8))) {
2184 max_nss
= (i
/ 8) + 1;
2185 arg
->peer_ht_rates
.rates
[n
++] = i
;
2189 * This is a workaround for HT-enabled STAs which break the spec
2190 * and have no HT capabilities RX mask (no HT RX MCS map).
2192 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2193 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2195 * Firmware asserts if such situation occurs.
2198 arg
->peer_ht_rates
.num_rates
= 8;
2199 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2200 arg
->peer_ht_rates
.rates
[i
] = i
;
2202 arg
->peer_ht_rates
.num_rates
= n
;
2203 arg
->peer_num_spatial_streams
= min(sta
->rx_nss
, max_nss
);
2206 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2208 arg
->peer_ht_rates
.num_rates
,
2209 arg
->peer_num_spatial_streams
);
2212 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2213 struct ath10k_vif
*arvif
,
2214 struct ieee80211_sta
*sta
)
2220 lockdep_assert_held(&ar
->conf_mutex
);
2222 if (sta
->wme
&& sta
->uapsd_queues
) {
2223 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2224 sta
->uapsd_queues
, sta
->max_sp
);
2226 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2227 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2228 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2229 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2230 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2231 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2232 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2233 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2234 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2235 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2236 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2237 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2239 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2240 max_sp
= sta
->max_sp
;
2242 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2244 WMI_AP_PS_PEER_PARAM_UAPSD
,
2247 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2248 arvif
->vdev_id
, ret
);
2252 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2254 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2257 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2258 arvif
->vdev_id
, ret
);
2262 /* TODO setup this based on STA listen interval and
2263 beacon interval. Currently we don't know
2264 sta->listen_interval - mac80211 patch required.
2265 Currently use 10 seconds */
2266 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2267 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2270 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2271 arvif
->vdev_id
, ret
);
2280 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set
,
2281 const u16 vht_mcs_limit
[NL80211_VHT_NSS_MAX
])
2288 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
2289 mcs_map
= ath10k_mac_get_max_vht_mcs_map(tx_mcs_set
, nss
) &
2293 idx_limit
= fls(mcs_map
) - 1;
2297 switch (idx_limit
) {
2298 case 0: /* fall through */
2299 case 1: /* fall through */
2300 case 2: /* fall through */
2301 case 3: /* fall through */
2302 case 4: /* fall through */
2303 case 5: /* fall through */
2304 case 6: /* fall through */
2306 /* see ath10k_mac_can_set_bitrate_mask() */
2310 mcs
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
2313 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_7
;
2316 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_8
;
2319 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_9
;
2323 tx_mcs_set
&= ~(0x3 << (nss
* 2));
2324 tx_mcs_set
|= mcs
<< (nss
* 2);
2330 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2331 struct ieee80211_vif
*vif
,
2332 struct ieee80211_sta
*sta
,
2333 struct wmi_peer_assoc_complete_arg
*arg
)
2335 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
2336 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2337 struct cfg80211_chan_def def
;
2338 enum ieee80211_band band
;
2339 const u16
*vht_mcs_mask
;
2342 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2345 if (!vht_cap
->vht_supported
)
2348 band
= def
.chan
->band
;
2349 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2351 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2354 arg
->peer_flags
|= WMI_PEER_VHT
;
2356 if (def
.chan
->band
== IEEE80211_BAND_2GHZ
)
2357 arg
->peer_flags
|= WMI_PEER_VHT_2G
;
2359 arg
->peer_vht_caps
= vht_cap
->cap
;
2361 ampdu_factor
= (vht_cap
->cap
&
2362 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2363 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2365 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2366 * zero in VHT IE. Using it would result in degraded throughput.
2367 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2368 * it if VHT max_mpdu is smaller. */
2369 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2370 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2371 ampdu_factor
)) - 1);
2373 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2374 arg
->peer_flags
|= WMI_PEER_80MHZ
;
2376 arg
->peer_vht_rates
.rx_max_rate
=
2377 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2378 arg
->peer_vht_rates
.rx_mcs_set
=
2379 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2380 arg
->peer_vht_rates
.tx_max_rate
=
2381 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2382 arg
->peer_vht_rates
.tx_mcs_set
= ath10k_peer_assoc_h_vht_limit(
2383 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
), vht_mcs_mask
);
2385 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2386 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
2389 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2390 struct ieee80211_vif
*vif
,
2391 struct ieee80211_sta
*sta
,
2392 struct wmi_peer_assoc_complete_arg
*arg
)
2394 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2396 switch (arvif
->vdev_type
) {
2397 case WMI_VDEV_TYPE_AP
:
2399 arg
->peer_flags
|= WMI_PEER_QOS
;
2401 if (sta
->wme
&& sta
->uapsd_queues
) {
2402 arg
->peer_flags
|= WMI_PEER_APSD
;
2403 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2406 case WMI_VDEV_TYPE_STA
:
2407 if (vif
->bss_conf
.qos
)
2408 arg
->peer_flags
|= WMI_PEER_QOS
;
2410 case WMI_VDEV_TYPE_IBSS
:
2412 arg
->peer_flags
|= WMI_PEER_QOS
;
2418 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2419 sta
->addr
, !!(arg
->peer_flags
& WMI_PEER_QOS
));
2422 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2424 return sta
->supp_rates
[IEEE80211_BAND_2GHZ
] >>
2425 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2428 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2429 struct ieee80211_vif
*vif
,
2430 struct ieee80211_sta
*sta
,
2431 struct wmi_peer_assoc_complete_arg
*arg
)
2433 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2434 struct cfg80211_chan_def def
;
2435 enum ieee80211_band band
;
2436 const u8
*ht_mcs_mask
;
2437 const u16
*vht_mcs_mask
;
2438 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2440 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2443 band
= def
.chan
->band
;
2444 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2445 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2448 case IEEE80211_BAND_2GHZ
:
2449 if (sta
->vht_cap
.vht_supported
&&
2450 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2451 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2452 phymode
= MODE_11AC_VHT40
;
2454 phymode
= MODE_11AC_VHT20
;
2455 } else if (sta
->ht_cap
.ht_supported
&&
2456 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2457 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2458 phymode
= MODE_11NG_HT40
;
2460 phymode
= MODE_11NG_HT20
;
2461 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2468 case IEEE80211_BAND_5GHZ
:
2472 if (sta
->vht_cap
.vht_supported
&&
2473 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2474 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2475 phymode
= MODE_11AC_VHT80
;
2476 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2477 phymode
= MODE_11AC_VHT40
;
2478 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2479 phymode
= MODE_11AC_VHT20
;
2480 } else if (sta
->ht_cap
.ht_supported
&&
2481 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2482 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
)
2483 phymode
= MODE_11NA_HT40
;
2485 phymode
= MODE_11NA_HT20
;
2495 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2496 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2498 arg
->peer_phymode
= phymode
;
2499 WARN_ON(phymode
== MODE_UNKNOWN
);
2502 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2503 struct ieee80211_vif
*vif
,
2504 struct ieee80211_sta
*sta
,
2505 struct wmi_peer_assoc_complete_arg
*arg
)
2507 lockdep_assert_held(&ar
->conf_mutex
);
2509 memset(arg
, 0, sizeof(*arg
));
2511 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2512 ath10k_peer_assoc_h_crypto(ar
, vif
, arg
);
2513 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2514 ath10k_peer_assoc_h_ht(ar
, vif
, sta
, arg
);
2515 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2516 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2517 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2522 static const u32 ath10k_smps_map
[] = {
2523 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2524 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2525 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2526 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2529 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2531 const struct ieee80211_sta_ht_cap
*ht_cap
)
2535 if (!ht_cap
->ht_supported
)
2538 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2539 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2541 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2544 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2545 WMI_PEER_SMPS_STATE
,
2546 ath10k_smps_map
[smps
]);
2549 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2550 struct ieee80211_vif
*vif
,
2551 struct ieee80211_sta_vht_cap vht_cap
)
2553 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2558 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_AFTER_ASSOC
)
2561 if (!(ar
->vht_cap_info
&
2562 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2563 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2564 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2565 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2568 param
= ar
->wmi
.vdev_param
->txbf
;
2571 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2574 /* The following logic is correct. If a remote STA advertises support
2575 * for being a beamformer then we should enable us being a beamformee.
2578 if (ar
->vht_cap_info
&
2579 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2580 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2581 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2582 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2584 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2585 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2588 if (ar
->vht_cap_info
&
2589 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2590 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2591 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2592 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2594 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2595 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2598 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2599 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2601 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2602 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2604 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2606 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2614 /* can be called only in mac80211 callbacks due to `key_count` usage */
2615 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2616 struct ieee80211_vif
*vif
,
2617 struct ieee80211_bss_conf
*bss_conf
)
2619 struct ath10k
*ar
= hw
->priv
;
2620 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2621 struct ieee80211_sta_ht_cap ht_cap
;
2622 struct ieee80211_sta_vht_cap vht_cap
;
2623 struct wmi_peer_assoc_complete_arg peer_arg
;
2624 struct ieee80211_sta
*ap_sta
;
2627 lockdep_assert_held(&ar
->conf_mutex
);
2629 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2630 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2634 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2636 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2637 bss_conf
->bssid
, arvif
->vdev_id
);
2642 /* ap_sta must be accessed only within rcu section which must be left
2643 * before calling ath10k_setup_peer_smps() which might sleep. */
2644 ht_cap
= ap_sta
->ht_cap
;
2645 vht_cap
= ap_sta
->vht_cap
;
2647 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2649 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2650 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2657 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2659 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2660 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2664 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2666 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2667 arvif
->vdev_id
, ret
);
2671 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2673 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2674 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2678 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2679 "mac vdev %d up (associated) bssid %pM aid %d\n",
2680 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2682 WARN_ON(arvif
->is_up
);
2684 arvif
->aid
= bss_conf
->aid
;
2685 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2687 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2689 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2690 arvif
->vdev_id
, ret
);
2694 arvif
->is_up
= true;
2696 /* Workaround: Some firmware revisions (tested with qca6174
2697 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2698 * poked with peer param command.
2700 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2701 WMI_PEER_DUMMY_VAR
, 1);
2703 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2704 arvif
->bssid
, arvif
->vdev_id
, ret
);
2709 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2710 struct ieee80211_vif
*vif
)
2712 struct ath10k
*ar
= hw
->priv
;
2713 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2714 struct ieee80211_sta_vht_cap vht_cap
= {};
2717 lockdep_assert_held(&ar
->conf_mutex
);
2719 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2720 arvif
->vdev_id
, arvif
->bssid
);
2722 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2724 ath10k_warn(ar
, "faield to down vdev %i: %d\n",
2725 arvif
->vdev_id
, ret
);
2727 arvif
->def_wep_key_idx
= -1;
2729 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2731 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2732 arvif
->vdev_id
, ret
);
2736 arvif
->is_up
= false;
2738 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
2741 static int ath10k_station_assoc(struct ath10k
*ar
,
2742 struct ieee80211_vif
*vif
,
2743 struct ieee80211_sta
*sta
,
2746 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2747 struct wmi_peer_assoc_complete_arg peer_arg
;
2750 lockdep_assert_held(&ar
->conf_mutex
);
2752 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2754 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2755 sta
->addr
, arvif
->vdev_id
, ret
);
2759 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2761 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2762 sta
->addr
, arvif
->vdev_id
, ret
);
2766 /* Re-assoc is run only to update supported rates for given station. It
2767 * doesn't make much sense to reconfigure the peer completely.
2770 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
2773 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
2774 arvif
->vdev_id
, ret
);
2778 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
2780 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
2781 sta
->addr
, arvif
->vdev_id
, ret
);
2786 arvif
->num_legacy_stations
++;
2787 ret
= ath10k_recalc_rtscts_prot(arvif
);
2789 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2790 arvif
->vdev_id
, ret
);
2795 /* Plumb cached keys only for static WEP */
2796 if (arvif
->def_wep_key_idx
!= -1) {
2797 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
2799 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
2800 arvif
->vdev_id
, ret
);
2809 static int ath10k_station_disassoc(struct ath10k
*ar
,
2810 struct ieee80211_vif
*vif
,
2811 struct ieee80211_sta
*sta
)
2813 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2816 lockdep_assert_held(&ar
->conf_mutex
);
2819 arvif
->num_legacy_stations
--;
2820 ret
= ath10k_recalc_rtscts_prot(arvif
);
2822 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2823 arvif
->vdev_id
, ret
);
2828 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
2830 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
2831 arvif
->vdev_id
, ret
);
2842 static int ath10k_update_channel_list(struct ath10k
*ar
)
2844 struct ieee80211_hw
*hw
= ar
->hw
;
2845 struct ieee80211_supported_band
**bands
;
2846 enum ieee80211_band band
;
2847 struct ieee80211_channel
*channel
;
2848 struct wmi_scan_chan_list_arg arg
= {0};
2849 struct wmi_channel_arg
*ch
;
2855 lockdep_assert_held(&ar
->conf_mutex
);
2857 bands
= hw
->wiphy
->bands
;
2858 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2862 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2863 if (bands
[band
]->channels
[i
].flags
&
2864 IEEE80211_CHAN_DISABLED
)
2871 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
2872 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
2877 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2881 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
2882 channel
= &bands
[band
]->channels
[i
];
2884 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
2887 ch
->allow_ht
= true;
2889 /* FIXME: when should we really allow VHT? */
2890 ch
->allow_vht
= true;
2893 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
2896 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
2899 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
2901 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
2902 ch
->passive
= passive
;
2904 ch
->freq
= channel
->center_freq
;
2905 ch
->band_center_freq1
= channel
->center_freq
;
2907 ch
->max_power
= channel
->max_power
* 2;
2908 ch
->max_reg_power
= channel
->max_reg_power
* 2;
2909 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
2910 ch
->reg_class_id
= 0; /* FIXME */
2912 /* FIXME: why use only legacy modes, why not any
2913 * HT/VHT modes? Would that even make any
2915 if (channel
->band
== IEEE80211_BAND_2GHZ
)
2916 ch
->mode
= MODE_11G
;
2918 ch
->mode
= MODE_11A
;
2920 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
2923 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
2924 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2925 ch
- arg
.channels
, arg
.n_channels
,
2926 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
2927 ch
->max_antenna_gain
, ch
->mode
);
2933 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
2934 kfree(arg
.channels
);
2939 static enum wmi_dfs_region
2940 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
2942 switch (dfs_region
) {
2943 case NL80211_DFS_UNSET
:
2944 return WMI_UNINIT_DFS_DOMAIN
;
2945 case NL80211_DFS_FCC
:
2946 return WMI_FCC_DFS_DOMAIN
;
2947 case NL80211_DFS_ETSI
:
2948 return WMI_ETSI_DFS_DOMAIN
;
2949 case NL80211_DFS_JP
:
2950 return WMI_MKK4_DFS_DOMAIN
;
2952 return WMI_UNINIT_DFS_DOMAIN
;
2955 static void ath10k_regd_update(struct ath10k
*ar
)
2957 struct reg_dmn_pair_mapping
*regpair
;
2959 enum wmi_dfs_region wmi_dfs_reg
;
2960 enum nl80211_dfs_regions nl_dfs_reg
;
2962 lockdep_assert_held(&ar
->conf_mutex
);
2964 ret
= ath10k_update_channel_list(ar
);
2966 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
2968 regpair
= ar
->ath_common
.regulatory
.regpair
;
2970 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
2971 nl_dfs_reg
= ar
->dfs_detector
->region
;
2972 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
2974 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
2977 /* Target allows setting up per-band regdomain but ath_common provides
2978 * a combined one only */
2979 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
2980 regpair
->reg_domain
,
2981 regpair
->reg_domain
, /* 2ghz */
2982 regpair
->reg_domain
, /* 5ghz */
2983 regpair
->reg_2ghz_ctl
,
2984 regpair
->reg_5ghz_ctl
,
2987 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
2990 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
2991 struct regulatory_request
*request
)
2993 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
2994 struct ath10k
*ar
= hw
->priv
;
2997 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
2999 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3000 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
3001 request
->dfs_region
);
3002 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
3003 request
->dfs_region
);
3005 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3006 request
->dfs_region
);
3009 mutex_lock(&ar
->conf_mutex
);
3010 if (ar
->state
== ATH10K_STATE_ON
)
3011 ath10k_regd_update(ar
);
3012 mutex_unlock(&ar
->conf_mutex
);
3019 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
3021 lockdep_assert_held(&ar
->htt
.tx_lock
);
3023 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3024 ar
->tx_paused
|= BIT(reason
);
3025 ieee80211_stop_queues(ar
->hw
);
3028 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
3029 struct ieee80211_vif
*vif
)
3031 struct ath10k
*ar
= data
;
3032 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3034 if (arvif
->tx_paused
)
3037 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3040 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
3042 lockdep_assert_held(&ar
->htt
.tx_lock
);
3044 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3045 ar
->tx_paused
&= ~BIT(reason
);
3050 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3051 IEEE80211_IFACE_ITER_RESUME_ALL
,
3052 ath10k_mac_tx_unlock_iter
,
3055 ieee80211_wake_queue(ar
->hw
, ar
->hw
->offchannel_tx_hw_queue
);
3058 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
3060 struct ath10k
*ar
= arvif
->ar
;
3062 lockdep_assert_held(&ar
->htt
.tx_lock
);
3064 WARN_ON(reason
>= BITS_PER_LONG
);
3065 arvif
->tx_paused
|= BIT(reason
);
3066 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
3069 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
3071 struct ath10k
*ar
= arvif
->ar
;
3073 lockdep_assert_held(&ar
->htt
.tx_lock
);
3075 WARN_ON(reason
>= BITS_PER_LONG
);
3076 arvif
->tx_paused
&= ~BIT(reason
);
3081 if (arvif
->tx_paused
)
3084 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3087 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
3088 enum wmi_tlv_tx_pause_id pause_id
,
3089 enum wmi_tlv_tx_pause_action action
)
3091 struct ath10k
*ar
= arvif
->ar
;
3093 lockdep_assert_held(&ar
->htt
.tx_lock
);
3096 case WMI_TLV_TX_PAUSE_ACTION_STOP
:
3097 ath10k_mac_vif_tx_lock(arvif
, pause_id
);
3099 case WMI_TLV_TX_PAUSE_ACTION_WAKE
:
3100 ath10k_mac_vif_tx_unlock(arvif
, pause_id
);
3103 ath10k_warn(ar
, "received unknown tx pause action %d on vdev %i, ignoring\n",
3104 action
, arvif
->vdev_id
);
3109 struct ath10k_mac_tx_pause
{
3111 enum wmi_tlv_tx_pause_id pause_id
;
3112 enum wmi_tlv_tx_pause_action action
;
3115 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
3116 struct ieee80211_vif
*vif
)
3118 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3119 struct ath10k_mac_tx_pause
*arg
= data
;
3121 if (arvif
->vdev_id
!= arg
->vdev_id
)
3124 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
3127 void ath10k_mac_handle_tx_pause_vdev(struct ath10k
*ar
, u32 vdev_id
,
3128 enum wmi_tlv_tx_pause_id pause_id
,
3129 enum wmi_tlv_tx_pause_action action
)
3131 struct ath10k_mac_tx_pause arg
= {
3133 .pause_id
= pause_id
,
3137 spin_lock_bh(&ar
->htt
.tx_lock
);
3138 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3139 IEEE80211_IFACE_ITER_RESUME_ALL
,
3140 ath10k_mac_handle_tx_pause_iter
,
3142 spin_unlock_bh(&ar
->htt
.tx_lock
);
3145 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
3147 if (ieee80211_is_mgmt(hdr
->frame_control
))
3148 return HTT_DATA_TX_EXT_TID_MGMT
;
3150 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3151 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3153 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
3154 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3156 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
3159 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
3162 return ath10k_vif_to_arvif(vif
)->vdev_id
;
3164 if (ar
->monitor_started
)
3165 return ar
->monitor_vdev_id
;
3167 ath10k_warn(ar
, "failed to resolve vdev id\n");
3171 static enum ath10k_hw_txrx_mode
3172 ath10k_tx_h_get_txmode(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
3173 struct ieee80211_sta
*sta
, struct sk_buff
*skb
)
3175 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3176 __le16 fc
= hdr
->frame_control
;
3178 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3179 return ATH10K_HW_TXRX_RAW
;
3181 if (ieee80211_is_mgmt(fc
))
3182 return ATH10K_HW_TXRX_MGMT
;
3186 * NullFunc frames are mostly used to ping if a client or AP are still
3187 * reachable and responsive. This implies tx status reports must be
3188 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3189 * come to a conclusion that the other end disappeared and tear down
3190 * BSS connection or it can never disconnect from BSS/client (which is
3193 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3194 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3195 * which seems to deliver correct tx reports for NullFunc frames. The
3196 * downside of using it is it ignores client powersave state so it can
3197 * end up disconnecting sleeping clients in AP mode. It should fix STA
3198 * mode though because AP don't sleep.
3200 if (ar
->htt
.target_version_major
< 3 &&
3201 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3202 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
, ar
->fw_features
))
3203 return ATH10K_HW_TXRX_MGMT
;
3207 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3208 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3209 * to work with Ethernet txmode so use it.
3211 * FIXME: Check if raw mode works with TDLS.
3213 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3214 return ATH10K_HW_TXRX_ETHERNET
;
3216 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
3217 return ATH10K_HW_TXRX_RAW
;
3219 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3222 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif
*vif
,
3223 struct sk_buff
*skb
) {
3224 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3225 const u32 mask
= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
3226 IEEE80211_TX_CTL_INJECTED
;
3227 if ((info
->flags
& mask
) == mask
)
3230 return !ath10k_vif_to_arvif(vif
)->nohwcrypt
;
3234 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3235 * Control in the header.
3237 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3239 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3240 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3243 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3246 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3247 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3248 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3249 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3251 /* Some firmware revisions don't handle sending QoS NullFunc well.
3252 * These frames are mainly used for CQM purposes so it doesn't really
3253 * matter whether QoS NullFunc or NullFunc are sent.
3255 hdr
= (void *)skb
->data
;
3256 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3257 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
3259 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3262 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3264 struct ieee80211_hdr
*hdr
;
3265 struct rfc1042_hdr
*rfc1042
;
3272 hdr
= (void *)skb
->data
;
3273 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3274 rfc1042
= (void *)skb
->data
+ hdrlen
;
3276 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3277 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3278 type
= rfc1042
->snap_type
;
3280 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3281 skb_push(skb
, sizeof(*eth
));
3283 eth
= (void *)skb
->data
;
3284 ether_addr_copy(eth
->h_dest
, da
);
3285 ether_addr_copy(eth
->h_source
, sa
);
3286 eth
->h_proto
= type
;
3289 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3290 struct ieee80211_vif
*vif
,
3291 struct sk_buff
*skb
)
3293 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3294 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3296 /* This is case only for P2P_GO */
3297 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
3298 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
3301 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3302 spin_lock_bh(&ar
->data_lock
);
3303 if (arvif
->u
.ap
.noa_data
)
3304 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3306 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
3307 arvif
->u
.ap
.noa_data
,
3308 arvif
->u
.ap
.noa_len
);
3309 spin_unlock_bh(&ar
->data_lock
);
3313 static bool ath10k_mac_need_offchan_tx_work(struct ath10k
*ar
)
3315 /* FIXME: Not really sure since when the behaviour changed. At some
3316 * point new firmware stopped requiring creation of peer entries for
3317 * offchannel tx (and actually creating them causes issues with wmi-htc
3318 * tx credit replenishment and reliability). Assuming it's at least 3.4
3319 * because that's when the `freq` was introduced to TX_FRM HTT command.
3321 return !(ar
->htt
.target_version_major
>= 3 &&
3322 ar
->htt
.target_version_minor
>= 4);
3325 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3327 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3330 spin_lock_bh(&ar
->data_lock
);
3332 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
3333 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3338 __skb_queue_tail(q
, skb
);
3339 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3342 spin_unlock_bh(&ar
->data_lock
);
3347 static void ath10k_mac_tx(struct ath10k
*ar
, struct sk_buff
*skb
)
3349 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3350 struct ath10k_htt
*htt
= &ar
->htt
;
3353 switch (cb
->txmode
) {
3354 case ATH10K_HW_TXRX_RAW
:
3355 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3356 case ATH10K_HW_TXRX_ETHERNET
:
3357 ret
= ath10k_htt_tx(htt
, skb
);
3359 case ATH10K_HW_TXRX_MGMT
:
3360 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3362 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
3363 else if (ar
->htt
.target_version_major
>= 3)
3364 ret
= ath10k_htt_tx(htt
, skb
);
3366 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
3371 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
3373 ieee80211_free_txskb(ar
->hw
, skb
);
3377 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
3379 struct sk_buff
*skb
;
3382 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3386 ieee80211_free_txskb(ar
->hw
, skb
);
3390 void ath10k_offchan_tx_work(struct work_struct
*work
)
3392 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
3393 struct ath10k_peer
*peer
;
3394 struct ieee80211_hdr
*hdr
;
3395 struct sk_buff
*skb
;
3396 const u8
*peer_addr
;
3399 unsigned long time_left
;
3400 bool tmp_peer_created
= false;
3402 /* FW requirement: We must create a peer before FW will send out
3403 * an offchannel frame. Otherwise the frame will be stuck and
3404 * never transmitted. We delete the peer upon tx completion.
3405 * It is unlikely that a peer for offchannel tx will already be
3406 * present. However it may be in some rare cases so account for that.
3407 * Otherwise we might remove a legitimate peer and break stuff. */
3410 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3414 mutex_lock(&ar
->conf_mutex
);
3416 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
3419 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3420 peer_addr
= ieee80211_get_DA(hdr
);
3421 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
3423 spin_lock_bh(&ar
->data_lock
);
3424 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
3425 spin_unlock_bh(&ar
->data_lock
);
3428 /* FIXME: should this use ath10k_warn()? */
3429 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
3430 peer_addr
, vdev_id
);
3433 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
,
3434 WMI_PEER_TYPE_DEFAULT
);
3436 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
3437 peer_addr
, vdev_id
, ret
);
3438 tmp_peer_created
= (ret
== 0);
3441 spin_lock_bh(&ar
->data_lock
);
3442 reinit_completion(&ar
->offchan_tx_completed
);
3443 ar
->offchan_tx_skb
= skb
;
3444 spin_unlock_bh(&ar
->data_lock
);
3446 ath10k_mac_tx(ar
, skb
);
3449 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
3451 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
3454 if (!peer
&& tmp_peer_created
) {
3455 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
3457 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
3458 peer_addr
, vdev_id
, ret
);
3461 mutex_unlock(&ar
->conf_mutex
);
3465 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
3467 struct sk_buff
*skb
;
3470 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3474 ieee80211_free_txskb(ar
->hw
, skb
);
3478 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
3480 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
3481 struct sk_buff
*skb
;
3485 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3489 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
3491 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
3493 ieee80211_free_txskb(ar
->hw
, skb
);
3502 void __ath10k_scan_finish(struct ath10k
*ar
)
3504 lockdep_assert_held(&ar
->data_lock
);
3506 switch (ar
->scan
.state
) {
3507 case ATH10K_SCAN_IDLE
:
3509 case ATH10K_SCAN_RUNNING
:
3510 case ATH10K_SCAN_ABORTING
:
3511 if (!ar
->scan
.is_roc
)
3512 ieee80211_scan_completed(ar
->hw
,
3514 ATH10K_SCAN_ABORTING
));
3515 else if (ar
->scan
.roc_notify
)
3516 ieee80211_remain_on_channel_expired(ar
->hw
);
3518 case ATH10K_SCAN_STARTING
:
3519 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3520 ar
->scan_channel
= NULL
;
3521 ath10k_offchan_tx_purge(ar
);
3522 cancel_delayed_work(&ar
->scan
.timeout
);
3523 complete_all(&ar
->scan
.completed
);
3528 void ath10k_scan_finish(struct ath10k
*ar
)
3530 spin_lock_bh(&ar
->data_lock
);
3531 __ath10k_scan_finish(ar
);
3532 spin_unlock_bh(&ar
->data_lock
);
3535 static int ath10k_scan_stop(struct ath10k
*ar
)
3537 struct wmi_stop_scan_arg arg
= {
3538 .req_id
= 1, /* FIXME */
3539 .req_type
= WMI_SCAN_STOP_ONE
,
3540 .u
.scan_id
= ATH10K_SCAN_ID
,
3544 lockdep_assert_held(&ar
->conf_mutex
);
3546 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
3548 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
3552 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
3554 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
3556 } else if (ret
> 0) {
3561 /* Scan state should be updated upon scan completion but in case
3562 * firmware fails to deliver the event (for whatever reason) it is
3563 * desired to clean up scan state anyway. Firmware may have just
3564 * dropped the scan completion event delivery due to transport pipe
3565 * being overflown with data and/or it can recover on its own before
3566 * next scan request is submitted.
3568 spin_lock_bh(&ar
->data_lock
);
3569 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
3570 __ath10k_scan_finish(ar
);
3571 spin_unlock_bh(&ar
->data_lock
);
3576 static void ath10k_scan_abort(struct ath10k
*ar
)
3580 lockdep_assert_held(&ar
->conf_mutex
);
3582 spin_lock_bh(&ar
->data_lock
);
3584 switch (ar
->scan
.state
) {
3585 case ATH10K_SCAN_IDLE
:
3586 /* This can happen if timeout worker kicked in and called
3587 * abortion while scan completion was being processed.
3590 case ATH10K_SCAN_STARTING
:
3591 case ATH10K_SCAN_ABORTING
:
3592 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3593 ath10k_scan_state_str(ar
->scan
.state
),
3596 case ATH10K_SCAN_RUNNING
:
3597 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
3598 spin_unlock_bh(&ar
->data_lock
);
3600 ret
= ath10k_scan_stop(ar
);
3602 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
3604 spin_lock_bh(&ar
->data_lock
);
3608 spin_unlock_bh(&ar
->data_lock
);
3611 void ath10k_scan_timeout_work(struct work_struct
*work
)
3613 struct ath10k
*ar
= container_of(work
, struct ath10k
,
3616 mutex_lock(&ar
->conf_mutex
);
3617 ath10k_scan_abort(ar
);
3618 mutex_unlock(&ar
->conf_mutex
);
3621 static int ath10k_start_scan(struct ath10k
*ar
,
3622 const struct wmi_start_scan_arg
*arg
)
3626 lockdep_assert_held(&ar
->conf_mutex
);
3628 ret
= ath10k_wmi_start_scan(ar
, arg
);
3632 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
3634 ret
= ath10k_scan_stop(ar
);
3636 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
3641 /* If we failed to start the scan, return error code at
3642 * this point. This is probably due to some issue in the
3643 * firmware, but no need to wedge the driver due to that...
3645 spin_lock_bh(&ar
->data_lock
);
3646 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
3647 spin_unlock_bh(&ar
->data_lock
);
3650 spin_unlock_bh(&ar
->data_lock
);
3655 /**********************/
3656 /* mac80211 callbacks */
3657 /**********************/
3659 static void ath10k_tx(struct ieee80211_hw
*hw
,
3660 struct ieee80211_tx_control
*control
,
3661 struct sk_buff
*skb
)
3663 struct ath10k
*ar
= hw
->priv
;
3664 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3665 struct ieee80211_vif
*vif
= info
->control
.vif
;
3666 struct ieee80211_sta
*sta
= control
->sta
;
3667 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3668 __le16 fc
= hdr
->frame_control
;
3670 /* We should disable CCK RATE due to P2P */
3671 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3672 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3674 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
3675 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3676 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
3677 ATH10K_SKB_CB(skb
)->htt
.nohwcrypt
= !ath10k_tx_h_use_hwcrypto(vif
, skb
);
3678 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
3679 ATH10K_SKB_CB(skb
)->txmode
= ath10k_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3680 ATH10K_SKB_CB(skb
)->is_protected
= ieee80211_has_protected(fc
);
3682 switch (ATH10K_SKB_CB(skb
)->txmode
) {
3683 case ATH10K_HW_TXRX_MGMT
:
3684 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3685 ath10k_tx_h_nwifi(hw
, skb
);
3686 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3687 ath10k_tx_h_seq_no(vif
, skb
);
3689 case ATH10K_HW_TXRX_ETHERNET
:
3690 ath10k_tx_h_8023(skb
);
3692 case ATH10K_HW_TXRX_RAW
:
3693 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
3695 ieee80211_free_txskb(hw
, skb
);
3700 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3701 spin_lock_bh(&ar
->data_lock
);
3702 ATH10K_SKB_CB(skb
)->htt
.freq
= ar
->scan
.roc_freq
;
3703 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
3704 spin_unlock_bh(&ar
->data_lock
);
3706 if (ath10k_mac_need_offchan_tx_work(ar
)) {
3707 ATH10K_SKB_CB(skb
)->htt
.freq
= 0;
3708 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
3710 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
3713 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3714 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3719 ath10k_mac_tx(ar
, skb
);
3722 /* Must not be called with conf_mutex held as workers can use that also. */
3723 void ath10k_drain_tx(struct ath10k
*ar
)
3725 /* make sure rcu-protected mac80211 tx path itself is drained */
3728 ath10k_offchan_tx_purge(ar
);
3729 ath10k_mgmt_over_wmi_tx_purge(ar
);
3731 cancel_work_sync(&ar
->offchan_tx_work
);
3732 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
3735 void ath10k_halt(struct ath10k
*ar
)
3737 struct ath10k_vif
*arvif
;
3739 lockdep_assert_held(&ar
->conf_mutex
);
3741 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
3742 ar
->filter_flags
= 0;
3743 ar
->monitor
= false;
3744 ar
->monitor_arvif
= NULL
;
3746 if (ar
->monitor_started
)
3747 ath10k_monitor_stop(ar
);
3749 ar
->monitor_started
= false;
3752 ath10k_scan_finish(ar
);
3753 ath10k_peer_cleanup_all(ar
);
3754 ath10k_core_stop(ar
);
3755 ath10k_hif_power_down(ar
);
3757 spin_lock_bh(&ar
->data_lock
);
3758 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
3759 ath10k_mac_vif_beacon_cleanup(arvif
);
3760 spin_unlock_bh(&ar
->data_lock
);
3763 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
3765 struct ath10k
*ar
= hw
->priv
;
3767 mutex_lock(&ar
->conf_mutex
);
3769 *tx_ant
= ar
->cfg_tx_chainmask
;
3770 *rx_ant
= ar
->cfg_rx_chainmask
;
3772 mutex_unlock(&ar
->conf_mutex
);
3777 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
3779 /* It is not clear that allowing gaps in chainmask
3780 * is helpful. Probably it will not do what user
3781 * is hoping for, so warn in that case.
3783 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
3786 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3790 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k
*ar
)
3792 int nsts
= ar
->vht_cap_info
;
3794 nsts
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
3795 nsts
>>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
3797 /* If firmware does not deliver to host number of space-time
3798 * streams supported, assume it support up to 4 BF STS and return
3799 * the value for VHT CAP: nsts-1)
3807 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k
*ar
)
3809 int sound_dim
= ar
->vht_cap_info
;
3811 sound_dim
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
3812 sound_dim
>>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
3814 /* If the sounding dimension is not advertised by the firmware,
3815 * let's use a default value of 1
3823 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
3825 struct ieee80211_sta_vht_cap vht_cap
= {0};
3830 vht_cap
.vht_supported
= 1;
3831 vht_cap
.cap
= ar
->vht_cap_info
;
3833 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
3834 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
3835 val
= ath10k_mac_get_vht_cap_bf_sts(ar
);
3836 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
3837 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
3842 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
3843 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
3844 val
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
3845 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
3846 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
3852 for (i
= 0; i
< 8; i
++) {
3853 if ((i
< ar
->num_rf_chains
) && (ar
->cfg_tx_chainmask
& BIT(i
)))
3854 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
* 2);
3856 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
* 2);
3859 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
3860 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
3865 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
3868 struct ieee80211_sta_ht_cap ht_cap
= {0};
3870 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
3873 ht_cap
.ht_supported
= 1;
3874 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
3875 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
3876 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
3877 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
3878 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
3880 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
3881 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
3883 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
3884 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
3886 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
3889 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
3890 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
3895 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
3896 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
3898 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
3901 stbc
= ar
->ht_cap_info
;
3902 stbc
&= WMI_HT_CAP_RX_STBC
;
3903 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
3904 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
3905 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
3910 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
3911 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
3913 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
3914 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
3916 /* max AMSDU is implicitly taken from vht_cap_info */
3917 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
3918 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
3920 for (i
= 0; i
< ar
->num_rf_chains
; i
++) {
3921 if (ar
->cfg_rx_chainmask
& BIT(i
))
3922 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
3925 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
3930 static void ath10k_mac_setup_ht_vht_cap(struct ath10k
*ar
)
3932 struct ieee80211_supported_band
*band
;
3933 struct ieee80211_sta_vht_cap vht_cap
;
3934 struct ieee80211_sta_ht_cap ht_cap
;
3936 ht_cap
= ath10k_get_ht_cap(ar
);
3937 vht_cap
= ath10k_create_vht_cap(ar
);
3939 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
3940 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
3941 band
->ht_cap
= ht_cap
;
3943 /* Enable the VHT support at 2.4 GHz */
3944 band
->vht_cap
= vht_cap
;
3946 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
3947 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
3948 band
->ht_cap
= ht_cap
;
3949 band
->vht_cap
= vht_cap
;
3953 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
3957 lockdep_assert_held(&ar
->conf_mutex
);
3959 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
3960 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
3962 ar
->cfg_tx_chainmask
= tx_ant
;
3963 ar
->cfg_rx_chainmask
= rx_ant
;
3965 if ((ar
->state
!= ATH10K_STATE_ON
) &&
3966 (ar
->state
!= ATH10K_STATE_RESTARTED
))
3969 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
3972 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
3977 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
3980 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
3985 /* Reload HT/VHT capability */
3986 ath10k_mac_setup_ht_vht_cap(ar
);
3991 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
3993 struct ath10k
*ar
= hw
->priv
;
3996 mutex_lock(&ar
->conf_mutex
);
3997 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
3998 mutex_unlock(&ar
->conf_mutex
);
4002 static int ath10k_start(struct ieee80211_hw
*hw
)
4004 struct ath10k
*ar
= hw
->priv
;
4009 * This makes sense only when restarting hw. It is harmless to call
4010 * uncoditionally. This is necessary to make sure no HTT/WMI tx
4011 * commands will be submitted while restarting.
4013 ath10k_drain_tx(ar
);
4015 mutex_lock(&ar
->conf_mutex
);
4017 switch (ar
->state
) {
4018 case ATH10K_STATE_OFF
:
4019 ar
->state
= ATH10K_STATE_ON
;
4021 case ATH10K_STATE_RESTARTING
:
4023 ar
->state
= ATH10K_STATE_RESTARTED
;
4025 case ATH10K_STATE_ON
:
4026 case ATH10K_STATE_RESTARTED
:
4027 case ATH10K_STATE_WEDGED
:
4031 case ATH10K_STATE_UTF
:
4036 ret
= ath10k_hif_power_up(ar
);
4038 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
4042 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
4044 ath10k_err(ar
, "Could not init core: %d\n", ret
);
4045 goto err_power_down
;
4048 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
4050 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
4054 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
4056 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
4060 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
4061 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
4063 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
4069 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
4070 burst_enable
= ar
->wmi
.pdev_param
->burst_enable
;
4071 ret
= ath10k_wmi_pdev_set_param(ar
, burst_enable
, 0);
4073 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
4078 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
, ar
->cfg_rx_chainmask
);
4081 * By default FW set ARP frames ac to voice (6). In that case ARP
4082 * exchange is not working properly for UAPSD enabled AP. ARP requests
4083 * which arrives with access category 0 are processed by network stack
4084 * and send back with access category 0, but FW changes access category
4085 * to 6. Set ARP frames access category to best effort (0) solves
4089 ret
= ath10k_wmi_pdev_set_param(ar
,
4090 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
4092 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
4097 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA
,
4099 ret
= ath10k_wmi_pdev_enable_adaptive_cca(ar
, 1,
4100 WMI_CCA_DETECT_LEVEL_AUTO
,
4101 WMI_CCA_DETECT_MARGIN_AUTO
);
4103 ath10k_warn(ar
, "failed to enable adaptive cca: %d\n",
4109 ret
= ath10k_wmi_pdev_set_param(ar
,
4110 ar
->wmi
.pdev_param
->ani_enable
, 1);
4112 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
4117 ar
->ani_enabled
= true;
4119 ar
->num_started_vdevs
= 0;
4120 ath10k_regd_update(ar
);
4122 ath10k_spectral_start(ar
);
4123 ath10k_thermal_set_throttling(ar
);
4125 mutex_unlock(&ar
->conf_mutex
);
4129 ath10k_core_stop(ar
);
4132 ath10k_hif_power_down(ar
);
4135 ar
->state
= ATH10K_STATE_OFF
;
4138 mutex_unlock(&ar
->conf_mutex
);
4142 static void ath10k_stop(struct ieee80211_hw
*hw
)
4144 struct ath10k
*ar
= hw
->priv
;
4146 ath10k_drain_tx(ar
);
4148 mutex_lock(&ar
->conf_mutex
);
4149 if (ar
->state
!= ATH10K_STATE_OFF
) {
4151 ar
->state
= ATH10K_STATE_OFF
;
4153 mutex_unlock(&ar
->conf_mutex
);
4155 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4156 cancel_work_sync(&ar
->restart_work
);
4159 static int ath10k_config_ps(struct ath10k
*ar
)
4161 struct ath10k_vif
*arvif
;
4164 lockdep_assert_held(&ar
->conf_mutex
);
4166 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
4167 ret
= ath10k_mac_vif_setup_ps(arvif
);
4169 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
4177 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
4182 lockdep_assert_held(&ar
->conf_mutex
);
4184 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
4186 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
4187 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
4189 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
4194 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
4195 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
4197 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
4205 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
4207 struct ath10k_vif
*arvif
;
4208 int ret
, txpower
= -1;
4210 lockdep_assert_held(&ar
->conf_mutex
);
4212 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
4213 if (arvif
->txpower
<= 0)
4217 txpower
= arvif
->txpower
;
4219 txpower
= min(txpower
, arvif
->txpower
);
4225 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
4227 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
4235 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
4237 struct ath10k
*ar
= hw
->priv
;
4238 struct ieee80211_conf
*conf
= &hw
->conf
;
4241 mutex_lock(&ar
->conf_mutex
);
4243 if (changed
& IEEE80211_CONF_CHANGE_PS
)
4244 ath10k_config_ps(ar
);
4246 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
4247 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
4248 ret
= ath10k_monitor_recalc(ar
);
4250 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4253 mutex_unlock(&ar
->conf_mutex
);
4257 static u32
get_nss_from_chainmask(u16 chain_mask
)
4259 if ((chain_mask
& 0xf) == 0xf)
4261 else if ((chain_mask
& 0x7) == 0x7)
4263 else if ((chain_mask
& 0x3) == 0x3)
4268 static int ath10k_mac_set_txbf_conf(struct ath10k_vif
*arvif
)
4271 struct ath10k
*ar
= arvif
->ar
;
4275 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_BEFORE_ASSOC
)
4278 nsts
= ath10k_mac_get_vht_cap_bf_sts(ar
);
4279 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
4280 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
))
4281 value
|= SM(nsts
, WMI_TXBF_STS_CAP_OFFSET
);
4283 sound_dim
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
4284 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
4285 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
))
4286 value
|= SM(sound_dim
, WMI_BF_SOUND_DIM_OFFSET
);
4291 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
4292 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
4294 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
4295 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER
|
4296 WMI_VDEV_PARAM_TXBF_SU_TX_BFER
);
4298 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
4299 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
4301 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
4302 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
|
4303 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
);
4305 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
4306 ar
->wmi
.vdev_param
->txbf
, value
);
4311 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4312 * because we will send mgmt frames without CCK. This requirement
4313 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4316 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
4317 struct ieee80211_vif
*vif
)
4319 struct ath10k
*ar
= hw
->priv
;
4320 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4321 enum wmi_sta_powersave_param param
;
4328 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
4330 mutex_lock(&ar
->conf_mutex
);
4332 memset(arvif
, 0, sizeof(*arvif
));
4337 INIT_LIST_HEAD(&arvif
->list
);
4338 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
4339 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
4340 ath10k_mac_vif_sta_connection_loss_work
);
4342 for (i
= 0; i
< ARRAY_SIZE(arvif
->bitrate_mask
.control
); i
++) {
4343 arvif
->bitrate_mask
.control
[i
].legacy
= 0xffffffff;
4344 memset(arvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
4345 sizeof(arvif
->bitrate_mask
.control
[i
].ht_mcs
));
4346 memset(arvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
4347 sizeof(arvif
->bitrate_mask
.control
[i
].vht_mcs
));
4350 if (ar
->num_peers
>= ar
->max_num_peers
) {
4351 ath10k_warn(ar
, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4356 if (ar
->free_vdev_map
== 0) {
4357 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
4361 bit
= __ffs64(ar
->free_vdev_map
);
4363 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
4364 bit
, ar
->free_vdev_map
);
4366 arvif
->vdev_id
= bit
;
4367 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
4369 switch (vif
->type
) {
4370 case NL80211_IFTYPE_P2P_DEVICE
:
4371 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4372 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
4374 case NL80211_IFTYPE_UNSPECIFIED
:
4375 case NL80211_IFTYPE_STATION
:
4376 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
4378 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
4380 case NL80211_IFTYPE_ADHOC
:
4381 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
4383 case NL80211_IFTYPE_MESH_POINT
:
4384 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
4386 ath10k_warn(ar
, "must load driver with rawmode=1 to add mesh interfaces\n");
4389 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
4391 case NL80211_IFTYPE_AP
:
4392 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
4395 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
4397 case NL80211_IFTYPE_MONITOR
:
4398 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
4405 /* Using vdev_id as queue number will make it very easy to do per-vif
4406 * tx queue locking. This shouldn't wrap due to interface combinations
4407 * but do a modulo for correctness sake and prevent using offchannel tx
4408 * queues for regular vif tx.
4410 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4411 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
4412 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
4414 /* Some firmware revisions don't wait for beacon tx completion before
4415 * sending another SWBA event. This could lead to hardware using old
4416 * (freed) beacon data in some cases, e.g. tx credit starvation
4417 * combined with missed TBTT. This is very very rare.
4419 * On non-IOMMU-enabled hosts this could be a possible security issue
4420 * because hw could beacon some random data on the air. On
4421 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4422 * device would crash.
4424 * Since there are no beacon tx completions (implicit nor explicit)
4425 * propagated to host the only workaround for this is to allocate a
4426 * DMA-coherent buffer for a lifetime of a vif and use it for all
4427 * beacon tx commands. Worst case for this approach is some beacons may
4428 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4430 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
4431 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
4432 vif
->type
== NL80211_IFTYPE_AP
) {
4433 arvif
->beacon_buf
= dma_zalloc_coherent(ar
->dev
,
4434 IEEE80211_MAX_FRAME_LEN
,
4435 &arvif
->beacon_paddr
,
4437 if (!arvif
->beacon_buf
) {
4439 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
4444 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
))
4445 arvif
->nohwcrypt
= true;
4447 if (arvif
->nohwcrypt
&&
4448 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
4449 ath10k_warn(ar
, "cryptmode module param needed for sw crypto\n");
4453 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4454 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
4455 arvif
->beacon_buf
? "single-buf" : "per-skb");
4457 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
4458 arvif
->vdev_subtype
, vif
->addr
);
4460 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
4461 arvif
->vdev_id
, ret
);
4465 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
4466 list_add(&arvif
->list
, &ar
->arvifs
);
4468 /* It makes no sense to have firmware do keepalives. mac80211 already
4469 * takes care of this with idle connection polling.
4471 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
4473 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
4474 arvif
->vdev_id
, ret
);
4475 goto err_vdev_delete
;
4478 arvif
->def_wep_key_idx
= -1;
4480 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
4481 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4482 ATH10K_HW_TXRX_NATIVE_WIFI
);
4483 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4484 if (ret
&& ret
!= -EOPNOTSUPP
) {
4485 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
4486 arvif
->vdev_id
, ret
);
4487 goto err_vdev_delete
;
4490 /* Configuring number of spatial stream for monitor interface is causing
4491 * target assert in qca9888 and qca6174.
4493 if (ar
->cfg_tx_chainmask
&& (vif
->type
!= NL80211_IFTYPE_MONITOR
)) {
4494 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
4496 vdev_param
= ar
->wmi
.vdev_param
->nss
;
4497 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4500 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4501 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
4503 goto err_vdev_delete
;
4507 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4508 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4509 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
,
4510 WMI_PEER_TYPE_DEFAULT
);
4512 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
4513 arvif
->vdev_id
, ret
);
4514 goto err_vdev_delete
;
4518 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
4519 ret
= ath10k_mac_set_kickout(arvif
);
4521 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
4522 arvif
->vdev_id
, ret
);
4523 goto err_peer_delete
;
4527 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
4528 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
4529 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
4530 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
4533 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
4534 arvif
->vdev_id
, ret
);
4535 goto err_peer_delete
;
4538 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
4540 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
4541 arvif
->vdev_id
, ret
);
4542 goto err_peer_delete
;
4545 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
4547 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
4548 arvif
->vdev_id
, ret
);
4549 goto err_peer_delete
;
4553 ret
= ath10k_mac_set_txbf_conf(arvif
);
4555 ath10k_warn(ar
, "failed to set txbf for vdev %d: %d\n",
4556 arvif
->vdev_id
, ret
);
4557 goto err_peer_delete
;
4560 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
4562 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
4563 arvif
->vdev_id
, ret
);
4564 goto err_peer_delete
;
4567 arvif
->txpower
= vif
->bss_conf
.txpower
;
4568 ret
= ath10k_mac_txpower_recalc(ar
);
4570 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4571 goto err_peer_delete
;
4574 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4575 ar
->monitor_arvif
= arvif
;
4576 ret
= ath10k_monitor_recalc(ar
);
4578 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4579 goto err_peer_delete
;
4583 spin_lock_bh(&ar
->htt
.tx_lock
);
4585 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
4586 spin_unlock_bh(&ar
->htt
.tx_lock
);
4588 mutex_unlock(&ar
->conf_mutex
);
4592 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4593 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
)
4594 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
4597 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4598 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4599 list_del(&arvif
->list
);
4602 if (arvif
->beacon_buf
) {
4603 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
4604 arvif
->beacon_buf
, arvif
->beacon_paddr
);
4605 arvif
->beacon_buf
= NULL
;
4608 mutex_unlock(&ar
->conf_mutex
);
4613 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
4617 for (i
= 0; i
< BITS_PER_LONG
; i
++)
4618 ath10k_mac_vif_tx_unlock(arvif
, i
);
4621 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
4622 struct ieee80211_vif
*vif
)
4624 struct ath10k
*ar
= hw
->priv
;
4625 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4628 cancel_work_sync(&arvif
->ap_csa_work
);
4629 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
4631 mutex_lock(&ar
->conf_mutex
);
4633 spin_lock_bh(&ar
->data_lock
);
4634 ath10k_mac_vif_beacon_cleanup(arvif
);
4635 spin_unlock_bh(&ar
->data_lock
);
4637 ret
= ath10k_spectral_vif_stop(arvif
);
4639 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
4640 arvif
->vdev_id
, ret
);
4642 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
4643 list_del(&arvif
->list
);
4645 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4646 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4647 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
4650 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4651 arvif
->vdev_id
, ret
);
4653 kfree(arvif
->u
.ap
.noa_data
);
4656 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
4659 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
4661 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
4662 arvif
->vdev_id
, ret
);
4664 /* Some firmware revisions don't notify host about self-peer removal
4665 * until after associated vdev is deleted.
4667 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
4668 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
4669 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
4672 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
4673 arvif
->vdev_id
, ret
);
4675 spin_lock_bh(&ar
->data_lock
);
4677 spin_unlock_bh(&ar
->data_lock
);
4680 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
4682 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4683 ar
->monitor_arvif
= NULL
;
4684 ret
= ath10k_monitor_recalc(ar
);
4686 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
4689 spin_lock_bh(&ar
->htt
.tx_lock
);
4690 ath10k_mac_vif_tx_unlock_all(arvif
);
4691 spin_unlock_bh(&ar
->htt
.tx_lock
);
4693 mutex_unlock(&ar
->conf_mutex
);
4697 * FIXME: Has to be verified.
4699 #define SUPPORTED_FILTERS \
4704 FIF_BCN_PRBRESP_PROMISC | \
4708 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
4709 unsigned int changed_flags
,
4710 unsigned int *total_flags
,
4713 struct ath10k
*ar
= hw
->priv
;
4716 mutex_lock(&ar
->conf_mutex
);
4718 changed_flags
&= SUPPORTED_FILTERS
;
4719 *total_flags
&= SUPPORTED_FILTERS
;
4720 ar
->filter_flags
= *total_flags
;
4722 ret
= ath10k_monitor_recalc(ar
);
4724 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
4726 mutex_unlock(&ar
->conf_mutex
);
4729 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
4730 struct ieee80211_vif
*vif
,
4731 struct ieee80211_bss_conf
*info
,
4734 struct ath10k
*ar
= hw
->priv
;
4735 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4737 u32 vdev_param
, pdev_param
, slottime
, preamble
;
4739 mutex_lock(&ar
->conf_mutex
);
4741 if (changed
& BSS_CHANGED_IBSS
)
4742 ath10k_control_ibss(arvif
, info
, vif
->addr
);
4744 if (changed
& BSS_CHANGED_BEACON_INT
) {
4745 arvif
->beacon_interval
= info
->beacon_int
;
4746 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
4747 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4748 arvif
->beacon_interval
);
4749 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4750 "mac vdev %d beacon_interval %d\n",
4751 arvif
->vdev_id
, arvif
->beacon_interval
);
4754 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
4755 arvif
->vdev_id
, ret
);
4758 if (changed
& BSS_CHANGED_BEACON
) {
4759 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4760 "vdev %d set beacon tx mode to staggered\n",
4763 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
4764 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
4765 WMI_BEACON_STAGGERED_MODE
);
4767 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
4768 arvif
->vdev_id
, ret
);
4770 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
4772 ath10k_warn(ar
, "failed to update beacon template: %d\n",
4775 if (ieee80211_vif_is_mesh(vif
)) {
4776 /* mesh doesn't use SSID but firmware needs it */
4777 strncpy(arvif
->u
.ap
.ssid
, "mesh",
4778 sizeof(arvif
->u
.ap
.ssid
));
4779 arvif
->u
.ap
.ssid_len
= 4;
4783 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
4784 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
4786 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
4787 arvif
->vdev_id
, ret
);
4790 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
4791 arvif
->dtim_period
= info
->dtim_period
;
4793 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4794 "mac vdev %d dtim_period %d\n",
4795 arvif
->vdev_id
, arvif
->dtim_period
);
4797 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
4798 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4799 arvif
->dtim_period
);
4801 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
4802 arvif
->vdev_id
, ret
);
4805 if (changed
& BSS_CHANGED_SSID
&&
4806 vif
->type
== NL80211_IFTYPE_AP
) {
4807 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
4809 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
4810 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
4813 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
4814 ether_addr_copy(arvif
->bssid
, info
->bssid
);
4816 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
4817 ath10k_control_beaconing(arvif
, info
);
4819 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
4820 arvif
->use_cts_prot
= info
->use_cts_prot
;
4822 ret
= ath10k_recalc_rtscts_prot(arvif
);
4824 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4825 arvif
->vdev_id
, ret
);
4827 if (ath10k_mac_can_set_cts_prot(arvif
)) {
4828 ret
= ath10k_mac_set_cts_prot(arvif
);
4830 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
4831 arvif
->vdev_id
, ret
);
4835 if (changed
& BSS_CHANGED_ERP_SLOT
) {
4836 if (info
->use_short_slot
)
4837 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
4840 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
4842 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
4843 arvif
->vdev_id
, slottime
);
4845 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
4846 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4849 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
4850 arvif
->vdev_id
, ret
);
4853 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
4854 if (info
->use_short_preamble
)
4855 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
4857 preamble
= WMI_VDEV_PREAMBLE_LONG
;
4859 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4860 "mac vdev %d preamble %dn",
4861 arvif
->vdev_id
, preamble
);
4863 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
4864 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4867 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
4868 arvif
->vdev_id
, ret
);
4871 if (changed
& BSS_CHANGED_ASSOC
) {
4873 /* Workaround: Make sure monitor vdev is not running
4874 * when associating to prevent some firmware revisions
4875 * (e.g. 10.1 and 10.2) from crashing.
4877 if (ar
->monitor_started
)
4878 ath10k_monitor_stop(ar
);
4879 ath10k_bss_assoc(hw
, vif
, info
);
4880 ath10k_monitor_recalc(ar
);
4882 ath10k_bss_disassoc(hw
, vif
);
4886 if (changed
& BSS_CHANGED_TXPOWER
) {
4887 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
4888 arvif
->vdev_id
, info
->txpower
);
4890 arvif
->txpower
= info
->txpower
;
4891 ret
= ath10k_mac_txpower_recalc(ar
);
4893 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
4896 if (changed
& BSS_CHANGED_PS
) {
4897 arvif
->ps
= vif
->bss_conf
.ps
;
4899 ret
= ath10k_config_ps(ar
);
4901 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
4902 arvif
->vdev_id
, ret
);
4905 mutex_unlock(&ar
->conf_mutex
);
4908 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
4909 struct ieee80211_vif
*vif
,
4910 struct ieee80211_scan_request
*hw_req
)
4912 struct ath10k
*ar
= hw
->priv
;
4913 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4914 struct cfg80211_scan_request
*req
= &hw_req
->req
;
4915 struct wmi_start_scan_arg arg
;
4919 mutex_lock(&ar
->conf_mutex
);
4921 spin_lock_bh(&ar
->data_lock
);
4922 switch (ar
->scan
.state
) {
4923 case ATH10K_SCAN_IDLE
:
4924 reinit_completion(&ar
->scan
.started
);
4925 reinit_completion(&ar
->scan
.completed
);
4926 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
4927 ar
->scan
.is_roc
= false;
4928 ar
->scan
.vdev_id
= arvif
->vdev_id
;
4931 case ATH10K_SCAN_STARTING
:
4932 case ATH10K_SCAN_RUNNING
:
4933 case ATH10K_SCAN_ABORTING
:
4937 spin_unlock_bh(&ar
->data_lock
);
4942 memset(&arg
, 0, sizeof(arg
));
4943 ath10k_wmi_start_scan_init(ar
, &arg
);
4944 arg
.vdev_id
= arvif
->vdev_id
;
4945 arg
.scan_id
= ATH10K_SCAN_ID
;
4948 arg
.ie_len
= req
->ie_len
;
4949 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
4953 arg
.n_ssids
= req
->n_ssids
;
4954 for (i
= 0; i
< arg
.n_ssids
; i
++) {
4955 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
4956 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
4959 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
4962 if (req
->n_channels
) {
4963 arg
.n_channels
= req
->n_channels
;
4964 for (i
= 0; i
< arg
.n_channels
; i
++)
4965 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
4968 ret
= ath10k_start_scan(ar
, &arg
);
4970 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
4971 spin_lock_bh(&ar
->data_lock
);
4972 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4973 spin_unlock_bh(&ar
->data_lock
);
4976 /* Add a 200ms margin to account for event/command processing */
4977 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
4978 msecs_to_jiffies(arg
.max_scan_time
+
4982 mutex_unlock(&ar
->conf_mutex
);
4986 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
4987 struct ieee80211_vif
*vif
)
4989 struct ath10k
*ar
= hw
->priv
;
4991 mutex_lock(&ar
->conf_mutex
);
4992 ath10k_scan_abort(ar
);
4993 mutex_unlock(&ar
->conf_mutex
);
4995 cancel_delayed_work_sync(&ar
->scan
.timeout
);
4998 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
4999 struct ath10k_vif
*arvif
,
5000 enum set_key_cmd cmd
,
5001 struct ieee80211_key_conf
*key
)
5003 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
5006 /* 10.1 firmware branch requires default key index to be set to group
5007 * key index after installing it. Otherwise FW/HW Txes corrupted
5008 * frames with multi-vif APs. This is not required for main firmware
5009 * branch (e.g. 636).
5011 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5013 * FIXME: It remains unknown if this is required for multi-vif STA
5014 * interfaces on 10.1.
5017 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
5018 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
5021 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
5024 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
5027 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
5033 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5036 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
5037 arvif
->vdev_id
, ret
);
5040 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
5041 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
5042 struct ieee80211_key_conf
*key
)
5044 struct ath10k
*ar
= hw
->priv
;
5045 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5046 struct ath10k_peer
*peer
;
5047 const u8
*peer_addr
;
5048 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
5049 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
5055 /* this one needs to be done in software */
5056 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
5059 if (arvif
->nohwcrypt
)
5062 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
5065 mutex_lock(&ar
->conf_mutex
);
5068 peer_addr
= sta
->addr
;
5069 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
5070 peer_addr
= vif
->bss_conf
.bssid
;
5072 peer_addr
= vif
->addr
;
5074 key
->hw_key_idx
= key
->keyidx
;
5078 arvif
->wep_keys
[key
->keyidx
] = key
;
5080 arvif
->wep_keys
[key
->keyidx
] = NULL
;
5083 /* the peer should not disappear in mid-way (unless FW goes awry) since
5084 * we already hold conf_mutex. we just make sure its there now. */
5085 spin_lock_bh(&ar
->data_lock
);
5086 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
5087 spin_unlock_bh(&ar
->data_lock
);
5090 if (cmd
== SET_KEY
) {
5091 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
5096 /* if the peer doesn't exist there is no key to disable
5102 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
5103 flags
|= WMI_KEY_PAIRWISE
;
5105 flags
|= WMI_KEY_GROUP
;
5108 if (cmd
== DISABLE_KEY
)
5109 ath10k_clear_vdev_key(arvif
, key
);
5111 /* When WEP keys are uploaded it's possible that there are
5112 * stations associated already (e.g. when merging) without any
5113 * keys. Static WEP needs an explicit per-peer key upload.
5115 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
5117 ath10k_mac_vif_update_wep_key(arvif
, key
);
5119 /* 802.1x never sets the def_wep_key_idx so each set_key()
5120 * call changes default tx key.
5122 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5123 * after first set_key().
5125 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
5126 flags
|= WMI_KEY_TX_USAGE
;
5129 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
5132 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
5133 arvif
->vdev_id
, peer_addr
, ret
);
5137 /* mac80211 sets static WEP keys as groupwise while firmware requires
5138 * them to be installed twice as both pairwise and groupwise.
5140 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
5142 flags2
&= ~WMI_KEY_GROUP
;
5143 flags2
|= WMI_KEY_PAIRWISE
;
5145 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
5148 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5149 arvif
->vdev_id
, peer_addr
, ret
);
5150 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
5154 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5155 arvif
->vdev_id
, peer_addr
, ret2
);
5161 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
5163 spin_lock_bh(&ar
->data_lock
);
5164 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
5165 if (peer
&& cmd
== SET_KEY
)
5166 peer
->keys
[key
->keyidx
] = key
;
5167 else if (peer
&& cmd
== DISABLE_KEY
)
5168 peer
->keys
[key
->keyidx
] = NULL
;
5169 else if (peer
== NULL
)
5170 /* impossible unless FW goes crazy */
5171 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
5172 spin_unlock_bh(&ar
->data_lock
);
5175 mutex_unlock(&ar
->conf_mutex
);
5179 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
5180 struct ieee80211_vif
*vif
,
5183 struct ath10k
*ar
= hw
->priv
;
5184 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5187 mutex_lock(&arvif
->ar
->conf_mutex
);
5189 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
5192 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
5193 arvif
->vdev_id
, keyidx
);
5195 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
5197 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
5201 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
5207 arvif
->def_wep_key_idx
= keyidx
;
5210 mutex_unlock(&arvif
->ar
->conf_mutex
);
5213 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
5216 struct ath10k_vif
*arvif
;
5217 struct ath10k_sta
*arsta
;
5218 struct ieee80211_sta
*sta
;
5219 struct cfg80211_chan_def def
;
5220 enum ieee80211_band band
;
5221 const u8
*ht_mcs_mask
;
5222 const u16
*vht_mcs_mask
;
5223 u32 changed
, bw
, nss
, smps
;
5226 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
5227 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
5228 arvif
= arsta
->arvif
;
5231 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
5234 band
= def
.chan
->band
;
5235 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
5236 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
5238 spin_lock_bh(&ar
->data_lock
);
5240 changed
= arsta
->changed
;
5247 spin_unlock_bh(&ar
->data_lock
);
5249 mutex_lock(&ar
->conf_mutex
);
5251 nss
= max_t(u32
, 1, nss
);
5252 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
5253 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
5255 if (changed
& IEEE80211_RC_BW_CHANGED
) {
5256 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
5259 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5260 WMI_PEER_CHAN_WIDTH
, bw
);
5262 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
5263 sta
->addr
, bw
, err
);
5266 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
5267 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
5270 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5273 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
5274 sta
->addr
, nss
, err
);
5277 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
5278 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
5281 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
5282 WMI_PEER_SMPS_STATE
, smps
);
5284 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
5285 sta
->addr
, smps
, err
);
5288 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
5289 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates\n",
5292 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
5294 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
5298 mutex_unlock(&ar
->conf_mutex
);
5301 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
5302 struct ieee80211_sta
*sta
)
5304 struct ath10k
*ar
= arvif
->ar
;
5306 lockdep_assert_held(&ar
->conf_mutex
);
5308 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
5311 if (ar
->num_stations
>= ar
->max_num_stations
)
5319 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
5320 struct ieee80211_sta
*sta
)
5322 struct ath10k
*ar
= arvif
->ar
;
5324 lockdep_assert_held(&ar
->conf_mutex
);
5326 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
5332 struct ath10k_mac_tdls_iter_data
{
5333 u32 num_tdls_stations
;
5334 struct ieee80211_vif
*curr_vif
;
5337 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
5338 struct ieee80211_sta
*sta
)
5340 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
5341 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5342 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
5344 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
5345 iter_data
->num_tdls_stations
++;
5348 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
5349 struct ieee80211_vif
*vif
)
5351 struct ath10k_mac_tdls_iter_data data
= {};
5353 data
.curr_vif
= vif
;
5355 ieee80211_iterate_stations_atomic(hw
,
5356 ath10k_mac_tdls_vif_stations_count_iter
,
5358 return data
.num_tdls_stations
;
5361 static void ath10k_mac_tdls_vifs_count_iter(void *data
, u8
*mac
,
5362 struct ieee80211_vif
*vif
)
5364 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5365 int *num_tdls_vifs
= data
;
5367 if (vif
->type
!= NL80211_IFTYPE_STATION
)
5370 if (ath10k_mac_tdls_vif_stations_count(arvif
->ar
->hw
, vif
) > 0)
5374 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw
*hw
)
5376 int num_tdls_vifs
= 0;
5378 ieee80211_iterate_active_interfaces_atomic(hw
,
5379 IEEE80211_IFACE_ITER_NORMAL
,
5380 ath10k_mac_tdls_vifs_count_iter
,
5382 return num_tdls_vifs
;
5385 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
5386 struct ieee80211_vif
*vif
,
5387 struct ieee80211_sta
*sta
,
5388 enum ieee80211_sta_state old_state
,
5389 enum ieee80211_sta_state new_state
)
5391 struct ath10k
*ar
= hw
->priv
;
5392 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5393 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
5396 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5397 new_state
== IEEE80211_STA_NONE
) {
5398 memset(arsta
, 0, sizeof(*arsta
));
5399 arsta
->arvif
= arvif
;
5400 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
5403 /* cancel must be done outside the mutex to avoid deadlock */
5404 if ((old_state
== IEEE80211_STA_NONE
&&
5405 new_state
== IEEE80211_STA_NOTEXIST
))
5406 cancel_work_sync(&arsta
->update_wk
);
5408 mutex_lock(&ar
->conf_mutex
);
5410 if (old_state
== IEEE80211_STA_NOTEXIST
&&
5411 new_state
== IEEE80211_STA_NONE
) {
5413 * New station addition.
5415 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
5416 u32 num_tdls_stations
;
5419 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5420 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5421 arvif
->vdev_id
, sta
->addr
,
5422 ar
->num_stations
+ 1, ar
->max_num_stations
,
5423 ar
->num_peers
+ 1, ar
->max_num_peers
);
5425 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
5427 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
5428 ar
->max_num_stations
);
5433 peer_type
= WMI_PEER_TYPE_TDLS
;
5435 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
,
5438 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5439 sta
->addr
, arvif
->vdev_id
, ret
);
5440 ath10k_mac_dec_num_stations(arvif
, sta
);
5447 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
5448 num_tdls_vifs
= ath10k_mac_tdls_vifs_count(hw
);
5450 if (num_tdls_vifs
>= ar
->max_num_tdls_vdevs
&&
5451 num_tdls_stations
== 0) {
5452 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5453 arvif
->vdev_id
, ar
->max_num_tdls_vdevs
);
5454 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5455 ath10k_mac_dec_num_stations(arvif
, sta
);
5460 if (num_tdls_stations
== 0) {
5461 /* This is the first tdls peer in current vif */
5462 enum wmi_tdls_state state
= WMI_TDLS_ENABLE_ACTIVE
;
5464 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5467 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5468 arvif
->vdev_id
, ret
);
5469 ath10k_peer_delete(ar
, arvif
->vdev_id
,
5471 ath10k_mac_dec_num_stations(arvif
, sta
);
5476 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5477 WMI_TDLS_PEER_STATE_PEERING
);
5480 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5481 sta
->addr
, arvif
->vdev_id
, ret
);
5482 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5483 ath10k_mac_dec_num_stations(arvif
, sta
);
5485 if (num_tdls_stations
!= 0)
5487 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5490 } else if ((old_state
== IEEE80211_STA_NONE
&&
5491 new_state
== IEEE80211_STA_NOTEXIST
)) {
5493 * Existing station deletion.
5495 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5496 "mac vdev %d peer delete %pM (sta gone)\n",
5497 arvif
->vdev_id
, sta
->addr
);
5500 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
,
5502 WMI_TDLS_PEER_STATE_TEARDOWN
);
5504 ath10k_warn(ar
, "failed to update tdls peer state for %pM state %d: %i\n",
5506 WMI_TDLS_PEER_STATE_TEARDOWN
, ret
);
5509 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
5511 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
5512 sta
->addr
, arvif
->vdev_id
, ret
);
5514 ath10k_mac_dec_num_stations(arvif
, sta
);
5519 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
5522 /* This was the last tdls peer in current vif */
5523 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
5526 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
5527 arvif
->vdev_id
, ret
);
5529 } else if (old_state
== IEEE80211_STA_AUTH
&&
5530 new_state
== IEEE80211_STA_ASSOC
&&
5531 (vif
->type
== NL80211_IFTYPE_AP
||
5532 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
5533 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5537 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
5540 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5542 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
5543 sta
->addr
, arvif
->vdev_id
, ret
);
5544 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5545 new_state
== IEEE80211_STA_AUTHORIZED
&&
5548 * Tdls station authorized.
5550 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
5553 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
5555 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
5556 sta
->addr
, arvif
->vdev_id
, ret
);
5560 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
5561 WMI_TDLS_PEER_STATE_CONNECTED
);
5563 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
5564 sta
->addr
, arvif
->vdev_id
, ret
);
5565 } else if (old_state
== IEEE80211_STA_ASSOC
&&
5566 new_state
== IEEE80211_STA_AUTH
&&
5567 (vif
->type
== NL80211_IFTYPE_AP
||
5568 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
5569 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
5573 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
5576 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
5578 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
5579 sta
->addr
, arvif
->vdev_id
, ret
);
5582 mutex_unlock(&ar
->conf_mutex
);
5586 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
5587 u16 ac
, bool enable
)
5589 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5590 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
5591 u32 prio
= 0, acc
= 0;
5595 lockdep_assert_held(&ar
->conf_mutex
);
5597 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
5601 case IEEE80211_AC_VO
:
5602 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
5603 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
5607 case IEEE80211_AC_VI
:
5608 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
5609 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
5613 case IEEE80211_AC_BE
:
5614 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
5615 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
5619 case IEEE80211_AC_BK
:
5620 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
5621 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
5628 arvif
->u
.sta
.uapsd
|= value
;
5630 arvif
->u
.sta
.uapsd
&= ~value
;
5632 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5633 WMI_STA_PS_PARAM_UAPSD
,
5634 arvif
->u
.sta
.uapsd
);
5636 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
5640 if (arvif
->u
.sta
.uapsd
)
5641 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
5643 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5645 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5646 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
5649 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
5651 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5653 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5654 arvif
->vdev_id
, ret
);
5658 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5660 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5661 arvif
->vdev_id
, ret
);
5665 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
5666 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
5667 /* Only userspace can make an educated decision when to send
5668 * trigger frame. The following effectively disables u-UAPSD
5669 * autotrigger in firmware (which is enabled by default
5670 * provided the autotrigger service is available).
5674 arg
.user_priority
= prio
;
5675 arg
.service_interval
= 0;
5676 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5677 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
5679 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
5680 arvif
->bssid
, &arg
, 1);
5682 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
5692 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
5693 struct ieee80211_vif
*vif
, u16 ac
,
5694 const struct ieee80211_tx_queue_params
*params
)
5696 struct ath10k
*ar
= hw
->priv
;
5697 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5698 struct wmi_wmm_params_arg
*p
= NULL
;
5701 mutex_lock(&ar
->conf_mutex
);
5704 case IEEE80211_AC_VO
:
5705 p
= &arvif
->wmm_params
.ac_vo
;
5707 case IEEE80211_AC_VI
:
5708 p
= &arvif
->wmm_params
.ac_vi
;
5710 case IEEE80211_AC_BE
:
5711 p
= &arvif
->wmm_params
.ac_be
;
5713 case IEEE80211_AC_BK
:
5714 p
= &arvif
->wmm_params
.ac_bk
;
5723 p
->cwmin
= params
->cw_min
;
5724 p
->cwmax
= params
->cw_max
;
5725 p
->aifs
= params
->aifs
;
5728 * The channel time duration programmed in the HW is in absolute
5729 * microseconds, while mac80211 gives the txop in units of
5732 p
->txop
= params
->txop
* 32;
5734 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
5735 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
5736 &arvif
->wmm_params
);
5738 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
5739 arvif
->vdev_id
, ret
);
5743 /* This won't work well with multi-interface cases but it's
5744 * better than nothing.
5746 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
5748 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
5753 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
5755 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
5758 mutex_unlock(&ar
->conf_mutex
);
5762 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5764 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
5765 struct ieee80211_vif
*vif
,
5766 struct ieee80211_channel
*chan
,
5768 enum ieee80211_roc_type type
)
5770 struct ath10k
*ar
= hw
->priv
;
5771 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
5772 struct wmi_start_scan_arg arg
;
5776 mutex_lock(&ar
->conf_mutex
);
5778 spin_lock_bh(&ar
->data_lock
);
5779 switch (ar
->scan
.state
) {
5780 case ATH10K_SCAN_IDLE
:
5781 reinit_completion(&ar
->scan
.started
);
5782 reinit_completion(&ar
->scan
.completed
);
5783 reinit_completion(&ar
->scan
.on_channel
);
5784 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
5785 ar
->scan
.is_roc
= true;
5786 ar
->scan
.vdev_id
= arvif
->vdev_id
;
5787 ar
->scan
.roc_freq
= chan
->center_freq
;
5788 ar
->scan
.roc_notify
= true;
5791 case ATH10K_SCAN_STARTING
:
5792 case ATH10K_SCAN_RUNNING
:
5793 case ATH10K_SCAN_ABORTING
:
5797 spin_unlock_bh(&ar
->data_lock
);
5802 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
5804 memset(&arg
, 0, sizeof(arg
));
5805 ath10k_wmi_start_scan_init(ar
, &arg
);
5806 arg
.vdev_id
= arvif
->vdev_id
;
5807 arg
.scan_id
= ATH10K_SCAN_ID
;
5809 arg
.channels
[0] = chan
->center_freq
;
5810 arg
.dwell_time_active
= scan_time_msec
;
5811 arg
.dwell_time_passive
= scan_time_msec
;
5812 arg
.max_scan_time
= scan_time_msec
;
5813 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
5814 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
5815 arg
.burst_duration_ms
= duration
;
5817 ret
= ath10k_start_scan(ar
, &arg
);
5819 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
5820 spin_lock_bh(&ar
->data_lock
);
5821 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
5822 spin_unlock_bh(&ar
->data_lock
);
5826 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
5828 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
5830 ret
= ath10k_scan_stop(ar
);
5832 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
5838 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
5839 msecs_to_jiffies(duration
));
5843 mutex_unlock(&ar
->conf_mutex
);
5847 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
5849 struct ath10k
*ar
= hw
->priv
;
5851 mutex_lock(&ar
->conf_mutex
);
5853 spin_lock_bh(&ar
->data_lock
);
5854 ar
->scan
.roc_notify
= false;
5855 spin_unlock_bh(&ar
->data_lock
);
5857 ath10k_scan_abort(ar
);
5859 mutex_unlock(&ar
->conf_mutex
);
5861 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5867 * Both RTS and Fragmentation threshold are interface-specific
5868 * in ath10k, but device-specific in mac80211.
5871 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
5873 struct ath10k
*ar
= hw
->priv
;
5874 struct ath10k_vif
*arvif
;
5877 mutex_lock(&ar
->conf_mutex
);
5878 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5879 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
5880 arvif
->vdev_id
, value
);
5882 ret
= ath10k_mac_set_rts(arvif
, value
);
5884 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5885 arvif
->vdev_id
, ret
);
5889 mutex_unlock(&ar
->conf_mutex
);
5894 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
5896 /* Even though there's a WMI enum for fragmentation threshold no known
5897 * firmware actually implements it. Moreover it is not possible to rely
5898 * frame fragmentation to mac80211 because firmware clears the "more
5899 * fragments" bit in frame control making it impossible for remote
5900 * devices to reassemble frames.
5902 * Hence implement a dummy callback just to say fragmentation isn't
5903 * supported. This effectively prevents mac80211 from doing frame
5904 * fragmentation in software.
5909 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
5910 u32 queues
, bool drop
)
5912 struct ath10k
*ar
= hw
->priv
;
5916 /* mac80211 doesn't care if we really xmit queued frames or not
5917 * we'll collect those frames either way if we stop/delete vdevs */
5921 mutex_lock(&ar
->conf_mutex
);
5923 if (ar
->state
== ATH10K_STATE_WEDGED
)
5926 time_left
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
5929 spin_lock_bh(&ar
->htt
.tx_lock
);
5930 empty
= (ar
->htt
.num_pending_tx
== 0);
5931 spin_unlock_bh(&ar
->htt
.tx_lock
);
5933 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
5934 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
5938 }), ATH10K_FLUSH_TIMEOUT_HZ
);
5940 if (time_left
== 0 || skip
)
5941 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5942 skip
, ar
->state
, time_left
);
5945 mutex_unlock(&ar
->conf_mutex
);
5948 /* TODO: Implement this function properly
5949 * For now it is needed to reply to Probe Requests in IBSS mode.
5950 * Propably we need this information from FW.
5952 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
5957 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
5958 enum ieee80211_reconfig_type reconfig_type
)
5960 struct ath10k
*ar
= hw
->priv
;
5962 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
5965 mutex_lock(&ar
->conf_mutex
);
5967 /* If device failed to restart it will be in a different state, e.g.
5968 * ATH10K_STATE_WEDGED */
5969 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
5970 ath10k_info(ar
, "device successfully recovered\n");
5971 ar
->state
= ATH10K_STATE_ON
;
5972 ieee80211_wake_queues(ar
->hw
);
5975 mutex_unlock(&ar
->conf_mutex
);
5978 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
5979 struct survey_info
*survey
)
5981 struct ath10k
*ar
= hw
->priv
;
5982 struct ieee80211_supported_band
*sband
;
5983 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
5986 mutex_lock(&ar
->conf_mutex
);
5988 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5989 if (sband
&& idx
>= sband
->n_channels
) {
5990 idx
-= sband
->n_channels
;
5995 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5997 if (!sband
|| idx
>= sband
->n_channels
) {
6002 spin_lock_bh(&ar
->data_lock
);
6003 memcpy(survey
, ar_survey
, sizeof(*survey
));
6004 spin_unlock_bh(&ar
->data_lock
);
6006 survey
->channel
= &sband
->channels
[idx
];
6008 if (ar
->rx_channel
== survey
->channel
)
6009 survey
->filled
|= SURVEY_INFO_IN_USE
;
6012 mutex_unlock(&ar
->conf_mutex
);
6017 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
6018 enum ieee80211_band band
,
6019 const struct cfg80211_bitrate_mask
*mask
)
6024 num_rates
+= hweight32(mask
->control
[band
].legacy
);
6026 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
6027 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
6029 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++)
6030 num_rates
+= hweight16(mask
->control
[band
].vht_mcs
[i
]);
6032 return num_rates
== 1;
6036 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
6037 enum ieee80211_band band
,
6038 const struct cfg80211_bitrate_mask
*mask
,
6041 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
6042 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
6044 u8 vht_nss_mask
= 0;
6047 if (mask
->control
[band
].legacy
)
6050 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
6051 if (mask
->control
[band
].ht_mcs
[i
] == 0)
6053 else if (mask
->control
[band
].ht_mcs
[i
] ==
6054 sband
->ht_cap
.mcs
.rx_mask
[i
])
6055 ht_nss_mask
|= BIT(i
);
6060 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6061 if (mask
->control
[band
].vht_mcs
[i
] == 0)
6063 else if (mask
->control
[band
].vht_mcs
[i
] ==
6064 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
6065 vht_nss_mask
|= BIT(i
);
6070 if (ht_nss_mask
!= vht_nss_mask
)
6073 if (ht_nss_mask
== 0)
6076 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
6079 *nss
= fls(ht_nss_mask
);
6085 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
6086 enum ieee80211_band band
,
6087 const struct cfg80211_bitrate_mask
*mask
,
6090 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
6097 if (hweight32(mask
->control
[band
].legacy
) == 1) {
6098 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
6100 hw_rate
= sband
->bitrates
[rate_idx
].hw_value
;
6101 bitrate
= sband
->bitrates
[rate_idx
].bitrate
;
6103 if (ath10k_mac_bitrate_is_cck(bitrate
))
6104 preamble
= WMI_RATE_PREAMBLE_CCK
;
6106 preamble
= WMI_RATE_PREAMBLE_OFDM
;
6109 *rate
= preamble
<< 6 |
6116 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
6117 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
6119 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
6121 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
6127 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6128 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
6130 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
6132 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
6141 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
6142 u8 rate
, u8 nss
, u8 sgi
, u8 ldpc
)
6144 struct ath10k
*ar
= arvif
->ar
;
6148 lockdep_assert_held(&ar
->conf_mutex
);
6150 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6151 arvif
->vdev_id
, rate
, nss
, sgi
);
6153 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
6154 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
6156 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
6161 vdev_param
= ar
->wmi
.vdev_param
->nss
;
6162 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
6164 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
6168 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
6169 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
6171 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
6175 vdev_param
= ar
->wmi
.vdev_param
->ldpc
;
6176 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, ldpc
);
6178 ath10k_warn(ar
, "failed to set ldpc param %d: %d\n", ldpc
, ret
);
6186 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
6187 enum ieee80211_band band
,
6188 const struct cfg80211_bitrate_mask
*mask
)
6193 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6194 * to express all VHT MCS rate masks. Effectively only the following
6195 * ranges can be used: none, 0-7, 0-8 and 0-9.
6197 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
6198 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
6207 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6215 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
6216 struct ieee80211_sta
*sta
)
6218 struct ath10k_vif
*arvif
= data
;
6219 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6220 struct ath10k
*ar
= arvif
->ar
;
6222 if (arsta
->arvif
!= arvif
)
6225 spin_lock_bh(&ar
->data_lock
);
6226 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
6227 spin_unlock_bh(&ar
->data_lock
);
6229 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
6232 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
6233 struct ieee80211_vif
*vif
,
6234 const struct cfg80211_bitrate_mask
*mask
)
6236 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6237 struct cfg80211_chan_def def
;
6238 struct ath10k
*ar
= arvif
->ar
;
6239 enum ieee80211_band band
;
6240 const u8
*ht_mcs_mask
;
6241 const u16
*vht_mcs_mask
;
6249 if (ath10k_mac_vif_chan(vif
, &def
))
6252 band
= def
.chan
->band
;
6253 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
6254 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
6255 ldpc
= !!(ar
->ht_cap_info
& WMI_HT_CAP_LDPC
);
6257 sgi
= mask
->control
[band
].gi
;
6258 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
6261 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
)) {
6262 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
6265 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
6266 arvif
->vdev_id
, ret
);
6269 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
6271 rate
= WMI_FIXED_RATE_NONE
;
6274 rate
= WMI_FIXED_RATE_NONE
;
6275 nss
= min(ar
->num_rf_chains
,
6276 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6277 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6279 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
))
6282 mutex_lock(&ar
->conf_mutex
);
6284 arvif
->bitrate_mask
= *mask
;
6285 ieee80211_iterate_stations_atomic(ar
->hw
,
6286 ath10k_mac_set_bitrate_mask_iter
,
6289 mutex_unlock(&ar
->conf_mutex
);
6292 mutex_lock(&ar
->conf_mutex
);
6294 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
, ldpc
);
6296 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
6297 arvif
->vdev_id
, ret
);
6302 mutex_unlock(&ar
->conf_mutex
);
6307 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
6308 struct ieee80211_vif
*vif
,
6309 struct ieee80211_sta
*sta
,
6312 struct ath10k
*ar
= hw
->priv
;
6313 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6314 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6315 struct ath10k_peer
*peer
;
6318 spin_lock_bh(&ar
->data_lock
);
6320 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
6322 spin_unlock_bh(&ar
->data_lock
);
6323 ath10k_warn(ar
, "mac sta rc update failed to find peer %pM on vdev %i\n",
6324 sta
->addr
, arvif
->vdev_id
);
6328 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6329 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6330 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
6333 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6334 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6336 switch (sta
->bandwidth
) {
6337 case IEEE80211_STA_RX_BW_20
:
6338 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6340 case IEEE80211_STA_RX_BW_40
:
6341 bw
= WMI_PEER_CHWIDTH_40MHZ
;
6343 case IEEE80211_STA_RX_BW_80
:
6344 bw
= WMI_PEER_CHWIDTH_80MHZ
;
6346 case IEEE80211_STA_RX_BW_160
:
6347 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
6348 sta
->bandwidth
, sta
->addr
);
6349 bw
= WMI_PEER_CHWIDTH_20MHZ
;
6356 if (changed
& IEEE80211_RC_NSS_CHANGED
)
6357 arsta
->nss
= sta
->rx_nss
;
6359 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6360 smps
= WMI_PEER_SMPS_PS_NONE
;
6362 switch (sta
->smps_mode
) {
6363 case IEEE80211_SMPS_AUTOMATIC
:
6364 case IEEE80211_SMPS_OFF
:
6365 smps
= WMI_PEER_SMPS_PS_NONE
;
6367 case IEEE80211_SMPS_STATIC
:
6368 smps
= WMI_PEER_SMPS_STATIC
;
6370 case IEEE80211_SMPS_DYNAMIC
:
6371 smps
= WMI_PEER_SMPS_DYNAMIC
;
6373 case IEEE80211_SMPS_NUM_MODES
:
6374 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
6375 sta
->smps_mode
, sta
->addr
);
6376 smps
= WMI_PEER_SMPS_PS_NONE
;
6383 arsta
->changed
|= changed
;
6385 spin_unlock_bh(&ar
->data_lock
);
6387 ieee80211_queue_work(hw
, &arsta
->update_wk
);
6390 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
6393 * FIXME: Return 0 for time being. Need to figure out whether FW
6394 * has the API to fetch 64-bit local TSF
6400 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
6401 struct ieee80211_vif
*vif
,
6402 struct ieee80211_ampdu_params
*params
)
6404 struct ath10k
*ar
= hw
->priv
;
6405 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
6406 struct ieee80211_sta
*sta
= params
->sta
;
6407 enum ieee80211_ampdu_mlme_action action
= params
->action
;
6408 u16 tid
= params
->tid
;
6410 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6411 arvif
->vdev_id
, sta
->addr
, tid
, action
);
6414 case IEEE80211_AMPDU_RX_START
:
6415 case IEEE80211_AMPDU_RX_STOP
:
6416 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6417 * creation/removal. Do we need to verify this?
6420 case IEEE80211_AMPDU_TX_START
:
6421 case IEEE80211_AMPDU_TX_STOP_CONT
:
6422 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
6423 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
6424 case IEEE80211_AMPDU_TX_OPERATIONAL
:
6425 /* Firmware offloads Tx aggregation entirely so deny mac80211
6426 * Tx aggregation requests.
6435 ath10k_mac_update_rx_channel(struct ath10k
*ar
,
6436 struct ieee80211_chanctx_conf
*ctx
,
6437 struct ieee80211_vif_chanctx_switch
*vifs
,
6440 struct cfg80211_chan_def
*def
= NULL
;
6442 /* Both locks are required because ar->rx_channel is modified. This
6443 * allows readers to hold either lock.
6445 lockdep_assert_held(&ar
->conf_mutex
);
6446 lockdep_assert_held(&ar
->data_lock
);
6448 WARN_ON(ctx
&& vifs
);
6449 WARN_ON(vifs
&& !n_vifs
);
6451 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6452 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6453 * ppdu on Rx may reduce performance on low-end systems. It should be
6454 * possible to make tables/hashmaps to speed the lookup up (be vary of
6455 * cpu data cache lines though regarding sizes) but to keep the initial
6456 * implementation simple and less intrusive fallback to the slow lookup
6457 * only for multi-channel cases. Single-channel cases will remain to
6458 * use the old channel derival and thus performance should not be
6462 if (!ctx
&& ath10k_mac_num_chanctxs(ar
) == 1) {
6463 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
6464 ath10k_mac_get_any_chandef_iter
,
6468 def
= &vifs
[0].new_ctx
->def
;
6470 ar
->rx_channel
= def
->chan
;
6471 } else if ((ctx
&& ath10k_mac_num_chanctxs(ar
) == 0) ||
6472 (ctx
&& (ar
->state
== ATH10K_STATE_RESTARTED
))) {
6473 /* During driver restart due to firmware assert, since mac80211
6474 * already has valid channel context for given radio, channel
6475 * context iteration return num_chanctx > 0. So fix rx_channel
6476 * when restart is in progress.
6478 ar
->rx_channel
= ctx
->def
.chan
;
6480 ar
->rx_channel
= NULL
;
6486 ath10k_mac_update_vif_chan(struct ath10k
*ar
,
6487 struct ieee80211_vif_chanctx_switch
*vifs
,
6490 struct ath10k_vif
*arvif
;
6494 lockdep_assert_held(&ar
->conf_mutex
);
6496 /* First stop monitor interface. Some FW versions crash if there's a
6497 * lone monitor interface.
6499 if (ar
->monitor_started
)
6500 ath10k_monitor_stop(ar
);
6502 for (i
= 0; i
< n_vifs
; i
++) {
6503 arvif
= ath10k_vif_to_arvif(vifs
[i
].vif
);
6505 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6506 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6508 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
6509 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
6510 vifs
[i
].old_ctx
->def
.width
,
6511 vifs
[i
].new_ctx
->def
.width
);
6513 if (WARN_ON(!arvif
->is_started
))
6516 if (WARN_ON(!arvif
->is_up
))
6519 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
6521 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
6522 arvif
->vdev_id
, ret
);
6527 /* All relevant vdevs are downed and associated channel resources
6528 * should be available for the channel switch now.
6531 spin_lock_bh(&ar
->data_lock
);
6532 ath10k_mac_update_rx_channel(ar
, NULL
, vifs
, n_vifs
);
6533 spin_unlock_bh(&ar
->data_lock
);
6535 for (i
= 0; i
< n_vifs
; i
++) {
6536 arvif
= ath10k_vif_to_arvif(vifs
[i
].vif
);
6538 if (WARN_ON(!arvif
->is_started
))
6541 if (WARN_ON(!arvif
->is_up
))
6544 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
6546 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
6549 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
6551 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
6554 ret
= ath10k_vdev_restart(arvif
, &vifs
[i
].new_ctx
->def
);
6556 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
6557 arvif
->vdev_id
, ret
);
6561 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
6564 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
6565 arvif
->vdev_id
, ret
);
6570 ath10k_monitor_recalc(ar
);
6574 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
6575 struct ieee80211_chanctx_conf
*ctx
)
6577 struct ath10k
*ar
= hw
->priv
;
6579 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6580 "mac chanctx add freq %hu width %d ptr %p\n",
6581 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6583 mutex_lock(&ar
->conf_mutex
);
6585 spin_lock_bh(&ar
->data_lock
);
6586 ath10k_mac_update_rx_channel(ar
, ctx
, NULL
, 0);
6587 spin_unlock_bh(&ar
->data_lock
);
6589 ath10k_recalc_radar_detection(ar
);
6590 ath10k_monitor_recalc(ar
);
6592 mutex_unlock(&ar
->conf_mutex
);
6598 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
6599 struct ieee80211_chanctx_conf
*ctx
)
6601 struct ath10k
*ar
= hw
->priv
;
6603 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6604 "mac chanctx remove freq %hu width %d ptr %p\n",
6605 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
6607 mutex_lock(&ar
->conf_mutex
);
6609 spin_lock_bh(&ar
->data_lock
);
6610 ath10k_mac_update_rx_channel(ar
, NULL
, NULL
, 0);
6611 spin_unlock_bh(&ar
->data_lock
);
6613 ath10k_recalc_radar_detection(ar
);
6614 ath10k_monitor_recalc(ar
);
6616 mutex_unlock(&ar
->conf_mutex
);
6619 struct ath10k_mac_change_chanctx_arg
{
6620 struct ieee80211_chanctx_conf
*ctx
;
6621 struct ieee80211_vif_chanctx_switch
*vifs
;
6627 ath10k_mac_change_chanctx_cnt_iter(void *data
, u8
*mac
,
6628 struct ieee80211_vif
*vif
)
6630 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
6632 if (rcu_access_pointer(vif
->chanctx_conf
) != arg
->ctx
)
6639 ath10k_mac_change_chanctx_fill_iter(void *data
, u8
*mac
,
6640 struct ieee80211_vif
*vif
)
6642 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
6643 struct ieee80211_chanctx_conf
*ctx
;
6645 ctx
= rcu_access_pointer(vif
->chanctx_conf
);
6646 if (ctx
!= arg
->ctx
)
6649 if (WARN_ON(arg
->next_vif
== arg
->n_vifs
))
6652 arg
->vifs
[arg
->next_vif
].vif
= vif
;
6653 arg
->vifs
[arg
->next_vif
].old_ctx
= ctx
;
6654 arg
->vifs
[arg
->next_vif
].new_ctx
= ctx
;
6659 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
6660 struct ieee80211_chanctx_conf
*ctx
,
6663 struct ath10k
*ar
= hw
->priv
;
6664 struct ath10k_mac_change_chanctx_arg arg
= { .ctx
= ctx
};
6666 mutex_lock(&ar
->conf_mutex
);
6668 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6669 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6670 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
, changed
);
6672 /* This shouldn't really happen because channel switching should use
6673 * switch_vif_chanctx().
6675 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
6678 if (changed
& IEEE80211_CHANCTX_CHANGE_WIDTH
) {
6679 ieee80211_iterate_active_interfaces_atomic(
6681 IEEE80211_IFACE_ITER_NORMAL
,
6682 ath10k_mac_change_chanctx_cnt_iter
,
6684 if (arg
.n_vifs
== 0)
6687 arg
.vifs
= kcalloc(arg
.n_vifs
, sizeof(arg
.vifs
[0]),
6692 ieee80211_iterate_active_interfaces_atomic(
6694 IEEE80211_IFACE_ITER_NORMAL
,
6695 ath10k_mac_change_chanctx_fill_iter
,
6697 ath10k_mac_update_vif_chan(ar
, arg
.vifs
, arg
.n_vifs
);
6702 ath10k_recalc_radar_detection(ar
);
6704 /* FIXME: How to configure Rx chains properly? */
6706 /* No other actions are actually necessary. Firmware maintains channel
6707 * definitions per vdev internally and there's no host-side channel
6708 * context abstraction to configure, e.g. channel width.
6712 mutex_unlock(&ar
->conf_mutex
);
6716 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
6717 struct ieee80211_vif
*vif
,
6718 struct ieee80211_chanctx_conf
*ctx
)
6720 struct ath10k
*ar
= hw
->priv
;
6721 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6724 mutex_lock(&ar
->conf_mutex
);
6726 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6727 "mac chanctx assign ptr %p vdev_id %i\n",
6728 ctx
, arvif
->vdev_id
);
6730 if (WARN_ON(arvif
->is_started
)) {
6731 mutex_unlock(&ar
->conf_mutex
);
6735 ret
= ath10k_vdev_start(arvif
, &ctx
->def
);
6737 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
6738 arvif
->vdev_id
, vif
->addr
,
6739 ctx
->def
.chan
->center_freq
, ret
);
6743 arvif
->is_started
= true;
6745 ret
= ath10k_mac_vif_setup_ps(arvif
);
6747 ath10k_warn(ar
, "failed to update vdev %i ps: %d\n",
6748 arvif
->vdev_id
, ret
);
6752 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6753 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
6755 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
6756 arvif
->vdev_id
, ret
);
6760 arvif
->is_up
= true;
6763 if (ath10k_mac_can_set_cts_prot(arvif
)) {
6764 ret
= ath10k_mac_set_cts_prot(arvif
);
6766 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
6767 arvif
->vdev_id
, ret
);
6770 mutex_unlock(&ar
->conf_mutex
);
6774 ath10k_vdev_stop(arvif
);
6775 arvif
->is_started
= false;
6776 ath10k_mac_vif_setup_ps(arvif
);
6779 mutex_unlock(&ar
->conf_mutex
);
6784 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
6785 struct ieee80211_vif
*vif
,
6786 struct ieee80211_chanctx_conf
*ctx
)
6788 struct ath10k
*ar
= hw
->priv
;
6789 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6792 mutex_lock(&ar
->conf_mutex
);
6794 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6795 "mac chanctx unassign ptr %p vdev_id %i\n",
6796 ctx
, arvif
->vdev_id
);
6798 WARN_ON(!arvif
->is_started
);
6800 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
6801 WARN_ON(!arvif
->is_up
);
6803 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
6805 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
6806 arvif
->vdev_id
, ret
);
6808 arvif
->is_up
= false;
6811 ret
= ath10k_vdev_stop(arvif
);
6813 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
6814 arvif
->vdev_id
, ret
);
6816 arvif
->is_started
= false;
6818 mutex_unlock(&ar
->conf_mutex
);
6822 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
6823 struct ieee80211_vif_chanctx_switch
*vifs
,
6825 enum ieee80211_chanctx_switch_mode mode
)
6827 struct ath10k
*ar
= hw
->priv
;
6829 mutex_lock(&ar
->conf_mutex
);
6831 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6832 "mac chanctx switch n_vifs %d mode %d\n",
6834 ath10k_mac_update_vif_chan(ar
, vifs
, n_vifs
);
6836 mutex_unlock(&ar
->conf_mutex
);
6840 static const struct ieee80211_ops ath10k_ops
= {
6842 .start
= ath10k_start
,
6843 .stop
= ath10k_stop
,
6844 .config
= ath10k_config
,
6845 .add_interface
= ath10k_add_interface
,
6846 .remove_interface
= ath10k_remove_interface
,
6847 .configure_filter
= ath10k_configure_filter
,
6848 .bss_info_changed
= ath10k_bss_info_changed
,
6849 .hw_scan
= ath10k_hw_scan
,
6850 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
6851 .set_key
= ath10k_set_key
,
6852 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
6853 .sta_state
= ath10k_sta_state
,
6854 .conf_tx
= ath10k_conf_tx
,
6855 .remain_on_channel
= ath10k_remain_on_channel
,
6856 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
6857 .set_rts_threshold
= ath10k_set_rts_threshold
,
6858 .set_frag_threshold
= ath10k_mac_op_set_frag_threshold
,
6859 .flush
= ath10k_flush
,
6860 .tx_last_beacon
= ath10k_tx_last_beacon
,
6861 .set_antenna
= ath10k_set_antenna
,
6862 .get_antenna
= ath10k_get_antenna
,
6863 .reconfig_complete
= ath10k_reconfig_complete
,
6864 .get_survey
= ath10k_get_survey
,
6865 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
6866 .sta_rc_update
= ath10k_sta_rc_update
,
6867 .get_tsf
= ath10k_get_tsf
,
6868 .ampdu_action
= ath10k_ampdu_action
,
6869 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
6870 .get_et_stats
= ath10k_debug_get_et_stats
,
6871 .get_et_strings
= ath10k_debug_get_et_strings
,
6872 .add_chanctx
= ath10k_mac_op_add_chanctx
,
6873 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
6874 .change_chanctx
= ath10k_mac_op_change_chanctx
,
6875 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
6876 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
6877 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
6879 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
6882 .suspend
= ath10k_wow_op_suspend
,
6883 .resume
= ath10k_wow_op_resume
,
6885 #ifdef CONFIG_MAC80211_DEBUGFS
6886 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
6890 #define CHAN2G(_channel, _freq, _flags) { \
6891 .band = IEEE80211_BAND_2GHZ, \
6892 .hw_value = (_channel), \
6893 .center_freq = (_freq), \
6894 .flags = (_flags), \
6895 .max_antenna_gain = 0, \
6899 #define CHAN5G(_channel, _freq, _flags) { \
6900 .band = IEEE80211_BAND_5GHZ, \
6901 .hw_value = (_channel), \
6902 .center_freq = (_freq), \
6903 .flags = (_flags), \
6904 .max_antenna_gain = 0, \
6908 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
6918 CHAN2G(10, 2457, 0),
6919 CHAN2G(11, 2462, 0),
6920 CHAN2G(12, 2467, 0),
6921 CHAN2G(13, 2472, 0),
6922 CHAN2G(14, 2484, 0),
6925 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
6926 CHAN5G(36, 5180, 0),
6927 CHAN5G(40, 5200, 0),
6928 CHAN5G(44, 5220, 0),
6929 CHAN5G(48, 5240, 0),
6930 CHAN5G(52, 5260, 0),
6931 CHAN5G(56, 5280, 0),
6932 CHAN5G(60, 5300, 0),
6933 CHAN5G(64, 5320, 0),
6934 CHAN5G(100, 5500, 0),
6935 CHAN5G(104, 5520, 0),
6936 CHAN5G(108, 5540, 0),
6937 CHAN5G(112, 5560, 0),
6938 CHAN5G(116, 5580, 0),
6939 CHAN5G(120, 5600, 0),
6940 CHAN5G(124, 5620, 0),
6941 CHAN5G(128, 5640, 0),
6942 CHAN5G(132, 5660, 0),
6943 CHAN5G(136, 5680, 0),
6944 CHAN5G(140, 5700, 0),
6945 CHAN5G(144, 5720, 0),
6946 CHAN5G(149, 5745, 0),
6947 CHAN5G(153, 5765, 0),
6948 CHAN5G(157, 5785, 0),
6949 CHAN5G(161, 5805, 0),
6950 CHAN5G(165, 5825, 0),
6953 struct ath10k
*ath10k_mac_create(size_t priv_size
)
6955 struct ieee80211_hw
*hw
;
6958 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
6968 void ath10k_mac_destroy(struct ath10k
*ar
)
6970 ieee80211_free_hw(ar
->hw
);
6973 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
6976 .types
= BIT(NL80211_IFTYPE_STATION
)
6977 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
6981 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
6985 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
6989 .types
= BIT(NL80211_IFTYPE_AP
)
6990 #ifdef CONFIG_MAC80211_MESH
6991 | BIT(NL80211_IFTYPE_MESH_POINT
)
6996 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
6999 .types
= BIT(NL80211_IFTYPE_AP
)
7000 #ifdef CONFIG_MAC80211_MESH
7001 | BIT(NL80211_IFTYPE_MESH_POINT
)
7006 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
7008 .limits
= ath10k_if_limits
,
7009 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
7010 .max_interfaces
= 8,
7011 .num_different_channels
= 1,
7012 .beacon_int_infra_match
= true,
7016 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
7018 .limits
= ath10k_10x_if_limits
,
7019 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
7020 .max_interfaces
= 8,
7021 .num_different_channels
= 1,
7022 .beacon_int_infra_match
= true,
7023 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7024 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
7025 BIT(NL80211_CHAN_WIDTH_20
) |
7026 BIT(NL80211_CHAN_WIDTH_40
) |
7027 BIT(NL80211_CHAN_WIDTH_80
),
7032 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
7035 .types
= BIT(NL80211_IFTYPE_STATION
),
7039 .types
= BIT(NL80211_IFTYPE_AP
) |
7040 #ifdef CONFIG_MAC80211_MESH
7041 BIT(NL80211_IFTYPE_MESH_POINT
) |
7043 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
7044 BIT(NL80211_IFTYPE_P2P_GO
),
7048 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
7052 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit
[] = {
7055 .types
= BIT(NL80211_IFTYPE_STATION
),
7059 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
),
7063 .types
= BIT(NL80211_IFTYPE_AP
) |
7064 #ifdef CONFIG_MAC80211_MESH
7065 BIT(NL80211_IFTYPE_MESH_POINT
) |
7067 BIT(NL80211_IFTYPE_P2P_GO
),
7071 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
7075 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
7078 .types
= BIT(NL80211_IFTYPE_STATION
),
7082 .types
= BIT(NL80211_IFTYPE_ADHOC
),
7086 /* FIXME: This is not thouroughly tested. These combinations may over- or
7087 * underestimate hw/fw capabilities.
7089 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
7091 .limits
= ath10k_tlv_if_limit
,
7092 .num_different_channels
= 1,
7093 .max_interfaces
= 4,
7094 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
7097 .limits
= ath10k_tlv_if_limit_ibss
,
7098 .num_different_channels
= 1,
7099 .max_interfaces
= 2,
7100 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
7104 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
7106 .limits
= ath10k_tlv_if_limit
,
7107 .num_different_channels
= 1,
7108 .max_interfaces
= 4,
7109 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
7112 .limits
= ath10k_tlv_qcs_if_limit
,
7113 .num_different_channels
= 2,
7114 .max_interfaces
= 4,
7115 .n_limits
= ARRAY_SIZE(ath10k_tlv_qcs_if_limit
),
7118 .limits
= ath10k_tlv_if_limit_ibss
,
7119 .num_different_channels
= 1,
7120 .max_interfaces
= 2,
7121 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
7125 static const struct ieee80211_iface_limit ath10k_10_4_if_limits
[] = {
7128 .types
= BIT(NL80211_IFTYPE_STATION
),
7132 .types
= BIT(NL80211_IFTYPE_AP
)
7133 #ifdef CONFIG_MAC80211_MESH
7134 | BIT(NL80211_IFTYPE_MESH_POINT
)
7139 static const struct ieee80211_iface_combination ath10k_10_4_if_comb
[] = {
7141 .limits
= ath10k_10_4_if_limits
,
7142 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
7143 .max_interfaces
= 16,
7144 .num_different_channels
= 1,
7145 .beacon_int_infra_match
= true,
7146 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7147 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
7148 BIT(NL80211_CHAN_WIDTH_20
) |
7149 BIT(NL80211_CHAN_WIDTH_40
) |
7150 BIT(NL80211_CHAN_WIDTH_80
),
7155 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
7156 struct ieee80211_vif
*vif
)
7158 struct ath10k_vif_iter
*arvif_iter
= data
;
7159 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
7161 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
7162 arvif_iter
->arvif
= arvif
;
7165 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
7167 struct ath10k_vif_iter arvif_iter
;
7170 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
7171 arvif_iter
.vdev_id
= vdev_id
;
7173 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
7174 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
7176 ath10k_get_arvif_iter
,
7178 if (!arvif_iter
.arvif
) {
7179 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
7183 return arvif_iter
.arvif
;
7186 int ath10k_mac_register(struct ath10k
*ar
)
7188 static const u32 cipher_suites
[] = {
7189 WLAN_CIPHER_SUITE_WEP40
,
7190 WLAN_CIPHER_SUITE_WEP104
,
7191 WLAN_CIPHER_SUITE_TKIP
,
7192 WLAN_CIPHER_SUITE_CCMP
,
7193 WLAN_CIPHER_SUITE_AES_CMAC
,
7195 struct ieee80211_supported_band
*band
;
7199 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
7201 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
7203 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
7204 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
7207 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
7208 channels
= kmemdup(ath10k_2ghz_channels
,
7209 sizeof(ath10k_2ghz_channels
),
7216 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
7217 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
7218 band
->channels
= channels
;
7219 band
->n_bitrates
= ath10k_g_rates_size
;
7220 band
->bitrates
= ath10k_g_rates
;
7222 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
7225 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
7226 channels
= kmemdup(ath10k_5ghz_channels
,
7227 sizeof(ath10k_5ghz_channels
),
7234 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
7235 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
7236 band
->channels
= channels
;
7237 band
->n_bitrates
= ath10k_a_rates_size
;
7238 band
->bitrates
= ath10k_a_rates
;
7239 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
7242 ath10k_mac_setup_ht_vht_cap(ar
);
7244 ar
->hw
->wiphy
->interface_modes
=
7245 BIT(NL80211_IFTYPE_STATION
) |
7246 BIT(NL80211_IFTYPE_AP
) |
7247 BIT(NL80211_IFTYPE_MESH_POINT
);
7249 ar
->hw
->wiphy
->available_antennas_rx
= ar
->cfg_rx_chainmask
;
7250 ar
->hw
->wiphy
->available_antennas_tx
= ar
->cfg_tx_chainmask
;
7252 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
7253 ar
->hw
->wiphy
->interface_modes
|=
7254 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
7255 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
7256 BIT(NL80211_IFTYPE_P2P_GO
);
7258 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
7259 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
7260 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
7261 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
7262 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
7263 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
7264 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
7265 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
7266 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
7267 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
7268 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
7269 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
7270 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
7271 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
7273 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
7274 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
7276 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
7277 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
7279 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
7280 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
7282 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
7283 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
7284 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
7287 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
7288 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
7290 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
7291 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
7293 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
7295 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
7296 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
7298 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7299 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7300 * correct Probe Responses. This is more of a hack advert..
7302 ar
->hw
->wiphy
->probe_resp_offload
|=
7303 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
7304 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
7305 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
7308 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
))
7309 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
7311 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
7312 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
7313 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
7315 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
7316 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
;
7318 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
7320 ret
= ath10k_wow_init(ar
);
7322 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
7326 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
7329 * on LL hardware queues are managed entirely by the FW
7330 * so we only advertise to mac we can do the queues thing
7332 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
7334 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7335 * something that vdev_ids can't reach so that we don't stop the queue
7338 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
7340 switch (ar
->wmi
.op_version
) {
7341 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
7342 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
7343 ar
->hw
->wiphy
->n_iface_combinations
=
7344 ARRAY_SIZE(ath10k_if_comb
);
7345 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
7347 case ATH10K_FW_WMI_OP_VERSION_TLV
:
7348 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
7349 ar
->hw
->wiphy
->iface_combinations
=
7350 ath10k_tlv_qcs_if_comb
;
7351 ar
->hw
->wiphy
->n_iface_combinations
=
7352 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
7354 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
7355 ar
->hw
->wiphy
->n_iface_combinations
=
7356 ARRAY_SIZE(ath10k_tlv_if_comb
);
7358 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
7360 case ATH10K_FW_WMI_OP_VERSION_10_1
:
7361 case ATH10K_FW_WMI_OP_VERSION_10_2
:
7362 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
7363 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
7364 ar
->hw
->wiphy
->n_iface_combinations
=
7365 ARRAY_SIZE(ath10k_10x_if_comb
);
7367 case ATH10K_FW_WMI_OP_VERSION_10_4
:
7368 ar
->hw
->wiphy
->iface_combinations
= ath10k_10_4_if_comb
;
7369 ar
->hw
->wiphy
->n_iface_combinations
=
7370 ARRAY_SIZE(ath10k_10_4_if_comb
);
7372 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
7373 case ATH10K_FW_WMI_OP_VERSION_MAX
:
7379 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
7380 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
7382 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
7383 /* Init ath dfs pattern detector */
7384 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
7385 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
7388 if (!ar
->dfs_detector
)
7389 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
7392 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
7393 ath10k_reg_notifier
);
7395 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
7396 goto err_dfs_detector_exit
;
7399 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
7400 ar
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
7402 ret
= ieee80211_register_hw(ar
->hw
);
7404 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
7405 goto err_dfs_detector_exit
;
7408 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
7409 ret
= regulatory_hint(ar
->hw
->wiphy
,
7410 ar
->ath_common
.regulatory
.alpha2
);
7412 goto err_unregister
;
7418 ieee80211_unregister_hw(ar
->hw
);
7420 err_dfs_detector_exit
:
7421 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
7422 ar
->dfs_detector
->exit(ar
->dfs_detector
);
7425 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
7426 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
7428 SET_IEEE80211_DEV(ar
->hw
, NULL
);
7432 void ath10k_mac_unregister(struct ath10k
*ar
)
7434 ieee80211_unregister_hw(ar
->hw
);
7436 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
7437 ar
->dfs_detector
->exit(ar
->dfs_detector
);
7439 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
7440 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
7442 SET_IEEE80211_DEV(ar
->hw
, NULL
);