1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2005-2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
6 * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
11 #include <net/cfg80211.h>
12 #include <net/mac80211.h>
13 #include <linux/etherdevice.h>
14 #include <linux/acpi.h>
16 #include <linux/bitfield.h>
34 static struct ieee80211_rate ath10k_rates
[] = {
36 .hw_value
= ATH10K_HW_RATE_CCK_LP_1M
},
38 .hw_value
= ATH10K_HW_RATE_CCK_LP_2M
,
39 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_2M
,
40 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
42 .hw_value
= ATH10K_HW_RATE_CCK_LP_5_5M
,
43 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_5_5M
,
44 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
46 .hw_value
= ATH10K_HW_RATE_CCK_LP_11M
,
47 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_11M
,
48 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
50 { .bitrate
= 60, .hw_value
= ATH10K_HW_RATE_OFDM_6M
},
51 { .bitrate
= 90, .hw_value
= ATH10K_HW_RATE_OFDM_9M
},
52 { .bitrate
= 120, .hw_value
= ATH10K_HW_RATE_OFDM_12M
},
53 { .bitrate
= 180, .hw_value
= ATH10K_HW_RATE_OFDM_18M
},
54 { .bitrate
= 240, .hw_value
= ATH10K_HW_RATE_OFDM_24M
},
55 { .bitrate
= 360, .hw_value
= ATH10K_HW_RATE_OFDM_36M
},
56 { .bitrate
= 480, .hw_value
= ATH10K_HW_RATE_OFDM_48M
},
57 { .bitrate
= 540, .hw_value
= ATH10K_HW_RATE_OFDM_54M
},
60 static struct ieee80211_rate ath10k_rates_rev2
[] = {
62 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_1M
},
64 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_2M
,
65 .hw_value_short
= ATH10K_HW_RATE_REV2_CCK_SP_2M
,
66 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
68 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_5_5M
,
69 .hw_value_short
= ATH10K_HW_RATE_REV2_CCK_SP_5_5M
,
70 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
72 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_11M
,
73 .hw_value_short
= ATH10K_HW_RATE_REV2_CCK_SP_11M
,
74 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
76 { .bitrate
= 60, .hw_value
= ATH10K_HW_RATE_OFDM_6M
},
77 { .bitrate
= 90, .hw_value
= ATH10K_HW_RATE_OFDM_9M
},
78 { .bitrate
= 120, .hw_value
= ATH10K_HW_RATE_OFDM_12M
},
79 { .bitrate
= 180, .hw_value
= ATH10K_HW_RATE_OFDM_18M
},
80 { .bitrate
= 240, .hw_value
= ATH10K_HW_RATE_OFDM_24M
},
81 { .bitrate
= 360, .hw_value
= ATH10K_HW_RATE_OFDM_36M
},
82 { .bitrate
= 480, .hw_value
= ATH10K_HW_RATE_OFDM_48M
},
83 { .bitrate
= 540, .hw_value
= ATH10K_HW_RATE_OFDM_54M
},
86 static const struct cfg80211_sar_freq_ranges ath10k_sar_freq_ranges
[] = {
87 {.start_freq
= 2402, .end_freq
= 2494 },
88 {.start_freq
= 5170, .end_freq
= 5875 },
91 static const struct cfg80211_sar_capa ath10k_sar_capa
= {
92 .type
= NL80211_SAR_TYPE_POWER
,
93 .num_freq_ranges
= (ARRAY_SIZE(ath10k_sar_freq_ranges
)),
94 .freq_ranges
= &ath10k_sar_freq_ranges
[0],
97 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
99 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
100 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
101 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
102 #define ath10k_g_rates (ath10k_rates + 0)
103 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
105 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
106 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
108 #define ath10k_wmi_legacy_rates ath10k_rates
110 static bool ath10k_mac_bitrate_is_cck(int bitrate
)
123 static u8
ath10k_mac_bitrate_to_rate(int bitrate
)
125 return DIV_ROUND_UP(bitrate
, 5) |
126 (ath10k_mac_bitrate_is_cck(bitrate
) ? BIT(7) : 0);
129 u8
ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band
*sband
,
130 u8 hw_rate
, bool cck
)
132 const struct ieee80211_rate
*rate
;
135 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
136 rate
= &sband
->bitrates
[i
];
138 if (ath10k_mac_bitrate_is_cck(rate
->bitrate
) != cck
)
141 if (rate
->hw_value
== hw_rate
)
143 else if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
&&
144 rate
->hw_value_short
== hw_rate
)
151 u8
ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band
*sband
,
156 for (i
= 0; i
< sband
->n_bitrates
; i
++)
157 if (sband
->bitrates
[i
].bitrate
== bitrate
)
163 static int ath10k_mac_get_rate_hw_value(int bitrate
)
166 u8 hw_value_prefix
= 0;
168 if (ath10k_mac_bitrate_is_cck(bitrate
))
169 hw_value_prefix
= WMI_RATE_PREAMBLE_CCK
<< 6;
171 for (i
= 0; i
< ARRAY_SIZE(ath10k_rates
); i
++) {
172 if (ath10k_rates
[i
].bitrate
== bitrate
)
173 return hw_value_prefix
| ath10k_rates
[i
].hw_value
;
179 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map
, int nss
)
181 switch ((mcs_map
>> (2 * nss
)) & 0x3) {
182 case IEEE80211_VHT_MCS_SUPPORT_0_7
: return BIT(8) - 1;
183 case IEEE80211_VHT_MCS_SUPPORT_0_8
: return BIT(9) - 1;
184 case IEEE80211_VHT_MCS_SUPPORT_0_9
: return BIT(10) - 1;
190 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
194 for (nss
= IEEE80211_HT_MCS_MASK_LEN
- 1; nss
>= 0; nss
--)
195 if (ht_mcs_mask
[nss
])
202 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
206 for (nss
= NL80211_VHT_NSS_MAX
- 1; nss
>= 0; nss
--)
207 if (vht_mcs_mask
[nss
])
213 int ath10k_mac_ext_resource_config(struct ath10k
*ar
, u32 val
)
215 enum wmi_host_platform_type platform_type
;
218 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC
, ar
->wmi
.svc_map
))
219 platform_type
= WMI_HOST_PLATFORM_LOW_PERF
;
221 platform_type
= WMI_HOST_PLATFORM_HIGH_PERF
;
223 ret
= ath10k_wmi_ext_resource_config(ar
, platform_type
, val
);
225 if (ret
&& ret
!= -EOPNOTSUPP
) {
226 ath10k_warn(ar
, "failed to configure ext resource: %d\n", ret
);
237 static int ath10k_send_key(struct ath10k_vif
*arvif
,
238 struct ieee80211_key_conf
*key
,
239 enum set_key_cmd cmd
,
240 const u8
*macaddr
, u32 flags
)
242 struct ath10k
*ar
= arvif
->ar
;
243 struct wmi_vdev_install_key_arg arg
= {
244 .vdev_id
= arvif
->vdev_id
,
245 .key_idx
= key
->keyidx
,
246 .key_len
= key
->keylen
,
247 .key_data
= key
->key
,
252 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
254 switch (key
->cipher
) {
255 case WLAN_CIPHER_SUITE_CCMP
:
256 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_AES_CCM
];
257 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
259 case WLAN_CIPHER_SUITE_TKIP
:
260 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_TKIP
];
261 arg
.key_txmic_len
= 8;
262 arg
.key_rxmic_len
= 8;
264 case WLAN_CIPHER_SUITE_WEP40
:
265 case WLAN_CIPHER_SUITE_WEP104
:
266 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_WEP
];
268 case WLAN_CIPHER_SUITE_CCMP_256
:
269 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_AES_CCM
];
271 case WLAN_CIPHER_SUITE_GCMP
:
272 case WLAN_CIPHER_SUITE_GCMP_256
:
273 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_AES_GCM
];
274 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
276 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
277 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
278 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
279 case WLAN_CIPHER_SUITE_AES_CMAC
:
283 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
287 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
288 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
290 if (cmd
== DISABLE_KEY
) {
291 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_NONE
];
295 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
298 static int ath10k_install_key(struct ath10k_vif
*arvif
,
299 struct ieee80211_key_conf
*key
,
300 enum set_key_cmd cmd
,
301 const u8
*macaddr
, u32 flags
)
303 struct ath10k
*ar
= arvif
->ar
;
305 unsigned long time_left
;
307 lockdep_assert_held(&ar
->conf_mutex
);
309 reinit_completion(&ar
->install_key_done
);
311 if (arvif
->nohwcrypt
)
314 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
318 time_left
= wait_for_completion_timeout(&ar
->install_key_done
, 3 * HZ
);
325 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
328 struct ath10k
*ar
= arvif
->ar
;
329 struct ath10k_peer
*peer
;
334 lockdep_assert_held(&ar
->conf_mutex
);
336 if (WARN_ON(arvif
->vif
->type
!= NL80211_IFTYPE_AP
&&
337 arvif
->vif
->type
!= NL80211_IFTYPE_ADHOC
&&
338 arvif
->vif
->type
!= NL80211_IFTYPE_MESH_POINT
))
341 spin_lock_bh(&ar
->data_lock
);
342 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
343 spin_unlock_bh(&ar
->data_lock
);
348 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
349 if (arvif
->wep_keys
[i
] == NULL
)
352 switch (arvif
->vif
->type
) {
353 case NL80211_IFTYPE_AP
:
354 flags
= WMI_KEY_PAIRWISE
;
356 if (arvif
->def_wep_key_idx
== i
)
357 flags
|= WMI_KEY_TX_USAGE
;
359 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
360 SET_KEY
, addr
, flags
);
364 case NL80211_IFTYPE_ADHOC
:
365 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
371 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
372 SET_KEY
, addr
, WMI_KEY_GROUP
);
381 spin_lock_bh(&ar
->data_lock
);
382 peer
->keys
[i
] = arvif
->wep_keys
[i
];
383 spin_unlock_bh(&ar
->data_lock
);
386 /* In some cases (notably with static WEP IBSS with multiple keys)
387 * multicast Tx becomes broken. Both pairwise and groupwise keys are
388 * installed already. Using WMI_KEY_TX_USAGE in different combinations
389 * didn't seem help. Using def_keyid vdev parameter seems to be
390 * effective so use that.
392 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
394 if (arvif
->vif
->type
!= NL80211_IFTYPE_ADHOC
)
397 if (arvif
->def_wep_key_idx
== -1)
400 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
402 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
403 arvif
->def_wep_key_idx
);
405 ath10k_warn(ar
, "failed to re-set def wpa key idxon vdev %i: %d\n",
406 arvif
->vdev_id
, ret
);
413 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
416 struct ath10k
*ar
= arvif
->ar
;
417 struct ath10k_peer
*peer
;
423 lockdep_assert_held(&ar
->conf_mutex
);
425 spin_lock_bh(&ar
->data_lock
);
426 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
427 spin_unlock_bh(&ar
->data_lock
);
432 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
433 if (peer
->keys
[i
] == NULL
)
436 /* key flags are not required to delete the key */
437 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
438 DISABLE_KEY
, addr
, flags
);
439 if (ret
< 0 && first_errno
== 0)
443 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
446 spin_lock_bh(&ar
->data_lock
);
447 peer
->keys
[i
] = NULL
;
448 spin_unlock_bh(&ar
->data_lock
);
454 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
457 struct ath10k_peer
*peer
;
460 lockdep_assert_held(&ar
->data_lock
);
462 /* We don't know which vdev this peer belongs to,
463 * since WMI doesn't give us that information.
465 * FIXME: multi-bss needs to be handled.
467 peer
= ath10k_peer_find(ar
, 0, addr
);
471 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
472 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
479 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
480 struct ieee80211_key_conf
*key
)
482 struct ath10k
*ar
= arvif
->ar
;
483 struct ath10k_peer
*peer
;
490 lockdep_assert_held(&ar
->conf_mutex
);
493 /* since ath10k_install_key we can't hold data_lock all the
494 * time, so we try to remove the keys incrementally
496 spin_lock_bh(&ar
->data_lock
);
498 list_for_each_entry(peer
, &ar
->peers
, list
) {
499 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
500 if (peer
->keys
[i
] == key
) {
501 ether_addr_copy(addr
, peer
->addr
);
502 peer
->keys
[i
] = NULL
;
507 if (i
< ARRAY_SIZE(peer
->keys
))
510 spin_unlock_bh(&ar
->data_lock
);
512 if (i
== ARRAY_SIZE(peer
->keys
))
514 /* key flags are not required to delete the key */
515 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
516 if (ret
< 0 && first_errno
== 0)
520 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
527 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
528 struct ieee80211_key_conf
*key
)
530 struct ath10k
*ar
= arvif
->ar
;
531 struct ath10k_peer
*peer
;
534 lockdep_assert_held(&ar
->conf_mutex
);
536 list_for_each_entry(peer
, &ar
->peers
, list
) {
537 if (ether_addr_equal(peer
->addr
, arvif
->vif
->addr
))
540 if (ether_addr_equal(peer
->addr
, arvif
->bssid
))
543 if (peer
->keys
[key
->keyidx
] == key
)
546 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
547 arvif
->vdev_id
, key
->keyidx
);
549 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
551 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
552 arvif
->vdev_id
, peer
->addr
, ret
);
560 /*********************/
561 /* General utilities */
562 /*********************/
564 static inline enum wmi_phy_mode
565 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
567 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
569 switch (chandef
->chan
->band
) {
570 case NL80211_BAND_2GHZ
:
571 switch (chandef
->width
) {
572 case NL80211_CHAN_WIDTH_20_NOHT
:
573 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
578 case NL80211_CHAN_WIDTH_20
:
579 phymode
= MODE_11NG_HT20
;
581 case NL80211_CHAN_WIDTH_40
:
582 phymode
= MODE_11NG_HT40
;
585 phymode
= MODE_UNKNOWN
;
589 case NL80211_BAND_5GHZ
:
590 switch (chandef
->width
) {
591 case NL80211_CHAN_WIDTH_20_NOHT
:
594 case NL80211_CHAN_WIDTH_20
:
595 phymode
= MODE_11NA_HT20
;
597 case NL80211_CHAN_WIDTH_40
:
598 phymode
= MODE_11NA_HT40
;
600 case NL80211_CHAN_WIDTH_80
:
601 phymode
= MODE_11AC_VHT80
;
603 case NL80211_CHAN_WIDTH_160
:
604 phymode
= MODE_11AC_VHT160
;
606 case NL80211_CHAN_WIDTH_80P80
:
607 phymode
= MODE_11AC_VHT80_80
;
610 phymode
= MODE_UNKNOWN
;
618 WARN_ON(phymode
== MODE_UNKNOWN
);
622 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
625 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
626 * 0 for no restriction
635 switch (mpdudensity
) {
641 /* Our lower layer calculations limit our precision to
658 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
659 struct cfg80211_chan_def
*def
)
661 struct ieee80211_chanctx_conf
*conf
;
664 conf
= rcu_dereference(vif
->bss_conf
.chanctx_conf
);
676 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
677 struct ieee80211_chanctx_conf
*conf
,
685 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
689 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
690 ath10k_mac_num_chanctxs_iter
,
697 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
698 struct ieee80211_chanctx_conf
*conf
,
701 struct cfg80211_chan_def
**def
= data
;
706 static void ath10k_wait_for_peer_delete_done(struct ath10k
*ar
, u32 vdev_id
,
709 unsigned long time_left
;
712 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
713 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
715 ath10k_warn(ar
, "failed wait for peer deleted");
719 time_left
= wait_for_completion_timeout(&ar
->peer_delete_done
,
722 ath10k_warn(ar
, "Timeout in receiving peer delete response\n");
726 static int ath10k_peer_create(struct ath10k
*ar
,
727 struct ieee80211_vif
*vif
,
728 struct ieee80211_sta
*sta
,
731 enum wmi_peer_type peer_type
)
733 struct ath10k_peer
*peer
;
736 lockdep_assert_held(&ar
->conf_mutex
);
738 /* Each vdev consumes a peer entry as well. */
739 if (ar
->num_peers
+ list_count_nodes(&ar
->arvifs
) >= ar
->max_num_peers
)
742 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
744 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
749 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
751 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
756 spin_lock_bh(&ar
->data_lock
);
758 peer
= ath10k_peer_find(ar
, vdev_id
, addr
);
760 spin_unlock_bh(&ar
->data_lock
);
761 ath10k_warn(ar
, "failed to find peer %pM on vdev %i after creation\n",
763 ath10k_wait_for_peer_delete_done(ar
, vdev_id
, addr
);
770 spin_unlock_bh(&ar
->data_lock
);
777 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
779 struct ath10k
*ar
= arvif
->ar
;
783 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
784 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
785 ATH10K_KICKOUT_THRESHOLD
);
787 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
788 arvif
->vdev_id
, ret
);
792 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
793 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
794 ATH10K_KEEPALIVE_MIN_IDLE
);
796 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
797 arvif
->vdev_id
, ret
);
801 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
802 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
803 ATH10K_KEEPALIVE_MAX_IDLE
);
805 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
806 arvif
->vdev_id
, ret
);
810 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
811 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
812 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
814 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
815 arvif
->vdev_id
, ret
);
822 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
824 struct ath10k
*ar
= arvif
->ar
;
827 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
828 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
831 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
835 lockdep_assert_held(&ar
->conf_mutex
);
837 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
841 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
845 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
846 unsigned long time_left
;
848 time_left
= wait_for_completion_timeout
849 (&ar
->peer_delete_done
, 5 * HZ
);
852 ath10k_warn(ar
, "Timeout in receiving peer delete response\n");
862 static void ath10k_peer_map_cleanup(struct ath10k
*ar
, struct ath10k_peer
*peer
)
866 lockdep_assert_held(&ar
->conf_mutex
);
868 for_each_set_bit(peer_id
, peer
->peer_ids
,
869 ATH10K_MAX_NUM_PEER_IDS
) {
870 ar
->peer_map
[peer_id
] = NULL
;
873 /* Double check that peer is properly un-referenced from
876 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
877 if (ar
->peer_map
[i
] == peer
) {
878 ath10k_warn(ar
, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
879 peer
->addr
, peer
, i
);
880 ar
->peer_map
[i
] = NULL
;
884 list_del(&peer
->list
);
889 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
891 struct ath10k_peer
*peer
, *tmp
;
893 lockdep_assert_held(&ar
->conf_mutex
);
895 spin_lock_bh(&ar
->data_lock
);
896 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
897 if (peer
->vdev_id
!= vdev_id
)
900 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
901 peer
->addr
, vdev_id
);
903 ath10k_peer_map_cleanup(ar
, peer
);
905 spin_unlock_bh(&ar
->data_lock
);
908 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
910 struct ath10k_peer
*peer
, *tmp
;
913 lockdep_assert_held(&ar
->conf_mutex
);
915 spin_lock_bh(&ar
->data_lock
);
916 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
917 list_del(&peer
->list
);
921 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++)
922 ar
->peer_map
[i
] = NULL
;
924 spin_unlock_bh(&ar
->data_lock
);
927 ar
->num_stations
= 0;
930 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
931 struct ieee80211_sta
*sta
,
932 enum wmi_tdls_peer_state state
)
935 struct wmi_tdls_peer_update_cmd_arg arg
= {};
936 struct wmi_tdls_peer_capab_arg cap
= {};
937 struct wmi_channel_arg chan_arg
= {};
939 lockdep_assert_held(&ar
->conf_mutex
);
941 arg
.vdev_id
= vdev_id
;
942 arg
.peer_state
= state
;
943 ether_addr_copy(arg
.addr
, sta
->addr
);
945 cap
.peer_max_sp
= sta
->max_sp
;
946 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
948 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
949 !sta
->tdls_initiator
)
950 cap
.is_peer_responder
= 1;
952 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
954 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
955 arg
.addr
, vdev_id
, ret
);
962 /************************/
963 /* Interface management */
964 /************************/
966 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
968 struct ath10k
*ar
= arvif
->ar
;
970 lockdep_assert_held(&ar
->data_lock
);
975 if (!arvif
->beacon_buf
)
976 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
977 arvif
->beacon
->len
, DMA_TO_DEVICE
);
979 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
980 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
983 dev_kfree_skb_any(arvif
->beacon
);
985 arvif
->beacon
= NULL
;
986 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
989 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
991 struct ath10k
*ar
= arvif
->ar
;
993 lockdep_assert_held(&ar
->data_lock
);
995 ath10k_mac_vif_beacon_free(arvif
);
997 if (arvif
->beacon_buf
) {
998 if (ar
->bus_param
.dev_type
== ATH10K_DEV_TYPE_HL
)
999 kfree(arvif
->beacon_buf
);
1001 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
1003 arvif
->beacon_paddr
);
1004 arvif
->beacon_buf
= NULL
;
1008 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
1010 unsigned long time_left
;
1012 lockdep_assert_held(&ar
->conf_mutex
);
1014 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
1017 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
1018 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
1022 return ar
->last_wmi_vdev_start_status
;
1025 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
1027 struct cfg80211_chan_def
*chandef
= NULL
;
1028 struct ieee80211_channel
*channel
= NULL
;
1029 struct wmi_vdev_start_request_arg arg
= {};
1032 lockdep_assert_held(&ar
->conf_mutex
);
1034 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1035 ath10k_mac_get_any_chandef_iter
,
1037 if (WARN_ON_ONCE(!chandef
))
1040 channel
= chandef
->chan
;
1042 arg
.vdev_id
= vdev_id
;
1043 arg
.channel
.freq
= channel
->center_freq
;
1044 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1045 arg
.channel
.band_center_freq2
= chandef
->center_freq2
;
1047 /* TODO setup this dynamically, what in case we
1048 * don't have any vifs?
1050 arg
.channel
.mode
= chan_to_phymode(chandef
);
1051 arg
.channel
.chan_radar
=
1052 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
1054 arg
.channel
.min_power
= 0;
1055 arg
.channel
.max_power
= channel
->max_power
* 2;
1056 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
1057 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
1059 reinit_completion(&ar
->vdev_setup_done
);
1060 reinit_completion(&ar
->vdev_delete_done
);
1062 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1064 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
1069 ret
= ath10k_vdev_setup_sync(ar
);
1071 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
1076 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
1078 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
1083 ar
->monitor_vdev_id
= vdev_id
;
1085 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
1086 ar
->monitor_vdev_id
);
1090 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
1092 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
1093 ar
->monitor_vdev_id
, ret
);
1098 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
1102 lockdep_assert_held(&ar
->conf_mutex
);
1104 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
1106 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
1107 ar
->monitor_vdev_id
, ret
);
1109 reinit_completion(&ar
->vdev_setup_done
);
1110 reinit_completion(&ar
->vdev_delete_done
);
1112 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
1114 ath10k_warn(ar
, "failed to request monitor vdev %i stop: %d\n",
1115 ar
->monitor_vdev_id
, ret
);
1117 ret
= ath10k_vdev_setup_sync(ar
);
1119 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
1120 ar
->monitor_vdev_id
, ret
);
1122 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
1123 ar
->monitor_vdev_id
);
1127 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
1131 lockdep_assert_held(&ar
->conf_mutex
);
1133 if (ar
->free_vdev_map
== 0) {
1134 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
1138 bit
= __ffs64(ar
->free_vdev_map
);
1140 ar
->monitor_vdev_id
= bit
;
1142 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
1143 WMI_VDEV_TYPE_MONITOR
,
1146 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
1147 ar
->monitor_vdev_id
, ret
);
1151 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
1152 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
1153 ar
->monitor_vdev_id
);
1158 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
1162 lockdep_assert_held(&ar
->conf_mutex
);
1164 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
1166 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
1167 ar
->monitor_vdev_id
, ret
);
1171 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
1173 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
1174 ar
->monitor_vdev_id
);
1178 static int ath10k_monitor_start(struct ath10k
*ar
)
1182 lockdep_assert_held(&ar
->conf_mutex
);
1184 ret
= ath10k_monitor_vdev_create(ar
);
1186 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
1190 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
1192 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
1193 ath10k_monitor_vdev_delete(ar
);
1197 ar
->monitor_started
= true;
1198 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
1203 static int ath10k_monitor_stop(struct ath10k
*ar
)
1207 lockdep_assert_held(&ar
->conf_mutex
);
1209 ret
= ath10k_monitor_vdev_stop(ar
);
1211 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1215 ret
= ath10k_monitor_vdev_delete(ar
);
1217 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1221 ar
->monitor_started
= false;
1222 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1227 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1231 /* At least one chanctx is required to derive a channel to start
1234 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1238 /* If there's already an existing special monitor interface then don't
1239 * bother creating another monitor vdev.
1241 if (ar
->monitor_arvif
)
1244 return ar
->monitor
||
1245 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST
,
1246 ar
->running_fw
->fw_file
.fw_features
) &&
1247 (ar
->filter_flags
& (FIF_OTHER_BSS
| FIF_MCAST_ACTION
))) ||
1248 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1251 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1255 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1257 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1258 * shouldn't allow this but make sure to prevent handling the following
1259 * case anyway since multi-channel DFS hasn't been tested at all.
1261 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1267 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1273 lockdep_assert_held(&ar
->conf_mutex
);
1275 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1276 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1278 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1279 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1280 ar
->monitor_started
, needed
, allowed
);
1282 if (WARN_ON(needed
&& !allowed
)) {
1283 if (ar
->monitor_started
) {
1284 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1286 ret
= ath10k_monitor_stop(ar
);
1288 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n",
1296 if (needed
== ar
->monitor_started
)
1300 return ath10k_monitor_start(ar
);
1302 return ath10k_monitor_stop(ar
);
1305 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif
*arvif
)
1307 struct ath10k
*ar
= arvif
->ar
;
1309 lockdep_assert_held(&ar
->conf_mutex
);
1311 if (!arvif
->is_started
) {
1312 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "defer cts setup, vdev is not ready yet\n");
1319 static int ath10k_mac_set_cts_prot(struct ath10k_vif
*arvif
)
1321 struct ath10k
*ar
= arvif
->ar
;
1324 lockdep_assert_held(&ar
->conf_mutex
);
1326 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
1328 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_protection %d\n",
1329 arvif
->vdev_id
, arvif
->use_cts_prot
);
1331 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1332 arvif
->use_cts_prot
? 1 : 0);
1335 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1337 struct ath10k
*ar
= arvif
->ar
;
1338 u32 vdev_param
, rts_cts
= 0;
1340 lockdep_assert_held(&ar
->conf_mutex
);
1342 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1344 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1346 if (arvif
->num_legacy_stations
> 0)
1347 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1348 WMI_RTSCTS_PROFILE
);
1350 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1351 WMI_RTSCTS_PROFILE
);
1353 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d recalc rts/cts prot %d\n",
1354 arvif
->vdev_id
, rts_cts
);
1356 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1360 static int ath10k_start_cac(struct ath10k
*ar
)
1364 lockdep_assert_held(&ar
->conf_mutex
);
1366 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1368 ret
= ath10k_monitor_recalc(ar
);
1370 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1371 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1375 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1376 ar
->monitor_vdev_id
);
1381 static int ath10k_stop_cac(struct ath10k
*ar
)
1383 lockdep_assert_held(&ar
->conf_mutex
);
1385 /* CAC is not running - do nothing */
1386 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1389 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1390 ath10k_monitor_stop(ar
);
1392 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1397 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1398 struct ieee80211_chanctx_conf
*conf
,
1403 if (!*ret
&& conf
->radar_enabled
)
1407 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1409 bool has_radar
= false;
1411 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1412 ath10k_mac_has_radar_iter
,
1418 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1422 lockdep_assert_held(&ar
->conf_mutex
);
1424 ath10k_stop_cac(ar
);
1426 if (!ath10k_mac_has_radar_enabled(ar
))
1429 if (ar
->num_started_vdevs
> 0)
1432 ret
= ath10k_start_cac(ar
);
1435 * Not possible to start CAC on current channel so starting
1436 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1437 * by indicating that radar was detected.
1439 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1440 ieee80211_radar_detected(ar
->hw
, NULL
);
1444 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1446 struct ath10k
*ar
= arvif
->ar
;
1449 lockdep_assert_held(&ar
->conf_mutex
);
1451 reinit_completion(&ar
->vdev_setup_done
);
1452 reinit_completion(&ar
->vdev_delete_done
);
1454 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1456 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1457 arvif
->vdev_id
, ret
);
1461 ret
= ath10k_vdev_setup_sync(ar
);
1463 ath10k_warn(ar
, "failed to synchronize setup for vdev %i: %d\n",
1464 arvif
->vdev_id
, ret
);
1468 WARN_ON(ar
->num_started_vdevs
== 0);
1470 if (ar
->num_started_vdevs
!= 0) {
1471 ar
->num_started_vdevs
--;
1472 ath10k_recalc_radar_detection(ar
);
1478 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1479 const struct cfg80211_chan_def
*chandef
,
1482 struct ath10k
*ar
= arvif
->ar
;
1483 struct wmi_vdev_start_request_arg arg
= {};
1486 lockdep_assert_held(&ar
->conf_mutex
);
1488 reinit_completion(&ar
->vdev_setup_done
);
1489 reinit_completion(&ar
->vdev_delete_done
);
1491 arg
.vdev_id
= arvif
->vdev_id
;
1492 arg
.dtim_period
= arvif
->dtim_period
;
1493 arg
.bcn_intval
= arvif
->beacon_interval
;
1495 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1496 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1497 arg
.channel
.band_center_freq2
= chandef
->center_freq2
;
1498 arg
.channel
.mode
= chan_to_phymode(chandef
);
1500 arg
.channel
.min_power
= 0;
1501 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1502 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1503 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
;
1505 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1506 arg
.ssid
= arvif
->u
.ap
.ssid
;
1507 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1508 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1510 /* For now allow DFS for AP mode */
1511 arg
.channel
.chan_radar
=
1512 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1513 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1514 arg
.ssid
= arvif
->vif
->cfg
.ssid
;
1515 arg
.ssid_len
= arvif
->vif
->cfg
.ssid_len
;
1518 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1519 "mac vdev %d start center_freq %d phymode %s\n",
1520 arg
.vdev_id
, arg
.channel
.freq
,
1521 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1524 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1526 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1529 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1534 ret
= ath10k_vdev_setup_sync(ar
);
1537 "failed to synchronize setup for vdev %i restart %d: %d\n",
1538 arg
.vdev_id
, restart
, ret
);
1542 ar
->num_started_vdevs
++;
1543 ath10k_recalc_radar_detection(ar
);
1548 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1549 const struct cfg80211_chan_def
*def
)
1551 return ath10k_vdev_start_restart(arvif
, def
, false);
1554 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1555 const struct cfg80211_chan_def
*def
)
1557 return ath10k_vdev_start_restart(arvif
, def
, true);
1560 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1561 struct sk_buff
*bcn
)
1563 struct ath10k
*ar
= arvif
->ar
;
1564 struct ieee80211_mgmt
*mgmt
;
1568 if (arvif
->vif
->type
!= NL80211_IFTYPE_AP
|| !arvif
->vif
->p2p
)
1571 mgmt
= (void *)bcn
->data
;
1572 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1573 mgmt
->u
.beacon
.variable
,
1574 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1579 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1581 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1582 arvif
->vdev_id
, ret
);
1589 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1590 u8 oui_type
, size_t ie_offset
)
1597 if (WARN_ON(skb
->len
< ie_offset
))
1600 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1601 skb
->data
+ ie_offset
,
1602 skb
->len
- ie_offset
);
1607 end
= skb
->data
+ skb
->len
;
1610 if (WARN_ON(next
> end
))
1613 memmove(ie
, next
, end
- next
);
1614 skb_trim(skb
, skb
->len
- len
);
1619 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1621 struct ath10k
*ar
= arvif
->ar
;
1622 struct ieee80211_hw
*hw
= ar
->hw
;
1623 struct ieee80211_vif
*vif
= arvif
->vif
;
1624 struct ieee80211_mutable_offsets offs
= {};
1625 struct sk_buff
*bcn
;
1628 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1631 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1632 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1635 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
, 0);
1637 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1641 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1643 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1648 /* P2P IE is inserted by firmware automatically (as configured above)
1649 * so remove it from the base beacon template to avoid duplicate P2P
1650 * IEs in beacon frames.
1652 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1653 offsetof(struct ieee80211_mgmt
,
1654 u
.beacon
.variable
));
1656 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1661 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1669 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1671 struct ath10k
*ar
= arvif
->ar
;
1672 struct ieee80211_hw
*hw
= ar
->hw
;
1673 struct ieee80211_vif
*vif
= arvif
->vif
;
1674 struct sk_buff
*prb
;
1677 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1680 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1683 /* For mesh, probe response and beacon share the same template */
1684 if (ieee80211_vif_is_mesh(vif
))
1687 prb
= ieee80211_proberesp_get(hw
, vif
);
1689 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1693 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1697 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1705 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1707 struct ath10k
*ar
= arvif
->ar
;
1708 struct cfg80211_chan_def def
;
1711 /* When originally vdev is started during assign_vif_chanctx() some
1712 * information is missing, notably SSID. Firmware revisions with beacon
1713 * offloading require the SSID to be provided during vdev (re)start to
1714 * handle hidden SSID properly.
1716 * Vdev restart must be done after vdev has been both started and
1717 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1718 * deliver vdev restart response event causing timeouts during vdev
1719 * syncing in ath10k.
1721 * Note: The vdev down/up and template reinstallation could be skipped
1722 * since only wmi-tlv firmware are known to have beacon offload and
1723 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1724 * response delivery. It's probably more robust to keep it as is.
1726 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1729 if (WARN_ON(!arvif
->is_started
))
1732 if (WARN_ON(!arvif
->is_up
))
1735 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1738 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1740 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1741 arvif
->vdev_id
, ret
);
1745 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1746 * firmware will crash upon vdev up.
1749 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1751 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1755 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1757 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1761 ret
= ath10k_vdev_restart(arvif
, &def
);
1763 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1764 arvif
->vdev_id
, ret
);
1768 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1771 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1772 arvif
->vdev_id
, ret
);
1779 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1780 struct ieee80211_bss_conf
*info
)
1782 struct ath10k
*ar
= arvif
->ar
;
1785 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1787 if (!info
->enable_beacon
) {
1788 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1790 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1791 arvif
->vdev_id
, ret
);
1793 arvif
->is_up
= false;
1795 spin_lock_bh(&arvif
->ar
->data_lock
);
1796 ath10k_mac_vif_beacon_free(arvif
);
1797 spin_unlock_bh(&arvif
->ar
->data_lock
);
1802 arvif
->tx_seq_no
= 0x1000;
1805 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1807 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1810 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1811 arvif
->vdev_id
, ret
);
1815 arvif
->is_up
= true;
1817 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1819 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1820 arvif
->vdev_id
, ret
);
1824 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1827 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1828 struct ieee80211_vif
*vif
)
1830 struct ath10k
*ar
= arvif
->ar
;
1834 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1836 if (!vif
->cfg
.ibss_joined
) {
1837 if (is_zero_ether_addr(arvif
->bssid
))
1840 eth_zero_addr(arvif
->bssid
);
1845 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1846 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1847 ATH10K_DEFAULT_ATIM
);
1849 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1850 arvif
->vdev_id
, ret
);
1853 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1855 struct ath10k
*ar
= arvif
->ar
;
1860 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1862 if (arvif
->u
.sta
.uapsd
)
1863 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1865 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1867 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1868 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1870 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1871 value
, arvif
->vdev_id
, ret
);
1878 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1880 struct ath10k
*ar
= arvif
->ar
;
1885 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1887 if (arvif
->u
.sta
.uapsd
)
1888 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1890 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1892 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1893 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1896 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1897 value
, arvif
->vdev_id
, ret
);
1904 static int ath10k_mac_num_vifs_started(struct ath10k
*ar
)
1906 struct ath10k_vif
*arvif
;
1909 lockdep_assert_held(&ar
->conf_mutex
);
1911 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1912 if (arvif
->is_started
)
1918 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1920 struct ath10k
*ar
= arvif
->ar
;
1921 struct ieee80211_vif
*vif
= arvif
->vif
;
1922 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1923 enum wmi_sta_powersave_param param
;
1924 enum wmi_sta_ps_mode psmode
;
1929 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1931 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1934 enable_ps
= arvif
->ps
;
1936 if (enable_ps
&& ath10k_mac_num_vifs_started(ar
) > 1 &&
1937 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1938 ar
->running_fw
->fw_file
.fw_features
)) {
1939 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1944 if (!arvif
->is_started
) {
1945 /* mac80211 can update vif powersave state while disconnected.
1946 * Firmware doesn't behave nicely and consumes more power than
1947 * necessary if PS is disabled on a non-started vdev. Hence
1948 * force-enable PS for non-running vdevs.
1950 psmode
= WMI_STA_PS_MODE_ENABLED
;
1951 } else if (enable_ps
) {
1952 psmode
= WMI_STA_PS_MODE_ENABLED
;
1953 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1955 ps_timeout
= conf
->dynamic_ps_timeout
;
1956 if (ps_timeout
== 0) {
1957 /* Firmware doesn't like 0 */
1958 ps_timeout
= ieee80211_tu_to_usec(
1959 vif
->bss_conf
.beacon_int
) / 1000;
1962 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1965 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1966 arvif
->vdev_id
, ret
);
1970 psmode
= WMI_STA_PS_MODE_DISABLED
;
1973 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1974 arvif
->vdev_id
, psmode
? "enable" : "disable");
1976 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1978 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1979 psmode
, arvif
->vdev_id
, ret
);
1986 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1988 struct ath10k
*ar
= arvif
->ar
;
1989 struct wmi_sta_keepalive_arg arg
= {};
1992 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1994 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1997 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
2000 /* Some firmware revisions have a bug and ignore the `enabled` field.
2001 * Instead use the interval to disable the keepalive.
2003 arg
.vdev_id
= arvif
->vdev_id
;
2005 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
2006 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
2008 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
2010 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
2011 arvif
->vdev_id
, ret
);
2018 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
2020 struct ath10k
*ar
= arvif
->ar
;
2021 struct ieee80211_vif
*vif
= arvif
->vif
;
2024 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
2026 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
2029 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
2032 if (!vif
->bss_conf
.csa_active
)
2038 if (!ieee80211_beacon_cntdwn_is_complete(vif
, 0)) {
2039 ieee80211_beacon_update_cntdwn(vif
, 0);
2041 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
2043 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
2046 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
2048 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
2051 ieee80211_csa_finish(vif
, 0);
2055 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
2057 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
2059 struct ath10k
*ar
= arvif
->ar
;
2061 mutex_lock(&ar
->conf_mutex
);
2062 ath10k_mac_vif_ap_csa_count_down(arvif
);
2063 mutex_unlock(&ar
->conf_mutex
);
2066 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
2067 struct ieee80211_vif
*vif
)
2069 struct sk_buff
*skb
= data
;
2070 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
2071 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2073 if (vif
->type
!= NL80211_IFTYPE_STATION
)
2076 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
2079 cancel_delayed_work(&arvif
->connection_loss_work
);
2082 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
2084 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2085 ATH10K_ITER_NORMAL_FLAGS
,
2086 ath10k_mac_handle_beacon_iter
,
2090 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
2091 struct ieee80211_vif
*vif
)
2093 u32
*vdev_id
= data
;
2094 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2095 struct ath10k
*ar
= arvif
->ar
;
2096 struct ieee80211_hw
*hw
= ar
->hw
;
2098 if (arvif
->vdev_id
!= *vdev_id
)
2104 ieee80211_beacon_loss(vif
);
2106 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2107 * (done by mac80211) succeeds but beacons do not resume then it
2108 * doesn't make sense to continue operation. Queue connection loss work
2109 * which can be cancelled when beacon is received.
2111 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
2112 ATH10K_CONNECTION_LOSS_HZ
);
2115 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
2117 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2118 ATH10K_ITER_NORMAL_FLAGS
,
2119 ath10k_mac_handle_beacon_miss_iter
,
2123 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
2125 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
2126 connection_loss_work
.work
);
2127 struct ieee80211_vif
*vif
= arvif
->vif
;
2132 ieee80211_connection_loss(vif
);
2135 /**********************/
2136 /* Station management */
2137 /**********************/
2139 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
2140 struct ieee80211_vif
*vif
)
2142 /* Some firmware revisions have unstable STA powersave when listen
2143 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2144 * generate NullFunc frames properly even if buffered frames have been
2145 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2146 * buffered frames. Often pinging the device from AP would simply fail.
2148 * As a workaround set it to 1.
2150 if (vif
->type
== NL80211_IFTYPE_STATION
)
2153 return ar
->hw
->conf
.listen_interval
;
2156 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
2157 struct ieee80211_vif
*vif
,
2158 struct ieee80211_sta
*sta
,
2159 struct wmi_peer_assoc_complete_arg
*arg
)
2161 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2164 lockdep_assert_held(&ar
->conf_mutex
);
2166 if (vif
->type
== NL80211_IFTYPE_STATION
)
2171 ether_addr_copy(arg
->addr
, sta
->addr
);
2172 arg
->vdev_id
= arvif
->vdev_id
;
2173 arg
->peer_aid
= aid
;
2174 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->auth
;
2175 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
2176 arg
->peer_num_spatial_streams
= 1;
2177 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
2180 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
2181 struct ieee80211_vif
*vif
,
2182 struct ieee80211_sta
*sta
,
2183 struct wmi_peer_assoc_complete_arg
*arg
)
2185 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
2186 struct cfg80211_chan_def def
;
2187 struct cfg80211_bss
*bss
;
2188 const u8
*rsnie
= NULL
;
2189 const u8
*wpaie
= NULL
;
2191 lockdep_assert_held(&ar
->conf_mutex
);
2193 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2196 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
,
2197 vif
->cfg
.ssid_len
? vif
->cfg
.ssid
: NULL
,
2199 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
2201 const struct cfg80211_bss_ies
*ies
;
2204 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
2206 ies
= rcu_dereference(bss
->ies
);
2208 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
2209 WLAN_OUI_TYPE_MICROSOFT_WPA
,
2213 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
2216 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2217 if (rsnie
|| wpaie
) {
2218 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
2219 arg
->peer_flags
|= ar
->wmi
.peer_flags
->need_ptk_4_way
;
2223 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
2224 arg
->peer_flags
|= ar
->wmi
.peer_flags
->need_gtk_2_way
;
2228 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT
,
2229 ar
->running_fw
->fw_file
.fw_features
)) {
2230 arg
->peer_flags
|= ar
->wmi
.peer_flags
->pmf
;
2234 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
2235 struct ieee80211_vif
*vif
,
2236 struct ieee80211_sta
*sta
,
2237 struct wmi_peer_assoc_complete_arg
*arg
)
2239 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2240 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
2241 struct cfg80211_chan_def def
;
2242 const struct ieee80211_supported_band
*sband
;
2243 const struct ieee80211_rate
*rates
;
2244 enum nl80211_band band
;
2249 lockdep_assert_held(&ar
->conf_mutex
);
2251 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2254 band
= def
.chan
->band
;
2255 sband
= ar
->hw
->wiphy
->bands
[band
];
2256 ratemask
= sta
->deflink
.supp_rates
[band
];
2257 ratemask
&= arvif
->bitrate_mask
.control
[band
].legacy
;
2258 rates
= sband
->bitrates
;
2260 rateset
->num_rates
= 0;
2262 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2263 if (!(ratemask
& 1))
2266 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2267 rateset
->rates
[rateset
->num_rates
] = rate
;
2268 rateset
->num_rates
++;
2273 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
2277 for (nss
= 0; nss
< IEEE80211_HT_MCS_MASK_LEN
; nss
++)
2278 if (ht_mcs_mask
[nss
])
2285 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
2289 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++)
2290 if (vht_mcs_mask
[nss
])
2296 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2297 struct ieee80211_vif
*vif
,
2298 struct ieee80211_sta
*sta
,
2299 struct wmi_peer_assoc_complete_arg
*arg
)
2301 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->deflink
.ht_cap
;
2302 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2303 struct cfg80211_chan_def def
;
2304 enum nl80211_band band
;
2305 const u8
*ht_mcs_mask
;
2306 const u16
*vht_mcs_mask
;
2311 lockdep_assert_held(&ar
->conf_mutex
);
2313 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2316 if (!ht_cap
->ht_supported
)
2319 band
= def
.chan
->band
;
2320 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2321 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2323 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
) &&
2324 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2327 arg
->peer_flags
|= ar
->wmi
.peer_flags
->ht
;
2328 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2329 ht_cap
->ampdu_factor
)) - 1;
2331 arg
->peer_mpdu_density
=
2332 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2334 arg
->peer_ht_caps
= ht_cap
->cap
;
2335 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2337 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2338 arg
->peer_flags
|= ar
->wmi
.peer_flags
->ldbc
;
2340 if (sta
->deflink
.bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2341 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw40
;
2342 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2345 if (arvif
->bitrate_mask
.control
[band
].gi
!= NL80211_TXRATE_FORCE_LGI
) {
2346 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2347 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2349 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2350 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2353 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2354 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2355 arg
->peer_flags
|= ar
->wmi
.peer_flags
->stbc
;
2358 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2359 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2360 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2361 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2362 arg
->peer_rate_caps
|= stbc
;
2363 arg
->peer_flags
|= ar
->wmi
.peer_flags
->stbc
;
2366 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2367 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2368 else if (ht_cap
->mcs
.rx_mask
[1])
2369 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2371 for (i
= 0, n
= 0, max_nss
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
* 8; i
++)
2372 if ((ht_cap
->mcs
.rx_mask
[i
/ 8] & BIT(i
% 8)) &&
2373 (ht_mcs_mask
[i
/ 8] & BIT(i
% 8))) {
2374 max_nss
= (i
/ 8) + 1;
2375 arg
->peer_ht_rates
.rates
[n
++] = i
;
2379 * This is a workaround for HT-enabled STAs which break the spec
2380 * and have no HT capabilities RX mask (no HT RX MCS map).
2382 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2383 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2385 * Firmware asserts if such situation occurs.
2388 arg
->peer_ht_rates
.num_rates
= 8;
2389 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2390 arg
->peer_ht_rates
.rates
[i
] = i
;
2392 arg
->peer_ht_rates
.num_rates
= n
;
2393 arg
->peer_num_spatial_streams
= min(sta
->deflink
.rx_nss
,
2397 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2399 arg
->peer_ht_rates
.num_rates
,
2400 arg
->peer_num_spatial_streams
);
2403 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2404 struct ath10k_vif
*arvif
,
2405 struct ieee80211_sta
*sta
)
2411 lockdep_assert_held(&ar
->conf_mutex
);
2413 if (sta
->wme
&& sta
->uapsd_queues
) {
2414 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2415 sta
->uapsd_queues
, sta
->max_sp
);
2417 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2418 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2419 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2420 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2421 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2422 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2423 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2424 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2425 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2426 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2427 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2428 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2430 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2431 max_sp
= sta
->max_sp
;
2433 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2435 WMI_AP_PS_PEER_PARAM_UAPSD
,
2438 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2439 arvif
->vdev_id
, ret
);
2443 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2445 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2448 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2449 arvif
->vdev_id
, ret
);
2453 /* TODO setup this based on STA listen interval and
2454 * beacon interval. Currently we don't know
2455 * sta->listen_interval - mac80211 patch required.
2456 * Currently use 10 seconds
2458 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2459 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2462 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2463 arvif
->vdev_id
, ret
);
2472 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set
,
2473 const u16 vht_mcs_limit
[NL80211_VHT_NSS_MAX
])
2480 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
2481 mcs_map
= ath10k_mac_get_max_vht_mcs_map(tx_mcs_set
, nss
) &
2485 idx_limit
= fls(mcs_map
) - 1;
2489 switch (idx_limit
) {
2498 /* see ath10k_mac_can_set_bitrate_mask() */
2502 mcs
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
2505 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_7
;
2508 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_8
;
2511 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_9
;
2515 tx_mcs_set
&= ~(0x3 << (nss
* 2));
2516 tx_mcs_set
|= mcs
<< (nss
* 2);
2522 static u32
get_160mhz_nss_from_maxrate(int rate
)
2534 nss
= 3; /* not support MCS9 from spec*/
2546 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2547 struct ieee80211_vif
*vif
,
2548 struct ieee80211_sta
*sta
,
2549 struct wmi_peer_assoc_complete_arg
*arg
)
2551 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->deflink
.vht_cap
;
2552 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2553 struct ath10k_hw_params
*hw
= &ar
->hw_params
;
2554 struct cfg80211_chan_def def
;
2555 enum nl80211_band band
;
2556 const u16
*vht_mcs_mask
;
2558 u8 max_nss
, vht_mcs
;
2561 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2564 if (!vht_cap
->vht_supported
)
2567 band
= def
.chan
->band
;
2568 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2570 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2573 arg
->peer_flags
|= ar
->wmi
.peer_flags
->vht
;
2575 if (def
.chan
->band
== NL80211_BAND_2GHZ
)
2576 arg
->peer_flags
|= ar
->wmi
.peer_flags
->vht_2g
;
2578 arg
->peer_vht_caps
= vht_cap
->cap
;
2580 ampdu_factor
= (vht_cap
->cap
&
2581 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2582 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2584 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2585 * zero in VHT IE. Using it would result in degraded throughput.
2586 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2587 * it if VHT max_mpdu is smaller.
2589 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2590 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2591 ampdu_factor
)) - 1);
2593 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_80
)
2594 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw80
;
2596 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_160
)
2597 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw160
;
2599 /* Calculate peer NSS capability from VHT capabilities if STA
2602 for (i
= 0, max_nss
= 0, vht_mcs
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
2603 vht_mcs
= __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
) >>
2606 if ((vht_mcs
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
) &&
2610 arg
->peer_num_spatial_streams
= min(sta
->deflink
.rx_nss
, max_nss
);
2611 arg
->peer_vht_rates
.rx_max_rate
=
2612 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2613 arg
->peer_vht_rates
.rx_mcs_set
=
2614 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2615 arg
->peer_vht_rates
.tx_max_rate
=
2616 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2617 arg
->peer_vht_rates
.tx_mcs_set
= ath10k_peer_assoc_h_vht_limit(
2618 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
), vht_mcs_mask
);
2620 /* Configure bandwidth-NSS mapping to FW
2621 * for the chip's tx chains setting on 160Mhz bw
2623 if (arg
->peer_phymode
== MODE_11AC_VHT160
||
2624 arg
->peer_phymode
== MODE_11AC_VHT80_80
) {
2628 max_rate
= arg
->peer_vht_rates
.rx_max_rate
;
2629 rx_nss
= get_160mhz_nss_from_maxrate(max_rate
);
2632 rx_nss
= arg
->peer_num_spatial_streams
;
2634 rx_nss
= min(arg
->peer_num_spatial_streams
, rx_nss
);
2636 max_rate
= hw
->vht160_mcs_tx_highest
;
2637 rx_nss
= min(rx_nss
, get_160mhz_nss_from_maxrate(max_rate
));
2639 arg
->peer_bw_rxnss_override
=
2640 FIELD_PREP(WMI_PEER_NSS_MAP_ENABLE
, 1) |
2641 FIELD_PREP(WMI_PEER_NSS_160MHZ_MASK
, (rx_nss
- 1));
2643 if (arg
->peer_phymode
== MODE_11AC_VHT80_80
) {
2644 arg
->peer_bw_rxnss_override
|=
2645 FIELD_PREP(WMI_PEER_NSS_80_80MHZ_MASK
, (rx_nss
- 1));
2648 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2649 "mac vht peer %pM max_mpdu %d flags 0x%x peer_rx_nss_override 0x%x\n",
2650 sta
->addr
, arg
->peer_max_mpdu
,
2651 arg
->peer_flags
, arg
->peer_bw_rxnss_override
);
2654 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2655 struct ieee80211_vif
*vif
,
2656 struct ieee80211_sta
*sta
,
2657 struct wmi_peer_assoc_complete_arg
*arg
)
2659 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2661 switch (arvif
->vdev_type
) {
2662 case WMI_VDEV_TYPE_AP
:
2664 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2666 if (sta
->wme
&& sta
->uapsd_queues
) {
2667 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->apsd
;
2668 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2671 case WMI_VDEV_TYPE_STA
:
2673 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2675 case WMI_VDEV_TYPE_IBSS
:
2677 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2683 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2684 sta
->addr
, !!(arg
->peer_flags
&
2685 arvif
->ar
->wmi
.peer_flags
->qos
));
2688 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2690 return sta
->deflink
.supp_rates
[NL80211_BAND_2GHZ
] >>
2691 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2694 static enum wmi_phy_mode
ath10k_mac_get_phymode_vht(struct ath10k
*ar
,
2695 struct ieee80211_sta
*sta
)
2697 struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->deflink
.vht_cap
;
2699 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_160
) {
2700 switch (vht_cap
->cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) {
2701 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
:
2702 return MODE_11AC_VHT160
;
2703 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
:
2704 return MODE_11AC_VHT80_80
;
2706 /* not sure if this is a valid case? */
2707 return MODE_11AC_VHT160
;
2711 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_80
)
2712 return MODE_11AC_VHT80
;
2714 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_40
)
2715 return MODE_11AC_VHT40
;
2717 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_20
)
2718 return MODE_11AC_VHT20
;
2720 return MODE_UNKNOWN
;
2723 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2724 struct ieee80211_vif
*vif
,
2725 struct ieee80211_sta
*sta
,
2726 struct wmi_peer_assoc_complete_arg
*arg
)
2728 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2729 struct cfg80211_chan_def def
;
2730 enum nl80211_band band
;
2731 const u8
*ht_mcs_mask
;
2732 const u16
*vht_mcs_mask
;
2733 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2735 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2738 band
= def
.chan
->band
;
2739 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2740 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2743 case NL80211_BAND_2GHZ
:
2744 if (sta
->deflink
.vht_cap
.vht_supported
&&
2745 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2746 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_40
)
2747 phymode
= MODE_11AC_VHT40
;
2749 phymode
= MODE_11AC_VHT20
;
2750 } else if (sta
->deflink
.ht_cap
.ht_supported
&&
2751 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2752 if (sta
->deflink
.bandwidth
== IEEE80211_STA_RX_BW_40
)
2753 phymode
= MODE_11NG_HT40
;
2755 phymode
= MODE_11NG_HT20
;
2756 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2763 case NL80211_BAND_5GHZ
:
2767 if (sta
->deflink
.vht_cap
.vht_supported
&&
2768 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2769 phymode
= ath10k_mac_get_phymode_vht(ar
, sta
);
2770 } else if (sta
->deflink
.ht_cap
.ht_supported
&&
2771 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2772 if (sta
->deflink
.bandwidth
>= IEEE80211_STA_RX_BW_40
)
2773 phymode
= MODE_11NA_HT40
;
2775 phymode
= MODE_11NA_HT20
;
2785 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2786 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2788 arg
->peer_phymode
= phymode
;
2789 WARN_ON(phymode
== MODE_UNKNOWN
);
2792 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2793 struct ieee80211_vif
*vif
,
2794 struct ieee80211_sta
*sta
,
2795 struct wmi_peer_assoc_complete_arg
*arg
)
2797 lockdep_assert_held(&ar
->conf_mutex
);
2799 memset(arg
, 0, sizeof(*arg
));
2801 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2802 ath10k_peer_assoc_h_crypto(ar
, vif
, sta
, arg
);
2803 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2804 ath10k_peer_assoc_h_ht(ar
, vif
, sta
, arg
);
2805 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2806 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2807 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2812 static const u32 ath10k_smps_map
[] = {
2813 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2814 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2815 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2816 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2819 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2821 const struct ieee80211_sta_ht_cap
*ht_cap
)
2825 if (!ht_cap
->ht_supported
)
2828 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2829 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2831 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2834 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2835 ar
->wmi
.peer_param
->smps_state
,
2836 ath10k_smps_map
[smps
]);
2839 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2840 struct ieee80211_vif
*vif
,
2841 struct ieee80211_sta_vht_cap vht_cap
)
2843 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2848 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_AFTER_ASSOC
)
2851 if (!(ar
->vht_cap_info
&
2852 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2853 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2854 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2855 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2858 param
= ar
->wmi
.vdev_param
->txbf
;
2861 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2864 /* The following logic is correct. If a remote STA advertises support
2865 * for being a beamformer then we should enable us being a beamformee.
2868 if (ar
->vht_cap_info
&
2869 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2870 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2871 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2872 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2874 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2875 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2878 if (ar
->vht_cap_info
&
2879 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2880 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2881 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2882 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2884 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2885 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2888 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2889 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2891 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2892 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2894 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2896 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2904 static bool ath10k_mac_is_connected(struct ath10k
*ar
)
2906 struct ath10k_vif
*arvif
;
2908 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2909 if (arvif
->is_up
&& arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
2916 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
2920 int tx_power_2g
, tx_power_5g
;
2923 lockdep_assert_held(&ar
->conf_mutex
);
2925 /* ath10k internally uses unit of 0.5 dBm so multiply by 2 */
2926 tx_power_2g
= txpower
* 2;
2927 tx_power_5g
= txpower
* 2;
2929 connected
= ath10k_mac_is_connected(ar
);
2931 if (connected
&& ar
->tx_power_2g_limit
)
2932 if (tx_power_2g
> ar
->tx_power_2g_limit
)
2933 tx_power_2g
= ar
->tx_power_2g_limit
;
2935 if (connected
&& ar
->tx_power_5g_limit
)
2936 if (tx_power_5g
> ar
->tx_power_5g_limit
)
2937 tx_power_5g
= ar
->tx_power_5g_limit
;
2939 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower 2g: %d, 5g: %d\n",
2940 tx_power_2g
, tx_power_5g
);
2942 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
2943 ret
= ath10k_wmi_pdev_set_param(ar
, param
, tx_power_2g
);
2945 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
2950 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
2951 ret
= ath10k_wmi_pdev_set_param(ar
, param
, tx_power_5g
);
2953 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
2961 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
2963 struct ath10k_vif
*arvif
;
2964 int ret
, txpower
= -1;
2966 lockdep_assert_held(&ar
->conf_mutex
);
2968 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2969 /* txpower not initialized yet? */
2970 if (arvif
->txpower
== INT_MIN
)
2974 txpower
= arvif
->txpower
;
2976 txpower
= min(txpower
, arvif
->txpower
);
2982 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
2984 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
2992 static int ath10k_mac_set_sar_power(struct ath10k
*ar
)
2994 if (!ar
->hw_params
.dynamic_sar_support
)
2997 if (!ath10k_mac_is_connected(ar
))
3000 /* if connected, then arvif->txpower must be valid */
3001 return ath10k_mac_txpower_recalc(ar
);
3004 static int ath10k_mac_set_sar_specs(struct ieee80211_hw
*hw
,
3005 const struct cfg80211_sar_specs
*sar
)
3007 const struct cfg80211_sar_sub_specs
*sub_specs
;
3008 struct ath10k
*ar
= hw
->priv
;
3012 mutex_lock(&ar
->conf_mutex
);
3014 if (!ar
->hw_params
.dynamic_sar_support
) {
3019 if (!sar
|| sar
->type
!= NL80211_SAR_TYPE_POWER
||
3020 sar
->num_sub_specs
== 0) {
3025 sub_specs
= sar
->sub_specs
;
3027 /* 0dbm is not a practical value for ath10k, so use 0
3028 * as no SAR limitation on it.
3030 ar
->tx_power_2g_limit
= 0;
3031 ar
->tx_power_5g_limit
= 0;
3033 /* note the power is in 0.25dbm unit, while ath10k uses
3036 for (i
= 0; i
< sar
->num_sub_specs
; i
++) {
3037 if (sub_specs
->freq_range_index
== 0)
3038 ar
->tx_power_2g_limit
= sub_specs
->power
/ 2;
3039 else if (sub_specs
->freq_range_index
== 1)
3040 ar
->tx_power_5g_limit
= sub_specs
->power
/ 2;
3045 ret
= ath10k_mac_set_sar_power(ar
);
3047 ath10k_warn(ar
, "failed to set sar power: %d", ret
);
3052 mutex_unlock(&ar
->conf_mutex
);
3056 /* can be called only in mac80211 callbacks due to `key_count` usage */
3057 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
3058 struct ieee80211_vif
*vif
,
3059 struct ieee80211_bss_conf
*bss_conf
)
3061 struct ath10k
*ar
= hw
->priv
;
3062 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3063 struct ieee80211_sta_ht_cap ht_cap
;
3064 struct ieee80211_sta_vht_cap vht_cap
;
3065 struct wmi_peer_assoc_complete_arg peer_arg
;
3066 struct ieee80211_sta
*ap_sta
;
3069 lockdep_assert_held(&ar
->conf_mutex
);
3071 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
3072 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
3076 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
3078 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
3079 bss_conf
->bssid
, arvif
->vdev_id
);
3084 /* ap_sta must be accessed only within rcu section which must be left
3085 * before calling ath10k_setup_peer_smps() which might sleep.
3087 ht_cap
= ap_sta
->deflink
.ht_cap
;
3088 vht_cap
= ap_sta
->deflink
.vht_cap
;
3090 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
3092 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
3093 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
3100 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
3102 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
3103 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
3107 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
3109 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
3110 arvif
->vdev_id
, ret
);
3114 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
3116 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
3117 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
3121 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3122 "mac vdev %d up (associated) bssid %pM aid %d\n",
3123 arvif
->vdev_id
, bss_conf
->bssid
, vif
->cfg
.aid
);
3125 WARN_ON(arvif
->is_up
);
3127 arvif
->aid
= vif
->cfg
.aid
;
3128 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
3130 ret
= ath10k_wmi_pdev_set_param(ar
,
3131 ar
->wmi
.pdev_param
->peer_stats_info_enable
, 1);
3133 ath10k_warn(ar
, "failed to enable peer stats info: %d\n", ret
);
3135 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
3137 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
3138 arvif
->vdev_id
, ret
);
3142 arvif
->is_up
= true;
3144 ath10k_mac_set_sar_power(ar
);
3146 /* Workaround: Some firmware revisions (tested with qca6174
3147 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
3148 * poked with peer param command.
3150 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
3151 ar
->wmi
.peer_param
->dummy_var
, 1);
3153 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
3154 arvif
->bssid
, arvif
->vdev_id
, ret
);
3159 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
3160 struct ieee80211_vif
*vif
)
3162 struct ath10k
*ar
= hw
->priv
;
3163 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3164 struct ieee80211_sta_vht_cap vht_cap
= {};
3167 lockdep_assert_held(&ar
->conf_mutex
);
3169 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
3170 arvif
->vdev_id
, arvif
->bssid
);
3172 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
3174 ath10k_warn(ar
, "failed to down vdev %i: %d\n",
3175 arvif
->vdev_id
, ret
);
3177 arvif
->def_wep_key_idx
= -1;
3179 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
3181 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
3182 arvif
->vdev_id
, ret
);
3186 arvif
->is_up
= false;
3188 ath10k_mac_txpower_recalc(ar
);
3190 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
3193 static int ath10k_new_peer_tid_config(struct ath10k
*ar
,
3194 struct ieee80211_sta
*sta
,
3195 struct ath10k_vif
*arvif
)
3197 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
3198 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3202 for (i
= 0; i
< ATH10K_TID_MAX
; i
++) {
3203 config_apply
= false;
3204 if (arvif
->retry_long
[i
] || arvif
->ampdu
[i
] ||
3205 arvif
->rate_ctrl
[i
] || arvif
->rtscts
[i
]) {
3206 config_apply
= true;
3208 arg
.vdev_id
= arvif
->vdev_id
;
3209 arg
.retry_count
= arvif
->retry_long
[i
];
3210 arg
.aggr_control
= arvif
->ampdu
[i
];
3211 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
3212 arg
.rcode_flags
= arvif
->rate_code
[i
];
3214 if (arvif
->rtscts
[i
])
3215 arg
.ext_tid_cfg_bitmap
=
3216 WMI_EXT_TID_RTS_CTS_CONFIG
;
3218 arg
.ext_tid_cfg_bitmap
= 0;
3220 arg
.rtscts_ctrl
= arvif
->rtscts
[i
];
3223 if (arvif
->noack
[i
]) {
3224 arg
.ack_policy
= arvif
->noack
[i
];
3225 arg
.rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE
;
3226 arg
.aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
3227 config_apply
= true;
3230 /* Assign default value(-1) to newly connected station.
3231 * This is to identify station specific tid configuration not
3232 * configured for the station.
3234 arsta
->retry_long
[i
] = -1;
3235 arsta
->noack
[i
] = -1;
3236 arsta
->ampdu
[i
] = -1;
3241 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
3243 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
3245 ath10k_warn(ar
, "failed to set per tid retry/aggr config for sta %pM: %d\n",
3250 memset(&arg
, 0, sizeof(arg
));
3256 static int ath10k_station_assoc(struct ath10k
*ar
,
3257 struct ieee80211_vif
*vif
,
3258 struct ieee80211_sta
*sta
,
3261 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3262 struct wmi_peer_assoc_complete_arg peer_arg
;
3265 lockdep_assert_held(&ar
->conf_mutex
);
3267 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
3269 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
3270 sta
->addr
, arvif
->vdev_id
, ret
);
3274 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
3276 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
3277 sta
->addr
, arvif
->vdev_id
, ret
);
3281 /* Re-assoc is run only to update supported rates for given station. It
3282 * doesn't make much sense to reconfigure the peer completely.
3285 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
3286 &sta
->deflink
.ht_cap
);
3288 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
3289 arvif
->vdev_id
, ret
);
3293 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
3295 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
3296 sta
->addr
, arvif
->vdev_id
, ret
);
3301 arvif
->num_legacy_stations
++;
3302 ret
= ath10k_recalc_rtscts_prot(arvif
);
3304 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3305 arvif
->vdev_id
, ret
);
3310 /* Plumb cached keys only for static WEP */
3311 if ((arvif
->def_wep_key_idx
!= -1) && (!sta
->tdls
)) {
3312 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
3314 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
3315 arvif
->vdev_id
, ret
);
3321 if (!test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT
, ar
->wmi
.svc_map
))
3324 return ath10k_new_peer_tid_config(ar
, sta
, arvif
);
3327 static int ath10k_station_disassoc(struct ath10k
*ar
,
3328 struct ieee80211_vif
*vif
,
3329 struct ieee80211_sta
*sta
)
3331 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3334 lockdep_assert_held(&ar
->conf_mutex
);
3337 arvif
->num_legacy_stations
--;
3338 ret
= ath10k_recalc_rtscts_prot(arvif
);
3340 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3341 arvif
->vdev_id
, ret
);
3346 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
3348 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
3349 arvif
->vdev_id
, ret
);
3360 static int ath10k_update_channel_list(struct ath10k
*ar
)
3362 struct ieee80211_hw
*hw
= ar
->hw
;
3363 struct ieee80211_supported_band
**bands
;
3364 enum nl80211_band band
;
3365 struct ieee80211_channel
*channel
;
3366 struct wmi_scan_chan_list_arg arg
= {0};
3367 struct wmi_channel_arg
*ch
;
3373 lockdep_assert_held(&ar
->conf_mutex
);
3375 bands
= hw
->wiphy
->bands
;
3376 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
3380 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
3381 if (bands
[band
]->channels
[i
].flags
&
3382 IEEE80211_CHAN_DISABLED
)
3389 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
3390 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
3395 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
3399 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
3400 channel
= &bands
[band
]->channels
[i
];
3402 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
3405 ch
->allow_ht
= true;
3407 /* FIXME: when should we really allow VHT? */
3408 ch
->allow_vht
= true;
3411 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
3414 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
3417 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
3419 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
3420 ch
->passive
= passive
;
3422 /* the firmware is ignoring the "radar" flag of the
3423 * channel and is scanning actively using Probe Requests
3424 * on "Radar detection"/DFS channels which are not
3425 * marked as "available"
3427 ch
->passive
|= ch
->chan_radar
;
3429 ch
->freq
= channel
->center_freq
;
3430 ch
->band_center_freq1
= channel
->center_freq
;
3432 ch
->max_power
= channel
->max_power
* 2;
3433 ch
->max_reg_power
= channel
->max_reg_power
* 2;
3434 ch
->max_antenna_gain
= channel
->max_antenna_gain
;
3435 ch
->reg_class_id
= 0; /* FIXME */
3437 /* FIXME: why use only legacy modes, why not any
3438 * HT/VHT modes? Would that even make any
3441 if (channel
->band
== NL80211_BAND_2GHZ
)
3442 ch
->mode
= MODE_11G
;
3444 ch
->mode
= MODE_11A
;
3446 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
3449 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
3450 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3451 ch
- arg
.channels
, arg
.n_channels
,
3452 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
3453 ch
->max_antenna_gain
, ch
->mode
);
3459 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
3460 kfree(arg
.channels
);
3465 static enum wmi_dfs_region
3466 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
3468 switch (dfs_region
) {
3469 case NL80211_DFS_UNSET
:
3470 return WMI_UNINIT_DFS_DOMAIN
;
3471 case NL80211_DFS_FCC
:
3472 return WMI_FCC_DFS_DOMAIN
;
3473 case NL80211_DFS_ETSI
:
3474 return WMI_ETSI_DFS_DOMAIN
;
3475 case NL80211_DFS_JP
:
3476 return WMI_MKK4_DFS_DOMAIN
;
3478 return WMI_UNINIT_DFS_DOMAIN
;
3481 static void ath10k_regd_update(struct ath10k
*ar
)
3483 struct reg_dmn_pair_mapping
*regpair
;
3485 enum wmi_dfs_region wmi_dfs_reg
;
3486 enum nl80211_dfs_regions nl_dfs_reg
;
3488 lockdep_assert_held(&ar
->conf_mutex
);
3490 ret
= ath10k_update_channel_list(ar
);
3492 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
3494 regpair
= ar
->ath_common
.regulatory
.regpair
;
3496 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3497 nl_dfs_reg
= ar
->dfs_detector
->region
;
3498 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
3500 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
3503 /* Target allows setting up per-band regdomain but ath_common provides
3504 * a combined one only
3506 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
3507 regpair
->reg_domain
,
3508 regpair
->reg_domain
, /* 2ghz */
3509 regpair
->reg_domain
, /* 5ghz */
3510 regpair
->reg_2ghz_ctl
,
3511 regpair
->reg_5ghz_ctl
,
3514 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
3517 static void ath10k_mac_update_channel_list(struct ath10k
*ar
,
3518 struct ieee80211_supported_band
*band
)
3522 if (ar
->low_5ghz_chan
&& ar
->high_5ghz_chan
) {
3523 for (i
= 0; i
< band
->n_channels
; i
++) {
3524 if (band
->channels
[i
].center_freq
< ar
->low_5ghz_chan
||
3525 band
->channels
[i
].center_freq
> ar
->high_5ghz_chan
)
3526 band
->channels
[i
].flags
|=
3527 IEEE80211_CHAN_DISABLED
;
3532 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
3533 struct regulatory_request
*request
)
3535 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
3536 struct ath10k
*ar
= hw
->priv
;
3539 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
3541 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3542 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
3543 request
->dfs_region
);
3544 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
3545 request
->dfs_region
);
3547 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3548 request
->dfs_region
);
3551 mutex_lock(&ar
->conf_mutex
);
3552 if (ar
->state
== ATH10K_STATE_ON
)
3553 ath10k_regd_update(ar
);
3554 mutex_unlock(&ar
->conf_mutex
);
3556 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
3557 ath10k_mac_update_channel_list(ar
,
3558 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
]);
3561 static void ath10k_stop_radar_confirmation(struct ath10k
*ar
)
3563 spin_lock_bh(&ar
->data_lock
);
3564 ar
->radar_conf_state
= ATH10K_RADAR_CONFIRMATION_STOPPED
;
3565 spin_unlock_bh(&ar
->data_lock
);
3567 cancel_work_sync(&ar
->radar_confirmation_work
);
3574 enum ath10k_mac_tx_path
{
3576 ATH10K_MAC_TX_HTT_MGMT
,
3577 ATH10K_MAC_TX_WMI_MGMT
,
3578 ATH10K_MAC_TX_UNKNOWN
,
3581 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
3583 lockdep_assert_held(&ar
->htt
.tx_lock
);
3585 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3586 ar
->tx_paused
|= BIT(reason
);
3587 ieee80211_stop_queues(ar
->hw
);
3590 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
3591 struct ieee80211_vif
*vif
)
3593 struct ath10k
*ar
= data
;
3594 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3596 if (arvif
->tx_paused
)
3599 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3602 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
3604 lockdep_assert_held(&ar
->htt
.tx_lock
);
3606 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3607 ar
->tx_paused
&= ~BIT(reason
);
3612 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3613 ATH10K_ITER_RESUME_FLAGS
,
3614 ath10k_mac_tx_unlock_iter
,
3617 ieee80211_wake_queue(ar
->hw
, ar
->hw
->offchannel_tx_hw_queue
);
3620 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
3622 struct ath10k
*ar
= arvif
->ar
;
3624 lockdep_assert_held(&ar
->htt
.tx_lock
);
3626 WARN_ON(reason
>= BITS_PER_LONG
);
3627 arvif
->tx_paused
|= BIT(reason
);
3628 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
3631 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
3633 struct ath10k
*ar
= arvif
->ar
;
3635 lockdep_assert_held(&ar
->htt
.tx_lock
);
3637 WARN_ON(reason
>= BITS_PER_LONG
);
3638 arvif
->tx_paused
&= ~BIT(reason
);
3643 if (arvif
->tx_paused
)
3646 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3649 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
3650 enum wmi_tlv_tx_pause_id pause_id
,
3651 enum wmi_tlv_tx_pause_action action
)
3653 struct ath10k
*ar
= arvif
->ar
;
3655 lockdep_assert_held(&ar
->htt
.tx_lock
);
3658 case WMI_TLV_TX_PAUSE_ACTION_STOP
:
3659 ath10k_mac_vif_tx_lock(arvif
, pause_id
);
3661 case WMI_TLV_TX_PAUSE_ACTION_WAKE
:
3662 ath10k_mac_vif_tx_unlock(arvif
, pause_id
);
3665 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
3666 "received unknown tx pause action %d on vdev %i, ignoring\n",
3667 action
, arvif
->vdev_id
);
3672 struct ath10k_mac_tx_pause
{
3674 enum wmi_tlv_tx_pause_id pause_id
;
3675 enum wmi_tlv_tx_pause_action action
;
3678 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
3679 struct ieee80211_vif
*vif
)
3681 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3682 struct ath10k_mac_tx_pause
*arg
= data
;
3684 if (arvif
->vdev_id
!= arg
->vdev_id
)
3687 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
3690 void ath10k_mac_handle_tx_pause_vdev(struct ath10k
*ar
, u32 vdev_id
,
3691 enum wmi_tlv_tx_pause_id pause_id
,
3692 enum wmi_tlv_tx_pause_action action
)
3694 struct ath10k_mac_tx_pause arg
= {
3696 .pause_id
= pause_id
,
3700 spin_lock_bh(&ar
->htt
.tx_lock
);
3701 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3702 ATH10K_ITER_RESUME_FLAGS
,
3703 ath10k_mac_handle_tx_pause_iter
,
3705 spin_unlock_bh(&ar
->htt
.tx_lock
);
3708 static enum ath10k_hw_txrx_mode
3709 ath10k_mac_tx_h_get_txmode(struct ath10k
*ar
,
3710 struct ieee80211_vif
*vif
,
3711 struct ieee80211_sta
*sta
,
3712 struct sk_buff
*skb
)
3714 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3715 const struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
3716 __le16 fc
= hdr
->frame_control
;
3718 if (IEEE80211_SKB_CB(skb
)->flags
& IEEE80211_TX_CTL_HW_80211_ENCAP
)
3719 return ATH10K_HW_TXRX_ETHERNET
;
3721 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3722 return ATH10K_HW_TXRX_RAW
;
3724 if (ieee80211_is_mgmt(fc
))
3725 return ATH10K_HW_TXRX_MGMT
;
3729 * NullFunc frames are mostly used to ping if a client or AP are still
3730 * reachable and responsive. This implies tx status reports must be
3731 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3732 * come to a conclusion that the other end disappeared and tear down
3733 * BSS connection or it can never disconnect from BSS/client (which is
3736 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3737 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3738 * which seems to deliver correct tx reports for NullFunc frames. The
3739 * downside of using it is it ignores client powersave state so it can
3740 * end up disconnecting sleeping clients in AP mode. It should fix STA
3741 * mode though because AP don't sleep.
3743 if (ar
->htt
.target_version_major
< 3 &&
3744 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3745 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3746 ar
->running_fw
->fw_file
.fw_features
))
3747 return ATH10K_HW_TXRX_MGMT
;
3751 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3752 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3753 * to work with Ethernet txmode so use it.
3755 * FIXME: Check if raw mode works with TDLS.
3757 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3758 return ATH10K_HW_TXRX_ETHERNET
;
3760 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
) ||
3761 skb_cb
->flags
& ATH10K_SKB_F_RAW_TX
)
3762 return ATH10K_HW_TXRX_RAW
;
3764 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3767 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif
*vif
,
3768 struct sk_buff
*skb
)
3770 const struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3771 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3772 const u32 mask
= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
3773 IEEE80211_TX_CTL_INJECTED
;
3775 if (!ieee80211_has_protected(hdr
->frame_control
))
3778 if ((info
->flags
& mask
) == mask
)
3782 return !((struct ath10k_vif
*)vif
->drv_priv
)->nohwcrypt
;
3787 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3788 * Control in the header.
3790 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3792 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3793 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3796 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3799 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3800 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3801 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3802 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3804 /* Some firmware revisions don't handle sending QoS NullFunc well.
3805 * These frames are mainly used for CQM purposes so it doesn't really
3806 * matter whether QoS NullFunc or NullFunc are sent.
3808 hdr
= (void *)skb
->data
;
3809 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3810 cb
->flags
&= ~ATH10K_SKB_F_QOS
;
3812 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3815 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3817 struct ieee80211_hdr
*hdr
;
3818 struct rfc1042_hdr
*rfc1042
;
3825 hdr
= (void *)skb
->data
;
3826 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3827 rfc1042
= (void *)skb
->data
+ hdrlen
;
3829 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3830 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3831 type
= rfc1042
->snap_type
;
3833 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3834 skb_push(skb
, sizeof(*eth
));
3836 eth
= (void *)skb
->data
;
3837 ether_addr_copy(eth
->h_dest
, da
);
3838 ether_addr_copy(eth
->h_source
, sa
);
3839 eth
->h_proto
= type
;
3842 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3843 struct ieee80211_vif
*vif
,
3844 struct sk_buff
*skb
)
3846 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3847 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3849 /* This is case only for P2P_GO */
3850 if (vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
)
3853 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3854 spin_lock_bh(&ar
->data_lock
);
3855 if (arvif
->u
.ap
.noa_data
)
3856 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3858 skb_put_data(skb
, arvif
->u
.ap
.noa_data
,
3859 arvif
->u
.ap
.noa_len
);
3860 spin_unlock_bh(&ar
->data_lock
);
3864 static void ath10k_mac_tx_h_fill_cb(struct ath10k
*ar
,
3865 struct ieee80211_vif
*vif
,
3866 struct ieee80211_txq
*txq
,
3867 struct ieee80211_sta
*sta
,
3868 struct sk_buff
*skb
, u16 airtime
)
3870 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3871 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3872 const struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3873 bool is_data
= ieee80211_is_data(hdr
->frame_control
) ||
3874 ieee80211_is_data_qos(hdr
->frame_control
);
3875 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3876 struct ath10k_sta
*arsta
;
3882 if (info
->flags
& IEEE80211_TX_CTL_HW_80211_ENCAP
) {
3883 cb
->flags
|= ATH10K_SKB_F_QOS
; /* Assume data frames are QoS */
3884 goto finish_cb_fill
;
3887 if (!ath10k_tx_h_use_hwcrypto(vif
, skb
))
3888 cb
->flags
|= ATH10K_SKB_F_NO_HWCRYPT
;
3890 if (ieee80211_is_mgmt(hdr
->frame_control
))
3891 cb
->flags
|= ATH10K_SKB_F_MGMT
;
3893 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
3894 cb
->flags
|= ATH10K_SKB_F_QOS
;
3895 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3896 tid
= (*qos_ctl
) & IEEE80211_QOS_CTL_TID_MASK
;
3898 if (arvif
->noack
[tid
] == WMI_PEER_TID_CONFIG_NOACK
)
3902 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3904 if (arsta
->noack
[tid
] == WMI_PEER_TID_CONFIG_NOACK
)
3907 if (arsta
->noack
[tid
] == WMI_PEER_TID_CONFIG_ACK
)
3912 cb
->flags
|= ATH10K_SKB_F_NOACK_TID
;
3915 /* Data frames encrypted in software will be posted to firmware
3916 * with tx encap mode set to RAW. Ex: Multicast traffic generated
3917 * for a specific VLAN group will always be encrypted in software.
3919 if (is_data
&& ieee80211_has_protected(hdr
->frame_control
) &&
3920 !info
->control
.hw_key
) {
3921 cb
->flags
|= ATH10K_SKB_F_NO_HWCRYPT
;
3922 cb
->flags
|= ATH10K_SKB_F_RAW_TX
;
3928 cb
->airtime_est
= airtime
;
3930 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3931 spin_lock_bh(&ar
->data_lock
);
3932 cb
->ucast_cipher
= arsta
->ucast_cipher
;
3933 spin_unlock_bh(&ar
->data_lock
);
3937 bool ath10k_mac_tx_frm_has_freq(struct ath10k
*ar
)
3939 /* FIXME: Not really sure since when the behaviour changed. At some
3940 * point new firmware stopped requiring creation of peer entries for
3941 * offchannel tx (and actually creating them causes issues with wmi-htc
3942 * tx credit replenishment and reliability). Assuming it's at least 3.4
3943 * because that's when the `freq` was introduced to TX_FRM HTT command.
3945 return (ar
->htt
.target_version_major
>= 3 &&
3946 ar
->htt
.target_version_minor
>= 4 &&
3947 ar
->running_fw
->fw_file
.htt_op_version
== ATH10K_FW_HTT_OP_VERSION_TLV
);
3950 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3952 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3954 if (skb_queue_len_lockless(q
) >= ATH10K_MAX_NUM_MGMT_PENDING
) {
3955 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3959 skb_queue_tail(q
, skb
);
3960 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3965 static enum ath10k_mac_tx_path
3966 ath10k_mac_tx_h_get_txpath(struct ath10k
*ar
,
3967 struct sk_buff
*skb
,
3968 enum ath10k_hw_txrx_mode txmode
)
3971 case ATH10K_HW_TXRX_RAW
:
3972 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3973 case ATH10K_HW_TXRX_ETHERNET
:
3974 return ATH10K_MAC_TX_HTT
;
3975 case ATH10K_HW_TXRX_MGMT
:
3976 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3977 ar
->running_fw
->fw_file
.fw_features
) ||
3978 test_bit(WMI_SERVICE_MGMT_TX_WMI
,
3980 return ATH10K_MAC_TX_WMI_MGMT
;
3981 else if (ar
->htt
.target_version_major
>= 3)
3982 return ATH10K_MAC_TX_HTT
;
3984 return ATH10K_MAC_TX_HTT_MGMT
;
3987 return ATH10K_MAC_TX_UNKNOWN
;
3990 static int ath10k_mac_tx_submit(struct ath10k
*ar
,
3991 enum ath10k_hw_txrx_mode txmode
,
3992 enum ath10k_mac_tx_path txpath
,
3993 struct sk_buff
*skb
)
3995 struct ath10k_htt
*htt
= &ar
->htt
;
3999 case ATH10K_MAC_TX_HTT
:
4000 ret
= ath10k_htt_tx(htt
, txmode
, skb
);
4002 case ATH10K_MAC_TX_HTT_MGMT
:
4003 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
4005 case ATH10K_MAC_TX_WMI_MGMT
:
4006 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
4008 case ATH10K_MAC_TX_UNKNOWN
:
4015 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
4017 ieee80211_free_txskb(ar
->hw
, skb
);
4023 /* This function consumes the sk_buff regardless of return value as far as
4024 * caller is concerned so no freeing is necessary afterwards.
4026 static int ath10k_mac_tx(struct ath10k
*ar
,
4027 struct ieee80211_vif
*vif
,
4028 enum ath10k_hw_txrx_mode txmode
,
4029 enum ath10k_mac_tx_path txpath
,
4030 struct sk_buff
*skb
, bool noque_offchan
)
4032 struct ieee80211_hw
*hw
= ar
->hw
;
4033 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
4034 const struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
4037 /* We should disable CCK RATE due to P2P */
4038 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
4039 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
4042 case ATH10K_HW_TXRX_MGMT
:
4043 case ATH10K_HW_TXRX_NATIVE_WIFI
:
4044 ath10k_tx_h_nwifi(hw
, skb
);
4045 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
4046 ath10k_tx_h_seq_no(vif
, skb
);
4048 case ATH10K_HW_TXRX_ETHERNET
:
4049 /* Convert 802.11->802.3 header only if the frame was earlier
4050 * encapsulated to 802.11 by mac80211. Otherwise pass it as is.
4052 if (!(info
->flags
& IEEE80211_TX_CTL_HW_80211_ENCAP
))
4053 ath10k_tx_h_8023(skb
);
4055 case ATH10K_HW_TXRX_RAW
:
4056 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
) &&
4057 !(skb_cb
->flags
& ATH10K_SKB_F_RAW_TX
)) {
4059 ieee80211_free_txskb(hw
, skb
);
4064 if (!noque_offchan
&& info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
4065 if (!ath10k_mac_tx_frm_has_freq(ar
)) {
4066 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac queued offchannel skb %pK len %d\n",
4069 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
4070 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
4075 ret
= ath10k_mac_tx_submit(ar
, txmode
, txpath
, skb
);
4077 ath10k_warn(ar
, "failed to submit frame: %d\n", ret
);
4084 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
4086 struct sk_buff
*skb
;
4089 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
4093 ieee80211_free_txskb(ar
->hw
, skb
);
4097 void ath10k_offchan_tx_work(struct work_struct
*work
)
4099 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
4100 struct ath10k_peer
*peer
;
4101 struct ath10k_vif
*arvif
;
4102 enum ath10k_hw_txrx_mode txmode
;
4103 enum ath10k_mac_tx_path txpath
;
4104 struct ieee80211_hdr
*hdr
;
4105 struct ieee80211_vif
*vif
;
4106 struct ieee80211_sta
*sta
;
4107 struct sk_buff
*skb
;
4108 const u8
*peer_addr
;
4111 unsigned long time_left
;
4112 bool tmp_peer_created
= false;
4114 /* FW requirement: We must create a peer before FW will send out
4115 * an offchannel frame. Otherwise the frame will be stuck and
4116 * never transmitted. We delete the peer upon tx completion.
4117 * It is unlikely that a peer for offchannel tx will already be
4118 * present. However it may be in some rare cases so account for that.
4119 * Otherwise we might remove a legitimate peer and break stuff.
4123 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
4127 mutex_lock(&ar
->conf_mutex
);
4129 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %pK len %d\n",
4132 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4133 peer_addr
= ieee80211_get_DA(hdr
);
4135 spin_lock_bh(&ar
->data_lock
);
4136 vdev_id
= ar
->scan
.vdev_id
;
4137 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
4138 spin_unlock_bh(&ar
->data_lock
);
4141 ath10k_warn(ar
, "peer %pM on vdev %d already present\n",
4142 peer_addr
, vdev_id
);
4144 ret
= ath10k_peer_create(ar
, NULL
, NULL
, vdev_id
,
4146 WMI_PEER_TYPE_DEFAULT
);
4148 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
4149 peer_addr
, vdev_id
, ret
);
4150 tmp_peer_created
= (ret
== 0);
4153 spin_lock_bh(&ar
->data_lock
);
4154 reinit_completion(&ar
->offchan_tx_completed
);
4155 ar
->offchan_tx_skb
= skb
;
4156 spin_unlock_bh(&ar
->data_lock
);
4158 /* It's safe to access vif and sta - conf_mutex guarantees that
4159 * sta_state() and remove_interface() are locked exclusively
4160 * out wrt to this offchannel worker.
4162 arvif
= ath10k_get_arvif(ar
, vdev_id
);
4165 sta
= ieee80211_find_sta(vif
, peer_addr
);
4171 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4172 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4174 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, true);
4176 ath10k_warn(ar
, "failed to transmit offchannel frame: %d\n",
4182 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
4184 ath10k_warn(ar
, "timed out waiting for offchannel skb %pK, len: %d\n",
4187 if (!peer
&& tmp_peer_created
) {
4188 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
4190 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
4191 peer_addr
, vdev_id
, ret
);
4194 mutex_unlock(&ar
->conf_mutex
);
4198 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
4200 struct sk_buff
*skb
;
4203 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
4207 ieee80211_free_txskb(ar
->hw
, skb
);
4211 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
4213 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
4214 struct sk_buff
*skb
;
4219 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
4223 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF
,
4224 ar
->running_fw
->fw_file
.fw_features
)) {
4225 paddr
= dma_map_single(ar
->dev
, skb
->data
,
4226 skb
->len
, DMA_TO_DEVICE
);
4227 if (dma_mapping_error(ar
->dev
, paddr
)) {
4228 ieee80211_free_txskb(ar
->hw
, skb
);
4231 ret
= ath10k_wmi_mgmt_tx_send(ar
, skb
, paddr
);
4233 ath10k_warn(ar
, "failed to transmit management frame by ref via WMI: %d\n",
4235 /* remove this msdu from idr tracking */
4236 ath10k_wmi_cleanup_mgmt_tx_send(ar
, skb
);
4238 dma_unmap_single(ar
->dev
, paddr
, skb
->len
,
4240 ieee80211_free_txskb(ar
->hw
, skb
);
4243 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
4245 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
4247 ieee80211_free_txskb(ar
->hw
, skb
);
4253 static void ath10k_mac_txq_init(struct ieee80211_txq
*txq
)
4255 struct ath10k_txq
*artxq
;
4260 artxq
= (void *)txq
->drv_priv
;
4261 INIT_LIST_HEAD(&artxq
->list
);
4264 static void ath10k_mac_txq_unref(struct ath10k
*ar
, struct ieee80211_txq
*txq
)
4266 struct ath10k_skb_cb
*cb
;
4267 struct sk_buff
*msdu
;
4273 spin_lock_bh(&ar
->htt
.tx_lock
);
4274 idr_for_each_entry(&ar
->htt
.pending_tx
, msdu
, msdu_id
) {
4275 cb
= ATH10K_SKB_CB(msdu
);
4279 spin_unlock_bh(&ar
->htt
.tx_lock
);
4282 struct ieee80211_txq
*ath10k_mac_txq_lookup(struct ath10k
*ar
,
4286 struct ath10k_peer
*peer
;
4288 lockdep_assert_held(&ar
->data_lock
);
4290 peer
= ar
->peer_map
[peer_id
];
4298 return peer
->sta
->txq
[tid
];
4300 return peer
->vif
->txq
;
4305 static bool ath10k_mac_tx_can_push(struct ieee80211_hw
*hw
,
4306 struct ieee80211_txq
*txq
)
4308 struct ath10k
*ar
= hw
->priv
;
4309 struct ath10k_txq
*artxq
= (void *)txq
->drv_priv
;
4311 /* No need to get locks */
4312 if (ar
->htt
.tx_q_state
.mode
== HTT_TX_MODE_SWITCH_PUSH
)
4315 if (ar
->htt
.num_pending_tx
< ar
->htt
.tx_q_state
.num_push_allowed
)
4318 if (artxq
->num_fw_queued
< artxq
->num_push_allowed
)
4324 /* Return estimated airtime in microsecond, which is calculated using last
4325 * reported TX rate. This is just a rough estimation because host driver has no
4326 * knowledge of the actual transmit rate, retries or aggregation. If actual
4327 * airtime can be reported by firmware, then delta between estimated and actual
4328 * airtime can be adjusted from deficit.
4330 #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
4331 #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
4332 static u16
ath10k_mac_update_airtime(struct ath10k
*ar
,
4333 struct ieee80211_txq
*txq
,
4334 struct sk_buff
*skb
)
4336 struct ath10k_sta
*arsta
;
4340 if (!txq
|| !txq
->sta
)
4343 if (test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
4346 spin_lock_bh(&ar
->data_lock
);
4347 arsta
= (struct ath10k_sta
*)txq
->sta
->drv_priv
;
4349 pktlen
= skb
->len
+ 38; /* Assume MAC header 30, SNAP 8 for most case */
4350 if (arsta
->last_tx_bitrate
) {
4351 /* airtime in us, last_tx_bitrate in 100kbps */
4352 airtime
= (pktlen
* 8 * (1000 / 100))
4353 / arsta
->last_tx_bitrate
;
4354 /* overhead for media access time and IFS */
4355 airtime
+= IEEE80211_ATF_OVERHEAD_IFS
;
4357 /* This is mostly for throttle excessive BC/MC frames, and the
4358 * airtime/rate doesn't need be exact. Airtime of BC/MC frames
4359 * in 2G get some discount, which helps prevent very low rate
4360 * frames from being blocked for too long.
4362 airtime
= (pktlen
* 8 * (1000 / 100)) / 60; /* 6M */
4363 airtime
+= IEEE80211_ATF_OVERHEAD
;
4365 spin_unlock_bh(&ar
->data_lock
);
4370 int ath10k_mac_tx_push_txq(struct ieee80211_hw
*hw
,
4371 struct ieee80211_txq
*txq
)
4373 struct ath10k
*ar
= hw
->priv
;
4374 struct ath10k_htt
*htt
= &ar
->htt
;
4375 struct ath10k_txq
*artxq
= (void *)txq
->drv_priv
;
4376 struct ieee80211_vif
*vif
= txq
->vif
;
4377 struct ieee80211_sta
*sta
= txq
->sta
;
4378 enum ath10k_hw_txrx_mode txmode
;
4379 enum ath10k_mac_tx_path txpath
;
4380 struct sk_buff
*skb
;
4381 struct ieee80211_hdr
*hdr
;
4383 bool is_mgmt
, is_presp
;
4387 spin_lock_bh(&ar
->htt
.tx_lock
);
4388 ret
= ath10k_htt_tx_inc_pending(htt
);
4389 spin_unlock_bh(&ar
->htt
.tx_lock
);
4394 skb
= ieee80211_tx_dequeue_ni(hw
, txq
);
4396 spin_lock_bh(&ar
->htt
.tx_lock
);
4397 ath10k_htt_tx_dec_pending(htt
);
4398 spin_unlock_bh(&ar
->htt
.tx_lock
);
4403 airtime
= ath10k_mac_update_airtime(ar
, txq
, skb
);
4404 ath10k_mac_tx_h_fill_cb(ar
, vif
, txq
, sta
, skb
, airtime
);
4407 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4408 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4409 is_mgmt
= (txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4412 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4413 is_presp
= ieee80211_is_probe_resp(hdr
->frame_control
);
4415 spin_lock_bh(&ar
->htt
.tx_lock
);
4416 ret
= ath10k_htt_tx_mgmt_inc_pending(htt
, is_mgmt
, is_presp
);
4419 ath10k_htt_tx_dec_pending(htt
);
4420 spin_unlock_bh(&ar
->htt
.tx_lock
);
4423 spin_unlock_bh(&ar
->htt
.tx_lock
);
4426 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, false);
4427 if (unlikely(ret
)) {
4428 ath10k_warn(ar
, "failed to push frame: %d\n", ret
);
4430 spin_lock_bh(&ar
->htt
.tx_lock
);
4431 ath10k_htt_tx_dec_pending(htt
);
4433 ath10k_htt_tx_mgmt_dec_pending(htt
);
4434 spin_unlock_bh(&ar
->htt
.tx_lock
);
4439 spin_lock_bh(&ar
->htt
.tx_lock
);
4440 artxq
->num_fw_queued
++;
4441 spin_unlock_bh(&ar
->htt
.tx_lock
);
4446 static int ath10k_mac_schedule_txq(struct ieee80211_hw
*hw
, u32 ac
)
4448 struct ieee80211_txq
*txq
;
4451 ieee80211_txq_schedule_start(hw
, ac
);
4452 while ((txq
= ieee80211_next_txq(hw
, ac
))) {
4453 while (ath10k_mac_tx_can_push(hw
, txq
)) {
4454 ret
= ath10k_mac_tx_push_txq(hw
, txq
);
4458 ieee80211_return_txq(hw
, txq
, false);
4459 ath10k_htt_tx_txq_update(hw
, txq
);
4463 ieee80211_txq_schedule_end(hw
, ac
);
4468 void ath10k_mac_tx_push_pending(struct ath10k
*ar
)
4470 struct ieee80211_hw
*hw
= ar
->hw
;
4473 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH
)
4476 if (ar
->htt
.num_pending_tx
>= (ar
->htt
.max_num_pending_tx
/ 2))
4480 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
4481 if (ath10k_mac_schedule_txq(hw
, ac
) == -EBUSY
)
4486 EXPORT_SYMBOL(ath10k_mac_tx_push_pending
);
4492 void __ath10k_scan_finish(struct ath10k
*ar
)
4494 lockdep_assert_held(&ar
->data_lock
);
4496 switch (ar
->scan
.state
) {
4497 case ATH10K_SCAN_IDLE
:
4499 case ATH10K_SCAN_RUNNING
:
4500 case ATH10K_SCAN_ABORTING
:
4501 if (ar
->scan
.is_roc
&& ar
->scan
.roc_notify
)
4502 ieee80211_remain_on_channel_expired(ar
->hw
);
4504 case ATH10K_SCAN_STARTING
:
4505 if (!ar
->scan
.is_roc
) {
4506 struct cfg80211_scan_info info
= {
4507 .aborted
= ((ar
->scan
.state
==
4508 ATH10K_SCAN_ABORTING
) ||
4510 ATH10K_SCAN_STARTING
)),
4513 ieee80211_scan_completed(ar
->hw
, &info
);
4516 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4517 ar
->scan_channel
= NULL
;
4518 ar
->scan
.roc_freq
= 0;
4519 ath10k_offchan_tx_purge(ar
);
4520 cancel_delayed_work(&ar
->scan
.timeout
);
4521 complete(&ar
->scan
.completed
);
4526 void ath10k_scan_finish(struct ath10k
*ar
)
4528 spin_lock_bh(&ar
->data_lock
);
4529 __ath10k_scan_finish(ar
);
4530 spin_unlock_bh(&ar
->data_lock
);
4533 static int ath10k_scan_stop(struct ath10k
*ar
)
4535 struct wmi_stop_scan_arg arg
= {
4536 .req_id
= 1, /* FIXME */
4537 .req_type
= WMI_SCAN_STOP_ONE
,
4538 .u
.scan_id
= ATH10K_SCAN_ID
,
4542 lockdep_assert_held(&ar
->conf_mutex
);
4544 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
4546 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
4550 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3 * HZ
);
4552 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
4554 } else if (ret
> 0) {
4559 /* Scan state should be updated upon scan completion but in case
4560 * firmware fails to deliver the event (for whatever reason) it is
4561 * desired to clean up scan state anyway. Firmware may have just
4562 * dropped the scan completion event delivery due to transport pipe
4563 * being overflown with data and/or it can recover on its own before
4564 * next scan request is submitted.
4566 spin_lock_bh(&ar
->data_lock
);
4567 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
4568 __ath10k_scan_finish(ar
);
4569 spin_unlock_bh(&ar
->data_lock
);
4574 static void ath10k_scan_abort(struct ath10k
*ar
)
4578 lockdep_assert_held(&ar
->conf_mutex
);
4580 spin_lock_bh(&ar
->data_lock
);
4582 switch (ar
->scan
.state
) {
4583 case ATH10K_SCAN_IDLE
:
4584 /* This can happen if timeout worker kicked in and called
4585 * abortion while scan completion was being processed.
4588 case ATH10K_SCAN_STARTING
:
4589 case ATH10K_SCAN_ABORTING
:
4590 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4591 ath10k_scan_state_str(ar
->scan
.state
),
4594 case ATH10K_SCAN_RUNNING
:
4595 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
4596 spin_unlock_bh(&ar
->data_lock
);
4598 ret
= ath10k_scan_stop(ar
);
4600 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
4602 spin_lock_bh(&ar
->data_lock
);
4606 spin_unlock_bh(&ar
->data_lock
);
4609 void ath10k_scan_timeout_work(struct work_struct
*work
)
4611 struct ath10k
*ar
= container_of(work
, struct ath10k
,
4614 mutex_lock(&ar
->conf_mutex
);
4615 ath10k_scan_abort(ar
);
4616 mutex_unlock(&ar
->conf_mutex
);
4619 static int ath10k_start_scan(struct ath10k
*ar
,
4620 const struct wmi_start_scan_arg
*arg
)
4624 lockdep_assert_held(&ar
->conf_mutex
);
4626 ret
= ath10k_wmi_start_scan(ar
, arg
);
4630 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1 * HZ
);
4632 ret
= ath10k_scan_stop(ar
);
4634 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
4639 /* If we failed to start the scan, return error code at
4640 * this point. This is probably due to some issue in the
4641 * firmware, but no need to wedge the driver due to that...
4643 spin_lock_bh(&ar
->data_lock
);
4644 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
4645 spin_unlock_bh(&ar
->data_lock
);
4648 spin_unlock_bh(&ar
->data_lock
);
4653 /**********************/
4654 /* mac80211 callbacks */
4655 /**********************/
4657 static void ath10k_mac_op_tx(struct ieee80211_hw
*hw
,
4658 struct ieee80211_tx_control
*control
,
4659 struct sk_buff
*skb
)
4661 struct ath10k
*ar
= hw
->priv
;
4662 struct ath10k_htt
*htt
= &ar
->htt
;
4663 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
4664 struct ieee80211_vif
*vif
= info
->control
.vif
;
4665 struct ieee80211_sta
*sta
= control
->sta
;
4666 struct ieee80211_txq
*txq
= NULL
;
4667 enum ath10k_hw_txrx_mode txmode
;
4668 enum ath10k_mac_tx_path txpath
;
4674 airtime
= ath10k_mac_update_airtime(ar
, txq
, skb
);
4675 ath10k_mac_tx_h_fill_cb(ar
, vif
, txq
, sta
, skb
, airtime
);
4677 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4678 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4679 is_htt
= (txpath
== ATH10K_MAC_TX_HTT
||
4680 txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4681 is_mgmt
= (txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4684 bool is_presp
= false;
4686 spin_lock_bh(&ar
->htt
.tx_lock
);
4687 if (!(info
->flags
& IEEE80211_TX_CTL_HW_80211_ENCAP
)) {
4688 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
4690 is_presp
= ieee80211_is_probe_resp(hdr
->frame_control
);
4693 ret
= ath10k_htt_tx_inc_pending(htt
);
4695 ath10k_warn(ar
, "failed to increase tx pending count: %d, dropping\n",
4697 spin_unlock_bh(&ar
->htt
.tx_lock
);
4698 ieee80211_free_txskb(ar
->hw
, skb
);
4702 ret
= ath10k_htt_tx_mgmt_inc_pending(htt
, is_mgmt
, is_presp
);
4704 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "failed to increase tx mgmt pending count: %d, dropping\n",
4706 ath10k_htt_tx_dec_pending(htt
);
4707 spin_unlock_bh(&ar
->htt
.tx_lock
);
4708 ieee80211_free_txskb(ar
->hw
, skb
);
4711 spin_unlock_bh(&ar
->htt
.tx_lock
);
4714 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, false);
4716 ath10k_warn(ar
, "failed to transmit frame: %d\n", ret
);
4718 spin_lock_bh(&ar
->htt
.tx_lock
);
4719 ath10k_htt_tx_dec_pending(htt
);
4721 ath10k_htt_tx_mgmt_dec_pending(htt
);
4722 spin_unlock_bh(&ar
->htt
.tx_lock
);
4728 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw
*hw
,
4729 struct ieee80211_txq
*txq
)
4731 struct ath10k
*ar
= hw
->priv
;
4735 ath10k_htt_tx_txq_update(hw
, txq
);
4736 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH
)
4739 spin_lock_bh(&ar
->queue_lock
[ac
]);
4741 ieee80211_txq_schedule_start(hw
, ac
);
4742 txq
= ieee80211_next_txq(hw
, ac
);
4746 while (ath10k_mac_tx_can_push(hw
, txq
)) {
4747 ret
= ath10k_mac_tx_push_txq(hw
, txq
);
4751 ieee80211_return_txq(hw
, txq
, false);
4752 ath10k_htt_tx_txq_update(hw
, txq
);
4754 ieee80211_txq_schedule_end(hw
, ac
);
4755 spin_unlock_bh(&ar
->queue_lock
[ac
]);
4758 /* Must not be called with conf_mutex held as workers can use that also. */
4759 void ath10k_drain_tx(struct ath10k
*ar
)
4761 lockdep_assert_not_held(&ar
->conf_mutex
);
4763 /* make sure rcu-protected mac80211 tx path itself is drained */
4766 ath10k_offchan_tx_purge(ar
);
4767 ath10k_mgmt_over_wmi_tx_purge(ar
);
4769 cancel_work_sync(&ar
->offchan_tx_work
);
4770 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
4773 void ath10k_halt(struct ath10k
*ar
)
4775 struct ath10k_vif
*arvif
;
4777 lockdep_assert_held(&ar
->conf_mutex
);
4779 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
4780 ar
->filter_flags
= 0;
4781 ar
->monitor
= false;
4782 ar
->monitor_arvif
= NULL
;
4784 if (ar
->monitor_started
)
4785 ath10k_monitor_stop(ar
);
4787 ar
->monitor_started
= false;
4790 ath10k_scan_finish(ar
);
4791 ath10k_peer_cleanup_all(ar
);
4792 ath10k_stop_radar_confirmation(ar
);
4793 ath10k_core_stop(ar
);
4794 ath10k_hif_power_down(ar
);
4796 spin_lock_bh(&ar
->data_lock
);
4797 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
4798 ath10k_mac_vif_beacon_cleanup(arvif
);
4799 spin_unlock_bh(&ar
->data_lock
);
4802 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
4804 struct ath10k
*ar
= hw
->priv
;
4806 mutex_lock(&ar
->conf_mutex
);
4808 *tx_ant
= ar
->cfg_tx_chainmask
;
4809 *rx_ant
= ar
->cfg_rx_chainmask
;
4811 mutex_unlock(&ar
->conf_mutex
);
4816 static bool ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
4818 /* It is not clear that allowing gaps in chainmask
4819 * is helpful. Probably it will not do what user
4820 * is hoping for, so warn in that case.
4822 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
4825 ath10k_warn(ar
, "mac %s antenna chainmask is invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4830 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k
*ar
)
4832 int nsts
= ar
->vht_cap_info
;
4834 nsts
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
4835 nsts
>>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
4837 /* If firmware does not deliver to host number of space-time
4838 * streams supported, assume it support up to 4 BF STS and return
4839 * the value for VHT CAP: nsts-1)
4847 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k
*ar
)
4849 int sound_dim
= ar
->vht_cap_info
;
4851 sound_dim
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
4852 sound_dim
>>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
4854 /* If the sounding dimension is not advertised by the firmware,
4855 * let's use a default value of 1
4863 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
4865 struct ieee80211_sta_vht_cap vht_cap
= {0};
4866 struct ath10k_hw_params
*hw
= &ar
->hw_params
;
4871 vht_cap
.vht_supported
= 1;
4872 vht_cap
.cap
= ar
->vht_cap_info
;
4874 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
4875 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
4876 val
= ath10k_mac_get_vht_cap_bf_sts(ar
);
4877 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
4878 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
4883 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
4884 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
4885 val
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
4886 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
4887 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
4893 for (i
= 0; i
< 8; i
++) {
4894 if ((i
< ar
->num_rf_chains
) && (ar
->cfg_tx_chainmask
& BIT(i
)))
4895 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
* 2);
4897 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
* 2);
4900 if (ar
->cfg_tx_chainmask
<= 1)
4901 vht_cap
.cap
&= ~IEEE80211_VHT_CAP_TXSTBC
;
4903 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
4904 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
4906 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4907 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4908 * user-space a clue if that is the case.
4910 if ((vht_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) &&
4911 (hw
->vht160_mcs_rx_highest
!= 0 ||
4912 hw
->vht160_mcs_tx_highest
!= 0)) {
4913 vht_cap
.vht_mcs
.rx_highest
= cpu_to_le16(hw
->vht160_mcs_rx_highest
);
4914 vht_cap
.vht_mcs
.tx_highest
= cpu_to_le16(hw
->vht160_mcs_tx_highest
);
4920 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
4923 struct ieee80211_sta_ht_cap ht_cap
= {0};
4925 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
4928 ht_cap
.ht_supported
= 1;
4929 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
4930 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
4931 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
4932 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
4934 WLAN_HT_CAP_SM_PS_DISABLED
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
4936 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
4937 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
4939 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
4940 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
4942 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
4945 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
4946 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
4951 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
&& (ar
->cfg_tx_chainmask
> 1))
4952 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
4954 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
4957 stbc
= ar
->ht_cap_info
;
4958 stbc
&= WMI_HT_CAP_RX_STBC
;
4959 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
4960 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
4961 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
4966 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
|| (ar
->ht_cap_info
&
4967 WMI_HT_CAP_RX_LDPC
&& (ar
->ht_cap_info
& WMI_HT_CAP_TX_LDPC
)))
4968 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
4970 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
4971 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
4973 /* max AMSDU is implicitly taken from vht_cap_info */
4974 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
4975 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
4977 for (i
= 0; i
< ar
->num_rf_chains
; i
++) {
4978 if (ar
->cfg_rx_chainmask
& BIT(i
))
4979 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
4982 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
4987 static void ath10k_mac_setup_ht_vht_cap(struct ath10k
*ar
)
4989 struct ieee80211_supported_band
*band
;
4990 struct ieee80211_sta_vht_cap vht_cap
;
4991 struct ieee80211_sta_ht_cap ht_cap
;
4993 ht_cap
= ath10k_get_ht_cap(ar
);
4994 vht_cap
= ath10k_create_vht_cap(ar
);
4996 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
4997 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
4998 band
->ht_cap
= ht_cap
;
5000 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
5001 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
5002 band
->ht_cap
= ht_cap
;
5003 band
->vht_cap
= vht_cap
;
5007 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
5010 bool is_valid_tx_chain_mask
, is_valid_rx_chain_mask
;
5012 lockdep_assert_held(&ar
->conf_mutex
);
5014 is_valid_tx_chain_mask
= ath10k_check_chain_mask(ar
, tx_ant
, "tx");
5015 is_valid_rx_chain_mask
= ath10k_check_chain_mask(ar
, rx_ant
, "rx");
5017 if (!is_valid_tx_chain_mask
|| !is_valid_rx_chain_mask
)
5020 ar
->cfg_tx_chainmask
= tx_ant
;
5021 ar
->cfg_rx_chainmask
= rx_ant
;
5023 if ((ar
->state
!= ATH10K_STATE_ON
) &&
5024 (ar
->state
!= ATH10K_STATE_RESTARTED
))
5027 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
5030 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
5035 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
5038 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
5043 /* Reload HT/VHT capability */
5044 ath10k_mac_setup_ht_vht_cap(ar
);
5049 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
5051 struct ath10k
*ar
= hw
->priv
;
5054 mutex_lock(&ar
->conf_mutex
);
5055 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
5056 mutex_unlock(&ar
->conf_mutex
);
5060 static int __ath10k_fetch_bb_timing_dt(struct ath10k
*ar
,
5061 struct wmi_bb_timing_cfg_arg
*bb_timing
)
5063 struct device_node
*node
;
5064 const char *fem_name
;
5067 node
= ar
->dev
->of_node
;
5071 ret
= of_property_read_string_index(node
, "ext-fem-name", 0, &fem_name
);
5076 * If external Front End module used in hardware, then default base band timing
5077 * parameter cannot be used since they were fine tuned for reference hardware,
5078 * so choosing different value suitable for that external FEM.
5080 if (!strcmp("microsemi-lx5586", fem_name
)) {
5081 bb_timing
->bb_tx_timing
= 0x00;
5082 bb_timing
->bb_xpa_timing
= 0x0101;
5087 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
5088 bb_timing
->bb_tx_timing
, bb_timing
->bb_xpa_timing
);
5092 static int ath10k_mac_rfkill_config(struct ath10k
*ar
)
5097 if (ar
->hw_values
->rfkill_pin
== 0) {
5098 ath10k_warn(ar
, "ath10k does not support hardware rfkill with this device\n");
5102 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5103 "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
5104 ar
->hw_values
->rfkill_pin
, ar
->hw_values
->rfkill_cfg
,
5105 ar
->hw_values
->rfkill_on_level
);
5107 param
= FIELD_PREP(WMI_TLV_RFKILL_CFG_RADIO_LEVEL
,
5108 ar
->hw_values
->rfkill_on_level
) |
5109 FIELD_PREP(WMI_TLV_RFKILL_CFG_GPIO_PIN_NUM
,
5110 ar
->hw_values
->rfkill_pin
) |
5111 FIELD_PREP(WMI_TLV_RFKILL_CFG_PIN_AS_GPIO
,
5112 ar
->hw_values
->rfkill_cfg
);
5114 ret
= ath10k_wmi_pdev_set_param(ar
,
5115 ar
->wmi
.pdev_param
->rfkill_config
,
5119 "failed to set rfkill config 0x%x: %d\n",
5126 int ath10k_mac_rfkill_enable_radio(struct ath10k
*ar
, bool enable
)
5128 enum wmi_tlv_rfkill_enable_radio param
;
5132 param
= WMI_TLV_RFKILL_ENABLE_RADIO_ON
;
5134 param
= WMI_TLV_RFKILL_ENABLE_RADIO_OFF
;
5136 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac rfkill enable %d", param
);
5138 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rfkill_enable
,
5141 ath10k_warn(ar
, "failed to set rfkill enable param %d: %d\n",
5149 static int ath10k_start(struct ieee80211_hw
*hw
)
5151 struct ath10k
*ar
= hw
->priv
;
5154 struct wmi_bb_timing_cfg_arg bb_timing
= {0};
5157 * This makes sense only when restarting hw. It is harmless to call
5158 * unconditionally. This is necessary to make sure no HTT/WMI tx
5159 * commands will be submitted while restarting.
5161 ath10k_drain_tx(ar
);
5163 mutex_lock(&ar
->conf_mutex
);
5165 switch (ar
->state
) {
5166 case ATH10K_STATE_OFF
:
5167 ar
->state
= ATH10K_STATE_ON
;
5169 case ATH10K_STATE_RESTARTING
:
5170 ar
->state
= ATH10K_STATE_RESTARTED
;
5172 case ATH10K_STATE_ON
:
5173 case ATH10K_STATE_RESTARTED
:
5174 case ATH10K_STATE_WEDGED
:
5178 case ATH10K_STATE_UTF
:
5183 spin_lock_bh(&ar
->data_lock
);
5185 if (ar
->hw_rfkill_on
) {
5186 ar
->hw_rfkill_on
= false;
5187 spin_unlock_bh(&ar
->data_lock
);
5191 spin_unlock_bh(&ar
->data_lock
);
5193 ret
= ath10k_hif_power_up(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
5195 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
5199 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
,
5200 &ar
->normal_mode_fw
);
5202 ath10k_err(ar
, "Could not init core: %d\n", ret
);
5203 goto err_power_down
;
5206 if (ar
->sys_cap_info
& WMI_TLV_SYS_CAP_INFO_RFKILL
) {
5207 ret
= ath10k_mac_rfkill_config(ar
);
5208 if (ret
&& ret
!= -EOPNOTSUPP
) {
5209 ath10k_warn(ar
, "failed to configure rfkill: %d", ret
);
5214 param
= ar
->wmi
.pdev_param
->pmf_qos
;
5215 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5217 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
5221 param
= ar
->wmi
.pdev_param
->dynamic_bw
;
5222 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5224 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
5228 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
5229 ret
= ath10k_wmi_scan_prob_req_oui(ar
, ar
->mac_addr
);
5231 ath10k_err(ar
, "failed to set prob req oui: %i\n", ret
);
5236 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
5237 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
5239 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
5245 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
5246 param
= ar
->wmi
.pdev_param
->burst_enable
;
5247 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
5249 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
5254 param
= ar
->wmi
.pdev_param
->idle_ps_config
;
5255 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5256 if (ret
&& ret
!= -EOPNOTSUPP
) {
5257 ath10k_warn(ar
, "failed to enable idle_ps_config: %d\n", ret
);
5261 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
, ar
->cfg_rx_chainmask
);
5264 * By default FW set ARP frames ac to voice (6). In that case ARP
5265 * exchange is not working properly for UAPSD enabled AP. ARP requests
5266 * which arrives with access category 0 are processed by network stack
5267 * and send back with access category 0, but FW changes access category
5268 * to 6. Set ARP frames access category to best effort (0) solves
5272 param
= ar
->wmi
.pdev_param
->arp_ac_override
;
5273 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
5275 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
5280 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA
,
5281 ar
->running_fw
->fw_file
.fw_features
)) {
5282 ret
= ath10k_wmi_pdev_enable_adaptive_cca(ar
, 1,
5283 WMI_CCA_DETECT_LEVEL_AUTO
,
5284 WMI_CCA_DETECT_MARGIN_AUTO
);
5286 ath10k_warn(ar
, "failed to enable adaptive cca: %d\n",
5292 param
= ar
->wmi
.pdev_param
->ani_enable
;
5293 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5295 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
5300 ar
->ani_enabled
= true;
5302 if (ath10k_peer_stats_enabled(ar
)) {
5303 param
= ar
->wmi
.pdev_param
->peer_stats_update_period
;
5304 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
5305 PEER_DEFAULT_STATS_UPDATE_PERIOD
);
5308 "failed to set peer stats period : %d\n",
5314 param
= ar
->wmi
.pdev_param
->enable_btcoex
;
5315 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
) &&
5316 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM
,
5317 ar
->running_fw
->fw_file
.fw_features
) &&
5319 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
5322 "failed to set btcoex param: %d\n", ret
);
5325 clear_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
5328 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT
, ar
->wmi
.svc_map
)) {
5329 ret
= __ath10k_fetch_bb_timing_dt(ar
, &bb_timing
);
5331 ret
= ath10k_wmi_pdev_bb_timing(ar
, &bb_timing
);
5334 "failed to set bb timings: %d\n",
5341 ar
->num_started_vdevs
= 0;
5342 ath10k_regd_update(ar
);
5344 ath10k_spectral_start(ar
);
5345 ath10k_thermal_set_throttling(ar
);
5347 ar
->radar_conf_state
= ATH10K_RADAR_CONFIRMATION_IDLE
;
5349 mutex_unlock(&ar
->conf_mutex
);
5353 ath10k_core_stop(ar
);
5356 ath10k_hif_power_down(ar
);
5359 ar
->state
= ATH10K_STATE_OFF
;
5362 mutex_unlock(&ar
->conf_mutex
);
5366 static void ath10k_stop(struct ieee80211_hw
*hw
, bool suspend
)
5368 struct ath10k
*ar
= hw
->priv
;
5371 ath10k_drain_tx(ar
);
5373 mutex_lock(&ar
->conf_mutex
);
5374 if (ar
->state
!= ATH10K_STATE_OFF
) {
5375 if (!ar
->hw_rfkill_on
) {
5376 /* If the current driver state is RESTARTING but not yet
5377 * fully RESTARTED because of incoming suspend event,
5378 * then ath10k_halt() is already called via
5379 * ath10k_core_restart() and should not be called here.
5381 if (ar
->state
!= ATH10K_STATE_RESTARTING
) {
5384 /* Suspending here, because when in RESTARTING
5385 * state, ath10k_core_stop() skips
5386 * ath10k_wait_for_suspend().
5388 opt
= WMI_PDEV_SUSPEND_AND_DISABLE_INTR
;
5389 ath10k_wait_for_suspend(ar
, opt
);
5392 ar
->state
= ATH10K_STATE_OFF
;
5394 mutex_unlock(&ar
->conf_mutex
);
5396 cancel_work_sync(&ar
->set_coverage_class_work
);
5397 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5398 cancel_work_sync(&ar
->restart_work
);
5401 static int ath10k_config_ps(struct ath10k
*ar
)
5403 struct ath10k_vif
*arvif
;
5406 lockdep_assert_held(&ar
->conf_mutex
);
5408 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5409 ret
= ath10k_mac_vif_setup_ps(arvif
);
5411 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
5419 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
5421 struct ath10k
*ar
= hw
->priv
;
5422 struct ieee80211_conf
*conf
= &hw
->conf
;
5425 mutex_lock(&ar
->conf_mutex
);
5427 if (changed
& IEEE80211_CONF_CHANGE_PS
)
5428 ath10k_config_ps(ar
);
5430 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
5431 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
5432 ret
= ath10k_monitor_recalc(ar
);
5434 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5437 mutex_unlock(&ar
->conf_mutex
);
5441 static u32
get_nss_from_chainmask(u16 chain_mask
)
5443 if ((chain_mask
& 0xf) == 0xf)
5445 else if ((chain_mask
& 0x7) == 0x7)
5447 else if ((chain_mask
& 0x3) == 0x3)
5452 static int ath10k_mac_set_txbf_conf(struct ath10k_vif
*arvif
)
5455 struct ath10k
*ar
= arvif
->ar
;
5459 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_BEFORE_ASSOC
)
5462 nsts
= ath10k_mac_get_vht_cap_bf_sts(ar
);
5463 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
5464 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
))
5465 value
|= SM(nsts
, WMI_TXBF_STS_CAP_OFFSET
);
5467 sound_dim
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
5468 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
5469 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
))
5470 value
|= SM(sound_dim
, WMI_BF_SOUND_DIM_OFFSET
);
5475 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
5476 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
5478 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
5479 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER
|
5480 WMI_VDEV_PARAM_TXBF_SU_TX_BFER
);
5482 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
5483 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
5485 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
5486 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
|
5487 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
);
5489 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5490 ar
->wmi
.vdev_param
->txbf
, value
);
5493 static void ath10k_update_vif_offload(struct ieee80211_hw
*hw
,
5494 struct ieee80211_vif
*vif
)
5496 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5497 struct ath10k
*ar
= hw
->priv
;
5501 if (ath10k_frame_mode
!= ATH10K_HW_TXRX_ETHERNET
||
5502 ar
->wmi
.vdev_param
->tx_encap_type
== WMI_VDEV_PARAM_UNSUPPORTED
||
5503 (vif
->type
!= NL80211_IFTYPE_STATION
&&
5504 vif
->type
!= NL80211_IFTYPE_AP
))
5505 vif
->offload_flags
&= ~IEEE80211_OFFLOAD_ENCAP_ENABLED
;
5507 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
5508 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5509 ATH10K_HW_TXRX_NATIVE_WIFI
);
5510 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5511 if (ret
&& ret
!= -EOPNOTSUPP
) {
5512 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
5513 arvif
->vdev_id
, ret
);
5519 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5520 * because we will send mgmt frames without CCK. This requirement
5521 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5524 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
5525 struct ieee80211_vif
*vif
)
5527 struct ath10k
*ar
= hw
->priv
;
5528 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5529 struct ath10k_peer
*peer
;
5530 enum wmi_sta_powersave_param param
;
5537 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
5539 mutex_lock(&ar
->conf_mutex
);
5541 memset(arvif
, 0, sizeof(*arvif
));
5542 ath10k_mac_txq_init(vif
->txq
);
5547 INIT_LIST_HEAD(&arvif
->list
);
5548 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
5549 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
5550 ath10k_mac_vif_sta_connection_loss_work
);
5552 for (i
= 0; i
< ARRAY_SIZE(arvif
->bitrate_mask
.control
); i
++) {
5553 arvif
->bitrate_mask
.control
[i
].legacy
= 0xffffffff;
5554 memset(arvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
5555 sizeof(arvif
->bitrate_mask
.control
[i
].ht_mcs
));
5556 memset(arvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
5557 sizeof(arvif
->bitrate_mask
.control
[i
].vht_mcs
));
5560 if (ar
->num_peers
>= ar
->max_num_peers
) {
5561 ath10k_warn(ar
, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5566 if (ar
->free_vdev_map
== 0) {
5567 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
5571 bit
= __ffs64(ar
->free_vdev_map
);
5573 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
5574 bit
, ar
->free_vdev_map
);
5576 arvif
->vdev_id
= bit
;
5577 arvif
->vdev_subtype
=
5578 ath10k_wmi_get_vdev_subtype(ar
, WMI_VDEV_SUBTYPE_NONE
);
5580 switch (vif
->type
) {
5581 case NL80211_IFTYPE_P2P_DEVICE
:
5582 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
5583 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5584 (ar
, WMI_VDEV_SUBTYPE_P2P_DEVICE
);
5586 case NL80211_IFTYPE_UNSPECIFIED
:
5587 case NL80211_IFTYPE_STATION
:
5588 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
5590 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5591 (ar
, WMI_VDEV_SUBTYPE_P2P_CLIENT
);
5593 case NL80211_IFTYPE_ADHOC
:
5594 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
5596 case NL80211_IFTYPE_MESH_POINT
:
5597 if (test_bit(WMI_SERVICE_MESH_11S
, ar
->wmi
.svc_map
)) {
5598 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5599 (ar
, WMI_VDEV_SUBTYPE_MESH_11S
);
5600 } else if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
5602 ath10k_warn(ar
, "must load driver with rawmode=1 to add mesh interfaces\n");
5605 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
5607 case NL80211_IFTYPE_AP
:
5608 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
5611 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5612 (ar
, WMI_VDEV_SUBTYPE_P2P_GO
);
5614 case NL80211_IFTYPE_MONITOR
:
5615 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
5622 /* Using vdev_id as queue number will make it very easy to do per-vif
5623 * tx queue locking. This shouldn't wrap due to interface combinations
5624 * but do a modulo for correctness sake and prevent using offchannel tx
5625 * queues for regular vif tx.
5627 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
5628 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
5629 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
5631 /* Some firmware revisions don't wait for beacon tx completion before
5632 * sending another SWBA event. This could lead to hardware using old
5633 * (freed) beacon data in some cases, e.g. tx credit starvation
5634 * combined with missed TBTT. This is very rare.
5636 * On non-IOMMU-enabled hosts this could be a possible security issue
5637 * because hw could beacon some random data on the air. On
5638 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5639 * device would crash.
5641 * Since there are no beacon tx completions (implicit nor explicit)
5642 * propagated to host the only workaround for this is to allocate a
5643 * DMA-coherent buffer for a lifetime of a vif and use it for all
5644 * beacon tx commands. Worst case for this approach is some beacons may
5645 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5647 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
5648 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
5649 vif
->type
== NL80211_IFTYPE_AP
) {
5650 if (ar
->bus_param
.dev_type
== ATH10K_DEV_TYPE_HL
) {
5651 arvif
->beacon_buf
= kmalloc(IEEE80211_MAX_FRAME_LEN
,
5654 /* Using a kernel pointer in place of a dma_addr_t
5655 * token can lead to undefined behavior if that
5656 * makes it into cache management functions. Use a
5657 * known-invalid address token instead, which
5658 * avoids the warning and makes it easier to catch
5659 * bugs if it does end up getting used.
5661 arvif
->beacon_paddr
= DMA_MAPPING_ERROR
;
5664 dma_alloc_coherent(ar
->dev
,
5665 IEEE80211_MAX_FRAME_LEN
,
5666 &arvif
->beacon_paddr
,
5669 if (!arvif
->beacon_buf
) {
5671 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
5676 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
))
5677 arvif
->nohwcrypt
= true;
5679 if (arvif
->nohwcrypt
&&
5680 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
5682 ath10k_warn(ar
, "cryptmode module param needed for sw crypto\n");
5686 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5687 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
5688 arvif
->beacon_buf
? "single-buf" : "per-skb");
5690 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
5691 arvif
->vdev_subtype
, vif
->addr
);
5693 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
5694 arvif
->vdev_id
, ret
);
5698 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT
,
5700 vdev_param
= ar
->wmi
.vdev_param
->disable_4addr_src_lrn
;
5701 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5702 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN
);
5703 if (ret
&& ret
!= -EOPNOTSUPP
) {
5704 ath10k_warn(ar
, "failed to disable 4addr src lrn vdev %i: %d\n",
5705 arvif
->vdev_id
, ret
);
5709 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
5710 spin_lock_bh(&ar
->data_lock
);
5711 list_add(&arvif
->list
, &ar
->arvifs
);
5712 spin_unlock_bh(&ar
->data_lock
);
5714 /* It makes no sense to have firmware do keepalives. mac80211 already
5715 * takes care of this with idle connection polling.
5717 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
5719 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
5720 arvif
->vdev_id
, ret
);
5721 goto err_vdev_delete
;
5724 arvif
->def_wep_key_idx
= -1;
5726 ath10k_update_vif_offload(hw
, vif
);
5728 /* Configuring number of spatial stream for monitor interface is causing
5729 * target assert in qca9888 and qca6174.
5731 if (ar
->cfg_tx_chainmask
&& (vif
->type
!= NL80211_IFTYPE_MONITOR
)) {
5732 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
5734 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5735 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5738 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5739 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
5741 goto err_vdev_delete
;
5745 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5746 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5747 ret
= ath10k_peer_create(ar
, vif
, NULL
, arvif
->vdev_id
,
5748 vif
->addr
, WMI_PEER_TYPE_DEFAULT
);
5750 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
5751 arvif
->vdev_id
, ret
);
5752 goto err_vdev_delete
;
5755 spin_lock_bh(&ar
->data_lock
);
5757 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, vif
->addr
);
5759 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
5760 vif
->addr
, arvif
->vdev_id
);
5761 spin_unlock_bh(&ar
->data_lock
);
5763 goto err_peer_delete
;
5766 arvif
->peer_id
= find_first_bit(peer
->peer_ids
,
5767 ATH10K_MAX_NUM_PEER_IDS
);
5769 spin_unlock_bh(&ar
->data_lock
);
5771 arvif
->peer_id
= HTT_INVALID_PEERID
;
5774 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
5775 ret
= ath10k_mac_set_kickout(arvif
);
5777 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
5778 arvif
->vdev_id
, ret
);
5779 goto err_peer_delete
;
5783 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
5784 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
5785 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5786 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5789 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
5790 arvif
->vdev_id
, ret
);
5791 goto err_peer_delete
;
5794 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5796 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5797 arvif
->vdev_id
, ret
);
5798 goto err_peer_delete
;
5801 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5803 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5804 arvif
->vdev_id
, ret
);
5805 goto err_peer_delete
;
5809 ret
= ath10k_mac_set_txbf_conf(arvif
);
5811 ath10k_warn(ar
, "failed to set txbf for vdev %d: %d\n",
5812 arvif
->vdev_id
, ret
);
5813 goto err_peer_delete
;
5816 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
5818 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5819 arvif
->vdev_id
, ret
);
5820 goto err_peer_delete
;
5823 arvif
->txpower
= vif
->bss_conf
.txpower
;
5824 ret
= ath10k_mac_txpower_recalc(ar
);
5826 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
5827 goto err_peer_delete
;
5830 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
)) {
5831 vdev_param
= ar
->wmi
.vdev_param
->rtt_responder_role
;
5832 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5833 arvif
->ftm_responder
);
5835 /* It is harmless to not set FTM role. Do not warn */
5836 if (ret
&& ret
!= -EOPNOTSUPP
)
5837 ath10k_warn(ar
, "failed to set vdev %i FTM Responder: %d\n",
5838 arvif
->vdev_id
, ret
);
5841 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
5842 ar
->monitor_arvif
= arvif
;
5843 ret
= ath10k_monitor_recalc(ar
);
5845 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5846 goto err_peer_delete
;
5850 spin_lock_bh(&ar
->htt
.tx_lock
);
5852 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
5853 spin_unlock_bh(&ar
->htt
.tx_lock
);
5855 mutex_unlock(&ar
->conf_mutex
);
5859 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5860 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5861 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
5862 ath10k_wait_for_peer_delete_done(ar
, arvif
->vdev_id
,
5867 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
5868 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
5869 spin_lock_bh(&ar
->data_lock
);
5870 list_del(&arvif
->list
);
5871 spin_unlock_bh(&ar
->data_lock
);
5874 if (arvif
->beacon_buf
) {
5875 if (ar
->bus_param
.dev_type
== ATH10K_DEV_TYPE_HL
)
5876 kfree(arvif
->beacon_buf
);
5878 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
5880 arvif
->beacon_paddr
);
5881 arvif
->beacon_buf
= NULL
;
5884 mutex_unlock(&ar
->conf_mutex
);
5889 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
5893 for (i
= 0; i
< BITS_PER_LONG
; i
++)
5894 ath10k_mac_vif_tx_unlock(arvif
, i
);
5897 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
5898 struct ieee80211_vif
*vif
)
5900 struct ath10k
*ar
= hw
->priv
;
5901 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5902 struct ath10k_peer
*peer
;
5903 unsigned long time_left
;
5907 cancel_work_sync(&arvif
->ap_csa_work
);
5908 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
5910 mutex_lock(&ar
->conf_mutex
);
5912 ret
= ath10k_spectral_vif_stop(arvif
);
5914 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
5915 arvif
->vdev_id
, ret
);
5917 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
5918 spin_lock_bh(&ar
->data_lock
);
5919 list_del(&arvif
->list
);
5920 spin_unlock_bh(&ar
->data_lock
);
5922 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5923 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5924 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
5927 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5928 arvif
->vdev_id
, ret
);
5930 ath10k_wait_for_peer_delete_done(ar
, arvif
->vdev_id
,
5932 kfree(arvif
->u
.ap
.noa_data
);
5935 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
5938 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
5940 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
5941 arvif
->vdev_id
, ret
);
5943 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
5944 time_left
= wait_for_completion_timeout(&ar
->vdev_delete_done
,
5945 ATH10K_VDEV_DELETE_TIMEOUT_HZ
);
5946 if (time_left
== 0) {
5947 ath10k_warn(ar
, "Timeout in receiving vdev delete response\n");
5952 /* Some firmware revisions don't notify host about self-peer removal
5953 * until after associated vdev is deleted.
5955 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5956 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5957 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
5960 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
5961 arvif
->vdev_id
, ret
);
5963 spin_lock_bh(&ar
->data_lock
);
5965 spin_unlock_bh(&ar
->data_lock
);
5968 spin_lock_bh(&ar
->data_lock
);
5969 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
5970 peer
= ar
->peer_map
[i
];
5974 if (peer
->vif
== vif
) {
5975 ath10k_warn(ar
, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5976 vif
->addr
, arvif
->vdev_id
);
5981 /* Clean this up late, less opportunity for firmware to access
5982 * DMA memory we have deleted.
5984 ath10k_mac_vif_beacon_cleanup(arvif
);
5985 spin_unlock_bh(&ar
->data_lock
);
5987 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
5988 ath10k_mac_txq_unref(ar
, vif
->txq
);
5990 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
5991 ar
->monitor_arvif
= NULL
;
5992 ret
= ath10k_monitor_recalc(ar
);
5994 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5997 ret
= ath10k_mac_txpower_recalc(ar
);
5999 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
6001 spin_lock_bh(&ar
->htt
.tx_lock
);
6002 ath10k_mac_vif_tx_unlock_all(arvif
);
6003 spin_unlock_bh(&ar
->htt
.tx_lock
);
6005 ath10k_mac_txq_unref(ar
, vif
->txq
);
6008 mutex_unlock(&ar
->conf_mutex
);
6012 * FIXME: Has to be verified.
6014 #define SUPPORTED_FILTERS \
6019 FIF_BCN_PRBRESP_PROMISC | \
6023 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
6024 unsigned int changed_flags
,
6025 unsigned int *total_flags
,
6028 struct ath10k
*ar
= hw
->priv
;
6030 unsigned int supported
= SUPPORTED_FILTERS
;
6032 mutex_lock(&ar
->conf_mutex
);
6034 if (ar
->hw_params
.mcast_frame_registration
)
6035 supported
|= FIF_MCAST_ACTION
;
6037 *total_flags
&= supported
;
6039 ar
->filter_flags
= *total_flags
;
6041 ret
= ath10k_monitor_recalc(ar
);
6043 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
6045 mutex_unlock(&ar
->conf_mutex
);
6048 static void ath10k_recalculate_mgmt_rate(struct ath10k
*ar
,
6049 struct ieee80211_vif
*vif
,
6050 struct cfg80211_chan_def
*def
)
6052 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6053 const struct ieee80211_supported_band
*sband
;
6060 lockdep_assert_held(&ar
->conf_mutex
);
6062 sband
= ar
->hw
->wiphy
->bands
[def
->chan
->band
];
6063 basic_rate_idx
= ffs(vif
->bss_conf
.basic_rates
) - 1;
6064 bitrate
= sband
->bitrates
[basic_rate_idx
].bitrate
;
6066 hw_rate_code
= ath10k_mac_get_rate_hw_value(bitrate
);
6067 if (hw_rate_code
< 0) {
6068 ath10k_warn(ar
, "bitrate not supported %d\n", bitrate
);
6072 vdev_param
= ar
->wmi
.vdev_param
->mgmt_rate
;
6073 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6076 ath10k_warn(ar
, "failed to set mgmt tx rate %d\n", ret
);
6079 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
6080 struct ieee80211_vif
*vif
,
6081 struct ieee80211_bss_conf
*info
,
6084 struct ath10k
*ar
= hw
->priv
;
6085 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6086 struct cfg80211_chan_def def
;
6087 u32 vdev_param
, pdev_param
, slottime
, preamble
;
6088 u16 bitrate
, hw_value
;
6090 int ret
= 0, mcast_rate
;
6091 enum nl80211_band band
;
6093 mutex_lock(&ar
->conf_mutex
);
6095 if (changed
& BSS_CHANGED_IBSS
)
6096 ath10k_control_ibss(arvif
, vif
);
6098 if (changed
& BSS_CHANGED_BEACON_INT
) {
6099 arvif
->beacon_interval
= info
->beacon_int
;
6100 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
6101 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6102 arvif
->beacon_interval
);
6103 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6104 "mac vdev %d beacon_interval %d\n",
6105 arvif
->vdev_id
, arvif
->beacon_interval
);
6108 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
6109 arvif
->vdev_id
, ret
);
6112 if (changed
& BSS_CHANGED_BEACON
) {
6113 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6114 "vdev %d set beacon tx mode to staggered\n",
6117 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
6118 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
6119 WMI_BEACON_STAGGERED_MODE
);
6121 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
6122 arvif
->vdev_id
, ret
);
6124 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
6126 ath10k_warn(ar
, "failed to update beacon template: %d\n",
6129 if (ieee80211_vif_is_mesh(vif
)) {
6130 /* mesh doesn't use SSID but firmware needs it */
6131 arvif
->u
.ap
.ssid_len
= 4;
6132 memcpy(arvif
->u
.ap
.ssid
, "mesh", arvif
->u
.ap
.ssid_len
);
6136 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
6137 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
6139 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
6140 arvif
->vdev_id
, ret
);
6143 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
6144 arvif
->dtim_period
= info
->dtim_period
;
6146 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6147 "mac vdev %d dtim_period %d\n",
6148 arvif
->vdev_id
, arvif
->dtim_period
);
6150 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
6151 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6152 arvif
->dtim_period
);
6154 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
6155 arvif
->vdev_id
, ret
);
6158 if (changed
& BSS_CHANGED_SSID
&&
6159 vif
->type
== NL80211_IFTYPE_AP
) {
6160 arvif
->u
.ap
.ssid_len
= vif
->cfg
.ssid_len
;
6161 if (vif
->cfg
.ssid_len
)
6162 memcpy(arvif
->u
.ap
.ssid
, vif
->cfg
.ssid
,
6164 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
6167 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
6168 ether_addr_copy(arvif
->bssid
, info
->bssid
);
6170 if (changed
& BSS_CHANGED_FTM_RESPONDER
&&
6171 arvif
->ftm_responder
!= info
->ftm_responder
&&
6172 test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
)) {
6173 arvif
->ftm_responder
= info
->ftm_responder
;
6175 vdev_param
= ar
->wmi
.vdev_param
->rtt_responder_role
;
6176 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6177 arvif
->ftm_responder
);
6179 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6180 "mac vdev %d ftm_responder %d:ret %d\n",
6181 arvif
->vdev_id
, arvif
->ftm_responder
, ret
);
6184 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
6185 ath10k_control_beaconing(arvif
, info
);
6187 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
6188 arvif
->use_cts_prot
= info
->use_cts_prot
;
6190 ret
= ath10k_recalc_rtscts_prot(arvif
);
6192 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
6193 arvif
->vdev_id
, ret
);
6195 if (ath10k_mac_can_set_cts_prot(arvif
)) {
6196 ret
= ath10k_mac_set_cts_prot(arvif
);
6198 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
6199 arvif
->vdev_id
, ret
);
6203 if (changed
& BSS_CHANGED_ERP_SLOT
) {
6204 if (info
->use_short_slot
)
6205 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
6208 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
6210 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
6211 arvif
->vdev_id
, slottime
);
6213 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
6214 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6217 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
6218 arvif
->vdev_id
, ret
);
6221 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
6222 if (info
->use_short_preamble
)
6223 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
6225 preamble
= WMI_VDEV_PREAMBLE_LONG
;
6227 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6228 "mac vdev %d preamble %dn",
6229 arvif
->vdev_id
, preamble
);
6231 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
6232 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6235 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
6236 arvif
->vdev_id
, ret
);
6239 if (changed
& BSS_CHANGED_ASSOC
) {
6240 if (vif
->cfg
.assoc
) {
6241 /* Workaround: Make sure monitor vdev is not running
6242 * when associating to prevent some firmware revisions
6243 * (e.g. 10.1 and 10.2) from crashing.
6245 if (ar
->monitor_started
)
6246 ath10k_monitor_stop(ar
);
6247 ath10k_bss_assoc(hw
, vif
, info
);
6248 ath10k_monitor_recalc(ar
);
6250 ath10k_bss_disassoc(hw
, vif
);
6254 if (changed
& BSS_CHANGED_TXPOWER
) {
6255 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
6256 arvif
->vdev_id
, info
->txpower
);
6258 arvif
->txpower
= info
->txpower
;
6259 ret
= ath10k_mac_txpower_recalc(ar
);
6261 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
6264 if (changed
& BSS_CHANGED_PS
) {
6265 arvif
->ps
= vif
->cfg
.ps
;
6267 ret
= ath10k_config_ps(ar
);
6269 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
6270 arvif
->vdev_id
, ret
);
6273 if (changed
& BSS_CHANGED_MCAST_RATE
&&
6274 !ath10k_mac_vif_chan(arvif
->vif
, &def
)) {
6275 band
= def
.chan
->band
;
6276 mcast_rate
= vif
->bss_conf
.mcast_rate
[band
];
6278 rateidx
= mcast_rate
- 1;
6280 rateidx
= ffs(vif
->bss_conf
.basic_rates
) - 1;
6282 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
6283 rateidx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
6285 bitrate
= ath10k_wmi_legacy_rates
[rateidx
].bitrate
;
6286 hw_value
= ath10k_wmi_legacy_rates
[rateidx
].hw_value
;
6287 if (ath10k_mac_bitrate_is_cck(bitrate
))
6288 preamble
= WMI_RATE_PREAMBLE_CCK
;
6290 preamble
= WMI_RATE_PREAMBLE_OFDM
;
6292 rate
= ATH10K_HW_RATECODE(hw_value
, 0, preamble
);
6294 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6295 "mac vdev %d mcast_rate %x\n",
6296 arvif
->vdev_id
, rate
);
6298 vdev_param
= ar
->wmi
.vdev_param
->mcast_data_rate
;
6299 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
6303 "failed to set mcast rate on vdev %i: %d\n",
6304 arvif
->vdev_id
, ret
);
6306 vdev_param
= ar
->wmi
.vdev_param
->bcast_data_rate
;
6307 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
6311 "failed to set bcast rate on vdev %i: %d\n",
6312 arvif
->vdev_id
, ret
);
6315 if (changed
& BSS_CHANGED_BASIC_RATES
&&
6316 !ath10k_mac_vif_chan(arvif
->vif
, &def
))
6317 ath10k_recalculate_mgmt_rate(ar
, vif
, &def
);
6319 mutex_unlock(&ar
->conf_mutex
);
6322 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw
*hw
, s16 value
)
6324 struct ath10k
*ar
= hw
->priv
;
6326 /* This function should never be called if setting the coverage class
6327 * is not supported on this hardware.
6329 if (!ar
->hw_params
.hw_ops
->set_coverage_class
) {
6333 ar
->hw_params
.hw_ops
->set_coverage_class(ar
, value
);
6336 struct ath10k_mac_tdls_iter_data
{
6337 u32 num_tdls_stations
;
6338 struct ieee80211_vif
*curr_vif
;
6341 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
6342 struct ieee80211_sta
*sta
)
6344 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
6345 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6346 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
6348 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
6349 iter_data
->num_tdls_stations
++;
6352 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
6353 struct ieee80211_vif
*vif
)
6355 struct ath10k_mac_tdls_iter_data data
= {};
6357 data
.curr_vif
= vif
;
6359 ieee80211_iterate_stations_atomic(hw
,
6360 ath10k_mac_tdls_vif_stations_count_iter
,
6362 return data
.num_tdls_stations
;
6365 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
6366 struct ieee80211_vif
*vif
,
6367 struct ieee80211_scan_request
*hw_req
)
6369 struct ath10k
*ar
= hw
->priv
;
6370 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6371 struct cfg80211_scan_request
*req
= &hw_req
->req
;
6372 struct wmi_start_scan_arg
*arg
= NULL
;
6377 mutex_lock(&ar
->conf_mutex
);
6379 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
6384 spin_lock_bh(&ar
->data_lock
);
6385 switch (ar
->scan
.state
) {
6386 case ATH10K_SCAN_IDLE
:
6387 reinit_completion(&ar
->scan
.started
);
6388 reinit_completion(&ar
->scan
.completed
);
6389 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
6390 ar
->scan
.is_roc
= false;
6391 ar
->scan
.vdev_id
= arvif
->vdev_id
;
6394 case ATH10K_SCAN_STARTING
:
6395 case ATH10K_SCAN_RUNNING
:
6396 case ATH10K_SCAN_ABORTING
:
6400 spin_unlock_bh(&ar
->data_lock
);
6405 arg
= kzalloc(sizeof(*arg
), GFP_KERNEL
);
6411 ath10k_wmi_start_scan_init(ar
, arg
);
6412 arg
->vdev_id
= arvif
->vdev_id
;
6413 arg
->scan_id
= ATH10K_SCAN_ID
;
6416 arg
->ie_len
= req
->ie_len
;
6417 memcpy(arg
->ie
, req
->ie
, arg
->ie_len
);
6421 arg
->n_ssids
= req
->n_ssids
;
6422 for (i
= 0; i
< arg
->n_ssids
; i
++) {
6423 arg
->ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
6424 arg
->ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
6427 arg
->scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
6430 if (req
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6431 arg
->scan_ctrl_flags
|= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ
;
6432 ether_addr_copy(arg
->mac_addr
.addr
, req
->mac_addr
);
6433 ether_addr_copy(arg
->mac_mask
.addr
, req
->mac_addr_mask
);
6436 if (req
->n_channels
) {
6437 arg
->n_channels
= req
->n_channels
;
6438 for (i
= 0; i
< arg
->n_channels
; i
++)
6439 arg
->channels
[i
] = req
->channels
[i
]->center_freq
;
6442 /* if duration is set, default dwell times will be overwritten */
6443 if (req
->duration
) {
6444 arg
->dwell_time_active
= req
->duration
;
6445 arg
->dwell_time_passive
= req
->duration
;
6446 arg
->burst_duration_ms
= req
->duration
;
6448 scan_timeout
= min_t(u32
, arg
->max_rest_time
*
6449 (arg
->n_channels
- 1) + (req
->duration
+
6450 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD
) *
6451 arg
->n_channels
, arg
->max_scan_time
);
6453 scan_timeout
= arg
->max_scan_time
;
6456 /* Add a 200ms margin to account for event/command processing */
6457 scan_timeout
+= 200;
6459 ret
= ath10k_start_scan(ar
, arg
);
6461 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
6462 spin_lock_bh(&ar
->data_lock
);
6463 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
6464 spin_unlock_bh(&ar
->data_lock
);
6467 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
6468 msecs_to_jiffies(scan_timeout
));
6473 mutex_unlock(&ar
->conf_mutex
);
6477 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
6478 struct ieee80211_vif
*vif
)
6480 struct ath10k
*ar
= hw
->priv
;
6482 mutex_lock(&ar
->conf_mutex
);
6483 ath10k_scan_abort(ar
);
6484 mutex_unlock(&ar
->conf_mutex
);
6486 cancel_delayed_work_sync(&ar
->scan
.timeout
);
6489 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
6490 struct ath10k_vif
*arvif
,
6491 enum set_key_cmd cmd
,
6492 struct ieee80211_key_conf
*key
)
6494 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
6497 /* 10.1 firmware branch requires default key index to be set to group
6498 * key index after installing it. Otherwise FW/HW Txes corrupted
6499 * frames with multi-vif APs. This is not required for main firmware
6500 * branch (e.g. 636).
6502 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6504 * FIXME: It remains unknown if this is required for multi-vif STA
6505 * interfaces on 10.1.
6508 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
6509 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
6512 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
6515 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
6518 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6524 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6527 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
6528 arvif
->vdev_id
, ret
);
6531 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6532 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
6533 struct ieee80211_key_conf
*key
)
6535 struct ath10k
*ar
= hw
->priv
;
6536 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6537 struct ath10k_sta
*arsta
;
6538 struct ath10k_peer
*peer
;
6539 const u8
*peer_addr
;
6540 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
6541 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
6547 /* this one needs to be done in software */
6548 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
6549 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
6550 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
||
6551 key
->cipher
== WLAN_CIPHER_SUITE_BIP_CMAC_256
)
6554 if (arvif
->nohwcrypt
)
6557 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
6560 mutex_lock(&ar
->conf_mutex
);
6563 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6564 peer_addr
= sta
->addr
;
6565 spin_lock_bh(&ar
->data_lock
);
6566 arsta
->ucast_cipher
= key
->cipher
;
6567 spin_unlock_bh(&ar
->data_lock
);
6568 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
6569 peer_addr
= vif
->bss_conf
.bssid
;
6571 peer_addr
= vif
->addr
;
6574 key
->hw_key_idx
= key
->keyidx
;
6578 arvif
->wep_keys
[key
->keyidx
] = key
;
6580 arvif
->wep_keys
[key
->keyidx
] = NULL
;
6583 /* the peer should not disappear in mid-way (unless FW goes awry) since
6584 * we already hold conf_mutex. we just make sure its there now.
6586 spin_lock_bh(&ar
->data_lock
);
6587 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6588 spin_unlock_bh(&ar
->data_lock
);
6591 if (cmd
== SET_KEY
) {
6592 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
6597 /* if the peer doesn't exist there is no key to disable anymore */
6602 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6603 flags
|= WMI_KEY_PAIRWISE
;
6605 flags
|= WMI_KEY_GROUP
;
6608 if (cmd
== DISABLE_KEY
)
6609 ath10k_clear_vdev_key(arvif
, key
);
6611 /* When WEP keys are uploaded it's possible that there are
6612 * stations associated already (e.g. when merging) without any
6613 * keys. Static WEP needs an explicit per-peer key upload.
6615 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
6617 ath10k_mac_vif_update_wep_key(arvif
, key
);
6619 /* 802.1x never sets the def_wep_key_idx so each set_key()
6620 * call changes default tx key.
6622 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6623 * after first set_key().
6625 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
6626 flags
|= WMI_KEY_TX_USAGE
;
6629 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
6632 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
6633 arvif
->vdev_id
, peer_addr
, ret
);
6637 /* mac80211 sets static WEP keys as groupwise while firmware requires
6638 * them to be installed twice as both pairwise and groupwise.
6640 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
6642 flags2
&= ~WMI_KEY_GROUP
;
6643 flags2
|= WMI_KEY_PAIRWISE
;
6645 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
6648 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6649 arvif
->vdev_id
, peer_addr
, ret
);
6650 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
6654 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6655 arvif
->vdev_id
, peer_addr
, ret2
);
6661 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
6663 spin_lock_bh(&ar
->data_lock
);
6664 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6665 if (peer
&& cmd
== SET_KEY
)
6666 peer
->keys
[key
->keyidx
] = key
;
6667 else if (peer
&& cmd
== DISABLE_KEY
)
6668 peer
->keys
[key
->keyidx
] = NULL
;
6669 else if (peer
== NULL
)
6670 /* impossible unless FW goes crazy */
6671 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
6672 spin_unlock_bh(&ar
->data_lock
);
6674 if (sta
&& sta
->tdls
)
6675 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6676 ar
->wmi
.peer_param
->authorize
, 1);
6677 else if (sta
&& cmd
== SET_KEY
&& (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
6678 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, peer_addr
,
6679 ar
->wmi
.peer_param
->authorize
, 1);
6682 mutex_unlock(&ar
->conf_mutex
);
6686 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
6687 struct ieee80211_vif
*vif
,
6690 struct ath10k
*ar
= hw
->priv
;
6691 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6694 mutex_lock(&arvif
->ar
->conf_mutex
);
6696 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
6699 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
6700 arvif
->vdev_id
, keyidx
);
6702 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
6704 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
6708 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
6714 arvif
->def_wep_key_idx
= keyidx
;
6717 mutex_unlock(&arvif
->ar
->conf_mutex
);
6720 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
6723 struct ath10k_vif
*arvif
;
6724 struct ath10k_sta
*arsta
;
6725 struct ieee80211_sta
*sta
;
6726 struct cfg80211_chan_def def
;
6727 enum nl80211_band band
;
6728 const u8
*ht_mcs_mask
;
6729 const u16
*vht_mcs_mask
;
6730 u32 changed
, bw
, nss
, smps
;
6733 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
6734 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
6735 arvif
= arsta
->arvif
;
6738 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
6741 band
= def
.chan
->band
;
6742 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
6743 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
6745 spin_lock_bh(&ar
->data_lock
);
6747 changed
= arsta
->changed
;
6754 spin_unlock_bh(&ar
->data_lock
);
6756 mutex_lock(&ar
->conf_mutex
);
6758 nss
= max_t(u32
, 1, nss
);
6759 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6760 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6762 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6763 enum wmi_phy_mode mode
;
6765 mode
= chan_to_phymode(&def
);
6766 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM peer bw %d phymode %d\n",
6767 sta
->addr
, bw
, mode
);
6769 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6770 ar
->wmi
.peer_param
->phymode
, mode
);
6772 ath10k_warn(ar
, "failed to update STA %pM peer phymode %d: %d\n",
6773 sta
->addr
, mode
, err
);
6777 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6778 ar
->wmi
.peer_param
->chan_width
, bw
);
6780 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
6781 sta
->addr
, bw
, err
);
6784 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
6785 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM nss %d\n",
6788 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6789 ar
->wmi
.peer_param
->nss
, nss
);
6791 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
6792 sta
->addr
, nss
, err
);
6795 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6796 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM smps %d\n",
6799 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6800 ar
->wmi
.peer_param
->smps_state
, smps
);
6802 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
6803 sta
->addr
, smps
, err
);
6806 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
6807 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM supp rates\n",
6810 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
6812 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
6817 mutex_unlock(&ar
->conf_mutex
);
6820 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
6821 struct ieee80211_sta
*sta
)
6823 struct ath10k
*ar
= arvif
->ar
;
6825 lockdep_assert_held(&ar
->conf_mutex
);
6827 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6830 if (ar
->num_stations
>= ar
->max_num_stations
)
6838 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
6839 struct ieee80211_sta
*sta
)
6841 struct ath10k
*ar
= arvif
->ar
;
6843 lockdep_assert_held(&ar
->conf_mutex
);
6845 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6851 static int ath10k_sta_set_txpwr(struct ieee80211_hw
*hw
,
6852 struct ieee80211_vif
*vif
,
6853 struct ieee80211_sta
*sta
)
6855 struct ath10k
*ar
= hw
->priv
;
6856 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6860 if (sta
->deflink
.txpwr
.type
== NL80211_TX_POWER_AUTOMATIC
) {
6863 txpwr
= sta
->deflink
.txpwr
.power
;
6868 if (txpwr
> ATH10K_TX_POWER_MAX_VAL
|| txpwr
< ATH10K_TX_POWER_MIN_VAL
)
6871 mutex_lock(&ar
->conf_mutex
);
6873 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6874 ar
->wmi
.peer_param
->use_fixed_power
, txpwr
);
6876 ath10k_warn(ar
, "failed to set tx power for station ret: %d\n",
6882 mutex_unlock(&ar
->conf_mutex
);
6886 struct ath10k_mac_iter_tid_conf_data
{
6887 struct ieee80211_vif
*curr_vif
;
6893 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
6894 enum nl80211_band band
,
6895 const struct cfg80211_bitrate_mask
*mask
,
6901 num_rates
+= hweight32(mask
->control
[band
].legacy
);
6903 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
6904 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
6907 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6908 tmp
= hweight16(mask
->control
[band
].vht_mcs
[i
]);
6910 *vht_num_rates
+= tmp
;
6913 return num_rates
== 1;
6917 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
6918 enum nl80211_band band
,
6919 const struct cfg80211_bitrate_mask
*mask
,
6920 u8
*rate
, u8
*nss
, bool vht_only
)
6931 if (hweight32(mask
->control
[band
].legacy
) == 1) {
6932 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
6934 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
6935 rate_idx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
6937 hw_rate
= ath10k_wmi_legacy_rates
[rate_idx
].hw_value
;
6938 bitrate
= ath10k_wmi_legacy_rates
[rate_idx
].bitrate
;
6940 if (ath10k_mac_bitrate_is_cck(bitrate
))
6941 preamble
= WMI_RATE_PREAMBLE_CCK
;
6943 preamble
= WMI_RATE_PREAMBLE_OFDM
;
6946 *rate
= preamble
<< 6 |
6953 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
6954 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
6956 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
6958 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
6965 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6966 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
6968 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
6970 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
6979 static int ath10k_mac_validate_rate_mask(struct ath10k
*ar
,
6980 struct ieee80211_sta
*sta
,
6981 u32 rate_ctrl_flag
, u8 nss
)
6983 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->deflink
.ht_cap
;
6984 struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->deflink
.vht_cap
;
6986 if (nss
> sta
->deflink
.rx_nss
) {
6987 ath10k_warn(ar
, "Invalid nss field, configured %u limit %u\n",
6988 nss
, sta
->deflink
.rx_nss
);
6992 if (ATH10K_HW_PREAMBLE(rate_ctrl_flag
) == WMI_RATE_PREAMBLE_VHT
) {
6993 if (!vht_cap
->vht_supported
) {
6994 ath10k_warn(ar
, "Invalid VHT rate for sta %pM\n",
6998 } else if (ATH10K_HW_PREAMBLE(rate_ctrl_flag
) == WMI_RATE_PREAMBLE_HT
) {
6999 if (!ht_cap
->ht_supported
|| vht_cap
->vht_supported
) {
7000 ath10k_warn(ar
, "Invalid HT rate for sta %pM\n",
7005 if (ht_cap
->ht_supported
|| vht_cap
->vht_supported
)
7013 ath10k_mac_tid_bitrate_config(struct ath10k
*ar
,
7014 struct ieee80211_vif
*vif
,
7015 struct ieee80211_sta
*sta
,
7016 u32
*rate_ctrl_flag
, u8
*rate_ctrl
,
7017 enum nl80211_tx_rate_setting txrate_type
,
7018 const struct cfg80211_bitrate_mask
*mask
)
7020 struct cfg80211_chan_def def
;
7021 enum nl80211_band band
;
7023 int vht_num_rates
, ret
;
7025 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
7028 if (txrate_type
== NL80211_TX_RATE_AUTOMATIC
) {
7029 *rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7030 *rate_ctrl_flag
= 0;
7034 band
= def
.chan
->band
;
7036 if (!ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
7041 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
7042 &rate
, &nss
, false);
7044 ath10k_warn(ar
, "failed to get single rate: %d\n",
7049 *rate_ctrl_flag
= rate
;
7051 if (sta
&& ath10k_mac_validate_rate_mask(ar
, sta
, *rate_ctrl_flag
, nss
))
7054 if (txrate_type
== NL80211_TX_RATE_FIXED
)
7055 *rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_FIXED_RATE
;
7056 else if (txrate_type
== NL80211_TX_RATE_LIMITED
&&
7057 (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT
,
7059 *rate_ctrl
= WMI_PEER_TID_CONFIG_RATE_UPPER_CAP
;
7066 static int ath10k_mac_set_tid_config(struct ath10k
*ar
, struct ieee80211_sta
*sta
,
7067 struct ieee80211_vif
*vif
, u32 changed
,
7068 struct wmi_per_peer_per_tid_cfg_arg
*arg
)
7070 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7071 struct ath10k_sta
*arsta
;
7078 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7080 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7081 if ((arsta
->retry_long
[arg
->tid
] > 0 ||
7082 arsta
->rate_code
[arg
->tid
] > 0 ||
7083 arsta
->ampdu
[arg
->tid
] ==
7084 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
) &&
7085 arg
->ack_policy
== WMI_PEER_TID_CONFIG_NOACK
) {
7086 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
7087 arg
->ack_policy
= 0;
7088 arg
->aggr_control
= 0;
7090 arg
->rcode_flags
= 0;
7094 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7095 if (arsta
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
||
7096 arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
7097 arg
->aggr_control
= 0;
7098 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
7102 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7103 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7104 if (arsta
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
||
7105 arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
7107 arg
->rcode_flags
= 0;
7111 ether_addr_copy(arg
->peer_macaddr
.addr
, sta
->addr
);
7113 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, arg
);
7117 /* Store the configured parameters in success case */
7118 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7119 arsta
->noack
[arg
->tid
] = arg
->ack_policy
;
7120 arg
->ack_policy
= 0;
7121 arg
->aggr_control
= 0;
7123 arg
->rcode_flags
= 0;
7126 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7127 arsta
->retry_long
[arg
->tid
] = arg
->retry_count
;
7128 arg
->retry_count
= 0;
7131 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7132 arsta
->ampdu
[arg
->tid
] = arg
->aggr_control
;
7133 arg
->aggr_control
= 0;
7136 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7137 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7138 arsta
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
7140 arg
->rcode_flags
= 0;
7143 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7144 arsta
->rtscts
[arg
->tid
] = arg
->rtscts_ctrl
;
7145 arg
->ext_tid_cfg_bitmap
= 0;
7148 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7149 if ((arvif
->retry_long
[arg
->tid
] ||
7150 arvif
->rate_code
[arg
->tid
] ||
7151 arvif
->ampdu
[arg
->tid
] ==
7152 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
) &&
7153 arg
->ack_policy
== WMI_PEER_TID_CONFIG_NOACK
) {
7154 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
7156 arvif
->noack
[arg
->tid
] = arg
->ack_policy
;
7157 arvif
->ampdu
[arg
->tid
] = arg
->aggr_control
;
7158 arvif
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
7162 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7163 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
)
7164 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
7166 arvif
->retry_long
[arg
->tid
] = arg
->retry_count
;
7169 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7170 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
)
7171 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
);
7173 arvif
->ampdu
[arg
->tid
] = arg
->aggr_control
;
7176 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7177 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7178 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
7179 changed
&= ~(BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7180 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
));
7182 arvif
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
7183 arvif
->rate_code
[arg
->tid
] = arg
->rcode_flags
;
7187 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7188 arvif
->rtscts
[arg
->tid
] = arg
->rtscts_ctrl
;
7189 arg
->ext_tid_cfg_bitmap
= 0;
7193 arvif
->tid_conf_changed
[arg
->tid
] |= changed
;
7200 ath10k_mac_parse_tid_config(struct ath10k
*ar
,
7201 struct ieee80211_sta
*sta
,
7202 struct ieee80211_vif
*vif
,
7203 struct cfg80211_tid_cfg
*tid_conf
,
7204 struct wmi_per_peer_per_tid_cfg_arg
*arg
)
7206 u32 changed
= tid_conf
->mask
;
7212 while (i
< ATH10K_TID_MAX
) {
7213 if (!(tid_conf
->tids
& BIT(i
))) {
7220 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7221 if (tid_conf
->noack
== NL80211_TID_CONFIG_ENABLE
) {
7222 arg
->ack_policy
= WMI_PEER_TID_CONFIG_NOACK
;
7224 WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE
;
7226 WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
7229 WMI_PEER_TID_CONFIG_ACK
;
7231 WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7233 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7237 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
))
7238 arg
->retry_count
= tid_conf
->retry_long
;
7240 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7241 if (tid_conf
->noack
== NL80211_TID_CONFIG_ENABLE
)
7242 arg
->aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7244 arg
->aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
7247 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7248 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7249 ret
= ath10k_mac_tid_bitrate_config(ar
, vif
, sta
,
7252 tid_conf
->txrate_type
,
7253 &tid_conf
->txrate_mask
);
7255 ath10k_warn(ar
, "failed to configure bitrate mask %d\n",
7257 arg
->rcode_flags
= 0;
7262 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7263 if (tid_conf
->rtscts
)
7264 arg
->rtscts_ctrl
= tid_conf
->rtscts
;
7266 arg
->ext_tid_cfg_bitmap
= WMI_EXT_TID_RTS_CTS_CONFIG
;
7269 ret
= ath10k_mac_set_tid_config(ar
, sta
, vif
, changed
, arg
);
7278 static int ath10k_mac_reset_tid_config(struct ath10k
*ar
,
7279 struct ieee80211_sta
*sta
,
7280 struct ath10k_vif
*arvif
,
7283 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7284 struct wmi_per_peer_per_tid_cfg_arg arg
;
7287 arg
.vdev_id
= arvif
->vdev_id
;
7288 while (i
< ATH10K_TID_MAX
) {
7289 if (!(tids
& BIT(i
))) {
7295 arg
.ack_policy
= WMI_PEER_TID_CONFIG_ACK
;
7296 arg
.retry_count
= ATH10K_MAX_RETRY_COUNT
;
7297 arg
.rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7298 arg
.aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7299 arg
.rtscts_ctrl
= WMI_TID_CONFIG_RTSCTS_CONTROL_ENABLE
;
7300 arg
.ext_tid_cfg_bitmap
= WMI_EXT_TID_RTS_CTS_CONFIG
;
7302 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
7304 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
7308 if (!arvif
->tids_rst
) {
7309 arsta
->retry_long
[i
] = -1;
7310 arsta
->noack
[i
] = -1;
7311 arsta
->ampdu
[i
] = -1;
7312 arsta
->rate_code
[i
] = -1;
7313 arsta
->rate_ctrl
[i
] = 0;
7314 arsta
->rtscts
[i
] = -1;
7316 arvif
->retry_long
[i
] = 0;
7317 arvif
->noack
[i
] = 0;
7318 arvif
->ampdu
[i
] = 0;
7319 arvif
->rate_code
[i
] = 0;
7320 arvif
->rate_ctrl
[i
] = 0;
7321 arvif
->rtscts
[i
] = 0;
7330 static void ath10k_sta_tid_cfg_wk(struct work_struct
*wk
)
7332 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
7333 struct ieee80211_sta
*sta
;
7334 struct ath10k_sta
*arsta
;
7335 struct ath10k_vif
*arvif
;
7342 arsta
= container_of(wk
, struct ath10k_sta
, tid_config_wk
);
7343 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
7344 arvif
= arsta
->arvif
;
7347 mutex_lock(&ar
->conf_mutex
);
7349 if (arvif
->tids_rst
) {
7350 ret
= ath10k_mac_reset_tid_config(ar
, sta
, arvif
,
7355 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
7357 for (i
= 0; i
< ATH10K_TID_MAX
; i
++) {
7358 config_apply
= false;
7359 changed
= arvif
->tid_conf_changed
[i
];
7361 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7362 if (arsta
->noack
[i
] != -1) {
7365 config_apply
= true;
7366 arg
.ack_policy
= arvif
->noack
[i
];
7367 arg
.aggr_control
= arvif
->ampdu
[i
];
7368 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
7372 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7373 if (arsta
->retry_long
[i
] != -1 ||
7374 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7375 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7376 arg
.retry_count
= 0;
7378 arg
.retry_count
= arvif
->retry_long
[i
];
7379 config_apply
= true;
7383 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7384 if (arsta
->ampdu
[i
] != -1 ||
7385 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7386 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7387 arg
.aggr_control
= 0;
7389 arg
.aggr_control
= arvif
->ampdu
[i
];
7390 config_apply
= true;
7394 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7395 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7396 nss
= ATH10K_HW_NSS(arvif
->rate_code
[i
]);
7397 ret
= ath10k_mac_validate_rate_mask(ar
, sta
,
7398 arvif
->rate_code
[i
],
7401 arvif
->rate_ctrl
[i
] > WMI_TID_CONFIG_RATE_CONTROL_AUTO
) {
7403 arg
.rcode_flags
= 0;
7406 if (arsta
->rate_ctrl
[i
] >
7407 WMI_TID_CONFIG_RATE_CONTROL_AUTO
||
7408 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7409 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7411 arg
.rcode_flags
= 0;
7413 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
7414 arg
.rcode_flags
= arvif
->rate_code
[i
];
7415 config_apply
= true;
7419 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7420 if (arsta
->rtscts
[i
]) {
7421 arg
.rtscts_ctrl
= 0;
7422 arg
.ext_tid_cfg_bitmap
= 0;
7424 arg
.rtscts_ctrl
= arvif
->rtscts
[i
] - 1;
7425 arg
.ext_tid_cfg_bitmap
=
7426 WMI_EXT_TID_RTS_CTS_CONFIG
;
7427 config_apply
= true;
7434 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
7436 ath10k_warn(ar
, "failed to set per tid config for sta %pM: %d\n",
7441 arg
.retry_count
= 0;
7442 arg
.aggr_control
= 0;
7444 arg
.rcode_flags
= 0;
7448 mutex_unlock(&ar
->conf_mutex
);
7451 static void ath10k_mac_vif_stations_tid_conf(void *data
,
7452 struct ieee80211_sta
*sta
)
7454 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7455 struct ath10k_mac_iter_tid_conf_data
*iter_data
= data
;
7456 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
7458 if (sta_vif
!= iter_data
->curr_vif
|| !sta
->wme
)
7461 ieee80211_queue_work(iter_data
->ar
->hw
, &arsta
->tid_config_wk
);
7464 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
7465 struct ieee80211_vif
*vif
,
7466 struct ieee80211_sta
*sta
,
7467 enum ieee80211_sta_state old_state
,
7468 enum ieee80211_sta_state new_state
)
7470 struct ath10k
*ar
= hw
->priv
;
7471 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7472 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7473 struct ath10k_peer
*peer
;
7477 if (old_state
== IEEE80211_STA_NOTEXIST
&&
7478 new_state
== IEEE80211_STA_NONE
) {
7479 memset(arsta
, 0, sizeof(*arsta
));
7480 arsta
->arvif
= arvif
;
7481 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
7482 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
7483 INIT_WORK(&arsta
->tid_config_wk
, ath10k_sta_tid_cfg_wk
);
7485 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
7486 ath10k_mac_txq_init(sta
->txq
[i
]);
7489 /* cancel must be done outside the mutex to avoid deadlock */
7490 if ((old_state
== IEEE80211_STA_NONE
&&
7491 new_state
== IEEE80211_STA_NOTEXIST
)) {
7492 cancel_work_sync(&arsta
->update_wk
);
7493 cancel_work_sync(&arsta
->tid_config_wk
);
7496 mutex_lock(&ar
->conf_mutex
);
7498 if (old_state
== IEEE80211_STA_NOTEXIST
&&
7499 new_state
== IEEE80211_STA_NONE
) {
7501 * New station addition.
7503 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
7504 u32 num_tdls_stations
;
7506 ath10k_dbg(ar
, ATH10K_DBG_STA
,
7507 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
7508 arvif
->vdev_id
, sta
->addr
,
7509 ar
->num_stations
+ 1, ar
->max_num_stations
,
7510 ar
->num_peers
+ 1, ar
->max_num_peers
);
7512 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
7515 if (num_tdls_stations
>= ar
->max_num_tdls_vdevs
) {
7516 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
7518 ar
->max_num_tdls_vdevs
);
7522 peer_type
= WMI_PEER_TYPE_TDLS
;
7525 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
7527 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
7528 ar
->max_num_stations
);
7532 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
7533 arsta
->tx_stats
= kzalloc(sizeof(*arsta
->tx_stats
),
7535 if (!arsta
->tx_stats
) {
7536 ath10k_mac_dec_num_stations(arvif
, sta
);
7542 ret
= ath10k_peer_create(ar
, vif
, sta
, arvif
->vdev_id
,
7543 sta
->addr
, peer_type
);
7545 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
7546 sta
->addr
, arvif
->vdev_id
, ret
);
7547 ath10k_mac_dec_num_stations(arvif
, sta
);
7548 kfree(arsta
->tx_stats
);
7552 spin_lock_bh(&ar
->data_lock
);
7554 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
7556 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
7557 vif
->addr
, arvif
->vdev_id
);
7558 spin_unlock_bh(&ar
->data_lock
);
7559 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7560 ath10k_mac_dec_num_stations(arvif
, sta
);
7561 kfree(arsta
->tx_stats
);
7566 arsta
->peer_id
= find_first_bit(peer
->peer_ids
,
7567 ATH10K_MAX_NUM_PEER_IDS
);
7569 spin_unlock_bh(&ar
->data_lock
);
7574 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7575 WMI_TDLS_ENABLE_ACTIVE
);
7577 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
7578 arvif
->vdev_id
, ret
);
7579 ath10k_peer_delete(ar
, arvif
->vdev_id
,
7581 ath10k_mac_dec_num_stations(arvif
, sta
);
7582 kfree(arsta
->tx_stats
);
7586 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
7587 WMI_TDLS_PEER_STATE_PEERING
);
7590 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
7591 sta
->addr
, arvif
->vdev_id
, ret
);
7592 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7593 ath10k_mac_dec_num_stations(arvif
, sta
);
7594 kfree(arsta
->tx_stats
);
7596 if (num_tdls_stations
!= 0)
7598 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7601 } else if ((old_state
== IEEE80211_STA_NONE
&&
7602 new_state
== IEEE80211_STA_NOTEXIST
)) {
7604 * Existing station deletion.
7606 ath10k_dbg(ar
, ATH10K_DBG_STA
,
7607 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
7608 arvif
->vdev_id
, sta
->addr
, sta
);
7611 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
,
7613 WMI_TDLS_PEER_STATE_TEARDOWN
);
7615 ath10k_warn(ar
, "failed to update tdls peer state for %pM state %d: %i\n",
7617 WMI_TDLS_PEER_STATE_TEARDOWN
, ret
);
7620 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7622 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
7623 sta
->addr
, arvif
->vdev_id
, ret
);
7625 ath10k_mac_dec_num_stations(arvif
, sta
);
7627 spin_lock_bh(&ar
->data_lock
);
7628 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
7629 peer
= ar
->peer_map
[i
];
7633 if (peer
->sta
== sta
) {
7634 ath10k_warn(ar
, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
7635 sta
->addr
, peer
, i
, arvif
->vdev_id
);
7638 /* Clean up the peer object as well since we
7639 * must have failed to do this above.
7641 ath10k_peer_map_cleanup(ar
, peer
);
7644 spin_unlock_bh(&ar
->data_lock
);
7646 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
7647 kfree(arsta
->tx_stats
);
7648 arsta
->tx_stats
= NULL
;
7651 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
7652 ath10k_mac_txq_unref(ar
, sta
->txq
[i
]);
7657 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
7660 /* This was the last tdls peer in current vif */
7661 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7664 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
7665 arvif
->vdev_id
, ret
);
7667 } else if (old_state
== IEEE80211_STA_AUTH
&&
7668 new_state
== IEEE80211_STA_ASSOC
&&
7669 (vif
->type
== NL80211_IFTYPE_AP
||
7670 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
7671 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
7675 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac sta %pM associated\n",
7678 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
7680 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
7681 sta
->addr
, arvif
->vdev_id
, ret
);
7682 } else if (old_state
== IEEE80211_STA_ASSOC
&&
7683 new_state
== IEEE80211_STA_AUTHORIZED
&&
7686 * Tdls station authorized.
7688 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac tdls sta %pM authorized\n",
7691 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
7693 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
7694 sta
->addr
, arvif
->vdev_id
, ret
);
7698 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
7699 WMI_TDLS_PEER_STATE_CONNECTED
);
7701 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
7702 sta
->addr
, arvif
->vdev_id
, ret
);
7703 } else if (old_state
== IEEE80211_STA_ASSOC
&&
7704 new_state
== IEEE80211_STA_AUTH
&&
7705 (vif
->type
== NL80211_IFTYPE_AP
||
7706 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
7707 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
7711 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac sta %pM disassociated\n",
7714 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
7716 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
7717 sta
->addr
, arvif
->vdev_id
, ret
);
7720 mutex_unlock(&ar
->conf_mutex
);
7724 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
7725 u16 ac
, bool enable
)
7727 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7728 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
7729 u32 prio
= 0, acc
= 0;
7733 lockdep_assert_held(&ar
->conf_mutex
);
7735 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
7739 case IEEE80211_AC_VO
:
7740 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
7741 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
7745 case IEEE80211_AC_VI
:
7746 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
7747 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
7751 case IEEE80211_AC_BE
:
7752 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
7753 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
7757 case IEEE80211_AC_BK
:
7758 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
7759 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
7766 arvif
->u
.sta
.uapsd
|= value
;
7768 arvif
->u
.sta
.uapsd
&= ~value
;
7770 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
7771 WMI_STA_PS_PARAM_UAPSD
,
7772 arvif
->u
.sta
.uapsd
);
7774 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
7778 if (arvif
->u
.sta
.uapsd
)
7779 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
7781 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
7783 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
7784 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
7787 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
7789 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
7791 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
7792 arvif
->vdev_id
, ret
);
7796 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
7798 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
7799 arvif
->vdev_id
, ret
);
7803 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
7804 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
7805 /* Only userspace can make an educated decision when to send
7806 * trigger frame. The following effectively disables u-UAPSD
7807 * autotrigger in firmware (which is enabled by default
7808 * provided the autotrigger service is available).
7812 arg
.user_priority
= prio
;
7813 arg
.service_interval
= 0;
7814 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
7815 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
7817 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
7818 arvif
->bssid
, &arg
, 1);
7820 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
7830 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
7831 struct ieee80211_vif
*vif
,
7832 unsigned int link_id
, u16 ac
,
7833 const struct ieee80211_tx_queue_params
*params
)
7835 struct ath10k
*ar
= hw
->priv
;
7836 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7837 struct wmi_wmm_params_arg
*p
= NULL
;
7840 mutex_lock(&ar
->conf_mutex
);
7843 case IEEE80211_AC_VO
:
7844 p
= &arvif
->wmm_params
.ac_vo
;
7846 case IEEE80211_AC_VI
:
7847 p
= &arvif
->wmm_params
.ac_vi
;
7849 case IEEE80211_AC_BE
:
7850 p
= &arvif
->wmm_params
.ac_be
;
7852 case IEEE80211_AC_BK
:
7853 p
= &arvif
->wmm_params
.ac_bk
;
7862 p
->cwmin
= params
->cw_min
;
7863 p
->cwmax
= params
->cw_max
;
7864 p
->aifs
= params
->aifs
;
7867 * The channel time duration programmed in the HW is in absolute
7868 * microseconds, while mac80211 gives the txop in units of
7871 p
->txop
= params
->txop
* 32;
7873 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
7874 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
7875 &arvif
->wmm_params
);
7877 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
7878 arvif
->vdev_id
, ret
);
7882 /* This won't work well with multi-interface cases but it's
7883 * better than nothing.
7885 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
7887 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
7892 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
7894 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
7897 mutex_unlock(&ar
->conf_mutex
);
7901 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
7902 struct ieee80211_vif
*vif
,
7903 struct ieee80211_channel
*chan
,
7905 enum ieee80211_roc_type type
)
7907 struct ath10k
*ar
= hw
->priv
;
7908 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7909 struct wmi_start_scan_arg
*arg
= NULL
;
7913 mutex_lock(&ar
->conf_mutex
);
7915 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
7920 spin_lock_bh(&ar
->data_lock
);
7921 switch (ar
->scan
.state
) {
7922 case ATH10K_SCAN_IDLE
:
7923 reinit_completion(&ar
->scan
.started
);
7924 reinit_completion(&ar
->scan
.completed
);
7925 reinit_completion(&ar
->scan
.on_channel
);
7926 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
7927 ar
->scan
.is_roc
= true;
7928 ar
->scan
.vdev_id
= arvif
->vdev_id
;
7929 ar
->scan
.roc_freq
= chan
->center_freq
;
7930 ar
->scan
.roc_notify
= true;
7933 case ATH10K_SCAN_STARTING
:
7934 case ATH10K_SCAN_RUNNING
:
7935 case ATH10K_SCAN_ABORTING
:
7939 spin_unlock_bh(&ar
->data_lock
);
7944 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
7946 arg
= kzalloc(sizeof(*arg
), GFP_KERNEL
);
7952 ath10k_wmi_start_scan_init(ar
, arg
);
7953 arg
->vdev_id
= arvif
->vdev_id
;
7954 arg
->scan_id
= ATH10K_SCAN_ID
;
7955 arg
->n_channels
= 1;
7956 arg
->channels
[0] = chan
->center_freq
;
7957 arg
->dwell_time_active
= scan_time_msec
;
7958 arg
->dwell_time_passive
= scan_time_msec
;
7959 arg
->max_scan_time
= scan_time_msec
;
7960 arg
->scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
7961 arg
->scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
7962 arg
->burst_duration_ms
= duration
;
7964 ret
= ath10k_start_scan(ar
, arg
);
7966 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
7967 spin_lock_bh(&ar
->data_lock
);
7968 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
7969 spin_unlock_bh(&ar
->data_lock
);
7973 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3 * HZ
);
7975 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
7977 ret
= ath10k_scan_stop(ar
);
7979 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
7985 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
7986 msecs_to_jiffies(duration
));
7992 mutex_unlock(&ar
->conf_mutex
);
7996 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
,
7997 struct ieee80211_vif
*vif
)
7999 struct ath10k
*ar
= hw
->priv
;
8001 mutex_lock(&ar
->conf_mutex
);
8003 spin_lock_bh(&ar
->data_lock
);
8004 ar
->scan
.roc_notify
= false;
8005 spin_unlock_bh(&ar
->data_lock
);
8007 ath10k_scan_abort(ar
);
8009 mutex_unlock(&ar
->conf_mutex
);
8011 cancel_delayed_work_sync(&ar
->scan
.timeout
);
8017 * Both RTS and Fragmentation threshold are interface-specific
8018 * in ath10k, but device-specific in mac80211.
8021 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
8023 struct ath10k
*ar
= hw
->priv
;
8024 struct ath10k_vif
*arvif
;
8027 mutex_lock(&ar
->conf_mutex
);
8028 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
8029 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
8030 arvif
->vdev_id
, value
);
8032 ret
= ath10k_mac_set_rts(arvif
, value
);
8034 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
8035 arvif
->vdev_id
, ret
);
8039 mutex_unlock(&ar
->conf_mutex
);
8044 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
8046 /* Even though there's a WMI enum for fragmentation threshold no known
8047 * firmware actually implements it. Moreover it is not possible to rely
8048 * frame fragmentation to mac80211 because firmware clears the "more
8049 * fragments" bit in frame control making it impossible for remote
8050 * devices to reassemble frames.
8052 * Hence implement a dummy callback just to say fragmentation isn't
8053 * supported. This effectively prevents mac80211 from doing frame
8054 * fragmentation in software.
8059 void ath10k_mac_wait_tx_complete(struct ath10k
*ar
)
8064 /* mac80211 doesn't care if we really xmit queued frames or not
8065 * we'll collect those frames either way if we stop/delete vdevs
8068 if (ar
->state
== ATH10K_STATE_WEDGED
)
8071 time_left
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
8074 spin_lock_bh(&ar
->htt
.tx_lock
);
8075 empty
= (ar
->htt
.num_pending_tx
== 0);
8076 spin_unlock_bh(&ar
->htt
.tx_lock
);
8078 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
8079 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
8083 }), ATH10K_FLUSH_TIMEOUT_HZ
);
8085 if (time_left
== 0 || skip
)
8086 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
8087 skip
, ar
->state
, time_left
);
8090 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
8091 u32 queues
, bool drop
)
8093 struct ath10k
*ar
= hw
->priv
;
8094 struct ath10k_vif
*arvif
;
8098 if (vif
&& vif
->type
== NL80211_IFTYPE_STATION
) {
8099 bitmap
= ~(1 << WMI_MGMT_TID
);
8100 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
8101 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
8102 ath10k_wmi_peer_flush(ar
, arvif
->vdev_id
,
8103 arvif
->bssid
, bitmap
);
8105 ath10k_htt_flush_tx(&ar
->htt
);
8110 mutex_lock(&ar
->conf_mutex
);
8111 ath10k_mac_wait_tx_complete(ar
);
8112 mutex_unlock(&ar
->conf_mutex
);
8115 /* TODO: Implement this function properly
8116 * For now it is needed to reply to Probe Requests in IBSS mode.
8117 * Probably we need this information from FW.
8119 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
8124 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
8125 enum ieee80211_reconfig_type reconfig_type
)
8127 struct ath10k
*ar
= hw
->priv
;
8128 struct ath10k_vif
*arvif
;
8130 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
8133 mutex_lock(&ar
->conf_mutex
);
8135 /* If device failed to restart it will be in a different state, e.g.
8136 * ATH10K_STATE_WEDGED
8138 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
8139 ath10k_info(ar
, "device successfully recovered\n");
8140 ar
->state
= ATH10K_STATE_ON
;
8141 ieee80211_wake_queues(ar
->hw
);
8142 clear_bit(ATH10K_FLAG_RESTARTING
, &ar
->dev_flags
);
8143 if (ar
->hw_params
.hw_restart_disconnect
) {
8144 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
8145 if (arvif
->is_up
&& arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
8146 ieee80211_hw_restart_disconnect(arvif
->vif
);
8151 mutex_unlock(&ar
->conf_mutex
);
8155 ath10k_mac_update_bss_chan_survey(struct ath10k
*ar
,
8156 struct ieee80211_channel
*channel
)
8159 enum wmi_bss_survey_req_type type
= WMI_BSS_SURVEY_REQ_TYPE_READ
;
8161 lockdep_assert_held(&ar
->conf_mutex
);
8163 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64
, ar
->wmi
.svc_map
) ||
8164 (ar
->rx_channel
!= channel
))
8167 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
) {
8168 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "ignoring bss chan info request while scanning..\n");
8172 reinit_completion(&ar
->bss_survey_done
);
8174 ret
= ath10k_wmi_pdev_bss_chan_info_request(ar
, type
);
8176 ath10k_warn(ar
, "failed to send pdev bss chan info request\n");
8180 ret
= wait_for_completion_timeout(&ar
->bss_survey_done
, 3 * HZ
);
8182 ath10k_warn(ar
, "bss channel survey timed out\n");
8187 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
8188 struct survey_info
*survey
)
8190 struct ath10k
*ar
= hw
->priv
;
8191 struct ieee80211_supported_band
*sband
;
8192 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
8195 mutex_lock(&ar
->conf_mutex
);
8197 sband
= hw
->wiphy
->bands
[NL80211_BAND_2GHZ
];
8198 if (sband
&& idx
>= sband
->n_channels
) {
8199 idx
-= sband
->n_channels
;
8204 sband
= hw
->wiphy
->bands
[NL80211_BAND_5GHZ
];
8206 if (!sband
|| idx
>= sband
->n_channels
) {
8211 ath10k_mac_update_bss_chan_survey(ar
, &sband
->channels
[idx
]);
8213 spin_lock_bh(&ar
->data_lock
);
8214 memcpy(survey
, ar_survey
, sizeof(*survey
));
8215 spin_unlock_bh(&ar
->data_lock
);
8217 survey
->channel
= &sband
->channels
[idx
];
8219 if (ar
->rx_channel
== survey
->channel
)
8220 survey
->filled
|= SURVEY_INFO_IN_USE
;
8223 mutex_unlock(&ar
->conf_mutex
);
8228 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
8229 enum nl80211_band band
,
8230 const struct cfg80211_bitrate_mask
*mask
,
8233 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
8234 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8236 u8 vht_nss_mask
= 0;
8239 if (mask
->control
[band
].legacy
)
8242 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
8243 if (mask
->control
[band
].ht_mcs
[i
] == 0)
8245 else if (mask
->control
[band
].ht_mcs
[i
] ==
8246 sband
->ht_cap
.mcs
.rx_mask
[i
])
8247 ht_nss_mask
|= BIT(i
);
8252 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
8253 if (mask
->control
[band
].vht_mcs
[i
] == 0)
8255 else if (mask
->control
[band
].vht_mcs
[i
] ==
8256 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
8257 vht_nss_mask
|= BIT(i
);
8262 if (ht_nss_mask
!= vht_nss_mask
)
8265 if (ht_nss_mask
== 0)
8268 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
8271 *nss
= fls(ht_nss_mask
);
8276 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
8277 u8 rate
, u8 nss
, u8 sgi
, u8 ldpc
)
8279 struct ath10k
*ar
= arvif
->ar
;
8283 lockdep_assert_held(&ar
->conf_mutex
);
8285 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n",
8286 arvif
->vdev_id
, rate
, nss
, sgi
);
8288 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
8289 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
8291 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
8296 vdev_param
= ar
->wmi
.vdev_param
->nss
;
8297 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
8299 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
8303 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
8304 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
8306 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
8310 vdev_param
= ar
->wmi
.vdev_param
->ldpc
;
8311 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, ldpc
);
8313 ath10k_warn(ar
, "failed to set ldpc param %d: %d\n", ldpc
, ret
);
8321 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
8322 enum nl80211_band band
,
8323 const struct cfg80211_bitrate_mask
*mask
,
8329 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
8330 * to express all VHT MCS rate masks. Effectively only the following
8331 * ranges can be used: none, 0-7, 0-8 and 0-9.
8333 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8334 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
8344 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
8352 static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k
*ar
,
8353 struct ath10k_vif
*arvif
,
8354 struct ieee80211_sta
*sta
)
8357 u8 rate
= arvif
->vht_pfr
;
8359 /* skip non vht and multiple rate peers */
8360 if (!sta
->deflink
.vht_cap
.vht_supported
|| arvif
->vht_num_rates
!= 1)
8363 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
8364 WMI_PEER_PARAM_FIXED_RATE
, rate
);
8366 ath10k_warn(ar
, "failed to enable STA %pM peer fixed rate: %d\n",
8372 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
8373 struct ieee80211_sta
*sta
)
8375 struct ath10k_vif
*arvif
= data
;
8376 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8377 struct ath10k
*ar
= arvif
->ar
;
8379 if (arsta
->arvif
!= arvif
)
8382 if (ath10k_mac_set_vht_bitrate_mask_fixup(ar
, arvif
, sta
))
8385 spin_lock_bh(&ar
->data_lock
);
8386 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
8387 spin_unlock_bh(&ar
->data_lock
);
8389 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
8392 static void ath10k_mac_clr_bitrate_mask_iter(void *data
,
8393 struct ieee80211_sta
*sta
)
8395 struct ath10k_vif
*arvif
= data
;
8396 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8397 struct ath10k
*ar
= arvif
->ar
;
8400 /* clear vht peers only */
8401 if (arsta
->arvif
!= arvif
|| !sta
->deflink
.vht_cap
.vht_supported
)
8404 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
8405 WMI_PEER_PARAM_FIXED_RATE
,
8406 WMI_FIXED_RATE_NONE
);
8408 ath10k_warn(ar
, "failed to clear STA %pM peer fixed rate: %d\n",
8412 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
8413 struct ieee80211_vif
*vif
,
8414 const struct cfg80211_bitrate_mask
*mask
)
8416 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8417 struct cfg80211_chan_def def
;
8418 struct ath10k
*ar
= arvif
->ar
;
8419 enum nl80211_band band
;
8420 const u8
*ht_mcs_mask
;
8421 const u16
*vht_mcs_mask
;
8428 int vht_num_rates
, allow_pfr
;
8430 bool update_bitrate_mask
= true;
8432 if (ath10k_mac_vif_chan(vif
, &def
))
8435 band
= def
.chan
->band
;
8436 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
8437 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
8438 ldpc
= !!(ar
->ht_cap_info
& WMI_HT_CAP_LDPC
);
8440 sgi
= mask
->control
[band
].gi
;
8441 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
8444 allow_pfr
= test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE
,
8445 ar
->normal_mode_fw
.fw_file
.fw_features
);
8447 mutex_lock(&ar
->conf_mutex
);
8448 ieee80211_iterate_stations_atomic(ar
->hw
,
8449 ath10k_mac_clr_bitrate_mask_iter
,
8451 mutex_unlock(&ar
->conf_mutex
);
8454 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
8456 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
8460 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
8461 arvif
->vdev_id
, ret
);
8464 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
8466 rate
= WMI_FIXED_RATE_NONE
;
8469 rate
= WMI_FIXED_RATE_NONE
;
8470 nss
= min(ar
->num_rf_chains
,
8471 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
8472 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
8474 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
,
8478 if (!allow_pfr
|| vht_num_rates
!= 1)
8481 /* Reach here, firmware supports peer fixed rate and has
8482 * single vht rate, and don't update vif birate_mask, as
8483 * the rate only for specific peer.
8485 ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
8489 update_bitrate_mask
= false;
8494 mutex_lock(&ar
->conf_mutex
);
8496 if (update_bitrate_mask
)
8497 arvif
->bitrate_mask
= *mask
;
8498 arvif
->vht_num_rates
= vht_num_rates
;
8499 arvif
->vht_pfr
= vht_pfr
;
8500 ieee80211_iterate_stations_atomic(ar
->hw
,
8501 ath10k_mac_set_bitrate_mask_iter
,
8504 mutex_unlock(&ar
->conf_mutex
);
8507 mutex_lock(&ar
->conf_mutex
);
8509 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
, ldpc
);
8511 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
8512 arvif
->vdev_id
, ret
);
8517 mutex_unlock(&ar
->conf_mutex
);
8522 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
8523 struct ieee80211_vif
*vif
,
8524 struct ieee80211_link_sta
*link_sta
,
8527 struct ieee80211_sta
*sta
= link_sta
->sta
;
8528 struct ath10k
*ar
= hw
->priv
;
8529 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8530 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8531 struct ath10k_peer
*peer
;
8534 spin_lock_bh(&ar
->data_lock
);
8536 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
8538 spin_unlock_bh(&ar
->data_lock
);
8539 ath10k_warn(ar
, "mac sta rc update failed to find peer %pM on vdev %i\n",
8540 sta
->addr
, arvif
->vdev_id
);
8544 ath10k_dbg(ar
, ATH10K_DBG_STA
,
8545 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
8546 sta
->addr
, changed
, sta
->deflink
.bandwidth
,
8547 sta
->deflink
.rx_nss
,
8548 sta
->deflink
.smps_mode
);
8550 if (changed
& IEEE80211_RC_BW_CHANGED
) {
8551 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8553 switch (sta
->deflink
.bandwidth
) {
8554 case IEEE80211_STA_RX_BW_20
:
8555 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8557 case IEEE80211_STA_RX_BW_40
:
8558 bw
= WMI_PEER_CHWIDTH_40MHZ
;
8560 case IEEE80211_STA_RX_BW_80
:
8561 bw
= WMI_PEER_CHWIDTH_80MHZ
;
8563 case IEEE80211_STA_RX_BW_160
:
8564 bw
= WMI_PEER_CHWIDTH_160MHZ
;
8567 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
8568 sta
->deflink
.bandwidth
, sta
->addr
);
8569 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8576 if (changed
& IEEE80211_RC_NSS_CHANGED
)
8577 arsta
->nss
= sta
->deflink
.rx_nss
;
8579 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
8580 smps
= WMI_PEER_SMPS_PS_NONE
;
8582 switch (sta
->deflink
.smps_mode
) {
8583 case IEEE80211_SMPS_AUTOMATIC
:
8584 case IEEE80211_SMPS_OFF
:
8585 smps
= WMI_PEER_SMPS_PS_NONE
;
8587 case IEEE80211_SMPS_STATIC
:
8588 smps
= WMI_PEER_SMPS_STATIC
;
8590 case IEEE80211_SMPS_DYNAMIC
:
8591 smps
= WMI_PEER_SMPS_DYNAMIC
;
8593 case IEEE80211_SMPS_NUM_MODES
:
8594 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
8595 sta
->deflink
.smps_mode
, sta
->addr
);
8596 smps
= WMI_PEER_SMPS_PS_NONE
;
8603 arsta
->changed
|= changed
;
8605 spin_unlock_bh(&ar
->data_lock
);
8607 ieee80211_queue_work(hw
, &arsta
->update_wk
);
8610 static void ath10k_offset_tsf(struct ieee80211_hw
*hw
,
8611 struct ieee80211_vif
*vif
, s64 tsf_offset
)
8613 struct ath10k
*ar
= hw
->priv
;
8614 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8615 u32 offset
, vdev_param
;
8618 if (tsf_offset
< 0) {
8619 vdev_param
= ar
->wmi
.vdev_param
->dec_tsf
;
8620 offset
= -tsf_offset
;
8622 vdev_param
= ar
->wmi
.vdev_param
->inc_tsf
;
8623 offset
= tsf_offset
;
8626 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
8627 vdev_param
, offset
);
8629 if (ret
&& ret
!= -EOPNOTSUPP
)
8630 ath10k_warn(ar
, "failed to set tsf offset %d cmd %d: %d\n",
8631 offset
, vdev_param
, ret
);
8634 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
8635 struct ieee80211_vif
*vif
,
8636 struct ieee80211_ampdu_params
*params
)
8638 struct ath10k
*ar
= hw
->priv
;
8639 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8640 struct ieee80211_sta
*sta
= params
->sta
;
8641 enum ieee80211_ampdu_mlme_action action
= params
->action
;
8642 u16 tid
= params
->tid
;
8644 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %u action %d\n",
8645 arvif
->vdev_id
, sta
->addr
, tid
, action
);
8648 case IEEE80211_AMPDU_RX_START
:
8649 case IEEE80211_AMPDU_RX_STOP
:
8650 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
8651 * creation/removal. Do we need to verify this?
8654 case IEEE80211_AMPDU_TX_START
:
8655 case IEEE80211_AMPDU_TX_STOP_CONT
:
8656 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
8657 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
8658 case IEEE80211_AMPDU_TX_OPERATIONAL
:
8659 /* Firmware offloads Tx aggregation entirely so deny mac80211
8660 * Tx aggregation requests.
8669 ath10k_mac_update_rx_channel(struct ath10k
*ar
,
8670 struct ieee80211_chanctx_conf
*ctx
,
8671 struct ieee80211_vif_chanctx_switch
*vifs
,
8674 struct cfg80211_chan_def
*def
= NULL
;
8676 /* Both locks are required because ar->rx_channel is modified. This
8677 * allows readers to hold either lock.
8679 lockdep_assert_held(&ar
->conf_mutex
);
8680 lockdep_assert_held(&ar
->data_lock
);
8682 WARN_ON(ctx
&& vifs
);
8683 WARN_ON(vifs
&& !n_vifs
);
8685 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
8686 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
8687 * ppdu on Rx may reduce performance on low-end systems. It should be
8688 * possible to make tables/hashmaps to speed the lookup up (be vary of
8689 * cpu data cache lines though regarding sizes) but to keep the initial
8690 * implementation simple and less intrusive fallback to the slow lookup
8691 * only for multi-channel cases. Single-channel cases will remain to
8692 * use the old channel derival and thus performance should not be
8696 if (!ctx
&& ath10k_mac_num_chanctxs(ar
) == 1) {
8697 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
8698 ath10k_mac_get_any_chandef_iter
,
8702 def
= &vifs
[0].new_ctx
->def
;
8704 ar
->rx_channel
= def
->chan
;
8705 } else if ((ctx
&& ath10k_mac_num_chanctxs(ar
) == 0) ||
8706 (ctx
&& (ar
->state
== ATH10K_STATE_RESTARTED
))) {
8707 /* During driver restart due to firmware assert, since mac80211
8708 * already has valid channel context for given radio, channel
8709 * context iteration return num_chanctx > 0. So fix rx_channel
8710 * when restart is in progress.
8712 ar
->rx_channel
= ctx
->def
.chan
;
8714 ar
->rx_channel
= NULL
;
8720 ath10k_mac_update_vif_chan(struct ath10k
*ar
,
8721 struct ieee80211_vif_chanctx_switch
*vifs
,
8724 struct ath10k_vif
*arvif
;
8728 lockdep_assert_held(&ar
->conf_mutex
);
8730 /* First stop monitor interface. Some FW versions crash if there's a
8731 * lone monitor interface.
8733 if (ar
->monitor_started
)
8734 ath10k_monitor_stop(ar
);
8736 for (i
= 0; i
< n_vifs
; i
++) {
8737 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
8739 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8740 "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n",
8742 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
8743 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
8744 vifs
[i
].old_ctx
->def
.width
,
8745 vifs
[i
].new_ctx
->def
.width
);
8747 if (WARN_ON(!arvif
->is_started
))
8750 if (WARN_ON(!arvif
->is_up
))
8753 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
8755 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
8756 arvif
->vdev_id
, ret
);
8761 /* All relevant vdevs are downed and associated channel resources
8762 * should be available for the channel switch now.
8765 spin_lock_bh(&ar
->data_lock
);
8766 ath10k_mac_update_rx_channel(ar
, NULL
, vifs
, n_vifs
);
8767 spin_unlock_bh(&ar
->data_lock
);
8769 for (i
= 0; i
< n_vifs
; i
++) {
8770 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
8772 if (WARN_ON(!arvif
->is_started
))
8775 if (WARN_ON(!arvif
->is_up
))
8778 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
8780 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
8783 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
8785 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
8788 ret
= ath10k_vdev_restart(arvif
, &vifs
[i
].new_ctx
->def
);
8790 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
8791 arvif
->vdev_id
, ret
);
8795 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
8798 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
8799 arvif
->vdev_id
, ret
);
8804 ath10k_monitor_recalc(ar
);
8808 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
8809 struct ieee80211_chanctx_conf
*ctx
)
8811 struct ath10k
*ar
= hw
->priv
;
8813 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8814 "mac chanctx add freq %u width %d ptr %pK\n",
8815 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8817 mutex_lock(&ar
->conf_mutex
);
8819 spin_lock_bh(&ar
->data_lock
);
8820 ath10k_mac_update_rx_channel(ar
, ctx
, NULL
, 0);
8821 spin_unlock_bh(&ar
->data_lock
);
8823 ath10k_recalc_radar_detection(ar
);
8824 ath10k_monitor_recalc(ar
);
8826 mutex_unlock(&ar
->conf_mutex
);
8832 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
8833 struct ieee80211_chanctx_conf
*ctx
)
8835 struct ath10k
*ar
= hw
->priv
;
8837 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8838 "mac chanctx remove freq %u width %d ptr %pK\n",
8839 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8841 mutex_lock(&ar
->conf_mutex
);
8843 spin_lock_bh(&ar
->data_lock
);
8844 ath10k_mac_update_rx_channel(ar
, NULL
, NULL
, 0);
8845 spin_unlock_bh(&ar
->data_lock
);
8847 ath10k_recalc_radar_detection(ar
);
8848 ath10k_monitor_recalc(ar
);
8850 mutex_unlock(&ar
->conf_mutex
);
8853 struct ath10k_mac_change_chanctx_arg
{
8854 struct ieee80211_chanctx_conf
*ctx
;
8855 struct ieee80211_vif_chanctx_switch
*vifs
;
8861 ath10k_mac_change_chanctx_cnt_iter(void *data
, u8
*mac
,
8862 struct ieee80211_vif
*vif
)
8864 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8866 if (rcu_access_pointer(vif
->bss_conf
.chanctx_conf
) != arg
->ctx
)
8873 ath10k_mac_change_chanctx_fill_iter(void *data
, u8
*mac
,
8874 struct ieee80211_vif
*vif
)
8876 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8877 struct ieee80211_chanctx_conf
*ctx
;
8879 ctx
= rcu_access_pointer(vif
->bss_conf
.chanctx_conf
);
8880 if (ctx
!= arg
->ctx
)
8883 if (WARN_ON(arg
->next_vif
== arg
->n_vifs
))
8886 arg
->vifs
[arg
->next_vif
].vif
= vif
;
8887 arg
->vifs
[arg
->next_vif
].old_ctx
= ctx
;
8888 arg
->vifs
[arg
->next_vif
].new_ctx
= ctx
;
8893 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
8894 struct ieee80211_chanctx_conf
*ctx
,
8897 struct ath10k
*ar
= hw
->priv
;
8898 struct ath10k_mac_change_chanctx_arg arg
= { .ctx
= ctx
};
8900 mutex_lock(&ar
->conf_mutex
);
8902 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8903 "mac chanctx change freq %u width %d ptr %pK changed %x\n",
8904 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
, changed
);
8906 /* This shouldn't really happen because channel switching should use
8907 * switch_vif_chanctx().
8909 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
8912 if (changed
& IEEE80211_CHANCTX_CHANGE_WIDTH
) {
8913 ieee80211_iterate_active_interfaces_atomic(
8915 ATH10K_ITER_NORMAL_FLAGS
,
8916 ath10k_mac_change_chanctx_cnt_iter
,
8918 if (arg
.n_vifs
== 0)
8921 arg
.vifs
= kcalloc(arg
.n_vifs
, sizeof(arg
.vifs
[0]),
8926 ieee80211_iterate_active_interfaces_atomic(
8928 ATH10K_ITER_NORMAL_FLAGS
,
8929 ath10k_mac_change_chanctx_fill_iter
,
8931 ath10k_mac_update_vif_chan(ar
, arg
.vifs
, arg
.n_vifs
);
8936 ath10k_recalc_radar_detection(ar
);
8938 /* FIXME: How to configure Rx chains properly? */
8940 /* No other actions are actually necessary. Firmware maintains channel
8941 * definitions per vdev internally and there's no host-side channel
8942 * context abstraction to configure, e.g. channel width.
8946 mutex_unlock(&ar
->conf_mutex
);
8950 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
8951 struct ieee80211_vif
*vif
,
8952 struct ieee80211_bss_conf
*link_conf
,
8953 struct ieee80211_chanctx_conf
*ctx
)
8955 struct ath10k
*ar
= hw
->priv
;
8956 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8959 mutex_lock(&ar
->conf_mutex
);
8961 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8962 "mac chanctx assign ptr %pK vdev_id %i\n",
8963 ctx
, arvif
->vdev_id
);
8965 if (WARN_ON(arvif
->is_started
)) {
8966 mutex_unlock(&ar
->conf_mutex
);
8970 ret
= ath10k_vdev_start(arvif
, &ctx
->def
);
8972 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
8973 arvif
->vdev_id
, vif
->addr
,
8974 ctx
->def
.chan
->center_freq
, ret
);
8978 arvif
->is_started
= true;
8980 ret
= ath10k_mac_vif_setup_ps(arvif
);
8982 ath10k_warn(ar
, "failed to update vdev %i ps: %d\n",
8983 arvif
->vdev_id
, ret
);
8987 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
8988 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
8990 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
8991 arvif
->vdev_id
, ret
);
8995 arvif
->is_up
= true;
8998 if (ath10k_mac_can_set_cts_prot(arvif
)) {
8999 ret
= ath10k_mac_set_cts_prot(arvif
);
9001 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
9002 arvif
->vdev_id
, ret
);
9005 if (ath10k_peer_stats_enabled(ar
) &&
9006 ar
->hw_params
.tx_stats_over_pktlog
) {
9007 ar
->pktlog_filter
|= ATH10K_PKTLOG_PEER_STATS
;
9008 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
9011 ath10k_warn(ar
, "failed to enable pktlog %d\n", ret
);
9016 mutex_unlock(&ar
->conf_mutex
);
9020 ath10k_vdev_stop(arvif
);
9021 arvif
->is_started
= false;
9022 ath10k_mac_vif_setup_ps(arvif
);
9025 mutex_unlock(&ar
->conf_mutex
);
9030 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
9031 struct ieee80211_vif
*vif
,
9032 struct ieee80211_bss_conf
*link_conf
,
9033 struct ieee80211_chanctx_conf
*ctx
)
9035 struct ath10k
*ar
= hw
->priv
;
9036 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9039 mutex_lock(&ar
->conf_mutex
);
9041 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9042 "mac chanctx unassign ptr %pK vdev_id %i\n",
9043 ctx
, arvif
->vdev_id
);
9045 WARN_ON(!arvif
->is_started
);
9047 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
9048 WARN_ON(!arvif
->is_up
);
9050 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
9052 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
9053 arvif
->vdev_id
, ret
);
9055 arvif
->is_up
= false;
9058 ret
= ath10k_vdev_stop(arvif
);
9060 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
9061 arvif
->vdev_id
, ret
);
9063 arvif
->is_started
= false;
9065 mutex_unlock(&ar
->conf_mutex
);
9069 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
9070 struct ieee80211_vif_chanctx_switch
*vifs
,
9072 enum ieee80211_chanctx_switch_mode mode
)
9074 struct ath10k
*ar
= hw
->priv
;
9076 mutex_lock(&ar
->conf_mutex
);
9078 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9079 "mac chanctx switch n_vifs %d mode %d\n",
9081 ath10k_mac_update_vif_chan(ar
, vifs
, n_vifs
);
9083 mutex_unlock(&ar
->conf_mutex
);
9087 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
9088 struct ieee80211_vif
*vif
,
9089 struct ieee80211_sta
*sta
)
9092 struct ath10k_peer
*peer
;
9096 list_for_each_entry(peer
, &ar
->peers
, list
)
9097 if (peer
->sta
== sta
)
9098 peer
->removed
= true;
9101 /* HT MCS parameters with Nss = 1 */
9102 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss1
[] = {
9103 /* MCS L20 L40 S20 S40 */
9104 {0, { 65, 135, 72, 150} },
9105 {1, { 130, 270, 144, 300} },
9106 {2, { 195, 405, 217, 450} },
9107 {3, { 260, 540, 289, 600} },
9108 {4, { 390, 810, 433, 900} },
9109 {5, { 520, 1080, 578, 1200} },
9110 {6, { 585, 1215, 650, 1350} },
9111 {7, { 650, 1350, 722, 1500} }
9114 /* HT MCS parameters with Nss = 2 */
9115 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss2
[] = {
9116 /* MCS L20 L40 S20 S40 */
9117 {0, {130, 270, 144, 300} },
9118 {1, {260, 540, 289, 600} },
9119 {2, {390, 810, 433, 900} },
9120 {3, {520, 1080, 578, 1200} },
9121 {4, {780, 1620, 867, 1800} },
9122 {5, {1040, 2160, 1156, 2400} },
9123 {6, {1170, 2430, 1300, 2700} },
9124 {7, {1300, 2700, 1444, 3000} }
9127 /* MCS parameters with Nss = 1 */
9128 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss1
[] = {
9129 /* MCS L80 S80 L40 S40 L20 S20 */
9130 {0, {293, 325}, {135, 150}, {65, 72} },
9131 {1, {585, 650}, {270, 300}, {130, 144} },
9132 {2, {878, 975}, {405, 450}, {195, 217} },
9133 {3, {1170, 1300}, {540, 600}, {260, 289} },
9134 {4, {1755, 1950}, {810, 900}, {390, 433} },
9135 {5, {2340, 2600}, {1080, 1200}, {520, 578} },
9136 {6, {2633, 2925}, {1215, 1350}, {585, 650} },
9137 {7, {2925, 3250}, {1350, 1500}, {650, 722} },
9138 {8, {3510, 3900}, {1620, 1800}, {780, 867} },
9139 {9, {3900, 4333}, {1800, 2000}, {865, 960} }
9142 /*MCS parameters with Nss = 2 */
9143 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss2
[] = {
9144 /* MCS L80 S80 L40 S40 L20 S20 */
9145 {0, {585, 650}, {270, 300}, {130, 144} },
9146 {1, {1170, 1300}, {540, 600}, {260, 289} },
9147 {2, {1755, 1950}, {810, 900}, {390, 433} },
9148 {3, {2340, 2600}, {1080, 1200}, {520, 578} },
9149 {4, {3510, 3900}, {1620, 1800}, {780, 867} },
9150 {5, {4680, 5200}, {2160, 2400}, {1040, 1156} },
9151 {6, {5265, 5850}, {2430, 2700}, {1170, 1300} },
9152 {7, {5850, 6500}, {2700, 3000}, {1300, 1444} },
9153 {8, {7020, 7800}, {3240, 3600}, {1560, 1733} },
9154 {9, {7800, 8667}, {3600, 4000}, {1730, 1920} }
9157 static void ath10k_mac_get_rate_flags_ht(struct ath10k
*ar
, u32 rate
, u8 nss
, u8 mcs
,
9160 struct ath10k_index_ht_data_rate_type
*mcs_rate
;
9162 size_t len_nss1
= ARRAY_SIZE(supported_ht_mcs_rate_nss1
);
9163 size_t len_nss2
= ARRAY_SIZE(supported_ht_mcs_rate_nss2
);
9165 if (mcs
>= (len_nss1
+ len_nss2
)) {
9166 ath10k_warn(ar
, "not supported mcs %d in current rate table", mcs
);
9170 mcs_rate
= (struct ath10k_index_ht_data_rate_type
*)
9171 ((nss
== 1) ? &supported_ht_mcs_rate_nss1
:
9172 &supported_ht_mcs_rate_nss2
);
9174 if (mcs
>= len_nss1
)
9175 index
= mcs
- len_nss1
;
9179 if (rate
== mcs_rate
[index
].supported_rate
[0]) {
9180 *bw
= RATE_INFO_BW_20
;
9181 } else if (rate
== mcs_rate
[index
].supported_rate
[1]) {
9182 *bw
|= RATE_INFO_BW_40
;
9183 } else if (rate
== mcs_rate
[index
].supported_rate
[2]) {
9184 *bw
|= RATE_INFO_BW_20
;
9185 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9186 } else if (rate
== mcs_rate
[index
].supported_rate
[3]) {
9187 *bw
|= RATE_INFO_BW_40
;
9188 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9190 ath10k_warn(ar
, "invalid ht params rate %d 100kbps nss %d mcs %d",
9195 static void ath10k_mac_get_rate_flags_vht(struct ath10k
*ar
, u32 rate
, u8 nss
, u8 mcs
,
9198 struct ath10k_index_vht_data_rate_type
*mcs_rate
;
9200 mcs_rate
= (struct ath10k_index_vht_data_rate_type
*)
9201 ((nss
== 1) ? &supported_vht_mcs_rate_nss1
:
9202 &supported_vht_mcs_rate_nss2
);
9204 if (rate
== mcs_rate
[mcs
].supported_VHT80_rate
[0]) {
9205 *bw
= RATE_INFO_BW_80
;
9206 } else if (rate
== mcs_rate
[mcs
].supported_VHT80_rate
[1]) {
9207 *bw
= RATE_INFO_BW_80
;
9208 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9209 } else if (rate
== mcs_rate
[mcs
].supported_VHT40_rate
[0]) {
9210 *bw
= RATE_INFO_BW_40
;
9211 } else if (rate
== mcs_rate
[mcs
].supported_VHT40_rate
[1]) {
9212 *bw
= RATE_INFO_BW_40
;
9213 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9214 } else if (rate
== mcs_rate
[mcs
].supported_VHT20_rate
[0]) {
9215 *bw
= RATE_INFO_BW_20
;
9216 } else if (rate
== mcs_rate
[mcs
].supported_VHT20_rate
[1]) {
9217 *bw
= RATE_INFO_BW_20
;
9218 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9220 ath10k_warn(ar
, "invalid vht params rate %d 100kbps nss %d mcs %d",
9225 static void ath10k_mac_get_rate_flags(struct ath10k
*ar
, u32 rate
,
9226 enum ath10k_phy_mode mode
, u8 nss
, u8 mcs
,
9229 if (mode
== ATH10K_PHY_MODE_HT
) {
9230 *flags
= RATE_INFO_FLAGS_MCS
;
9231 ath10k_mac_get_rate_flags_ht(ar
, rate
, nss
, mcs
, flags
, bw
);
9232 } else if (mode
== ATH10K_PHY_MODE_VHT
) {
9233 *flags
= RATE_INFO_FLAGS_VHT_MCS
;
9234 ath10k_mac_get_rate_flags_vht(ar
, rate
, nss
, mcs
, flags
, bw
);
9238 static void ath10k_mac_parse_bitrate(struct ath10k
*ar
, u32 rate_code
,
9239 u32 bitrate_kbps
, struct rate_info
*rate
)
9241 enum ath10k_phy_mode mode
= ATH10K_PHY_MODE_LEGACY
;
9242 enum wmi_rate_preamble preamble
= WMI_TLV_GET_HW_RC_PREAM_V1(rate_code
);
9243 u8 nss
= WMI_TLV_GET_HW_RC_NSS_V1(rate_code
) + 1;
9244 u8 mcs
= WMI_TLV_GET_HW_RC_RATE_V1(rate_code
);
9245 u8 flags
= 0, bw
= 0;
9247 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac parse rate code 0x%x bitrate %d kbps\n",
9248 rate_code
, bitrate_kbps
);
9250 if (preamble
== WMI_RATE_PREAMBLE_HT
)
9251 mode
= ATH10K_PHY_MODE_HT
;
9252 else if (preamble
== WMI_RATE_PREAMBLE_VHT
)
9253 mode
= ATH10K_PHY_MODE_VHT
;
9255 ath10k_mac_get_rate_flags(ar
, bitrate_kbps
/ 100, mode
, nss
, mcs
, &flags
, &bw
);
9257 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9258 "mac parse bitrate preamble %d mode %d nss %d mcs %d flags %x bw %d\n",
9259 preamble
, mode
, nss
, mcs
, flags
, bw
);
9261 rate
->flags
= flags
;
9263 rate
->legacy
= bitrate_kbps
/ 100;
9268 static void ath10k_mac_sta_get_peer_stats_info(struct ath10k
*ar
,
9269 struct ieee80211_sta
*sta
,
9270 struct station_info
*sinfo
)
9272 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
9273 struct ath10k_peer
*peer
;
9274 unsigned long time_left
;
9277 if (!(ar
->hw_params
.supports_peer_stats_info
&&
9278 arsta
->arvif
->vdev_type
== WMI_VDEV_TYPE_STA
))
9281 spin_lock_bh(&ar
->data_lock
);
9282 peer
= ath10k_peer_find(ar
, arsta
->arvif
->vdev_id
, sta
->addr
);
9283 spin_unlock_bh(&ar
->data_lock
);
9287 reinit_completion(&ar
->peer_stats_info_complete
);
9289 ret
= ath10k_wmi_request_peer_stats_info(ar
,
9290 arsta
->arvif
->vdev_id
,
9291 WMI_REQUEST_ONE_PEER_STATS_INFO
,
9292 arsta
->arvif
->bssid
,
9294 if (ret
&& ret
!= -EOPNOTSUPP
) {
9295 ath10k_warn(ar
, "could not request peer stats info: %d\n", ret
);
9299 time_left
= wait_for_completion_timeout(&ar
->peer_stats_info_complete
, 3 * HZ
);
9300 if (time_left
== 0) {
9301 ath10k_warn(ar
, "timed out waiting peer stats info\n");
9305 if (arsta
->rx_rate_code
!= 0 && arsta
->rx_bitrate_kbps
!= 0) {
9306 ath10k_mac_parse_bitrate(ar
, arsta
->rx_rate_code
,
9307 arsta
->rx_bitrate_kbps
,
9310 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_BITRATE
);
9311 arsta
->rx_rate_code
= 0;
9312 arsta
->rx_bitrate_kbps
= 0;
9315 if (arsta
->tx_rate_code
!= 0 && arsta
->tx_bitrate_kbps
!= 0) {
9316 ath10k_mac_parse_bitrate(ar
, arsta
->tx_rate_code
,
9317 arsta
->tx_bitrate_kbps
,
9320 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
9321 arsta
->tx_rate_code
= 0;
9322 arsta
->tx_bitrate_kbps
= 0;
9326 static void ath10k_sta_statistics(struct ieee80211_hw
*hw
,
9327 struct ieee80211_vif
*vif
,
9328 struct ieee80211_sta
*sta
,
9329 struct station_info
*sinfo
)
9331 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
9332 struct ath10k
*ar
= arsta
->arvif
->ar
;
9334 if (!ath10k_peer_stats_enabled(ar
))
9337 mutex_lock(&ar
->conf_mutex
);
9338 ath10k_debug_fw_stats_request(ar
);
9339 mutex_unlock(&ar
->conf_mutex
);
9341 sinfo
->rx_duration
= arsta
->rx_duration
;
9342 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_DURATION
);
9344 if (arsta
->txrate
.legacy
|| arsta
->txrate
.nss
) {
9345 if (arsta
->txrate
.legacy
) {
9346 sinfo
->txrate
.legacy
= arsta
->txrate
.legacy
;
9348 sinfo
->txrate
.mcs
= arsta
->txrate
.mcs
;
9349 sinfo
->txrate
.nss
= arsta
->txrate
.nss
;
9350 sinfo
->txrate
.bw
= arsta
->txrate
.bw
;
9352 sinfo
->txrate
.flags
= arsta
->txrate
.flags
;
9353 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
9356 if (ar
->htt
.disable_tx_comp
) {
9357 sinfo
->tx_failed
= arsta
->tx_failed
;
9358 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_FAILED
);
9361 sinfo
->tx_retries
= arsta
->tx_retries
;
9362 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_RETRIES
);
9364 ath10k_mac_sta_get_peer_stats_info(ar
, sta
, sinfo
);
9367 static int ath10k_mac_op_set_tid_config(struct ieee80211_hw
*hw
,
9368 struct ieee80211_vif
*vif
,
9369 struct ieee80211_sta
*sta
,
9370 struct cfg80211_tid_config
*tid_config
)
9372 struct ath10k
*ar
= hw
->priv
;
9373 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9374 struct ath10k_mac_iter_tid_conf_data data
= {};
9375 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
9378 mutex_lock(&ar
->conf_mutex
);
9379 arg
.vdev_id
= arvif
->vdev_id
;
9381 arvif
->tids_rst
= 0;
9382 memset(arvif
->tid_conf_changed
, 0, sizeof(arvif
->tid_conf_changed
));
9384 for (i
= 0; i
< tid_config
->n_tid_conf
; i
++) {
9385 ret
= ath10k_mac_parse_tid_config(ar
, sta
, vif
,
9386 &tid_config
->tid_conf
[i
],
9397 arvif
->tids_rst
= 0;
9398 data
.curr_vif
= vif
;
9401 ieee80211_iterate_stations_atomic(hw
, ath10k_mac_vif_stations_tid_conf
,
9405 mutex_unlock(&ar
->conf_mutex
);
9409 static int ath10k_mac_op_reset_tid_config(struct ieee80211_hw
*hw
,
9410 struct ieee80211_vif
*vif
,
9411 struct ieee80211_sta
*sta
,
9414 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9415 struct ath10k_mac_iter_tid_conf_data data
= {};
9416 struct ath10k
*ar
= hw
->priv
;
9419 mutex_lock(&ar
->conf_mutex
);
9422 arvif
->tids_rst
= 0;
9423 ret
= ath10k_mac_reset_tid_config(ar
, sta
, arvif
, tids
);
9427 arvif
->tids_rst
= tids
;
9428 data
.curr_vif
= vif
;
9430 ieee80211_iterate_stations_atomic(hw
, ath10k_mac_vif_stations_tid_conf
,
9434 mutex_unlock(&ar
->conf_mutex
);
9438 static const struct ieee80211_ops ath10k_ops
= {
9439 .tx
= ath10k_mac_op_tx
,
9440 .wake_tx_queue
= ath10k_mac_op_wake_tx_queue
,
9441 .start
= ath10k_start
,
9442 .stop
= ath10k_stop
,
9443 .config
= ath10k_config
,
9444 .add_interface
= ath10k_add_interface
,
9445 .update_vif_offload
= ath10k_update_vif_offload
,
9446 .remove_interface
= ath10k_remove_interface
,
9447 .configure_filter
= ath10k_configure_filter
,
9448 .bss_info_changed
= ath10k_bss_info_changed
,
9449 .set_coverage_class
= ath10k_mac_op_set_coverage_class
,
9450 .hw_scan
= ath10k_hw_scan
,
9451 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
9452 .set_key
= ath10k_set_key
,
9453 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
9454 .sta_state
= ath10k_sta_state
,
9455 .sta_set_txpwr
= ath10k_sta_set_txpwr
,
9456 .conf_tx
= ath10k_conf_tx
,
9457 .remain_on_channel
= ath10k_remain_on_channel
,
9458 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
9459 .set_rts_threshold
= ath10k_set_rts_threshold
,
9460 .set_frag_threshold
= ath10k_mac_op_set_frag_threshold
,
9461 .flush
= ath10k_flush
,
9462 .tx_last_beacon
= ath10k_tx_last_beacon
,
9463 .set_antenna
= ath10k_set_antenna
,
9464 .get_antenna
= ath10k_get_antenna
,
9465 .reconfig_complete
= ath10k_reconfig_complete
,
9466 .get_survey
= ath10k_get_survey
,
9467 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
9468 .link_sta_rc_update
= ath10k_sta_rc_update
,
9469 .offset_tsf
= ath10k_offset_tsf
,
9470 .ampdu_action
= ath10k_ampdu_action
,
9471 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
9472 .get_et_stats
= ath10k_debug_get_et_stats
,
9473 .get_et_strings
= ath10k_debug_get_et_strings
,
9474 .add_chanctx
= ath10k_mac_op_add_chanctx
,
9475 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
9476 .change_chanctx
= ath10k_mac_op_change_chanctx
,
9477 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
9478 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
9479 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
9480 .sta_pre_rcu_remove
= ath10k_mac_op_sta_pre_rcu_remove
,
9481 .sta_statistics
= ath10k_sta_statistics
,
9482 .set_tid_config
= ath10k_mac_op_set_tid_config
,
9483 .reset_tid_config
= ath10k_mac_op_reset_tid_config
,
9485 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
9488 .suspend
= ath10k_wow_op_suspend
,
9489 .resume
= ath10k_wow_op_resume
,
9490 .set_wakeup
= ath10k_wow_op_set_wakeup
,
9492 #ifdef CONFIG_MAC80211_DEBUGFS
9493 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
9495 .set_sar_specs
= ath10k_mac_set_sar_specs
,
9498 #define CHAN2G(_channel, _freq, _flags) { \
9499 .band = NL80211_BAND_2GHZ, \
9500 .hw_value = (_channel), \
9501 .center_freq = (_freq), \
9502 .flags = (_flags), \
9503 .max_antenna_gain = 0, \
9507 #define CHAN5G(_channel, _freq, _flags) { \
9508 .band = NL80211_BAND_5GHZ, \
9509 .hw_value = (_channel), \
9510 .center_freq = (_freq), \
9511 .flags = (_flags), \
9512 .max_antenna_gain = 0, \
9516 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
9526 CHAN2G(10, 2457, 0),
9527 CHAN2G(11, 2462, 0),
9528 CHAN2G(12, 2467, 0),
9529 CHAN2G(13, 2472, 0),
9530 CHAN2G(14, 2484, 0),
9533 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
9534 CHAN5G(36, 5180, 0),
9535 CHAN5G(40, 5200, 0),
9536 CHAN5G(44, 5220, 0),
9537 CHAN5G(48, 5240, 0),
9538 CHAN5G(52, 5260, 0),
9539 CHAN5G(56, 5280, 0),
9540 CHAN5G(60, 5300, 0),
9541 CHAN5G(64, 5320, 0),
9542 CHAN5G(100, 5500, 0),
9543 CHAN5G(104, 5520, 0),
9544 CHAN5G(108, 5540, 0),
9545 CHAN5G(112, 5560, 0),
9546 CHAN5G(116, 5580, 0),
9547 CHAN5G(120, 5600, 0),
9548 CHAN5G(124, 5620, 0),
9549 CHAN5G(128, 5640, 0),
9550 CHAN5G(132, 5660, 0),
9551 CHAN5G(136, 5680, 0),
9552 CHAN5G(140, 5700, 0),
9553 CHAN5G(144, 5720, 0),
9554 CHAN5G(149, 5745, 0),
9555 CHAN5G(153, 5765, 0),
9556 CHAN5G(157, 5785, 0),
9557 CHAN5G(161, 5805, 0),
9558 CHAN5G(165, 5825, 0),
9559 CHAN5G(169, 5845, 0),
9560 CHAN5G(173, 5865, 0),
9561 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
9562 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
9565 struct ath10k
*ath10k_mac_create(size_t priv_size
)
9567 struct ieee80211_hw
*hw
;
9568 struct ieee80211_ops
*ops
;
9571 ops
= kmemdup(&ath10k_ops
, sizeof(ath10k_ops
), GFP_KERNEL
);
9575 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, ops
);
9588 void ath10k_mac_destroy(struct ath10k
*ar
)
9590 struct ieee80211_ops
*ops
= ar
->ops
;
9592 ieee80211_free_hw(ar
->hw
);
9596 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
9599 .types
= BIT(NL80211_IFTYPE_STATION
)
9600 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
9604 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
9608 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
9612 .types
= BIT(NL80211_IFTYPE_AP
)
9613 #ifdef CONFIG_MAC80211_MESH
9614 | BIT(NL80211_IFTYPE_MESH_POINT
)
9619 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
9622 .types
= BIT(NL80211_IFTYPE_AP
)
9623 #ifdef CONFIG_MAC80211_MESH
9624 | BIT(NL80211_IFTYPE_MESH_POINT
)
9629 .types
= BIT(NL80211_IFTYPE_STATION
)
9633 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
9635 .limits
= ath10k_if_limits
,
9636 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
9637 .max_interfaces
= 8,
9638 .num_different_channels
= 1,
9639 .beacon_int_infra_match
= true,
9643 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
9645 .limits
= ath10k_10x_if_limits
,
9646 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
9647 .max_interfaces
= 8,
9648 .num_different_channels
= 1,
9649 .beacon_int_infra_match
= true,
9650 .beacon_int_min_gcd
= 1,
9651 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9652 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9653 BIT(NL80211_CHAN_WIDTH_20
) |
9654 BIT(NL80211_CHAN_WIDTH_40
) |
9655 BIT(NL80211_CHAN_WIDTH_80
),
9660 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
9663 .types
= BIT(NL80211_IFTYPE_STATION
),
9667 .types
= BIT(NL80211_IFTYPE_AP
) |
9668 #ifdef CONFIG_MAC80211_MESH
9669 BIT(NL80211_IFTYPE_MESH_POINT
) |
9671 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
9672 BIT(NL80211_IFTYPE_P2P_GO
),
9676 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
9680 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit
[] = {
9683 .types
= BIT(NL80211_IFTYPE_STATION
),
9687 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
),
9691 .types
= BIT(NL80211_IFTYPE_AP
) |
9692 #ifdef CONFIG_MAC80211_MESH
9693 BIT(NL80211_IFTYPE_MESH_POINT
) |
9695 BIT(NL80211_IFTYPE_P2P_GO
),
9699 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
9703 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
9706 .types
= BIT(NL80211_IFTYPE_STATION
),
9710 .types
= BIT(NL80211_IFTYPE_ADHOC
),
9714 /* FIXME: This is not thoroughly tested. These combinations may over- or
9715 * underestimate hw/fw capabilities.
9717 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
9719 .limits
= ath10k_tlv_if_limit
,
9720 .num_different_channels
= 1,
9721 .max_interfaces
= 4,
9722 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
9725 .limits
= ath10k_tlv_if_limit_ibss
,
9726 .num_different_channels
= 1,
9727 .max_interfaces
= 2,
9728 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
9732 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
9734 .limits
= ath10k_tlv_if_limit
,
9735 .num_different_channels
= 1,
9736 .max_interfaces
= 4,
9737 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
9740 .limits
= ath10k_tlv_qcs_if_limit
,
9741 .num_different_channels
= 2,
9742 .max_interfaces
= 4,
9743 .n_limits
= ARRAY_SIZE(ath10k_tlv_qcs_if_limit
),
9746 .limits
= ath10k_tlv_if_limit_ibss
,
9747 .num_different_channels
= 1,
9748 .max_interfaces
= 2,
9749 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
9753 static const struct ieee80211_iface_limit ath10k_10_4_if_limits
[] = {
9756 .types
= BIT(NL80211_IFTYPE_STATION
),
9760 .types
= BIT(NL80211_IFTYPE_AP
)
9761 #ifdef CONFIG_MAC80211_MESH
9762 | BIT(NL80211_IFTYPE_MESH_POINT
)
9767 static const struct ieee80211_iface_combination ath10k_10_4_if_comb
[] = {
9769 .limits
= ath10k_10_4_if_limits
,
9770 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
9771 .max_interfaces
= 16,
9772 .num_different_channels
= 1,
9773 .beacon_int_infra_match
= true,
9774 .beacon_int_min_gcd
= 1,
9775 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9776 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9777 BIT(NL80211_CHAN_WIDTH_20
) |
9778 BIT(NL80211_CHAN_WIDTH_40
) |
9779 BIT(NL80211_CHAN_WIDTH_80
) |
9780 BIT(NL80211_CHAN_WIDTH_80P80
) |
9781 BIT(NL80211_CHAN_WIDTH_160
),
9787 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb
[] = {
9789 .limits
= ath10k_10_4_if_limits
,
9790 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
9791 .max_interfaces
= 16,
9792 .num_different_channels
= 1,
9793 .beacon_int_infra_match
= true,
9794 .beacon_int_min_gcd
= 100,
9795 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9796 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9797 BIT(NL80211_CHAN_WIDTH_20
) |
9798 BIT(NL80211_CHAN_WIDTH_40
) |
9799 BIT(NL80211_CHAN_WIDTH_80
) |
9800 BIT(NL80211_CHAN_WIDTH_80P80
) |
9801 BIT(NL80211_CHAN_WIDTH_160
),
9806 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
9807 struct ieee80211_vif
*vif
)
9809 struct ath10k_vif_iter
*arvif_iter
= data
;
9810 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9812 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
9813 arvif_iter
->arvif
= arvif
;
9816 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
9818 struct ath10k_vif_iter arvif_iter
;
9820 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
9821 arvif_iter
.vdev_id
= vdev_id
;
9823 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
9824 ATH10K_ITER_RESUME_FLAGS
,
9825 ath10k_get_arvif_iter
,
9827 if (!arvif_iter
.arvif
) {
9828 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
9832 return arvif_iter
.arvif
;
9835 #define WRD_METHOD "WRDD"
9836 #define WRDD_WIFI (0x07)
9838 static u32
ath10k_mac_wrdd_get_mcc(struct ath10k
*ar
, union acpi_object
*wrdd
)
9840 union acpi_object
*mcc_pkg
;
9841 union acpi_object
*domain_type
;
9842 union acpi_object
*mcc_value
;
9845 if (wrdd
->type
!= ACPI_TYPE_PACKAGE
||
9846 wrdd
->package
.count
< 2 ||
9847 wrdd
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
9848 wrdd
->package
.elements
[0].integer
.value
!= 0) {
9849 ath10k_warn(ar
, "ignoring malformed/unsupported wrdd structure\n");
9853 for (i
= 1; i
< wrdd
->package
.count
; ++i
) {
9854 mcc_pkg
= &wrdd
->package
.elements
[i
];
9856 if (mcc_pkg
->type
!= ACPI_TYPE_PACKAGE
)
9858 if (mcc_pkg
->package
.count
< 2)
9860 if (mcc_pkg
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
9861 mcc_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
)
9864 domain_type
= &mcc_pkg
->package
.elements
[0];
9865 if (domain_type
->integer
.value
!= WRDD_WIFI
)
9868 mcc_value
= &mcc_pkg
->package
.elements
[1];
9869 return mcc_value
->integer
.value
;
9874 static int ath10k_mac_get_wrdd_regulatory(struct ath10k
*ar
, u16
*rd
)
9876 acpi_handle root_handle
;
9878 struct acpi_buffer wrdd
= {ACPI_ALLOCATE_BUFFER
, NULL
};
9883 root_handle
= ACPI_HANDLE(ar
->dev
);
9887 status
= acpi_get_handle(root_handle
, (acpi_string
)WRD_METHOD
, &handle
);
9888 if (ACPI_FAILURE(status
)) {
9889 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9890 "failed to get wrd method %d\n", status
);
9894 status
= acpi_evaluate_object(handle
, NULL
, NULL
, &wrdd
);
9895 if (ACPI_FAILURE(status
)) {
9896 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9897 "failed to call wrdc %d\n", status
);
9901 alpha2_code
= ath10k_mac_wrdd_get_mcc(ar
, wrdd
.pointer
);
9902 kfree(wrdd
.pointer
);
9906 alpha2
[0] = (alpha2_code
>> 8) & 0xff;
9907 alpha2
[1] = (alpha2_code
>> 0) & 0xff;
9910 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9911 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2
);
9913 *rd
= ath_regd_find_country_by_name(alpha2
);
9917 *rd
|= COUNTRY_ERD_FLAG
;
9921 static int ath10k_mac_init_rd(struct ath10k
*ar
)
9926 ret
= ath10k_mac_get_wrdd_regulatory(ar
, &rd
);
9928 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9929 "fallback to eeprom programmed regulatory settings\n");
9930 rd
= ar
->hw_eeprom_rd
;
9933 ar
->ath_common
.regulatory
.current_rd
= rd
;
9937 int ath10k_mac_register(struct ath10k
*ar
)
9939 static const u32 cipher_suites
[] = {
9940 WLAN_CIPHER_SUITE_WEP40
,
9941 WLAN_CIPHER_SUITE_WEP104
,
9942 WLAN_CIPHER_SUITE_TKIP
,
9943 WLAN_CIPHER_SUITE_CCMP
,
9945 /* Do not add hardware supported ciphers before this line.
9946 * Allow software encryption for all chips. Don't forget to
9947 * update n_cipher_suites below.
9949 WLAN_CIPHER_SUITE_AES_CMAC
,
9950 WLAN_CIPHER_SUITE_BIP_CMAC_256
,
9951 WLAN_CIPHER_SUITE_BIP_GMAC_128
,
9952 WLAN_CIPHER_SUITE_BIP_GMAC_256
,
9954 /* Only QCA99x0 and QCA4019 variants support GCMP-128, GCMP-256
9955 * and CCMP-256 in hardware.
9957 WLAN_CIPHER_SUITE_GCMP
,
9958 WLAN_CIPHER_SUITE_GCMP_256
,
9959 WLAN_CIPHER_SUITE_CCMP_256
,
9961 struct ieee80211_supported_band
*band
;
9965 if (!is_valid_ether_addr(ar
->mac_addr
)) {
9966 ath10k_warn(ar
, "invalid MAC address; choosing random\n");
9967 eth_random_addr(ar
->mac_addr
);
9969 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
9971 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
9973 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
9974 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
9977 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
9978 channels
= kmemdup(ath10k_2ghz_channels
,
9979 sizeof(ath10k_2ghz_channels
),
9986 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
9987 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
9988 band
->channels
= channels
;
9990 if (ar
->hw_params
.cck_rate_map_rev2
) {
9991 band
->n_bitrates
= ath10k_g_rates_rev2_size
;
9992 band
->bitrates
= ath10k_g_rates_rev2
;
9994 band
->n_bitrates
= ath10k_g_rates_size
;
9995 band
->bitrates
= ath10k_g_rates
;
9998 ar
->hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = band
;
10001 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
10002 channels
= kmemdup(ath10k_5ghz_channels
,
10003 sizeof(ath10k_5ghz_channels
),
10010 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
10011 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
10012 band
->channels
= channels
;
10013 band
->n_bitrates
= ath10k_a_rates_size
;
10014 band
->bitrates
= ath10k_a_rates
;
10015 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = band
;
10018 wiphy_read_of_freq_limits(ar
->hw
->wiphy
);
10019 ath10k_mac_setup_ht_vht_cap(ar
);
10021 ar
->hw
->wiphy
->interface_modes
=
10022 BIT(NL80211_IFTYPE_STATION
) |
10023 BIT(NL80211_IFTYPE_AP
) |
10024 BIT(NL80211_IFTYPE_MESH_POINT
);
10026 ar
->hw
->wiphy
->available_antennas_rx
= ar
->cfg_rx_chainmask
;
10027 ar
->hw
->wiphy
->available_antennas_tx
= ar
->cfg_tx_chainmask
;
10029 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->normal_mode_fw
.fw_file
.fw_features
))
10030 ar
->hw
->wiphy
->interface_modes
|=
10031 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
10032 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
10033 BIT(NL80211_IFTYPE_P2P_GO
);
10035 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
10037 if (!test_bit(ATH10K_FW_FEATURE_NO_PS
,
10038 ar
->running_fw
->fw_file
.fw_features
)) {
10039 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
10040 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
10043 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
10044 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
10045 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
10046 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
10047 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
10048 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
10049 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
10050 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
10051 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
10052 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
10053 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
10054 ieee80211_hw_set(ar
->hw
, SUPPORTS_TX_FRAG
);
10055 ieee80211_hw_set(ar
->hw
, REPORTS_LOW_ACK
);
10057 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
10058 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
10060 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
10061 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
10063 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
10064 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
10066 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
10067 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
10068 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
10071 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
10072 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
10074 if (test_bit(WMI_SERVICE_NLO
, ar
->wmi
.svc_map
)) {
10075 ar
->hw
->wiphy
->max_sched_scan_ssids
= WMI_PNO_MAX_SUPP_NETWORKS
;
10076 ar
->hw
->wiphy
->max_match_sets
= WMI_PNO_MAX_SUPP_NETWORKS
;
10077 ar
->hw
->wiphy
->max_sched_scan_ie_len
= WMI_PNO_MAX_IE_LENGTH
;
10078 ar
->hw
->wiphy
->max_sched_scan_plans
= WMI_PNO_MAX_SCHED_SCAN_PLANS
;
10079 ar
->hw
->wiphy
->max_sched_scan_plan_interval
=
10080 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT
;
10081 ar
->hw
->wiphy
->max_sched_scan_plan_iterations
=
10082 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS
;
10083 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
10086 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
10087 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
10088 ar
->hw
->txq_data_size
= sizeof(struct ath10k_txq
);
10090 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
10092 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
10093 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
10095 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
10096 * that userspace (e.g. wpa_supplicant/hostapd) can generate
10097 * correct Probe Responses. This is more of a hack advert..
10099 ar
->hw
->wiphy
->probe_resp_offload
|=
10100 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
10101 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
10102 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
10105 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
) ||
10106 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY
, ar
->wmi
.svc_map
)) {
10107 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
10108 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH
, ar
->wmi
.svc_map
))
10109 ieee80211_hw_set(ar
->hw
, TDLS_WIDER_BW
);
10112 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA
, ar
->wmi
.svc_map
))
10113 ieee80211_hw_set(ar
->hw
, SUPPORTS_TDLS_BUFFER_STA
);
10115 if (ath10k_frame_mode
== ATH10K_HW_TXRX_ETHERNET
) {
10116 if (ar
->wmi
.vdev_param
->tx_encap_type
!=
10117 WMI_VDEV_PARAM_UNSUPPORTED
)
10118 ieee80211_hw_set(ar
->hw
, SUPPORTS_TX_ENCAP_OFFLOAD
);
10121 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
10122 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
10123 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
10125 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
10126 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
10127 NL80211_FEATURE_AP_SCAN
;
10129 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
10131 ret
= ath10k_wow_init(ar
);
10133 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
10137 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
10138 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10139 NL80211_EXT_FEATURE_SET_SCAN_DWELL
);
10140 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_AQL
);
10142 if (ar
->hw_params
.mcast_frame_registration
)
10143 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10144 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS
);
10146 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI
, ar
->wmi
.svc_map
) ||
10147 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS
, ar
->wmi
.svc_map
))
10148 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10149 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT
);
10151 if (ath10k_peer_stats_enabled(ar
) ||
10152 test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
10153 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10154 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
);
10156 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
))
10157 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10158 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
);
10160 if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER
, ar
->wmi
.svc_map
))
10161 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10162 NL80211_EXT_FEATURE_STA_TX_PWR
);
10164 if (test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT
, ar
->wmi
.svc_map
)) {
10165 ar
->hw
->wiphy
->tid_config_support
.vif
|=
10166 BIT(NL80211_TID_CONFIG_ATTR_NOACK
) |
10167 BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT
) |
10168 BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
) |
10169 BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
) |
10170 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
10171 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
);
10173 if (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT
,
10174 ar
->wmi
.svc_map
)) {
10175 ar
->hw
->wiphy
->tid_config_support
.vif
|=
10176 BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
);
10179 ar
->hw
->wiphy
->tid_config_support
.peer
=
10180 ar
->hw
->wiphy
->tid_config_support
.vif
;
10181 ar
->hw
->wiphy
->max_data_retry_count
= ATH10K_MAX_RETRY_COUNT
;
10183 ar
->ops
->set_tid_config
= NULL
;
10186 * on LL hardware queues are managed entirely by the FW
10187 * so we only advertise to mac we can do the queues thing
10189 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
10191 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
10192 * something that vdev_ids can't reach so that we don't stop the queue
10195 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
10197 switch (ar
->running_fw
->fw_file
.wmi_op_version
) {
10198 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
10199 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
10200 ar
->hw
->wiphy
->n_iface_combinations
=
10201 ARRAY_SIZE(ath10k_if_comb
);
10202 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
10204 case ATH10K_FW_WMI_OP_VERSION_TLV
:
10205 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
10206 ar
->hw
->wiphy
->iface_combinations
=
10207 ath10k_tlv_qcs_if_comb
;
10208 ar
->hw
->wiphy
->n_iface_combinations
=
10209 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
10211 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
10212 ar
->hw
->wiphy
->n_iface_combinations
=
10213 ARRAY_SIZE(ath10k_tlv_if_comb
);
10215 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
10217 case ATH10K_FW_WMI_OP_VERSION_10_1
:
10218 case ATH10K_FW_WMI_OP_VERSION_10_2
:
10219 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
10220 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
10221 ar
->hw
->wiphy
->n_iface_combinations
=
10222 ARRAY_SIZE(ath10k_10x_if_comb
);
10224 case ATH10K_FW_WMI_OP_VERSION_10_4
:
10225 ar
->hw
->wiphy
->iface_combinations
= ath10k_10_4_if_comb
;
10226 ar
->hw
->wiphy
->n_iface_combinations
=
10227 ARRAY_SIZE(ath10k_10_4_if_comb
);
10228 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT
,
10229 ar
->wmi
.svc_map
)) {
10230 ar
->hw
->wiphy
->iface_combinations
=
10231 ath10k_10_4_bcn_int_if_comb
;
10232 ar
->hw
->wiphy
->n_iface_combinations
=
10233 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb
);
10236 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
10237 case ATH10K_FW_WMI_OP_VERSION_MAX
:
10243 if (ar
->hw_params
.dynamic_sar_support
)
10244 ar
->hw
->wiphy
->sar_capa
= &ath10k_sar_capa
;
10246 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
10247 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
10249 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
10250 /* Init ath dfs pattern detector */
10251 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
10252 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
10253 NL80211_DFS_UNSET
);
10255 if (!ar
->dfs_detector
)
10256 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
10259 ret
= ath10k_mac_init_rd(ar
);
10261 ath10k_err(ar
, "failed to derive regdom: %d\n", ret
);
10262 goto err_dfs_detector_exit
;
10265 /* Disable set_coverage_class for chipsets that do not support it. */
10266 if (!ar
->hw_params
.hw_ops
->set_coverage_class
)
10267 ar
->ops
->set_coverage_class
= NULL
;
10269 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
10270 ath10k_reg_notifier
);
10272 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
10273 goto err_dfs_detector_exit
;
10276 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
10277 ar
->hw
->wiphy
->features
|=
10278 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
10281 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
10283 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
10284 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
10285 * from chip specific hw_param table.
10287 if (!ar
->hw_params
.n_cipher_suites
||
10288 ar
->hw_params
.n_cipher_suites
> ARRAY_SIZE(cipher_suites
)) {
10289 ath10k_err(ar
, "invalid hw_params.n_cipher_suites %d\n",
10290 ar
->hw_params
.n_cipher_suites
);
10291 ar
->hw_params
.n_cipher_suites
= 8;
10293 ar
->hw
->wiphy
->n_cipher_suites
= ar
->hw_params
.n_cipher_suites
;
10295 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_CQM_RSSI_LIST
);
10297 ar
->hw
->weight_multiplier
= ATH10K_AIRTIME_WEIGHT_MULTIPLIER
;
10299 ret
= ieee80211_register_hw(ar
->hw
);
10301 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
10302 goto err_dfs_detector_exit
;
10305 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT
, ar
->wmi
.svc_map
)) {
10306 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
10307 ar
->hw
->wiphy
->software_iftypes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
10310 if (!ath_is_world_regd(&ar
->ath_common
.reg_world_copy
) &&
10311 !ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
10312 ret
= regulatory_hint(ar
->hw
->wiphy
,
10313 ar
->ath_common
.regulatory
.alpha2
);
10315 goto err_unregister
;
10321 ieee80211_unregister_hw(ar
->hw
);
10323 err_dfs_detector_exit
:
10324 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
10325 ar
->dfs_detector
->exit(ar
->dfs_detector
);
10328 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
10329 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
10331 SET_IEEE80211_DEV(ar
->hw
, NULL
);
10335 void ath10k_mac_unregister(struct ath10k
*ar
)
10337 ieee80211_unregister_hw(ar
->hw
);
10339 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
10340 ar
->dfs_detector
->exit(ar
->dfs_detector
);
10342 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
10343 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
10345 SET_IEEE80211_DEV(ar
->hw
, NULL
);