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
;
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 memset(&arg
, 0, sizeof(arg
));
6406 ath10k_wmi_start_scan_init(ar
, &arg
);
6407 arg
.vdev_id
= arvif
->vdev_id
;
6408 arg
.scan_id
= ATH10K_SCAN_ID
;
6411 arg
.ie_len
= req
->ie_len
;
6412 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
6416 arg
.n_ssids
= req
->n_ssids
;
6417 for (i
= 0; i
< arg
.n_ssids
; i
++) {
6418 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
6419 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
6422 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
6425 if (req
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6426 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ
;
6427 ether_addr_copy(arg
.mac_addr
.addr
, req
->mac_addr
);
6428 ether_addr_copy(arg
.mac_mask
.addr
, req
->mac_addr_mask
);
6431 if (req
->n_channels
) {
6432 arg
.n_channels
= req
->n_channels
;
6433 for (i
= 0; i
< arg
.n_channels
; i
++)
6434 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
6437 /* if duration is set, default dwell times will be overwritten */
6438 if (req
->duration
) {
6439 arg
.dwell_time_active
= req
->duration
;
6440 arg
.dwell_time_passive
= req
->duration
;
6441 arg
.burst_duration_ms
= req
->duration
;
6443 scan_timeout
= min_t(u32
, arg
.max_rest_time
*
6444 (arg
.n_channels
- 1) + (req
->duration
+
6445 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD
) *
6446 arg
.n_channels
, arg
.max_scan_time
);
6448 scan_timeout
= arg
.max_scan_time
;
6451 /* Add a 200ms margin to account for event/command processing */
6452 scan_timeout
+= 200;
6454 ret
= ath10k_start_scan(ar
, &arg
);
6456 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
6457 spin_lock_bh(&ar
->data_lock
);
6458 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
6459 spin_unlock_bh(&ar
->data_lock
);
6462 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
6463 msecs_to_jiffies(scan_timeout
));
6466 mutex_unlock(&ar
->conf_mutex
);
6470 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
6471 struct ieee80211_vif
*vif
)
6473 struct ath10k
*ar
= hw
->priv
;
6475 mutex_lock(&ar
->conf_mutex
);
6476 ath10k_scan_abort(ar
);
6477 mutex_unlock(&ar
->conf_mutex
);
6479 cancel_delayed_work_sync(&ar
->scan
.timeout
);
6482 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
6483 struct ath10k_vif
*arvif
,
6484 enum set_key_cmd cmd
,
6485 struct ieee80211_key_conf
*key
)
6487 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
6490 /* 10.1 firmware branch requires default key index to be set to group
6491 * key index after installing it. Otherwise FW/HW Txes corrupted
6492 * frames with multi-vif APs. This is not required for main firmware
6493 * branch (e.g. 636).
6495 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6497 * FIXME: It remains unknown if this is required for multi-vif STA
6498 * interfaces on 10.1.
6501 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
6502 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
6505 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
6508 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
6511 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6517 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6520 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
6521 arvif
->vdev_id
, ret
);
6524 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6525 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
6526 struct ieee80211_key_conf
*key
)
6528 struct ath10k
*ar
= hw
->priv
;
6529 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6530 struct ath10k_sta
*arsta
;
6531 struct ath10k_peer
*peer
;
6532 const u8
*peer_addr
;
6533 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
6534 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
6540 /* this one needs to be done in software */
6541 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
6542 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
6543 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
||
6544 key
->cipher
== WLAN_CIPHER_SUITE_BIP_CMAC_256
)
6547 if (arvif
->nohwcrypt
)
6550 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
6553 mutex_lock(&ar
->conf_mutex
);
6556 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6557 peer_addr
= sta
->addr
;
6558 spin_lock_bh(&ar
->data_lock
);
6559 arsta
->ucast_cipher
= key
->cipher
;
6560 spin_unlock_bh(&ar
->data_lock
);
6561 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
6562 peer_addr
= vif
->bss_conf
.bssid
;
6564 peer_addr
= vif
->addr
;
6567 key
->hw_key_idx
= key
->keyidx
;
6571 arvif
->wep_keys
[key
->keyidx
] = key
;
6573 arvif
->wep_keys
[key
->keyidx
] = NULL
;
6576 /* the peer should not disappear in mid-way (unless FW goes awry) since
6577 * we already hold conf_mutex. we just make sure its there now.
6579 spin_lock_bh(&ar
->data_lock
);
6580 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6581 spin_unlock_bh(&ar
->data_lock
);
6584 if (cmd
== SET_KEY
) {
6585 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
6590 /* if the peer doesn't exist there is no key to disable anymore */
6595 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6596 flags
|= WMI_KEY_PAIRWISE
;
6598 flags
|= WMI_KEY_GROUP
;
6601 if (cmd
== DISABLE_KEY
)
6602 ath10k_clear_vdev_key(arvif
, key
);
6604 /* When WEP keys are uploaded it's possible that there are
6605 * stations associated already (e.g. when merging) without any
6606 * keys. Static WEP needs an explicit per-peer key upload.
6608 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
6610 ath10k_mac_vif_update_wep_key(arvif
, key
);
6612 /* 802.1x never sets the def_wep_key_idx so each set_key()
6613 * call changes default tx key.
6615 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6616 * after first set_key().
6618 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
6619 flags
|= WMI_KEY_TX_USAGE
;
6622 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
6625 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
6626 arvif
->vdev_id
, peer_addr
, ret
);
6630 /* mac80211 sets static WEP keys as groupwise while firmware requires
6631 * them to be installed twice as both pairwise and groupwise.
6633 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
6635 flags2
&= ~WMI_KEY_GROUP
;
6636 flags2
|= WMI_KEY_PAIRWISE
;
6638 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
6641 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6642 arvif
->vdev_id
, peer_addr
, ret
);
6643 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
6647 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6648 arvif
->vdev_id
, peer_addr
, ret2
);
6654 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
6656 spin_lock_bh(&ar
->data_lock
);
6657 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6658 if (peer
&& cmd
== SET_KEY
)
6659 peer
->keys
[key
->keyidx
] = key
;
6660 else if (peer
&& cmd
== DISABLE_KEY
)
6661 peer
->keys
[key
->keyidx
] = NULL
;
6662 else if (peer
== NULL
)
6663 /* impossible unless FW goes crazy */
6664 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
6665 spin_unlock_bh(&ar
->data_lock
);
6667 if (sta
&& sta
->tdls
)
6668 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6669 ar
->wmi
.peer_param
->authorize
, 1);
6670 else if (sta
&& cmd
== SET_KEY
&& (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
6671 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, peer_addr
,
6672 ar
->wmi
.peer_param
->authorize
, 1);
6675 mutex_unlock(&ar
->conf_mutex
);
6679 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
6680 struct ieee80211_vif
*vif
,
6683 struct ath10k
*ar
= hw
->priv
;
6684 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6687 mutex_lock(&arvif
->ar
->conf_mutex
);
6689 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
6692 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
6693 arvif
->vdev_id
, keyidx
);
6695 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
6697 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
6701 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
6707 arvif
->def_wep_key_idx
= keyidx
;
6710 mutex_unlock(&arvif
->ar
->conf_mutex
);
6713 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
6716 struct ath10k_vif
*arvif
;
6717 struct ath10k_sta
*arsta
;
6718 struct ieee80211_sta
*sta
;
6719 struct cfg80211_chan_def def
;
6720 enum nl80211_band band
;
6721 const u8
*ht_mcs_mask
;
6722 const u16
*vht_mcs_mask
;
6723 u32 changed
, bw
, nss
, smps
;
6726 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
6727 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
6728 arvif
= arsta
->arvif
;
6731 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
6734 band
= def
.chan
->band
;
6735 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
6736 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
6738 spin_lock_bh(&ar
->data_lock
);
6740 changed
= arsta
->changed
;
6747 spin_unlock_bh(&ar
->data_lock
);
6749 mutex_lock(&ar
->conf_mutex
);
6751 nss
= max_t(u32
, 1, nss
);
6752 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6753 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6755 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6756 enum wmi_phy_mode mode
;
6758 mode
= chan_to_phymode(&def
);
6759 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM peer bw %d phymode %d\n",
6760 sta
->addr
, bw
, mode
);
6762 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6763 ar
->wmi
.peer_param
->phymode
, mode
);
6765 ath10k_warn(ar
, "failed to update STA %pM peer phymode %d: %d\n",
6766 sta
->addr
, mode
, err
);
6770 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6771 ar
->wmi
.peer_param
->chan_width
, bw
);
6773 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
6774 sta
->addr
, bw
, err
);
6777 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
6778 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM nss %d\n",
6781 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6782 ar
->wmi
.peer_param
->nss
, nss
);
6784 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
6785 sta
->addr
, nss
, err
);
6788 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6789 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM smps %d\n",
6792 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6793 ar
->wmi
.peer_param
->smps_state
, smps
);
6795 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
6796 sta
->addr
, smps
, err
);
6799 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
6800 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac update sta %pM supp rates\n",
6803 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
6805 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
6810 mutex_unlock(&ar
->conf_mutex
);
6813 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
6814 struct ieee80211_sta
*sta
)
6816 struct ath10k
*ar
= arvif
->ar
;
6818 lockdep_assert_held(&ar
->conf_mutex
);
6820 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6823 if (ar
->num_stations
>= ar
->max_num_stations
)
6831 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
6832 struct ieee80211_sta
*sta
)
6834 struct ath10k
*ar
= arvif
->ar
;
6836 lockdep_assert_held(&ar
->conf_mutex
);
6838 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6844 static int ath10k_sta_set_txpwr(struct ieee80211_hw
*hw
,
6845 struct ieee80211_vif
*vif
,
6846 struct ieee80211_sta
*sta
)
6848 struct ath10k
*ar
= hw
->priv
;
6849 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6853 if (sta
->deflink
.txpwr
.type
== NL80211_TX_POWER_AUTOMATIC
) {
6856 txpwr
= sta
->deflink
.txpwr
.power
;
6861 if (txpwr
> ATH10K_TX_POWER_MAX_VAL
|| txpwr
< ATH10K_TX_POWER_MIN_VAL
)
6864 mutex_lock(&ar
->conf_mutex
);
6866 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6867 ar
->wmi
.peer_param
->use_fixed_power
, txpwr
);
6869 ath10k_warn(ar
, "failed to set tx power for station ret: %d\n",
6875 mutex_unlock(&ar
->conf_mutex
);
6879 struct ath10k_mac_iter_tid_conf_data
{
6880 struct ieee80211_vif
*curr_vif
;
6886 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
6887 enum nl80211_band band
,
6888 const struct cfg80211_bitrate_mask
*mask
,
6894 num_rates
+= hweight32(mask
->control
[band
].legacy
);
6896 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
6897 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
6900 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6901 tmp
= hweight16(mask
->control
[band
].vht_mcs
[i
]);
6903 *vht_num_rates
+= tmp
;
6906 return num_rates
== 1;
6910 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
6911 enum nl80211_band band
,
6912 const struct cfg80211_bitrate_mask
*mask
,
6913 u8
*rate
, u8
*nss
, bool vht_only
)
6924 if (hweight32(mask
->control
[band
].legacy
) == 1) {
6925 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
6927 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
6928 rate_idx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
6930 hw_rate
= ath10k_wmi_legacy_rates
[rate_idx
].hw_value
;
6931 bitrate
= ath10k_wmi_legacy_rates
[rate_idx
].bitrate
;
6933 if (ath10k_mac_bitrate_is_cck(bitrate
))
6934 preamble
= WMI_RATE_PREAMBLE_CCK
;
6936 preamble
= WMI_RATE_PREAMBLE_OFDM
;
6939 *rate
= preamble
<< 6 |
6946 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
6947 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
6949 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
6951 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
6958 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6959 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
6961 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
6963 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
6972 static int ath10k_mac_validate_rate_mask(struct ath10k
*ar
,
6973 struct ieee80211_sta
*sta
,
6974 u32 rate_ctrl_flag
, u8 nss
)
6976 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->deflink
.ht_cap
;
6977 struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->deflink
.vht_cap
;
6979 if (nss
> sta
->deflink
.rx_nss
) {
6980 ath10k_warn(ar
, "Invalid nss field, configured %u limit %u\n",
6981 nss
, sta
->deflink
.rx_nss
);
6985 if (ATH10K_HW_PREAMBLE(rate_ctrl_flag
) == WMI_RATE_PREAMBLE_VHT
) {
6986 if (!vht_cap
->vht_supported
) {
6987 ath10k_warn(ar
, "Invalid VHT rate for sta %pM\n",
6991 } else if (ATH10K_HW_PREAMBLE(rate_ctrl_flag
) == WMI_RATE_PREAMBLE_HT
) {
6992 if (!ht_cap
->ht_supported
|| vht_cap
->vht_supported
) {
6993 ath10k_warn(ar
, "Invalid HT rate for sta %pM\n",
6998 if (ht_cap
->ht_supported
|| vht_cap
->vht_supported
)
7006 ath10k_mac_tid_bitrate_config(struct ath10k
*ar
,
7007 struct ieee80211_vif
*vif
,
7008 struct ieee80211_sta
*sta
,
7009 u32
*rate_ctrl_flag
, u8
*rate_ctrl
,
7010 enum nl80211_tx_rate_setting txrate_type
,
7011 const struct cfg80211_bitrate_mask
*mask
)
7013 struct cfg80211_chan_def def
;
7014 enum nl80211_band band
;
7016 int vht_num_rates
, ret
;
7018 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
7021 if (txrate_type
== NL80211_TX_RATE_AUTOMATIC
) {
7022 *rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7023 *rate_ctrl_flag
= 0;
7027 band
= def
.chan
->band
;
7029 if (!ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
7034 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
7035 &rate
, &nss
, false);
7037 ath10k_warn(ar
, "failed to get single rate: %d\n",
7042 *rate_ctrl_flag
= rate
;
7044 if (sta
&& ath10k_mac_validate_rate_mask(ar
, sta
, *rate_ctrl_flag
, nss
))
7047 if (txrate_type
== NL80211_TX_RATE_FIXED
)
7048 *rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_FIXED_RATE
;
7049 else if (txrate_type
== NL80211_TX_RATE_LIMITED
&&
7050 (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT
,
7052 *rate_ctrl
= WMI_PEER_TID_CONFIG_RATE_UPPER_CAP
;
7059 static int ath10k_mac_set_tid_config(struct ath10k
*ar
, struct ieee80211_sta
*sta
,
7060 struct ieee80211_vif
*vif
, u32 changed
,
7061 struct wmi_per_peer_per_tid_cfg_arg
*arg
)
7063 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7064 struct ath10k_sta
*arsta
;
7071 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7073 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7074 if ((arsta
->retry_long
[arg
->tid
] > 0 ||
7075 arsta
->rate_code
[arg
->tid
] > 0 ||
7076 arsta
->ampdu
[arg
->tid
] ==
7077 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
) &&
7078 arg
->ack_policy
== WMI_PEER_TID_CONFIG_NOACK
) {
7079 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
7080 arg
->ack_policy
= 0;
7081 arg
->aggr_control
= 0;
7083 arg
->rcode_flags
= 0;
7087 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7088 if (arsta
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
||
7089 arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
7090 arg
->aggr_control
= 0;
7091 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
7095 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7096 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7097 if (arsta
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
||
7098 arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
7100 arg
->rcode_flags
= 0;
7104 ether_addr_copy(arg
->peer_macaddr
.addr
, sta
->addr
);
7106 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, arg
);
7110 /* Store the configured parameters in success case */
7111 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7112 arsta
->noack
[arg
->tid
] = arg
->ack_policy
;
7113 arg
->ack_policy
= 0;
7114 arg
->aggr_control
= 0;
7116 arg
->rcode_flags
= 0;
7119 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7120 arsta
->retry_long
[arg
->tid
] = arg
->retry_count
;
7121 arg
->retry_count
= 0;
7124 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7125 arsta
->ampdu
[arg
->tid
] = arg
->aggr_control
;
7126 arg
->aggr_control
= 0;
7129 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7130 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7131 arsta
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
7133 arg
->rcode_flags
= 0;
7136 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7137 arsta
->rtscts
[arg
->tid
] = arg
->rtscts_ctrl
;
7138 arg
->ext_tid_cfg_bitmap
= 0;
7141 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7142 if ((arvif
->retry_long
[arg
->tid
] ||
7143 arvif
->rate_code
[arg
->tid
] ||
7144 arvif
->ampdu
[arg
->tid
] ==
7145 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
) &&
7146 arg
->ack_policy
== WMI_PEER_TID_CONFIG_NOACK
) {
7147 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
7149 arvif
->noack
[arg
->tid
] = arg
->ack_policy
;
7150 arvif
->ampdu
[arg
->tid
] = arg
->aggr_control
;
7151 arvif
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
7155 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7156 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
)
7157 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
7159 arvif
->retry_long
[arg
->tid
] = arg
->retry_count
;
7162 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7163 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
)
7164 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
);
7166 arvif
->ampdu
[arg
->tid
] = arg
->aggr_control
;
7169 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7170 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7171 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
7172 changed
&= ~(BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7173 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
));
7175 arvif
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
7176 arvif
->rate_code
[arg
->tid
] = arg
->rcode_flags
;
7180 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7181 arvif
->rtscts
[arg
->tid
] = arg
->rtscts_ctrl
;
7182 arg
->ext_tid_cfg_bitmap
= 0;
7186 arvif
->tid_conf_changed
[arg
->tid
] |= changed
;
7193 ath10k_mac_parse_tid_config(struct ath10k
*ar
,
7194 struct ieee80211_sta
*sta
,
7195 struct ieee80211_vif
*vif
,
7196 struct cfg80211_tid_cfg
*tid_conf
,
7197 struct wmi_per_peer_per_tid_cfg_arg
*arg
)
7199 u32 changed
= tid_conf
->mask
;
7205 while (i
< ATH10K_TID_MAX
) {
7206 if (!(tid_conf
->tids
& BIT(i
))) {
7213 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7214 if (tid_conf
->noack
== NL80211_TID_CONFIG_ENABLE
) {
7215 arg
->ack_policy
= WMI_PEER_TID_CONFIG_NOACK
;
7217 WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE
;
7219 WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
7222 WMI_PEER_TID_CONFIG_ACK
;
7224 WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7226 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7230 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
))
7231 arg
->retry_count
= tid_conf
->retry_long
;
7233 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7234 if (tid_conf
->noack
== NL80211_TID_CONFIG_ENABLE
)
7235 arg
->aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7237 arg
->aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
7240 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7241 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7242 ret
= ath10k_mac_tid_bitrate_config(ar
, vif
, sta
,
7245 tid_conf
->txrate_type
,
7246 &tid_conf
->txrate_mask
);
7248 ath10k_warn(ar
, "failed to configure bitrate mask %d\n",
7250 arg
->rcode_flags
= 0;
7255 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7256 if (tid_conf
->rtscts
)
7257 arg
->rtscts_ctrl
= tid_conf
->rtscts
;
7259 arg
->ext_tid_cfg_bitmap
= WMI_EXT_TID_RTS_CTS_CONFIG
;
7262 ret
= ath10k_mac_set_tid_config(ar
, sta
, vif
, changed
, arg
);
7271 static int ath10k_mac_reset_tid_config(struct ath10k
*ar
,
7272 struct ieee80211_sta
*sta
,
7273 struct ath10k_vif
*arvif
,
7276 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7277 struct wmi_per_peer_per_tid_cfg_arg arg
;
7280 arg
.vdev_id
= arvif
->vdev_id
;
7281 while (i
< ATH10K_TID_MAX
) {
7282 if (!(tids
& BIT(i
))) {
7288 arg
.ack_policy
= WMI_PEER_TID_CONFIG_ACK
;
7289 arg
.retry_count
= ATH10K_MAX_RETRY_COUNT
;
7290 arg
.rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7291 arg
.aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7292 arg
.rtscts_ctrl
= WMI_TID_CONFIG_RTSCTS_CONTROL_ENABLE
;
7293 arg
.ext_tid_cfg_bitmap
= WMI_EXT_TID_RTS_CTS_CONFIG
;
7295 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
7297 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
7301 if (!arvif
->tids_rst
) {
7302 arsta
->retry_long
[i
] = -1;
7303 arsta
->noack
[i
] = -1;
7304 arsta
->ampdu
[i
] = -1;
7305 arsta
->rate_code
[i
] = -1;
7306 arsta
->rate_ctrl
[i
] = 0;
7307 arsta
->rtscts
[i
] = -1;
7309 arvif
->retry_long
[i
] = 0;
7310 arvif
->noack
[i
] = 0;
7311 arvif
->ampdu
[i
] = 0;
7312 arvif
->rate_code
[i
] = 0;
7313 arvif
->rate_ctrl
[i
] = 0;
7314 arvif
->rtscts
[i
] = 0;
7323 static void ath10k_sta_tid_cfg_wk(struct work_struct
*wk
)
7325 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
7326 struct ieee80211_sta
*sta
;
7327 struct ath10k_sta
*arsta
;
7328 struct ath10k_vif
*arvif
;
7335 arsta
= container_of(wk
, struct ath10k_sta
, tid_config_wk
);
7336 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
7337 arvif
= arsta
->arvif
;
7340 mutex_lock(&ar
->conf_mutex
);
7342 if (arvif
->tids_rst
) {
7343 ret
= ath10k_mac_reset_tid_config(ar
, sta
, arvif
,
7348 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
7350 for (i
= 0; i
< ATH10K_TID_MAX
; i
++) {
7351 config_apply
= false;
7352 changed
= arvif
->tid_conf_changed
[i
];
7354 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7355 if (arsta
->noack
[i
] != -1) {
7358 config_apply
= true;
7359 arg
.ack_policy
= arvif
->noack
[i
];
7360 arg
.aggr_control
= arvif
->ampdu
[i
];
7361 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
7365 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7366 if (arsta
->retry_long
[i
] != -1 ||
7367 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7368 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7369 arg
.retry_count
= 0;
7371 arg
.retry_count
= arvif
->retry_long
[i
];
7372 config_apply
= true;
7376 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7377 if (arsta
->ampdu
[i
] != -1 ||
7378 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7379 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7380 arg
.aggr_control
= 0;
7382 arg
.aggr_control
= arvif
->ampdu
[i
];
7383 config_apply
= true;
7387 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7388 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7389 nss
= ATH10K_HW_NSS(arvif
->rate_code
[i
]);
7390 ret
= ath10k_mac_validate_rate_mask(ar
, sta
,
7391 arvif
->rate_code
[i
],
7394 arvif
->rate_ctrl
[i
] > WMI_TID_CONFIG_RATE_CONTROL_AUTO
) {
7396 arg
.rcode_flags
= 0;
7399 if (arsta
->rate_ctrl
[i
] >
7400 WMI_TID_CONFIG_RATE_CONTROL_AUTO
||
7401 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7402 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7404 arg
.rcode_flags
= 0;
7406 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
7407 arg
.rcode_flags
= arvif
->rate_code
[i
];
7408 config_apply
= true;
7412 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7413 if (arsta
->rtscts
[i
]) {
7414 arg
.rtscts_ctrl
= 0;
7415 arg
.ext_tid_cfg_bitmap
= 0;
7417 arg
.rtscts_ctrl
= arvif
->rtscts
[i
] - 1;
7418 arg
.ext_tid_cfg_bitmap
=
7419 WMI_EXT_TID_RTS_CTS_CONFIG
;
7420 config_apply
= true;
7427 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
7429 ath10k_warn(ar
, "failed to set per tid config for sta %pM: %d\n",
7434 arg
.retry_count
= 0;
7435 arg
.aggr_control
= 0;
7437 arg
.rcode_flags
= 0;
7441 mutex_unlock(&ar
->conf_mutex
);
7444 static void ath10k_mac_vif_stations_tid_conf(void *data
,
7445 struct ieee80211_sta
*sta
)
7447 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7448 struct ath10k_mac_iter_tid_conf_data
*iter_data
= data
;
7449 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
7451 if (sta_vif
!= iter_data
->curr_vif
|| !sta
->wme
)
7454 ieee80211_queue_work(iter_data
->ar
->hw
, &arsta
->tid_config_wk
);
7457 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
7458 struct ieee80211_vif
*vif
,
7459 struct ieee80211_sta
*sta
,
7460 enum ieee80211_sta_state old_state
,
7461 enum ieee80211_sta_state new_state
)
7463 struct ath10k
*ar
= hw
->priv
;
7464 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7465 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7466 struct ath10k_peer
*peer
;
7470 if (old_state
== IEEE80211_STA_NOTEXIST
&&
7471 new_state
== IEEE80211_STA_NONE
) {
7472 memset(arsta
, 0, sizeof(*arsta
));
7473 arsta
->arvif
= arvif
;
7474 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
7475 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
7476 INIT_WORK(&arsta
->tid_config_wk
, ath10k_sta_tid_cfg_wk
);
7478 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
7479 ath10k_mac_txq_init(sta
->txq
[i
]);
7482 /* cancel must be done outside the mutex to avoid deadlock */
7483 if ((old_state
== IEEE80211_STA_NONE
&&
7484 new_state
== IEEE80211_STA_NOTEXIST
)) {
7485 cancel_work_sync(&arsta
->update_wk
);
7486 cancel_work_sync(&arsta
->tid_config_wk
);
7489 mutex_lock(&ar
->conf_mutex
);
7491 if (old_state
== IEEE80211_STA_NOTEXIST
&&
7492 new_state
== IEEE80211_STA_NONE
) {
7494 * New station addition.
7496 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
7497 u32 num_tdls_stations
;
7499 ath10k_dbg(ar
, ATH10K_DBG_STA
,
7500 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
7501 arvif
->vdev_id
, sta
->addr
,
7502 ar
->num_stations
+ 1, ar
->max_num_stations
,
7503 ar
->num_peers
+ 1, ar
->max_num_peers
);
7505 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
7508 if (num_tdls_stations
>= ar
->max_num_tdls_vdevs
) {
7509 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
7511 ar
->max_num_tdls_vdevs
);
7515 peer_type
= WMI_PEER_TYPE_TDLS
;
7518 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
7520 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
7521 ar
->max_num_stations
);
7525 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
7526 arsta
->tx_stats
= kzalloc(sizeof(*arsta
->tx_stats
),
7528 if (!arsta
->tx_stats
) {
7529 ath10k_mac_dec_num_stations(arvif
, sta
);
7535 ret
= ath10k_peer_create(ar
, vif
, sta
, arvif
->vdev_id
,
7536 sta
->addr
, peer_type
);
7538 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
7539 sta
->addr
, arvif
->vdev_id
, ret
);
7540 ath10k_mac_dec_num_stations(arvif
, sta
);
7541 kfree(arsta
->tx_stats
);
7545 spin_lock_bh(&ar
->data_lock
);
7547 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
7549 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
7550 vif
->addr
, arvif
->vdev_id
);
7551 spin_unlock_bh(&ar
->data_lock
);
7552 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7553 ath10k_mac_dec_num_stations(arvif
, sta
);
7554 kfree(arsta
->tx_stats
);
7559 arsta
->peer_id
= find_first_bit(peer
->peer_ids
,
7560 ATH10K_MAX_NUM_PEER_IDS
);
7562 spin_unlock_bh(&ar
->data_lock
);
7567 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7568 WMI_TDLS_ENABLE_ACTIVE
);
7570 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
7571 arvif
->vdev_id
, ret
);
7572 ath10k_peer_delete(ar
, arvif
->vdev_id
,
7574 ath10k_mac_dec_num_stations(arvif
, sta
);
7575 kfree(arsta
->tx_stats
);
7579 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
7580 WMI_TDLS_PEER_STATE_PEERING
);
7583 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
7584 sta
->addr
, arvif
->vdev_id
, ret
);
7585 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7586 ath10k_mac_dec_num_stations(arvif
, sta
);
7587 kfree(arsta
->tx_stats
);
7589 if (num_tdls_stations
!= 0)
7591 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7594 } else if ((old_state
== IEEE80211_STA_NONE
&&
7595 new_state
== IEEE80211_STA_NOTEXIST
)) {
7597 * Existing station deletion.
7599 ath10k_dbg(ar
, ATH10K_DBG_STA
,
7600 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
7601 arvif
->vdev_id
, sta
->addr
, sta
);
7604 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
,
7606 WMI_TDLS_PEER_STATE_TEARDOWN
);
7608 ath10k_warn(ar
, "failed to update tdls peer state for %pM state %d: %i\n",
7610 WMI_TDLS_PEER_STATE_TEARDOWN
, ret
);
7613 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7615 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
7616 sta
->addr
, arvif
->vdev_id
, ret
);
7618 ath10k_mac_dec_num_stations(arvif
, sta
);
7620 spin_lock_bh(&ar
->data_lock
);
7621 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
7622 peer
= ar
->peer_map
[i
];
7626 if (peer
->sta
== sta
) {
7627 ath10k_warn(ar
, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
7628 sta
->addr
, peer
, i
, arvif
->vdev_id
);
7631 /* Clean up the peer object as well since we
7632 * must have failed to do this above.
7634 ath10k_peer_map_cleanup(ar
, peer
);
7637 spin_unlock_bh(&ar
->data_lock
);
7639 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
7640 kfree(arsta
->tx_stats
);
7641 arsta
->tx_stats
= NULL
;
7644 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
7645 ath10k_mac_txq_unref(ar
, sta
->txq
[i
]);
7650 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
7653 /* This was the last tdls peer in current vif */
7654 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7657 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
7658 arvif
->vdev_id
, ret
);
7660 } else if (old_state
== IEEE80211_STA_AUTH
&&
7661 new_state
== IEEE80211_STA_ASSOC
&&
7662 (vif
->type
== NL80211_IFTYPE_AP
||
7663 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
7664 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
7668 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac sta %pM associated\n",
7671 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
7673 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
7674 sta
->addr
, arvif
->vdev_id
, ret
);
7675 } else if (old_state
== IEEE80211_STA_ASSOC
&&
7676 new_state
== IEEE80211_STA_AUTHORIZED
&&
7679 * Tdls station authorized.
7681 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac tdls sta %pM authorized\n",
7684 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
7686 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
7687 sta
->addr
, arvif
->vdev_id
, ret
);
7691 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
7692 WMI_TDLS_PEER_STATE_CONNECTED
);
7694 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
7695 sta
->addr
, arvif
->vdev_id
, ret
);
7696 } else if (old_state
== IEEE80211_STA_ASSOC
&&
7697 new_state
== IEEE80211_STA_AUTH
&&
7698 (vif
->type
== NL80211_IFTYPE_AP
||
7699 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
7700 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
7704 ath10k_dbg(ar
, ATH10K_DBG_STA
, "mac sta %pM disassociated\n",
7707 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
7709 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
7710 sta
->addr
, arvif
->vdev_id
, ret
);
7713 mutex_unlock(&ar
->conf_mutex
);
7717 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
7718 u16 ac
, bool enable
)
7720 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7721 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
7722 u32 prio
= 0, acc
= 0;
7726 lockdep_assert_held(&ar
->conf_mutex
);
7728 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
7732 case IEEE80211_AC_VO
:
7733 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
7734 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
7738 case IEEE80211_AC_VI
:
7739 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
7740 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
7744 case IEEE80211_AC_BE
:
7745 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
7746 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
7750 case IEEE80211_AC_BK
:
7751 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
7752 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
7759 arvif
->u
.sta
.uapsd
|= value
;
7761 arvif
->u
.sta
.uapsd
&= ~value
;
7763 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
7764 WMI_STA_PS_PARAM_UAPSD
,
7765 arvif
->u
.sta
.uapsd
);
7767 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
7771 if (arvif
->u
.sta
.uapsd
)
7772 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
7774 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
7776 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
7777 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
7780 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
7782 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
7784 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
7785 arvif
->vdev_id
, ret
);
7789 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
7791 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
7792 arvif
->vdev_id
, ret
);
7796 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
7797 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
7798 /* Only userspace can make an educated decision when to send
7799 * trigger frame. The following effectively disables u-UAPSD
7800 * autotrigger in firmware (which is enabled by default
7801 * provided the autotrigger service is available).
7805 arg
.user_priority
= prio
;
7806 arg
.service_interval
= 0;
7807 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
7808 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
7810 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
7811 arvif
->bssid
, &arg
, 1);
7813 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
7823 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
7824 struct ieee80211_vif
*vif
,
7825 unsigned int link_id
, u16 ac
,
7826 const struct ieee80211_tx_queue_params
*params
)
7828 struct ath10k
*ar
= hw
->priv
;
7829 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7830 struct wmi_wmm_params_arg
*p
= NULL
;
7833 mutex_lock(&ar
->conf_mutex
);
7836 case IEEE80211_AC_VO
:
7837 p
= &arvif
->wmm_params
.ac_vo
;
7839 case IEEE80211_AC_VI
:
7840 p
= &arvif
->wmm_params
.ac_vi
;
7842 case IEEE80211_AC_BE
:
7843 p
= &arvif
->wmm_params
.ac_be
;
7845 case IEEE80211_AC_BK
:
7846 p
= &arvif
->wmm_params
.ac_bk
;
7855 p
->cwmin
= params
->cw_min
;
7856 p
->cwmax
= params
->cw_max
;
7857 p
->aifs
= params
->aifs
;
7860 * The channel time duration programmed in the HW is in absolute
7861 * microseconds, while mac80211 gives the txop in units of
7864 p
->txop
= params
->txop
* 32;
7866 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
7867 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
7868 &arvif
->wmm_params
);
7870 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
7871 arvif
->vdev_id
, ret
);
7875 /* This won't work well with multi-interface cases but it's
7876 * better than nothing.
7878 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
7880 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
7885 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
7887 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
7890 mutex_unlock(&ar
->conf_mutex
);
7894 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
7895 struct ieee80211_vif
*vif
,
7896 struct ieee80211_channel
*chan
,
7898 enum ieee80211_roc_type type
)
7900 struct ath10k
*ar
= hw
->priv
;
7901 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7902 struct wmi_start_scan_arg arg
;
7906 mutex_lock(&ar
->conf_mutex
);
7908 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
7913 spin_lock_bh(&ar
->data_lock
);
7914 switch (ar
->scan
.state
) {
7915 case ATH10K_SCAN_IDLE
:
7916 reinit_completion(&ar
->scan
.started
);
7917 reinit_completion(&ar
->scan
.completed
);
7918 reinit_completion(&ar
->scan
.on_channel
);
7919 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
7920 ar
->scan
.is_roc
= true;
7921 ar
->scan
.vdev_id
= arvif
->vdev_id
;
7922 ar
->scan
.roc_freq
= chan
->center_freq
;
7923 ar
->scan
.roc_notify
= true;
7926 case ATH10K_SCAN_STARTING
:
7927 case ATH10K_SCAN_RUNNING
:
7928 case ATH10K_SCAN_ABORTING
:
7932 spin_unlock_bh(&ar
->data_lock
);
7937 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
7939 memset(&arg
, 0, sizeof(arg
));
7940 ath10k_wmi_start_scan_init(ar
, &arg
);
7941 arg
.vdev_id
= arvif
->vdev_id
;
7942 arg
.scan_id
= ATH10K_SCAN_ID
;
7944 arg
.channels
[0] = chan
->center_freq
;
7945 arg
.dwell_time_active
= scan_time_msec
;
7946 arg
.dwell_time_passive
= scan_time_msec
;
7947 arg
.max_scan_time
= scan_time_msec
;
7948 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
7949 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
7950 arg
.burst_duration_ms
= duration
;
7952 ret
= ath10k_start_scan(ar
, &arg
);
7954 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
7955 spin_lock_bh(&ar
->data_lock
);
7956 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
7957 spin_unlock_bh(&ar
->data_lock
);
7961 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3 * HZ
);
7963 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
7965 ret
= ath10k_scan_stop(ar
);
7967 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
7973 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
7974 msecs_to_jiffies(duration
));
7978 mutex_unlock(&ar
->conf_mutex
);
7982 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
,
7983 struct ieee80211_vif
*vif
)
7985 struct ath10k
*ar
= hw
->priv
;
7987 mutex_lock(&ar
->conf_mutex
);
7989 spin_lock_bh(&ar
->data_lock
);
7990 ar
->scan
.roc_notify
= false;
7991 spin_unlock_bh(&ar
->data_lock
);
7993 ath10k_scan_abort(ar
);
7995 mutex_unlock(&ar
->conf_mutex
);
7997 cancel_delayed_work_sync(&ar
->scan
.timeout
);
8003 * Both RTS and Fragmentation threshold are interface-specific
8004 * in ath10k, but device-specific in mac80211.
8007 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
8009 struct ath10k
*ar
= hw
->priv
;
8010 struct ath10k_vif
*arvif
;
8013 mutex_lock(&ar
->conf_mutex
);
8014 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
8015 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
8016 arvif
->vdev_id
, value
);
8018 ret
= ath10k_mac_set_rts(arvif
, value
);
8020 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
8021 arvif
->vdev_id
, ret
);
8025 mutex_unlock(&ar
->conf_mutex
);
8030 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
8032 /* Even though there's a WMI enum for fragmentation threshold no known
8033 * firmware actually implements it. Moreover it is not possible to rely
8034 * frame fragmentation to mac80211 because firmware clears the "more
8035 * fragments" bit in frame control making it impossible for remote
8036 * devices to reassemble frames.
8038 * Hence implement a dummy callback just to say fragmentation isn't
8039 * supported. This effectively prevents mac80211 from doing frame
8040 * fragmentation in software.
8045 void ath10k_mac_wait_tx_complete(struct ath10k
*ar
)
8050 /* mac80211 doesn't care if we really xmit queued frames or not
8051 * we'll collect those frames either way if we stop/delete vdevs
8054 if (ar
->state
== ATH10K_STATE_WEDGED
)
8057 time_left
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
8060 spin_lock_bh(&ar
->htt
.tx_lock
);
8061 empty
= (ar
->htt
.num_pending_tx
== 0);
8062 spin_unlock_bh(&ar
->htt
.tx_lock
);
8064 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
8065 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
8069 }), ATH10K_FLUSH_TIMEOUT_HZ
);
8071 if (time_left
== 0 || skip
)
8072 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
8073 skip
, ar
->state
, time_left
);
8076 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
8077 u32 queues
, bool drop
)
8079 struct ath10k
*ar
= hw
->priv
;
8080 struct ath10k_vif
*arvif
;
8084 if (vif
&& vif
->type
== NL80211_IFTYPE_STATION
) {
8085 bitmap
= ~(1 << WMI_MGMT_TID
);
8086 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
8087 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
8088 ath10k_wmi_peer_flush(ar
, arvif
->vdev_id
,
8089 arvif
->bssid
, bitmap
);
8091 ath10k_htt_flush_tx(&ar
->htt
);
8096 mutex_lock(&ar
->conf_mutex
);
8097 ath10k_mac_wait_tx_complete(ar
);
8098 mutex_unlock(&ar
->conf_mutex
);
8101 /* TODO: Implement this function properly
8102 * For now it is needed to reply to Probe Requests in IBSS mode.
8103 * Probably we need this information from FW.
8105 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
8110 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
8111 enum ieee80211_reconfig_type reconfig_type
)
8113 struct ath10k
*ar
= hw
->priv
;
8114 struct ath10k_vif
*arvif
;
8116 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
8119 mutex_lock(&ar
->conf_mutex
);
8121 /* If device failed to restart it will be in a different state, e.g.
8122 * ATH10K_STATE_WEDGED
8124 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
8125 ath10k_info(ar
, "device successfully recovered\n");
8126 ar
->state
= ATH10K_STATE_ON
;
8127 ieee80211_wake_queues(ar
->hw
);
8128 clear_bit(ATH10K_FLAG_RESTARTING
, &ar
->dev_flags
);
8129 if (ar
->hw_params
.hw_restart_disconnect
) {
8130 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
8131 if (arvif
->is_up
&& arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
8132 ieee80211_hw_restart_disconnect(arvif
->vif
);
8137 mutex_unlock(&ar
->conf_mutex
);
8141 ath10k_mac_update_bss_chan_survey(struct ath10k
*ar
,
8142 struct ieee80211_channel
*channel
)
8145 enum wmi_bss_survey_req_type type
= WMI_BSS_SURVEY_REQ_TYPE_READ
;
8147 lockdep_assert_held(&ar
->conf_mutex
);
8149 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64
, ar
->wmi
.svc_map
) ||
8150 (ar
->rx_channel
!= channel
))
8153 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
) {
8154 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "ignoring bss chan info request while scanning..\n");
8158 reinit_completion(&ar
->bss_survey_done
);
8160 ret
= ath10k_wmi_pdev_bss_chan_info_request(ar
, type
);
8162 ath10k_warn(ar
, "failed to send pdev bss chan info request\n");
8166 ret
= wait_for_completion_timeout(&ar
->bss_survey_done
, 3 * HZ
);
8168 ath10k_warn(ar
, "bss channel survey timed out\n");
8173 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
8174 struct survey_info
*survey
)
8176 struct ath10k
*ar
= hw
->priv
;
8177 struct ieee80211_supported_band
*sband
;
8178 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
8181 mutex_lock(&ar
->conf_mutex
);
8183 sband
= hw
->wiphy
->bands
[NL80211_BAND_2GHZ
];
8184 if (sband
&& idx
>= sband
->n_channels
) {
8185 idx
-= sband
->n_channels
;
8190 sband
= hw
->wiphy
->bands
[NL80211_BAND_5GHZ
];
8192 if (!sband
|| idx
>= sband
->n_channels
) {
8197 ath10k_mac_update_bss_chan_survey(ar
, &sband
->channels
[idx
]);
8199 spin_lock_bh(&ar
->data_lock
);
8200 memcpy(survey
, ar_survey
, sizeof(*survey
));
8201 spin_unlock_bh(&ar
->data_lock
);
8203 survey
->channel
= &sband
->channels
[idx
];
8205 if (ar
->rx_channel
== survey
->channel
)
8206 survey
->filled
|= SURVEY_INFO_IN_USE
;
8209 mutex_unlock(&ar
->conf_mutex
);
8214 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
8215 enum nl80211_band band
,
8216 const struct cfg80211_bitrate_mask
*mask
,
8219 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
8220 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8222 u8 vht_nss_mask
= 0;
8225 if (mask
->control
[band
].legacy
)
8228 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
8229 if (mask
->control
[band
].ht_mcs
[i
] == 0)
8231 else if (mask
->control
[band
].ht_mcs
[i
] ==
8232 sband
->ht_cap
.mcs
.rx_mask
[i
])
8233 ht_nss_mask
|= BIT(i
);
8238 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
8239 if (mask
->control
[band
].vht_mcs
[i
] == 0)
8241 else if (mask
->control
[band
].vht_mcs
[i
] ==
8242 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
8243 vht_nss_mask
|= BIT(i
);
8248 if (ht_nss_mask
!= vht_nss_mask
)
8251 if (ht_nss_mask
== 0)
8254 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
8257 *nss
= fls(ht_nss_mask
);
8262 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
8263 u8 rate
, u8 nss
, u8 sgi
, u8 ldpc
)
8265 struct ath10k
*ar
= arvif
->ar
;
8269 lockdep_assert_held(&ar
->conf_mutex
);
8271 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n",
8272 arvif
->vdev_id
, rate
, nss
, sgi
);
8274 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
8275 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
8277 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
8282 vdev_param
= ar
->wmi
.vdev_param
->nss
;
8283 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
8285 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
8289 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
8290 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
8292 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
8296 vdev_param
= ar
->wmi
.vdev_param
->ldpc
;
8297 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, ldpc
);
8299 ath10k_warn(ar
, "failed to set ldpc param %d: %d\n", ldpc
, ret
);
8307 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
8308 enum nl80211_band band
,
8309 const struct cfg80211_bitrate_mask
*mask
,
8315 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
8316 * to express all VHT MCS rate masks. Effectively only the following
8317 * ranges can be used: none, 0-7, 0-8 and 0-9.
8319 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8320 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
8330 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
8338 static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k
*ar
,
8339 struct ath10k_vif
*arvif
,
8340 struct ieee80211_sta
*sta
)
8343 u8 rate
= arvif
->vht_pfr
;
8345 /* skip non vht and multiple rate peers */
8346 if (!sta
->deflink
.vht_cap
.vht_supported
|| arvif
->vht_num_rates
!= 1)
8349 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
8350 WMI_PEER_PARAM_FIXED_RATE
, rate
);
8352 ath10k_warn(ar
, "failed to enable STA %pM peer fixed rate: %d\n",
8358 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
8359 struct ieee80211_sta
*sta
)
8361 struct ath10k_vif
*arvif
= data
;
8362 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8363 struct ath10k
*ar
= arvif
->ar
;
8365 if (arsta
->arvif
!= arvif
)
8368 if (ath10k_mac_set_vht_bitrate_mask_fixup(ar
, arvif
, sta
))
8371 spin_lock_bh(&ar
->data_lock
);
8372 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
8373 spin_unlock_bh(&ar
->data_lock
);
8375 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
8378 static void ath10k_mac_clr_bitrate_mask_iter(void *data
,
8379 struct ieee80211_sta
*sta
)
8381 struct ath10k_vif
*arvif
= data
;
8382 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8383 struct ath10k
*ar
= arvif
->ar
;
8386 /* clear vht peers only */
8387 if (arsta
->arvif
!= arvif
|| !sta
->deflink
.vht_cap
.vht_supported
)
8390 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
8391 WMI_PEER_PARAM_FIXED_RATE
,
8392 WMI_FIXED_RATE_NONE
);
8394 ath10k_warn(ar
, "failed to clear STA %pM peer fixed rate: %d\n",
8398 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
8399 struct ieee80211_vif
*vif
,
8400 const struct cfg80211_bitrate_mask
*mask
)
8402 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8403 struct cfg80211_chan_def def
;
8404 struct ath10k
*ar
= arvif
->ar
;
8405 enum nl80211_band band
;
8406 const u8
*ht_mcs_mask
;
8407 const u16
*vht_mcs_mask
;
8414 int vht_num_rates
, allow_pfr
;
8416 bool update_bitrate_mask
= true;
8418 if (ath10k_mac_vif_chan(vif
, &def
))
8421 band
= def
.chan
->band
;
8422 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
8423 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
8424 ldpc
= !!(ar
->ht_cap_info
& WMI_HT_CAP_LDPC
);
8426 sgi
= mask
->control
[band
].gi
;
8427 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
8430 allow_pfr
= test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE
,
8431 ar
->normal_mode_fw
.fw_file
.fw_features
);
8433 mutex_lock(&ar
->conf_mutex
);
8434 ieee80211_iterate_stations_atomic(ar
->hw
,
8435 ath10k_mac_clr_bitrate_mask_iter
,
8437 mutex_unlock(&ar
->conf_mutex
);
8440 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
8442 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
8446 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
8447 arvif
->vdev_id
, ret
);
8450 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
8452 rate
= WMI_FIXED_RATE_NONE
;
8455 rate
= WMI_FIXED_RATE_NONE
;
8456 nss
= min(ar
->num_rf_chains
,
8457 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
8458 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
8460 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
,
8464 if (!allow_pfr
|| vht_num_rates
!= 1)
8467 /* Reach here, firmware supports peer fixed rate and has
8468 * single vht rate, and don't update vif birate_mask, as
8469 * the rate only for specific peer.
8471 ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
8475 update_bitrate_mask
= false;
8480 mutex_lock(&ar
->conf_mutex
);
8482 if (update_bitrate_mask
)
8483 arvif
->bitrate_mask
= *mask
;
8484 arvif
->vht_num_rates
= vht_num_rates
;
8485 arvif
->vht_pfr
= vht_pfr
;
8486 ieee80211_iterate_stations_atomic(ar
->hw
,
8487 ath10k_mac_set_bitrate_mask_iter
,
8490 mutex_unlock(&ar
->conf_mutex
);
8493 mutex_lock(&ar
->conf_mutex
);
8495 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
, ldpc
);
8497 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
8498 arvif
->vdev_id
, ret
);
8503 mutex_unlock(&ar
->conf_mutex
);
8508 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
8509 struct ieee80211_vif
*vif
,
8510 struct ieee80211_sta
*sta
,
8513 struct ath10k
*ar
= hw
->priv
;
8514 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8515 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8516 struct ath10k_peer
*peer
;
8519 spin_lock_bh(&ar
->data_lock
);
8521 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
8523 spin_unlock_bh(&ar
->data_lock
);
8524 ath10k_warn(ar
, "mac sta rc update failed to find peer %pM on vdev %i\n",
8525 sta
->addr
, arvif
->vdev_id
);
8529 ath10k_dbg(ar
, ATH10K_DBG_STA
,
8530 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
8531 sta
->addr
, changed
, sta
->deflink
.bandwidth
,
8532 sta
->deflink
.rx_nss
,
8533 sta
->deflink
.smps_mode
);
8535 if (changed
& IEEE80211_RC_BW_CHANGED
) {
8536 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8538 switch (sta
->deflink
.bandwidth
) {
8539 case IEEE80211_STA_RX_BW_20
:
8540 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8542 case IEEE80211_STA_RX_BW_40
:
8543 bw
= WMI_PEER_CHWIDTH_40MHZ
;
8545 case IEEE80211_STA_RX_BW_80
:
8546 bw
= WMI_PEER_CHWIDTH_80MHZ
;
8548 case IEEE80211_STA_RX_BW_160
:
8549 bw
= WMI_PEER_CHWIDTH_160MHZ
;
8552 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
8553 sta
->deflink
.bandwidth
, sta
->addr
);
8554 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8561 if (changed
& IEEE80211_RC_NSS_CHANGED
)
8562 arsta
->nss
= sta
->deflink
.rx_nss
;
8564 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
8565 smps
= WMI_PEER_SMPS_PS_NONE
;
8567 switch (sta
->deflink
.smps_mode
) {
8568 case IEEE80211_SMPS_AUTOMATIC
:
8569 case IEEE80211_SMPS_OFF
:
8570 smps
= WMI_PEER_SMPS_PS_NONE
;
8572 case IEEE80211_SMPS_STATIC
:
8573 smps
= WMI_PEER_SMPS_STATIC
;
8575 case IEEE80211_SMPS_DYNAMIC
:
8576 smps
= WMI_PEER_SMPS_DYNAMIC
;
8578 case IEEE80211_SMPS_NUM_MODES
:
8579 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
8580 sta
->deflink
.smps_mode
, sta
->addr
);
8581 smps
= WMI_PEER_SMPS_PS_NONE
;
8588 arsta
->changed
|= changed
;
8590 spin_unlock_bh(&ar
->data_lock
);
8592 ieee80211_queue_work(hw
, &arsta
->update_wk
);
8595 static void ath10k_offset_tsf(struct ieee80211_hw
*hw
,
8596 struct ieee80211_vif
*vif
, s64 tsf_offset
)
8598 struct ath10k
*ar
= hw
->priv
;
8599 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8600 u32 offset
, vdev_param
;
8603 if (tsf_offset
< 0) {
8604 vdev_param
= ar
->wmi
.vdev_param
->dec_tsf
;
8605 offset
= -tsf_offset
;
8607 vdev_param
= ar
->wmi
.vdev_param
->inc_tsf
;
8608 offset
= tsf_offset
;
8611 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
8612 vdev_param
, offset
);
8614 if (ret
&& ret
!= -EOPNOTSUPP
)
8615 ath10k_warn(ar
, "failed to set tsf offset %d cmd %d: %d\n",
8616 offset
, vdev_param
, ret
);
8619 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
8620 struct ieee80211_vif
*vif
,
8621 struct ieee80211_ampdu_params
*params
)
8623 struct ath10k
*ar
= hw
->priv
;
8624 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8625 struct ieee80211_sta
*sta
= params
->sta
;
8626 enum ieee80211_ampdu_mlme_action action
= params
->action
;
8627 u16 tid
= params
->tid
;
8629 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %u action %d\n",
8630 arvif
->vdev_id
, sta
->addr
, tid
, action
);
8633 case IEEE80211_AMPDU_RX_START
:
8634 case IEEE80211_AMPDU_RX_STOP
:
8635 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
8636 * creation/removal. Do we need to verify this?
8639 case IEEE80211_AMPDU_TX_START
:
8640 case IEEE80211_AMPDU_TX_STOP_CONT
:
8641 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
8642 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
8643 case IEEE80211_AMPDU_TX_OPERATIONAL
:
8644 /* Firmware offloads Tx aggregation entirely so deny mac80211
8645 * Tx aggregation requests.
8654 ath10k_mac_update_rx_channel(struct ath10k
*ar
,
8655 struct ieee80211_chanctx_conf
*ctx
,
8656 struct ieee80211_vif_chanctx_switch
*vifs
,
8659 struct cfg80211_chan_def
*def
= NULL
;
8661 /* Both locks are required because ar->rx_channel is modified. This
8662 * allows readers to hold either lock.
8664 lockdep_assert_held(&ar
->conf_mutex
);
8665 lockdep_assert_held(&ar
->data_lock
);
8667 WARN_ON(ctx
&& vifs
);
8668 WARN_ON(vifs
&& !n_vifs
);
8670 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
8671 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
8672 * ppdu on Rx may reduce performance on low-end systems. It should be
8673 * possible to make tables/hashmaps to speed the lookup up (be vary of
8674 * cpu data cache lines though regarding sizes) but to keep the initial
8675 * implementation simple and less intrusive fallback to the slow lookup
8676 * only for multi-channel cases. Single-channel cases will remain to
8677 * use the old channel derival and thus performance should not be
8681 if (!ctx
&& ath10k_mac_num_chanctxs(ar
) == 1) {
8682 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
8683 ath10k_mac_get_any_chandef_iter
,
8687 def
= &vifs
[0].new_ctx
->def
;
8689 ar
->rx_channel
= def
->chan
;
8690 } else if ((ctx
&& ath10k_mac_num_chanctxs(ar
) == 0) ||
8691 (ctx
&& (ar
->state
== ATH10K_STATE_RESTARTED
))) {
8692 /* During driver restart due to firmware assert, since mac80211
8693 * already has valid channel context for given radio, channel
8694 * context iteration return num_chanctx > 0. So fix rx_channel
8695 * when restart is in progress.
8697 ar
->rx_channel
= ctx
->def
.chan
;
8699 ar
->rx_channel
= NULL
;
8705 ath10k_mac_update_vif_chan(struct ath10k
*ar
,
8706 struct ieee80211_vif_chanctx_switch
*vifs
,
8709 struct ath10k_vif
*arvif
;
8713 lockdep_assert_held(&ar
->conf_mutex
);
8715 /* First stop monitor interface. Some FW versions crash if there's a
8716 * lone monitor interface.
8718 if (ar
->monitor_started
)
8719 ath10k_monitor_stop(ar
);
8721 for (i
= 0; i
< n_vifs
; i
++) {
8722 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
8724 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8725 "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n",
8727 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
8728 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
8729 vifs
[i
].old_ctx
->def
.width
,
8730 vifs
[i
].new_ctx
->def
.width
);
8732 if (WARN_ON(!arvif
->is_started
))
8735 if (WARN_ON(!arvif
->is_up
))
8738 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
8740 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
8741 arvif
->vdev_id
, ret
);
8746 /* All relevant vdevs are downed and associated channel resources
8747 * should be available for the channel switch now.
8750 spin_lock_bh(&ar
->data_lock
);
8751 ath10k_mac_update_rx_channel(ar
, NULL
, vifs
, n_vifs
);
8752 spin_unlock_bh(&ar
->data_lock
);
8754 for (i
= 0; i
< n_vifs
; i
++) {
8755 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
8757 if (WARN_ON(!arvif
->is_started
))
8760 if (WARN_ON(!arvif
->is_up
))
8763 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
8765 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
8768 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
8770 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
8773 ret
= ath10k_vdev_restart(arvif
, &vifs
[i
].new_ctx
->def
);
8775 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
8776 arvif
->vdev_id
, ret
);
8780 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
8783 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
8784 arvif
->vdev_id
, ret
);
8789 ath10k_monitor_recalc(ar
);
8793 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
8794 struct ieee80211_chanctx_conf
*ctx
)
8796 struct ath10k
*ar
= hw
->priv
;
8798 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8799 "mac chanctx add freq %u width %d ptr %pK\n",
8800 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8802 mutex_lock(&ar
->conf_mutex
);
8804 spin_lock_bh(&ar
->data_lock
);
8805 ath10k_mac_update_rx_channel(ar
, ctx
, NULL
, 0);
8806 spin_unlock_bh(&ar
->data_lock
);
8808 ath10k_recalc_radar_detection(ar
);
8809 ath10k_monitor_recalc(ar
);
8811 mutex_unlock(&ar
->conf_mutex
);
8817 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
8818 struct ieee80211_chanctx_conf
*ctx
)
8820 struct ath10k
*ar
= hw
->priv
;
8822 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8823 "mac chanctx remove freq %u width %d ptr %pK\n",
8824 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8826 mutex_lock(&ar
->conf_mutex
);
8828 spin_lock_bh(&ar
->data_lock
);
8829 ath10k_mac_update_rx_channel(ar
, NULL
, NULL
, 0);
8830 spin_unlock_bh(&ar
->data_lock
);
8832 ath10k_recalc_radar_detection(ar
);
8833 ath10k_monitor_recalc(ar
);
8835 mutex_unlock(&ar
->conf_mutex
);
8838 struct ath10k_mac_change_chanctx_arg
{
8839 struct ieee80211_chanctx_conf
*ctx
;
8840 struct ieee80211_vif_chanctx_switch
*vifs
;
8846 ath10k_mac_change_chanctx_cnt_iter(void *data
, u8
*mac
,
8847 struct ieee80211_vif
*vif
)
8849 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8851 if (rcu_access_pointer(vif
->bss_conf
.chanctx_conf
) != arg
->ctx
)
8858 ath10k_mac_change_chanctx_fill_iter(void *data
, u8
*mac
,
8859 struct ieee80211_vif
*vif
)
8861 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8862 struct ieee80211_chanctx_conf
*ctx
;
8864 ctx
= rcu_access_pointer(vif
->bss_conf
.chanctx_conf
);
8865 if (ctx
!= arg
->ctx
)
8868 if (WARN_ON(arg
->next_vif
== arg
->n_vifs
))
8871 arg
->vifs
[arg
->next_vif
].vif
= vif
;
8872 arg
->vifs
[arg
->next_vif
].old_ctx
= ctx
;
8873 arg
->vifs
[arg
->next_vif
].new_ctx
= ctx
;
8878 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
8879 struct ieee80211_chanctx_conf
*ctx
,
8882 struct ath10k
*ar
= hw
->priv
;
8883 struct ath10k_mac_change_chanctx_arg arg
= { .ctx
= ctx
};
8885 mutex_lock(&ar
->conf_mutex
);
8887 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8888 "mac chanctx change freq %u width %d ptr %pK changed %x\n",
8889 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
, changed
);
8891 /* This shouldn't really happen because channel switching should use
8892 * switch_vif_chanctx().
8894 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
8897 if (changed
& IEEE80211_CHANCTX_CHANGE_WIDTH
) {
8898 ieee80211_iterate_active_interfaces_atomic(
8900 ATH10K_ITER_NORMAL_FLAGS
,
8901 ath10k_mac_change_chanctx_cnt_iter
,
8903 if (arg
.n_vifs
== 0)
8906 arg
.vifs
= kcalloc(arg
.n_vifs
, sizeof(arg
.vifs
[0]),
8911 ieee80211_iterate_active_interfaces_atomic(
8913 ATH10K_ITER_NORMAL_FLAGS
,
8914 ath10k_mac_change_chanctx_fill_iter
,
8916 ath10k_mac_update_vif_chan(ar
, arg
.vifs
, arg
.n_vifs
);
8921 ath10k_recalc_radar_detection(ar
);
8923 /* FIXME: How to configure Rx chains properly? */
8925 /* No other actions are actually necessary. Firmware maintains channel
8926 * definitions per vdev internally and there's no host-side channel
8927 * context abstraction to configure, e.g. channel width.
8931 mutex_unlock(&ar
->conf_mutex
);
8935 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
8936 struct ieee80211_vif
*vif
,
8937 struct ieee80211_bss_conf
*link_conf
,
8938 struct ieee80211_chanctx_conf
*ctx
)
8940 struct ath10k
*ar
= hw
->priv
;
8941 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8944 mutex_lock(&ar
->conf_mutex
);
8946 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8947 "mac chanctx assign ptr %pK vdev_id %i\n",
8948 ctx
, arvif
->vdev_id
);
8950 if (WARN_ON(arvif
->is_started
)) {
8951 mutex_unlock(&ar
->conf_mutex
);
8955 ret
= ath10k_vdev_start(arvif
, &ctx
->def
);
8957 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
8958 arvif
->vdev_id
, vif
->addr
,
8959 ctx
->def
.chan
->center_freq
, ret
);
8963 arvif
->is_started
= true;
8965 ret
= ath10k_mac_vif_setup_ps(arvif
);
8967 ath10k_warn(ar
, "failed to update vdev %i ps: %d\n",
8968 arvif
->vdev_id
, ret
);
8972 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
8973 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
8975 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
8976 arvif
->vdev_id
, ret
);
8980 arvif
->is_up
= true;
8983 if (ath10k_mac_can_set_cts_prot(arvif
)) {
8984 ret
= ath10k_mac_set_cts_prot(arvif
);
8986 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
8987 arvif
->vdev_id
, ret
);
8990 if (ath10k_peer_stats_enabled(ar
) &&
8991 ar
->hw_params
.tx_stats_over_pktlog
) {
8992 ar
->pktlog_filter
|= ATH10K_PKTLOG_PEER_STATS
;
8993 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
8996 ath10k_warn(ar
, "failed to enable pktlog %d\n", ret
);
9001 mutex_unlock(&ar
->conf_mutex
);
9005 ath10k_vdev_stop(arvif
);
9006 arvif
->is_started
= false;
9007 ath10k_mac_vif_setup_ps(arvif
);
9010 mutex_unlock(&ar
->conf_mutex
);
9015 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
9016 struct ieee80211_vif
*vif
,
9017 struct ieee80211_bss_conf
*link_conf
,
9018 struct ieee80211_chanctx_conf
*ctx
)
9020 struct ath10k
*ar
= hw
->priv
;
9021 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9024 mutex_lock(&ar
->conf_mutex
);
9026 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9027 "mac chanctx unassign ptr %pK vdev_id %i\n",
9028 ctx
, arvif
->vdev_id
);
9030 WARN_ON(!arvif
->is_started
);
9032 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
9033 WARN_ON(!arvif
->is_up
);
9035 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
9037 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
9038 arvif
->vdev_id
, ret
);
9040 arvif
->is_up
= false;
9043 ret
= ath10k_vdev_stop(arvif
);
9045 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
9046 arvif
->vdev_id
, ret
);
9048 arvif
->is_started
= false;
9050 mutex_unlock(&ar
->conf_mutex
);
9054 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
9055 struct ieee80211_vif_chanctx_switch
*vifs
,
9057 enum ieee80211_chanctx_switch_mode mode
)
9059 struct ath10k
*ar
= hw
->priv
;
9061 mutex_lock(&ar
->conf_mutex
);
9063 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9064 "mac chanctx switch n_vifs %d mode %d\n",
9066 ath10k_mac_update_vif_chan(ar
, vifs
, n_vifs
);
9068 mutex_unlock(&ar
->conf_mutex
);
9072 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
9073 struct ieee80211_vif
*vif
,
9074 struct ieee80211_sta
*sta
)
9077 struct ath10k_peer
*peer
;
9081 list_for_each_entry(peer
, &ar
->peers
, list
)
9082 if (peer
->sta
== sta
)
9083 peer
->removed
= true;
9086 /* HT MCS parameters with Nss = 1 */
9087 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss1
[] = {
9088 /* MCS L20 L40 S20 S40 */
9089 {0, { 65, 135, 72, 150} },
9090 {1, { 130, 270, 144, 300} },
9091 {2, { 195, 405, 217, 450} },
9092 {3, { 260, 540, 289, 600} },
9093 {4, { 390, 810, 433, 900} },
9094 {5, { 520, 1080, 578, 1200} },
9095 {6, { 585, 1215, 650, 1350} },
9096 {7, { 650, 1350, 722, 1500} }
9099 /* HT MCS parameters with Nss = 2 */
9100 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss2
[] = {
9101 /* MCS L20 L40 S20 S40 */
9102 {0, {130, 270, 144, 300} },
9103 {1, {260, 540, 289, 600} },
9104 {2, {390, 810, 433, 900} },
9105 {3, {520, 1080, 578, 1200} },
9106 {4, {780, 1620, 867, 1800} },
9107 {5, {1040, 2160, 1156, 2400} },
9108 {6, {1170, 2430, 1300, 2700} },
9109 {7, {1300, 2700, 1444, 3000} }
9112 /* MCS parameters with Nss = 1 */
9113 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss1
[] = {
9114 /* MCS L80 S80 L40 S40 L20 S20 */
9115 {0, {293, 325}, {135, 150}, {65, 72} },
9116 {1, {585, 650}, {270, 300}, {130, 144} },
9117 {2, {878, 975}, {405, 450}, {195, 217} },
9118 {3, {1170, 1300}, {540, 600}, {260, 289} },
9119 {4, {1755, 1950}, {810, 900}, {390, 433} },
9120 {5, {2340, 2600}, {1080, 1200}, {520, 578} },
9121 {6, {2633, 2925}, {1215, 1350}, {585, 650} },
9122 {7, {2925, 3250}, {1350, 1500}, {650, 722} },
9123 {8, {3510, 3900}, {1620, 1800}, {780, 867} },
9124 {9, {3900, 4333}, {1800, 2000}, {780, 867} }
9127 /*MCS parameters with Nss = 2 */
9128 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss2
[] = {
9129 /* MCS L80 S80 L40 S40 L20 S20 */
9130 {0, {585, 650}, {270, 300}, {130, 144} },
9131 {1, {1170, 1300}, {540, 600}, {260, 289} },
9132 {2, {1755, 1950}, {810, 900}, {390, 433} },
9133 {3, {2340, 2600}, {1080, 1200}, {520, 578} },
9134 {4, {3510, 3900}, {1620, 1800}, {780, 867} },
9135 {5, {4680, 5200}, {2160, 2400}, {1040, 1156} },
9136 {6, {5265, 5850}, {2430, 2700}, {1170, 1300} },
9137 {7, {5850, 6500}, {2700, 3000}, {1300, 1444} },
9138 {8, {7020, 7800}, {3240, 3600}, {1560, 1733} },
9139 {9, {7800, 8667}, {3600, 4000}, {1560, 1733} }
9142 static void ath10k_mac_get_rate_flags_ht(struct ath10k
*ar
, u32 rate
, u8 nss
, u8 mcs
,
9145 struct ath10k_index_ht_data_rate_type
*mcs_rate
;
9147 size_t len_nss1
= ARRAY_SIZE(supported_ht_mcs_rate_nss1
);
9148 size_t len_nss2
= ARRAY_SIZE(supported_ht_mcs_rate_nss2
);
9150 if (mcs
>= (len_nss1
+ len_nss2
)) {
9151 ath10k_warn(ar
, "not supported mcs %d in current rate table", mcs
);
9155 mcs_rate
= (struct ath10k_index_ht_data_rate_type
*)
9156 ((nss
== 1) ? &supported_ht_mcs_rate_nss1
:
9157 &supported_ht_mcs_rate_nss2
);
9159 if (mcs
>= len_nss1
)
9160 index
= mcs
- len_nss1
;
9164 if (rate
== mcs_rate
[index
].supported_rate
[0]) {
9165 *bw
= RATE_INFO_BW_20
;
9166 } else if (rate
== mcs_rate
[index
].supported_rate
[1]) {
9167 *bw
|= RATE_INFO_BW_40
;
9168 } else if (rate
== mcs_rate
[index
].supported_rate
[2]) {
9169 *bw
|= RATE_INFO_BW_20
;
9170 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9171 } else if (rate
== mcs_rate
[index
].supported_rate
[3]) {
9172 *bw
|= RATE_INFO_BW_40
;
9173 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9175 ath10k_warn(ar
, "invalid ht params rate %d 100kbps nss %d mcs %d",
9180 static void ath10k_mac_get_rate_flags_vht(struct ath10k
*ar
, u32 rate
, u8 nss
, u8 mcs
,
9183 struct ath10k_index_vht_data_rate_type
*mcs_rate
;
9185 mcs_rate
= (struct ath10k_index_vht_data_rate_type
*)
9186 ((nss
== 1) ? &supported_vht_mcs_rate_nss1
:
9187 &supported_vht_mcs_rate_nss2
);
9189 if (rate
== mcs_rate
[mcs
].supported_VHT80_rate
[0]) {
9190 *bw
= RATE_INFO_BW_80
;
9191 } else if (rate
== mcs_rate
[mcs
].supported_VHT80_rate
[1]) {
9192 *bw
= RATE_INFO_BW_80
;
9193 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9194 } else if (rate
== mcs_rate
[mcs
].supported_VHT40_rate
[0]) {
9195 *bw
= RATE_INFO_BW_40
;
9196 } else if (rate
== mcs_rate
[mcs
].supported_VHT40_rate
[1]) {
9197 *bw
= RATE_INFO_BW_40
;
9198 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9199 } else if (rate
== mcs_rate
[mcs
].supported_VHT20_rate
[0]) {
9200 *bw
= RATE_INFO_BW_20
;
9201 } else if (rate
== mcs_rate
[mcs
].supported_VHT20_rate
[1]) {
9202 *bw
= RATE_INFO_BW_20
;
9203 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9205 ath10k_warn(ar
, "invalid vht params rate %d 100kbps nss %d mcs %d",
9210 static void ath10k_mac_get_rate_flags(struct ath10k
*ar
, u32 rate
,
9211 enum ath10k_phy_mode mode
, u8 nss
, u8 mcs
,
9214 if (mode
== ATH10K_PHY_MODE_HT
) {
9215 *flags
= RATE_INFO_FLAGS_MCS
;
9216 ath10k_mac_get_rate_flags_ht(ar
, rate
, nss
, mcs
, flags
, bw
);
9217 } else if (mode
== ATH10K_PHY_MODE_VHT
) {
9218 *flags
= RATE_INFO_FLAGS_VHT_MCS
;
9219 ath10k_mac_get_rate_flags_vht(ar
, rate
, nss
, mcs
, flags
, bw
);
9223 static void ath10k_mac_parse_bitrate(struct ath10k
*ar
, u32 rate_code
,
9224 u32 bitrate_kbps
, struct rate_info
*rate
)
9226 enum ath10k_phy_mode mode
= ATH10K_PHY_MODE_LEGACY
;
9227 enum wmi_rate_preamble preamble
= WMI_TLV_GET_HW_RC_PREAM_V1(rate_code
);
9228 u8 nss
= WMI_TLV_GET_HW_RC_NSS_V1(rate_code
) + 1;
9229 u8 mcs
= WMI_TLV_GET_HW_RC_RATE_V1(rate_code
);
9230 u8 flags
= 0, bw
= 0;
9232 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac parse rate code 0x%x bitrate %d kbps\n",
9233 rate_code
, bitrate_kbps
);
9235 if (preamble
== WMI_RATE_PREAMBLE_HT
)
9236 mode
= ATH10K_PHY_MODE_HT
;
9237 else if (preamble
== WMI_RATE_PREAMBLE_VHT
)
9238 mode
= ATH10K_PHY_MODE_VHT
;
9240 ath10k_mac_get_rate_flags(ar
, bitrate_kbps
/ 100, mode
, nss
, mcs
, &flags
, &bw
);
9242 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9243 "mac parse bitrate preamble %d mode %d nss %d mcs %d flags %x bw %d\n",
9244 preamble
, mode
, nss
, mcs
, flags
, bw
);
9246 rate
->flags
= flags
;
9248 rate
->legacy
= bitrate_kbps
/ 100;
9253 static void ath10k_mac_sta_get_peer_stats_info(struct ath10k
*ar
,
9254 struct ieee80211_sta
*sta
,
9255 struct station_info
*sinfo
)
9257 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
9258 struct ath10k_peer
*peer
;
9259 unsigned long time_left
;
9262 if (!(ar
->hw_params
.supports_peer_stats_info
&&
9263 arsta
->arvif
->vdev_type
== WMI_VDEV_TYPE_STA
))
9266 spin_lock_bh(&ar
->data_lock
);
9267 peer
= ath10k_peer_find(ar
, arsta
->arvif
->vdev_id
, sta
->addr
);
9268 spin_unlock_bh(&ar
->data_lock
);
9272 reinit_completion(&ar
->peer_stats_info_complete
);
9274 ret
= ath10k_wmi_request_peer_stats_info(ar
,
9275 arsta
->arvif
->vdev_id
,
9276 WMI_REQUEST_ONE_PEER_STATS_INFO
,
9277 arsta
->arvif
->bssid
,
9279 if (ret
&& ret
!= -EOPNOTSUPP
) {
9280 ath10k_warn(ar
, "could not request peer stats info: %d\n", ret
);
9284 time_left
= wait_for_completion_timeout(&ar
->peer_stats_info_complete
, 3 * HZ
);
9285 if (time_left
== 0) {
9286 ath10k_warn(ar
, "timed out waiting peer stats info\n");
9290 if (arsta
->rx_rate_code
!= 0 && arsta
->rx_bitrate_kbps
!= 0) {
9291 ath10k_mac_parse_bitrate(ar
, arsta
->rx_rate_code
,
9292 arsta
->rx_bitrate_kbps
,
9295 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_BITRATE
);
9296 arsta
->rx_rate_code
= 0;
9297 arsta
->rx_bitrate_kbps
= 0;
9300 if (arsta
->tx_rate_code
!= 0 && arsta
->tx_bitrate_kbps
!= 0) {
9301 ath10k_mac_parse_bitrate(ar
, arsta
->tx_rate_code
,
9302 arsta
->tx_bitrate_kbps
,
9305 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
9306 arsta
->tx_rate_code
= 0;
9307 arsta
->tx_bitrate_kbps
= 0;
9311 static void ath10k_sta_statistics(struct ieee80211_hw
*hw
,
9312 struct ieee80211_vif
*vif
,
9313 struct ieee80211_sta
*sta
,
9314 struct station_info
*sinfo
)
9316 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
9317 struct ath10k
*ar
= arsta
->arvif
->ar
;
9319 if (!ath10k_peer_stats_enabled(ar
))
9322 mutex_lock(&ar
->conf_mutex
);
9323 ath10k_debug_fw_stats_request(ar
);
9324 mutex_unlock(&ar
->conf_mutex
);
9326 sinfo
->rx_duration
= arsta
->rx_duration
;
9327 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_DURATION
);
9329 if (arsta
->txrate
.legacy
|| arsta
->txrate
.nss
) {
9330 if (arsta
->txrate
.legacy
) {
9331 sinfo
->txrate
.legacy
= arsta
->txrate
.legacy
;
9333 sinfo
->txrate
.mcs
= arsta
->txrate
.mcs
;
9334 sinfo
->txrate
.nss
= arsta
->txrate
.nss
;
9335 sinfo
->txrate
.bw
= arsta
->txrate
.bw
;
9337 sinfo
->txrate
.flags
= arsta
->txrate
.flags
;
9338 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
9341 if (ar
->htt
.disable_tx_comp
) {
9342 sinfo
->tx_failed
= arsta
->tx_failed
;
9343 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_FAILED
);
9346 sinfo
->tx_retries
= arsta
->tx_retries
;
9347 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_RETRIES
);
9349 ath10k_mac_sta_get_peer_stats_info(ar
, sta
, sinfo
);
9352 static int ath10k_mac_op_set_tid_config(struct ieee80211_hw
*hw
,
9353 struct ieee80211_vif
*vif
,
9354 struct ieee80211_sta
*sta
,
9355 struct cfg80211_tid_config
*tid_config
)
9357 struct ath10k
*ar
= hw
->priv
;
9358 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9359 struct ath10k_mac_iter_tid_conf_data data
= {};
9360 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
9363 mutex_lock(&ar
->conf_mutex
);
9364 arg
.vdev_id
= arvif
->vdev_id
;
9366 arvif
->tids_rst
= 0;
9367 memset(arvif
->tid_conf_changed
, 0, sizeof(arvif
->tid_conf_changed
));
9369 for (i
= 0; i
< tid_config
->n_tid_conf
; i
++) {
9370 ret
= ath10k_mac_parse_tid_config(ar
, sta
, vif
,
9371 &tid_config
->tid_conf
[i
],
9382 arvif
->tids_rst
= 0;
9383 data
.curr_vif
= vif
;
9386 ieee80211_iterate_stations_atomic(hw
, ath10k_mac_vif_stations_tid_conf
,
9390 mutex_unlock(&ar
->conf_mutex
);
9394 static int ath10k_mac_op_reset_tid_config(struct ieee80211_hw
*hw
,
9395 struct ieee80211_vif
*vif
,
9396 struct ieee80211_sta
*sta
,
9399 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9400 struct ath10k_mac_iter_tid_conf_data data
= {};
9401 struct ath10k
*ar
= hw
->priv
;
9404 mutex_lock(&ar
->conf_mutex
);
9407 arvif
->tids_rst
= 0;
9408 ret
= ath10k_mac_reset_tid_config(ar
, sta
, arvif
, tids
);
9412 arvif
->tids_rst
= tids
;
9413 data
.curr_vif
= vif
;
9415 ieee80211_iterate_stations_atomic(hw
, ath10k_mac_vif_stations_tid_conf
,
9419 mutex_unlock(&ar
->conf_mutex
);
9423 static const struct ieee80211_ops ath10k_ops
= {
9424 .tx
= ath10k_mac_op_tx
,
9425 .wake_tx_queue
= ath10k_mac_op_wake_tx_queue
,
9426 .start
= ath10k_start
,
9427 .stop
= ath10k_stop
,
9428 .config
= ath10k_config
,
9429 .add_interface
= ath10k_add_interface
,
9430 .update_vif_offload
= ath10k_update_vif_offload
,
9431 .remove_interface
= ath10k_remove_interface
,
9432 .configure_filter
= ath10k_configure_filter
,
9433 .bss_info_changed
= ath10k_bss_info_changed
,
9434 .set_coverage_class
= ath10k_mac_op_set_coverage_class
,
9435 .hw_scan
= ath10k_hw_scan
,
9436 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
9437 .set_key
= ath10k_set_key
,
9438 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
9439 .sta_state
= ath10k_sta_state
,
9440 .sta_set_txpwr
= ath10k_sta_set_txpwr
,
9441 .conf_tx
= ath10k_conf_tx
,
9442 .remain_on_channel
= ath10k_remain_on_channel
,
9443 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
9444 .set_rts_threshold
= ath10k_set_rts_threshold
,
9445 .set_frag_threshold
= ath10k_mac_op_set_frag_threshold
,
9446 .flush
= ath10k_flush
,
9447 .tx_last_beacon
= ath10k_tx_last_beacon
,
9448 .set_antenna
= ath10k_set_antenna
,
9449 .get_antenna
= ath10k_get_antenna
,
9450 .reconfig_complete
= ath10k_reconfig_complete
,
9451 .get_survey
= ath10k_get_survey
,
9452 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
9453 .sta_rc_update
= ath10k_sta_rc_update
,
9454 .offset_tsf
= ath10k_offset_tsf
,
9455 .ampdu_action
= ath10k_ampdu_action
,
9456 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
9457 .get_et_stats
= ath10k_debug_get_et_stats
,
9458 .get_et_strings
= ath10k_debug_get_et_strings
,
9459 .add_chanctx
= ath10k_mac_op_add_chanctx
,
9460 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
9461 .change_chanctx
= ath10k_mac_op_change_chanctx
,
9462 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
9463 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
9464 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
9465 .sta_pre_rcu_remove
= ath10k_mac_op_sta_pre_rcu_remove
,
9466 .sta_statistics
= ath10k_sta_statistics
,
9467 .set_tid_config
= ath10k_mac_op_set_tid_config
,
9468 .reset_tid_config
= ath10k_mac_op_reset_tid_config
,
9470 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
9473 .suspend
= ath10k_wow_op_suspend
,
9474 .resume
= ath10k_wow_op_resume
,
9475 .set_wakeup
= ath10k_wow_op_set_wakeup
,
9477 #ifdef CONFIG_MAC80211_DEBUGFS
9478 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
9480 .set_sar_specs
= ath10k_mac_set_sar_specs
,
9483 #define CHAN2G(_channel, _freq, _flags) { \
9484 .band = NL80211_BAND_2GHZ, \
9485 .hw_value = (_channel), \
9486 .center_freq = (_freq), \
9487 .flags = (_flags), \
9488 .max_antenna_gain = 0, \
9492 #define CHAN5G(_channel, _freq, _flags) { \
9493 .band = NL80211_BAND_5GHZ, \
9494 .hw_value = (_channel), \
9495 .center_freq = (_freq), \
9496 .flags = (_flags), \
9497 .max_antenna_gain = 0, \
9501 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
9511 CHAN2G(10, 2457, 0),
9512 CHAN2G(11, 2462, 0),
9513 CHAN2G(12, 2467, 0),
9514 CHAN2G(13, 2472, 0),
9515 CHAN2G(14, 2484, 0),
9518 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
9519 CHAN5G(36, 5180, 0),
9520 CHAN5G(40, 5200, 0),
9521 CHAN5G(44, 5220, 0),
9522 CHAN5G(48, 5240, 0),
9523 CHAN5G(52, 5260, 0),
9524 CHAN5G(56, 5280, 0),
9525 CHAN5G(60, 5300, 0),
9526 CHAN5G(64, 5320, 0),
9527 CHAN5G(100, 5500, 0),
9528 CHAN5G(104, 5520, 0),
9529 CHAN5G(108, 5540, 0),
9530 CHAN5G(112, 5560, 0),
9531 CHAN5G(116, 5580, 0),
9532 CHAN5G(120, 5600, 0),
9533 CHAN5G(124, 5620, 0),
9534 CHAN5G(128, 5640, 0),
9535 CHAN5G(132, 5660, 0),
9536 CHAN5G(136, 5680, 0),
9537 CHAN5G(140, 5700, 0),
9538 CHAN5G(144, 5720, 0),
9539 CHAN5G(149, 5745, 0),
9540 CHAN5G(153, 5765, 0),
9541 CHAN5G(157, 5785, 0),
9542 CHAN5G(161, 5805, 0),
9543 CHAN5G(165, 5825, 0),
9544 CHAN5G(169, 5845, 0),
9545 CHAN5G(173, 5865, 0),
9546 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
9547 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
9550 struct ath10k
*ath10k_mac_create(size_t priv_size
)
9552 struct ieee80211_hw
*hw
;
9553 struct ieee80211_ops
*ops
;
9556 ops
= kmemdup(&ath10k_ops
, sizeof(ath10k_ops
), GFP_KERNEL
);
9560 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, ops
);
9573 void ath10k_mac_destroy(struct ath10k
*ar
)
9575 struct ieee80211_ops
*ops
= ar
->ops
;
9577 ieee80211_free_hw(ar
->hw
);
9581 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
9584 .types
= BIT(NL80211_IFTYPE_STATION
)
9585 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
9589 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
9593 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
9597 .types
= BIT(NL80211_IFTYPE_AP
)
9598 #ifdef CONFIG_MAC80211_MESH
9599 | BIT(NL80211_IFTYPE_MESH_POINT
)
9604 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
9607 .types
= BIT(NL80211_IFTYPE_AP
)
9608 #ifdef CONFIG_MAC80211_MESH
9609 | BIT(NL80211_IFTYPE_MESH_POINT
)
9614 .types
= BIT(NL80211_IFTYPE_STATION
)
9618 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
9620 .limits
= ath10k_if_limits
,
9621 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
9622 .max_interfaces
= 8,
9623 .num_different_channels
= 1,
9624 .beacon_int_infra_match
= true,
9628 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
9630 .limits
= ath10k_10x_if_limits
,
9631 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
9632 .max_interfaces
= 8,
9633 .num_different_channels
= 1,
9634 .beacon_int_infra_match
= true,
9635 .beacon_int_min_gcd
= 1,
9636 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9637 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9638 BIT(NL80211_CHAN_WIDTH_20
) |
9639 BIT(NL80211_CHAN_WIDTH_40
) |
9640 BIT(NL80211_CHAN_WIDTH_80
),
9645 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
9648 .types
= BIT(NL80211_IFTYPE_STATION
),
9652 .types
= BIT(NL80211_IFTYPE_AP
) |
9653 #ifdef CONFIG_MAC80211_MESH
9654 BIT(NL80211_IFTYPE_MESH_POINT
) |
9656 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
9657 BIT(NL80211_IFTYPE_P2P_GO
),
9661 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
9665 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit
[] = {
9668 .types
= BIT(NL80211_IFTYPE_STATION
),
9672 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
),
9676 .types
= BIT(NL80211_IFTYPE_AP
) |
9677 #ifdef CONFIG_MAC80211_MESH
9678 BIT(NL80211_IFTYPE_MESH_POINT
) |
9680 BIT(NL80211_IFTYPE_P2P_GO
),
9684 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
9688 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
9691 .types
= BIT(NL80211_IFTYPE_STATION
),
9695 .types
= BIT(NL80211_IFTYPE_ADHOC
),
9699 /* FIXME: This is not thoroughly tested. These combinations may over- or
9700 * underestimate hw/fw capabilities.
9702 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
9704 .limits
= ath10k_tlv_if_limit
,
9705 .num_different_channels
= 1,
9706 .max_interfaces
= 4,
9707 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
9710 .limits
= ath10k_tlv_if_limit_ibss
,
9711 .num_different_channels
= 1,
9712 .max_interfaces
= 2,
9713 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
9717 static struct ieee80211_iface_combination ath10k_tlv_qcs_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_qcs_if_limit
,
9726 .num_different_channels
= 2,
9727 .max_interfaces
= 4,
9728 .n_limits
= ARRAY_SIZE(ath10k_tlv_qcs_if_limit
),
9731 .limits
= ath10k_tlv_if_limit_ibss
,
9732 .num_different_channels
= 1,
9733 .max_interfaces
= 2,
9734 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
9738 static const struct ieee80211_iface_limit ath10k_10_4_if_limits
[] = {
9741 .types
= BIT(NL80211_IFTYPE_STATION
),
9745 .types
= BIT(NL80211_IFTYPE_AP
)
9746 #ifdef CONFIG_MAC80211_MESH
9747 | BIT(NL80211_IFTYPE_MESH_POINT
)
9752 static const struct ieee80211_iface_combination ath10k_10_4_if_comb
[] = {
9754 .limits
= ath10k_10_4_if_limits
,
9755 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
9756 .max_interfaces
= 16,
9757 .num_different_channels
= 1,
9758 .beacon_int_infra_match
= true,
9759 .beacon_int_min_gcd
= 1,
9760 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9761 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9762 BIT(NL80211_CHAN_WIDTH_20
) |
9763 BIT(NL80211_CHAN_WIDTH_40
) |
9764 BIT(NL80211_CHAN_WIDTH_80
) |
9765 BIT(NL80211_CHAN_WIDTH_80P80
) |
9766 BIT(NL80211_CHAN_WIDTH_160
),
9772 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb
[] = {
9774 .limits
= ath10k_10_4_if_limits
,
9775 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
9776 .max_interfaces
= 16,
9777 .num_different_channels
= 1,
9778 .beacon_int_infra_match
= true,
9779 .beacon_int_min_gcd
= 100,
9780 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9781 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9782 BIT(NL80211_CHAN_WIDTH_20
) |
9783 BIT(NL80211_CHAN_WIDTH_40
) |
9784 BIT(NL80211_CHAN_WIDTH_80
) |
9785 BIT(NL80211_CHAN_WIDTH_80P80
) |
9786 BIT(NL80211_CHAN_WIDTH_160
),
9791 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
9792 struct ieee80211_vif
*vif
)
9794 struct ath10k_vif_iter
*arvif_iter
= data
;
9795 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9797 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
9798 arvif_iter
->arvif
= arvif
;
9801 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
9803 struct ath10k_vif_iter arvif_iter
;
9805 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
9806 arvif_iter
.vdev_id
= vdev_id
;
9808 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
9809 ATH10K_ITER_RESUME_FLAGS
,
9810 ath10k_get_arvif_iter
,
9812 if (!arvif_iter
.arvif
) {
9813 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
9817 return arvif_iter
.arvif
;
9820 #define WRD_METHOD "WRDD"
9821 #define WRDD_WIFI (0x07)
9823 static u32
ath10k_mac_wrdd_get_mcc(struct ath10k
*ar
, union acpi_object
*wrdd
)
9825 union acpi_object
*mcc_pkg
;
9826 union acpi_object
*domain_type
;
9827 union acpi_object
*mcc_value
;
9830 if (wrdd
->type
!= ACPI_TYPE_PACKAGE
||
9831 wrdd
->package
.count
< 2 ||
9832 wrdd
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
9833 wrdd
->package
.elements
[0].integer
.value
!= 0) {
9834 ath10k_warn(ar
, "ignoring malformed/unsupported wrdd structure\n");
9838 for (i
= 1; i
< wrdd
->package
.count
; ++i
) {
9839 mcc_pkg
= &wrdd
->package
.elements
[i
];
9841 if (mcc_pkg
->type
!= ACPI_TYPE_PACKAGE
)
9843 if (mcc_pkg
->package
.count
< 2)
9845 if (mcc_pkg
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
9846 mcc_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
)
9849 domain_type
= &mcc_pkg
->package
.elements
[0];
9850 if (domain_type
->integer
.value
!= WRDD_WIFI
)
9853 mcc_value
= &mcc_pkg
->package
.elements
[1];
9854 return mcc_value
->integer
.value
;
9859 static int ath10k_mac_get_wrdd_regulatory(struct ath10k
*ar
, u16
*rd
)
9861 acpi_handle root_handle
;
9863 struct acpi_buffer wrdd
= {ACPI_ALLOCATE_BUFFER
, NULL
};
9868 root_handle
= ACPI_HANDLE(ar
->dev
);
9872 status
= acpi_get_handle(root_handle
, (acpi_string
)WRD_METHOD
, &handle
);
9873 if (ACPI_FAILURE(status
)) {
9874 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9875 "failed to get wrd method %d\n", status
);
9879 status
= acpi_evaluate_object(handle
, NULL
, NULL
, &wrdd
);
9880 if (ACPI_FAILURE(status
)) {
9881 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9882 "failed to call wrdc %d\n", status
);
9886 alpha2_code
= ath10k_mac_wrdd_get_mcc(ar
, wrdd
.pointer
);
9887 kfree(wrdd
.pointer
);
9891 alpha2
[0] = (alpha2_code
>> 8) & 0xff;
9892 alpha2
[1] = (alpha2_code
>> 0) & 0xff;
9895 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9896 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2
);
9898 *rd
= ath_regd_find_country_by_name(alpha2
);
9902 *rd
|= COUNTRY_ERD_FLAG
;
9906 static int ath10k_mac_init_rd(struct ath10k
*ar
)
9911 ret
= ath10k_mac_get_wrdd_regulatory(ar
, &rd
);
9913 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9914 "fallback to eeprom programmed regulatory settings\n");
9915 rd
= ar
->hw_eeprom_rd
;
9918 ar
->ath_common
.regulatory
.current_rd
= rd
;
9922 int ath10k_mac_register(struct ath10k
*ar
)
9924 static const u32 cipher_suites
[] = {
9925 WLAN_CIPHER_SUITE_WEP40
,
9926 WLAN_CIPHER_SUITE_WEP104
,
9927 WLAN_CIPHER_SUITE_TKIP
,
9928 WLAN_CIPHER_SUITE_CCMP
,
9930 /* Do not add hardware supported ciphers before this line.
9931 * Allow software encryption for all chips. Don't forget to
9932 * update n_cipher_suites below.
9934 WLAN_CIPHER_SUITE_AES_CMAC
,
9935 WLAN_CIPHER_SUITE_BIP_CMAC_256
,
9936 WLAN_CIPHER_SUITE_BIP_GMAC_128
,
9937 WLAN_CIPHER_SUITE_BIP_GMAC_256
,
9939 /* Only QCA99x0 and QCA4019 variants support GCMP-128, GCMP-256
9940 * and CCMP-256 in hardware.
9942 WLAN_CIPHER_SUITE_GCMP
,
9943 WLAN_CIPHER_SUITE_GCMP_256
,
9944 WLAN_CIPHER_SUITE_CCMP_256
,
9946 struct ieee80211_supported_band
*band
;
9950 if (!is_valid_ether_addr(ar
->mac_addr
)) {
9951 ath10k_warn(ar
, "invalid MAC address; choosing random\n");
9952 eth_random_addr(ar
->mac_addr
);
9954 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
9956 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
9958 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
9959 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
9962 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
9963 channels
= kmemdup(ath10k_2ghz_channels
,
9964 sizeof(ath10k_2ghz_channels
),
9971 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
9972 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
9973 band
->channels
= channels
;
9975 if (ar
->hw_params
.cck_rate_map_rev2
) {
9976 band
->n_bitrates
= ath10k_g_rates_rev2_size
;
9977 band
->bitrates
= ath10k_g_rates_rev2
;
9979 band
->n_bitrates
= ath10k_g_rates_size
;
9980 band
->bitrates
= ath10k_g_rates
;
9983 ar
->hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = band
;
9986 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
9987 channels
= kmemdup(ath10k_5ghz_channels
,
9988 sizeof(ath10k_5ghz_channels
),
9995 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
9996 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
9997 band
->channels
= channels
;
9998 band
->n_bitrates
= ath10k_a_rates_size
;
9999 band
->bitrates
= ath10k_a_rates
;
10000 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = band
;
10003 wiphy_read_of_freq_limits(ar
->hw
->wiphy
);
10004 ath10k_mac_setup_ht_vht_cap(ar
);
10006 ar
->hw
->wiphy
->interface_modes
=
10007 BIT(NL80211_IFTYPE_STATION
) |
10008 BIT(NL80211_IFTYPE_AP
) |
10009 BIT(NL80211_IFTYPE_MESH_POINT
);
10011 ar
->hw
->wiphy
->available_antennas_rx
= ar
->cfg_rx_chainmask
;
10012 ar
->hw
->wiphy
->available_antennas_tx
= ar
->cfg_tx_chainmask
;
10014 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->normal_mode_fw
.fw_file
.fw_features
))
10015 ar
->hw
->wiphy
->interface_modes
|=
10016 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
10017 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
10018 BIT(NL80211_IFTYPE_P2P_GO
);
10020 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
10022 if (!test_bit(ATH10K_FW_FEATURE_NO_PS
,
10023 ar
->running_fw
->fw_file
.fw_features
)) {
10024 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
10025 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
10028 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
10029 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
10030 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
10031 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
10032 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
10033 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
10034 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
10035 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
10036 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
10037 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
10038 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
10039 ieee80211_hw_set(ar
->hw
, SUPPORTS_TX_FRAG
);
10040 ieee80211_hw_set(ar
->hw
, REPORTS_LOW_ACK
);
10042 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
10043 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
10045 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
10046 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
10048 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
10049 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
10051 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
10052 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
10053 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
10056 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
10057 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
10059 if (test_bit(WMI_SERVICE_NLO
, ar
->wmi
.svc_map
)) {
10060 ar
->hw
->wiphy
->max_sched_scan_ssids
= WMI_PNO_MAX_SUPP_NETWORKS
;
10061 ar
->hw
->wiphy
->max_match_sets
= WMI_PNO_MAX_SUPP_NETWORKS
;
10062 ar
->hw
->wiphy
->max_sched_scan_ie_len
= WMI_PNO_MAX_IE_LENGTH
;
10063 ar
->hw
->wiphy
->max_sched_scan_plans
= WMI_PNO_MAX_SCHED_SCAN_PLANS
;
10064 ar
->hw
->wiphy
->max_sched_scan_plan_interval
=
10065 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT
;
10066 ar
->hw
->wiphy
->max_sched_scan_plan_iterations
=
10067 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS
;
10068 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
10071 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
10072 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
10073 ar
->hw
->txq_data_size
= sizeof(struct ath10k_txq
);
10075 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
10077 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
10078 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
10080 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
10081 * that userspace (e.g. wpa_supplicant/hostapd) can generate
10082 * correct Probe Responses. This is more of a hack advert..
10084 ar
->hw
->wiphy
->probe_resp_offload
|=
10085 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
10086 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
10087 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
10090 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
) ||
10091 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY
, ar
->wmi
.svc_map
)) {
10092 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
10093 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH
, ar
->wmi
.svc_map
))
10094 ieee80211_hw_set(ar
->hw
, TDLS_WIDER_BW
);
10097 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA
, ar
->wmi
.svc_map
))
10098 ieee80211_hw_set(ar
->hw
, SUPPORTS_TDLS_BUFFER_STA
);
10100 if (ath10k_frame_mode
== ATH10K_HW_TXRX_ETHERNET
) {
10101 if (ar
->wmi
.vdev_param
->tx_encap_type
!=
10102 WMI_VDEV_PARAM_UNSUPPORTED
)
10103 ieee80211_hw_set(ar
->hw
, SUPPORTS_TX_ENCAP_OFFLOAD
);
10106 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
10107 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
10108 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
10110 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
10111 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
10112 NL80211_FEATURE_AP_SCAN
;
10114 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
10116 ret
= ath10k_wow_init(ar
);
10118 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
10122 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
10123 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10124 NL80211_EXT_FEATURE_SET_SCAN_DWELL
);
10125 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_AQL
);
10127 if (ar
->hw_params
.mcast_frame_registration
)
10128 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10129 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS
);
10131 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI
, ar
->wmi
.svc_map
) ||
10132 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS
, ar
->wmi
.svc_map
))
10133 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10134 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT
);
10136 if (ath10k_peer_stats_enabled(ar
) ||
10137 test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
10138 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10139 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
);
10141 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
))
10142 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10143 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
);
10145 if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER
, ar
->wmi
.svc_map
))
10146 wiphy_ext_feature_set(ar
->hw
->wiphy
,
10147 NL80211_EXT_FEATURE_STA_TX_PWR
);
10149 if (test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT
, ar
->wmi
.svc_map
)) {
10150 ar
->hw
->wiphy
->tid_config_support
.vif
|=
10151 BIT(NL80211_TID_CONFIG_ATTR_NOACK
) |
10152 BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT
) |
10153 BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
) |
10154 BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
) |
10155 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
10156 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
);
10158 if (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT
,
10159 ar
->wmi
.svc_map
)) {
10160 ar
->hw
->wiphy
->tid_config_support
.vif
|=
10161 BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
);
10164 ar
->hw
->wiphy
->tid_config_support
.peer
=
10165 ar
->hw
->wiphy
->tid_config_support
.vif
;
10166 ar
->hw
->wiphy
->max_data_retry_count
= ATH10K_MAX_RETRY_COUNT
;
10168 ar
->ops
->set_tid_config
= NULL
;
10171 * on LL hardware queues are managed entirely by the FW
10172 * so we only advertise to mac we can do the queues thing
10174 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
10176 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
10177 * something that vdev_ids can't reach so that we don't stop the queue
10180 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
10182 switch (ar
->running_fw
->fw_file
.wmi_op_version
) {
10183 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
10184 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
10185 ar
->hw
->wiphy
->n_iface_combinations
=
10186 ARRAY_SIZE(ath10k_if_comb
);
10187 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
10189 case ATH10K_FW_WMI_OP_VERSION_TLV
:
10190 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
10191 ar
->hw
->wiphy
->iface_combinations
=
10192 ath10k_tlv_qcs_if_comb
;
10193 ar
->hw
->wiphy
->n_iface_combinations
=
10194 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
10196 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
10197 ar
->hw
->wiphy
->n_iface_combinations
=
10198 ARRAY_SIZE(ath10k_tlv_if_comb
);
10200 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
10202 case ATH10K_FW_WMI_OP_VERSION_10_1
:
10203 case ATH10K_FW_WMI_OP_VERSION_10_2
:
10204 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
10205 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
10206 ar
->hw
->wiphy
->n_iface_combinations
=
10207 ARRAY_SIZE(ath10k_10x_if_comb
);
10209 case ATH10K_FW_WMI_OP_VERSION_10_4
:
10210 ar
->hw
->wiphy
->iface_combinations
= ath10k_10_4_if_comb
;
10211 ar
->hw
->wiphy
->n_iface_combinations
=
10212 ARRAY_SIZE(ath10k_10_4_if_comb
);
10213 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT
,
10214 ar
->wmi
.svc_map
)) {
10215 ar
->hw
->wiphy
->iface_combinations
=
10216 ath10k_10_4_bcn_int_if_comb
;
10217 ar
->hw
->wiphy
->n_iface_combinations
=
10218 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb
);
10221 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
10222 case ATH10K_FW_WMI_OP_VERSION_MAX
:
10228 if (ar
->hw_params
.dynamic_sar_support
)
10229 ar
->hw
->wiphy
->sar_capa
= &ath10k_sar_capa
;
10231 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
10232 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
10234 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
10235 /* Init ath dfs pattern detector */
10236 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
10237 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
10238 NL80211_DFS_UNSET
);
10240 if (!ar
->dfs_detector
)
10241 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
10244 ret
= ath10k_mac_init_rd(ar
);
10246 ath10k_err(ar
, "failed to derive regdom: %d\n", ret
);
10247 goto err_dfs_detector_exit
;
10250 /* Disable set_coverage_class for chipsets that do not support it. */
10251 if (!ar
->hw_params
.hw_ops
->set_coverage_class
)
10252 ar
->ops
->set_coverage_class
= NULL
;
10254 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
10255 ath10k_reg_notifier
);
10257 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
10258 goto err_dfs_detector_exit
;
10261 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
10262 ar
->hw
->wiphy
->features
|=
10263 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
10266 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
10268 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
10269 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
10270 * from chip specific hw_param table.
10272 if (!ar
->hw_params
.n_cipher_suites
||
10273 ar
->hw_params
.n_cipher_suites
> ARRAY_SIZE(cipher_suites
)) {
10274 ath10k_err(ar
, "invalid hw_params.n_cipher_suites %d\n",
10275 ar
->hw_params
.n_cipher_suites
);
10276 ar
->hw_params
.n_cipher_suites
= 8;
10278 ar
->hw
->wiphy
->n_cipher_suites
= ar
->hw_params
.n_cipher_suites
;
10280 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_CQM_RSSI_LIST
);
10282 ar
->hw
->weight_multiplier
= ATH10K_AIRTIME_WEIGHT_MULTIPLIER
;
10284 ret
= ieee80211_register_hw(ar
->hw
);
10286 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
10287 goto err_dfs_detector_exit
;
10290 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT
, ar
->wmi
.svc_map
)) {
10291 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
10292 ar
->hw
->wiphy
->software_iftypes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
10295 if (!ath_is_world_regd(&ar
->ath_common
.reg_world_copy
) &&
10296 !ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
10297 ret
= regulatory_hint(ar
->hw
->wiphy
,
10298 ar
->ath_common
.regulatory
.alpha2
);
10300 goto err_unregister
;
10306 ieee80211_unregister_hw(ar
->hw
);
10308 err_dfs_detector_exit
:
10309 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
10310 ar
->dfs_detector
->exit(ar
->dfs_detector
);
10313 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
10314 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
10316 SET_IEEE80211_DEV(ar
->hw
, NULL
);
10320 void ath10k_mac_unregister(struct ath10k
*ar
)
10322 ieee80211_unregister_hw(ar
->hw
);
10324 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
10325 ar
->dfs_detector
->exit(ar
->dfs_detector
);
10327 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
10328 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
10330 SET_IEEE80211_DEV(ar
->hw
, NULL
);