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.
10 #include <net/cfg80211.h>
11 #include <net/mac80211.h>
12 #include <linux/etherdevice.h>
13 #include <linux/acpi.h>
15 #include <linux/bitfield.h>
32 static struct ieee80211_rate ath10k_rates
[] = {
34 .hw_value
= ATH10K_HW_RATE_CCK_LP_1M
},
36 .hw_value
= ATH10K_HW_RATE_CCK_LP_2M
,
37 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_2M
,
38 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
40 .hw_value
= ATH10K_HW_RATE_CCK_LP_5_5M
,
41 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_5_5M
,
42 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
44 .hw_value
= ATH10K_HW_RATE_CCK_LP_11M
,
45 .hw_value_short
= ATH10K_HW_RATE_CCK_SP_11M
,
46 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
48 { .bitrate
= 60, .hw_value
= ATH10K_HW_RATE_OFDM_6M
},
49 { .bitrate
= 90, .hw_value
= ATH10K_HW_RATE_OFDM_9M
},
50 { .bitrate
= 120, .hw_value
= ATH10K_HW_RATE_OFDM_12M
},
51 { .bitrate
= 180, .hw_value
= ATH10K_HW_RATE_OFDM_18M
},
52 { .bitrate
= 240, .hw_value
= ATH10K_HW_RATE_OFDM_24M
},
53 { .bitrate
= 360, .hw_value
= ATH10K_HW_RATE_OFDM_36M
},
54 { .bitrate
= 480, .hw_value
= ATH10K_HW_RATE_OFDM_48M
},
55 { .bitrate
= 540, .hw_value
= ATH10K_HW_RATE_OFDM_54M
},
58 static struct ieee80211_rate ath10k_rates_rev2
[] = {
60 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_1M
},
62 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_2M
,
63 .hw_value_short
= ATH10K_HW_RATE_REV2_CCK_SP_2M
,
64 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
66 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_5_5M
,
67 .hw_value_short
= ATH10K_HW_RATE_REV2_CCK_SP_5_5M
,
68 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
70 .hw_value
= ATH10K_HW_RATE_REV2_CCK_LP_11M
,
71 .hw_value_short
= ATH10K_HW_RATE_REV2_CCK_SP_11M
,
72 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
74 { .bitrate
= 60, .hw_value
= ATH10K_HW_RATE_OFDM_6M
},
75 { .bitrate
= 90, .hw_value
= ATH10K_HW_RATE_OFDM_9M
},
76 { .bitrate
= 120, .hw_value
= ATH10K_HW_RATE_OFDM_12M
},
77 { .bitrate
= 180, .hw_value
= ATH10K_HW_RATE_OFDM_18M
},
78 { .bitrate
= 240, .hw_value
= ATH10K_HW_RATE_OFDM_24M
},
79 { .bitrate
= 360, .hw_value
= ATH10K_HW_RATE_OFDM_36M
},
80 { .bitrate
= 480, .hw_value
= ATH10K_HW_RATE_OFDM_48M
},
81 { .bitrate
= 540, .hw_value
= ATH10K_HW_RATE_OFDM_54M
},
84 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
86 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
87 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
88 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
89 #define ath10k_g_rates (ath10k_rates + 0)
90 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
92 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
93 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
95 #define ath10k_wmi_legacy_rates ath10k_rates
97 static bool ath10k_mac_bitrate_is_cck(int bitrate
)
110 static u8
ath10k_mac_bitrate_to_rate(int bitrate
)
112 return DIV_ROUND_UP(bitrate
, 5) |
113 (ath10k_mac_bitrate_is_cck(bitrate
) ? BIT(7) : 0);
116 u8
ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band
*sband
,
117 u8 hw_rate
, bool cck
)
119 const struct ieee80211_rate
*rate
;
122 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
123 rate
= &sband
->bitrates
[i
];
125 if (ath10k_mac_bitrate_is_cck(rate
->bitrate
) != cck
)
128 if (rate
->hw_value
== hw_rate
)
130 else if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
&&
131 rate
->hw_value_short
== hw_rate
)
138 u8
ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band
*sband
,
143 for (i
= 0; i
< sband
->n_bitrates
; i
++)
144 if (sband
->bitrates
[i
].bitrate
== bitrate
)
150 static int ath10k_mac_get_rate_hw_value(int bitrate
)
153 u8 hw_value_prefix
= 0;
155 if (ath10k_mac_bitrate_is_cck(bitrate
))
156 hw_value_prefix
= WMI_RATE_PREAMBLE_CCK
<< 6;
158 for (i
= 0; i
< ARRAY_SIZE(ath10k_rates
); i
++) {
159 if (ath10k_rates
[i
].bitrate
== bitrate
)
160 return hw_value_prefix
| ath10k_rates
[i
].hw_value
;
166 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map
, int nss
)
168 switch ((mcs_map
>> (2 * nss
)) & 0x3) {
169 case IEEE80211_VHT_MCS_SUPPORT_0_7
: return BIT(8) - 1;
170 case IEEE80211_VHT_MCS_SUPPORT_0_8
: return BIT(9) - 1;
171 case IEEE80211_VHT_MCS_SUPPORT_0_9
: return BIT(10) - 1;
177 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
181 for (nss
= IEEE80211_HT_MCS_MASK_LEN
- 1; nss
>= 0; nss
--)
182 if (ht_mcs_mask
[nss
])
189 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
193 for (nss
= NL80211_VHT_NSS_MAX
- 1; nss
>= 0; nss
--)
194 if (vht_mcs_mask
[nss
])
200 int ath10k_mac_ext_resource_config(struct ath10k
*ar
, u32 val
)
202 enum wmi_host_platform_type platform_type
;
205 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC
, ar
->wmi
.svc_map
))
206 platform_type
= WMI_HOST_PLATFORM_LOW_PERF
;
208 platform_type
= WMI_HOST_PLATFORM_HIGH_PERF
;
210 ret
= ath10k_wmi_ext_resource_config(ar
, platform_type
, val
);
212 if (ret
&& ret
!= -EOPNOTSUPP
) {
213 ath10k_warn(ar
, "failed to configure ext resource: %d\n", ret
);
224 static int ath10k_send_key(struct ath10k_vif
*arvif
,
225 struct ieee80211_key_conf
*key
,
226 enum set_key_cmd cmd
,
227 const u8
*macaddr
, u32 flags
)
229 struct ath10k
*ar
= arvif
->ar
;
230 struct wmi_vdev_install_key_arg arg
= {
231 .vdev_id
= arvif
->vdev_id
,
232 .key_idx
= key
->keyidx
,
233 .key_len
= key
->keylen
,
234 .key_data
= key
->key
,
239 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
241 switch (key
->cipher
) {
242 case WLAN_CIPHER_SUITE_CCMP
:
243 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_AES_CCM
];
244 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
246 case WLAN_CIPHER_SUITE_TKIP
:
247 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_TKIP
];
248 arg
.key_txmic_len
= 8;
249 arg
.key_rxmic_len
= 8;
251 case WLAN_CIPHER_SUITE_WEP40
:
252 case WLAN_CIPHER_SUITE_WEP104
:
253 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_WEP
];
255 case WLAN_CIPHER_SUITE_CCMP_256
:
256 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_AES_CCM
];
258 case WLAN_CIPHER_SUITE_GCMP
:
259 case WLAN_CIPHER_SUITE_GCMP_256
:
260 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_AES_GCM
];
261 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
263 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
264 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
265 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
266 case WLAN_CIPHER_SUITE_AES_CMAC
:
270 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
274 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
275 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
277 if (cmd
== DISABLE_KEY
) {
278 arg
.key_cipher
= ar
->wmi_key_cipher
[WMI_CIPHER_NONE
];
282 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
285 static int ath10k_install_key(struct ath10k_vif
*arvif
,
286 struct ieee80211_key_conf
*key
,
287 enum set_key_cmd cmd
,
288 const u8
*macaddr
, u32 flags
)
290 struct ath10k
*ar
= arvif
->ar
;
292 unsigned long time_left
;
294 lockdep_assert_held(&ar
->conf_mutex
);
296 reinit_completion(&ar
->install_key_done
);
298 if (arvif
->nohwcrypt
)
301 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
, flags
);
305 time_left
= wait_for_completion_timeout(&ar
->install_key_done
, 3 * HZ
);
312 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
315 struct ath10k
*ar
= arvif
->ar
;
316 struct ath10k_peer
*peer
;
321 lockdep_assert_held(&ar
->conf_mutex
);
323 if (WARN_ON(arvif
->vif
->type
!= NL80211_IFTYPE_AP
&&
324 arvif
->vif
->type
!= NL80211_IFTYPE_ADHOC
&&
325 arvif
->vif
->type
!= NL80211_IFTYPE_MESH_POINT
))
328 spin_lock_bh(&ar
->data_lock
);
329 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
330 spin_unlock_bh(&ar
->data_lock
);
335 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
336 if (arvif
->wep_keys
[i
] == NULL
)
339 switch (arvif
->vif
->type
) {
340 case NL80211_IFTYPE_AP
:
341 flags
= WMI_KEY_PAIRWISE
;
343 if (arvif
->def_wep_key_idx
== i
)
344 flags
|= WMI_KEY_TX_USAGE
;
346 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
347 SET_KEY
, addr
, flags
);
351 case NL80211_IFTYPE_ADHOC
:
352 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
358 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
],
359 SET_KEY
, addr
, WMI_KEY_GROUP
);
368 spin_lock_bh(&ar
->data_lock
);
369 peer
->keys
[i
] = arvif
->wep_keys
[i
];
370 spin_unlock_bh(&ar
->data_lock
);
373 /* In some cases (notably with static WEP IBSS with multiple keys)
374 * multicast Tx becomes broken. Both pairwise and groupwise keys are
375 * installed already. Using WMI_KEY_TX_USAGE in different combinations
376 * didn't seem help. Using def_keyid vdev parameter seems to be
377 * effective so use that.
379 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
381 if (arvif
->vif
->type
!= NL80211_IFTYPE_ADHOC
)
384 if (arvif
->def_wep_key_idx
== -1)
387 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
389 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
390 arvif
->def_wep_key_idx
);
392 ath10k_warn(ar
, "failed to re-set def wpa key idxon vdev %i: %d\n",
393 arvif
->vdev_id
, ret
);
400 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
403 struct ath10k
*ar
= arvif
->ar
;
404 struct ath10k_peer
*peer
;
410 lockdep_assert_held(&ar
->conf_mutex
);
412 spin_lock_bh(&ar
->data_lock
);
413 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
414 spin_unlock_bh(&ar
->data_lock
);
419 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
420 if (peer
->keys
[i
] == NULL
)
423 /* key flags are not required to delete the key */
424 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
425 DISABLE_KEY
, addr
, flags
);
426 if (ret
< 0 && first_errno
== 0)
430 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
433 spin_lock_bh(&ar
->data_lock
);
434 peer
->keys
[i
] = NULL
;
435 spin_unlock_bh(&ar
->data_lock
);
441 bool ath10k_mac_is_peer_wep_key_set(struct ath10k
*ar
, const u8
*addr
,
444 struct ath10k_peer
*peer
;
447 lockdep_assert_held(&ar
->data_lock
);
449 /* We don't know which vdev this peer belongs to,
450 * since WMI doesn't give us that information.
452 * FIXME: multi-bss needs to be handled.
454 peer
= ath10k_peer_find(ar
, 0, addr
);
458 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
459 if (peer
->keys
[i
] && peer
->keys
[i
]->keyidx
== keyidx
)
466 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
467 struct ieee80211_key_conf
*key
)
469 struct ath10k
*ar
= arvif
->ar
;
470 struct ath10k_peer
*peer
;
477 lockdep_assert_held(&ar
->conf_mutex
);
480 /* since ath10k_install_key we can't hold data_lock all the
481 * time, so we try to remove the keys incrementally
483 spin_lock_bh(&ar
->data_lock
);
485 list_for_each_entry(peer
, &ar
->peers
, list
) {
486 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
487 if (peer
->keys
[i
] == key
) {
488 ether_addr_copy(addr
, peer
->addr
);
489 peer
->keys
[i
] = NULL
;
494 if (i
< ARRAY_SIZE(peer
->keys
))
497 spin_unlock_bh(&ar
->data_lock
);
499 if (i
== ARRAY_SIZE(peer
->keys
))
501 /* key flags are not required to delete the key */
502 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
, flags
);
503 if (ret
< 0 && first_errno
== 0)
507 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
514 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif
*arvif
,
515 struct ieee80211_key_conf
*key
)
517 struct ath10k
*ar
= arvif
->ar
;
518 struct ath10k_peer
*peer
;
521 lockdep_assert_held(&ar
->conf_mutex
);
523 list_for_each_entry(peer
, &ar
->peers
, list
) {
524 if (ether_addr_equal(peer
->addr
, arvif
->vif
->addr
))
527 if (ether_addr_equal(peer
->addr
, arvif
->bssid
))
530 if (peer
->keys
[key
->keyidx
] == key
)
533 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vif vdev %i update key %i needs update\n",
534 arvif
->vdev_id
, key
->keyidx
);
536 ret
= ath10k_install_peer_wep_keys(arvif
, peer
->addr
);
538 ath10k_warn(ar
, "failed to update wep keys on vdev %i for peer %pM: %d\n",
539 arvif
->vdev_id
, peer
->addr
, ret
);
547 /*********************/
548 /* General utilities */
549 /*********************/
551 static inline enum wmi_phy_mode
552 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
554 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
556 switch (chandef
->chan
->band
) {
557 case NL80211_BAND_2GHZ
:
558 switch (chandef
->width
) {
559 case NL80211_CHAN_WIDTH_20_NOHT
:
560 if (chandef
->chan
->flags
& IEEE80211_CHAN_NO_OFDM
)
565 case NL80211_CHAN_WIDTH_20
:
566 phymode
= MODE_11NG_HT20
;
568 case NL80211_CHAN_WIDTH_40
:
569 phymode
= MODE_11NG_HT40
;
572 phymode
= MODE_UNKNOWN
;
576 case NL80211_BAND_5GHZ
:
577 switch (chandef
->width
) {
578 case NL80211_CHAN_WIDTH_20_NOHT
:
581 case NL80211_CHAN_WIDTH_20
:
582 phymode
= MODE_11NA_HT20
;
584 case NL80211_CHAN_WIDTH_40
:
585 phymode
= MODE_11NA_HT40
;
587 case NL80211_CHAN_WIDTH_80
:
588 phymode
= MODE_11AC_VHT80
;
590 case NL80211_CHAN_WIDTH_160
:
591 phymode
= MODE_11AC_VHT160
;
593 case NL80211_CHAN_WIDTH_80P80
:
594 phymode
= MODE_11AC_VHT80_80
;
597 phymode
= MODE_UNKNOWN
;
605 WARN_ON(phymode
== MODE_UNKNOWN
);
609 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
612 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
613 * 0 for no restriction
622 switch (mpdudensity
) {
628 /* Our lower layer calculations limit our precision to
645 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
646 struct cfg80211_chan_def
*def
)
648 struct ieee80211_chanctx_conf
*conf
;
651 conf
= rcu_dereference(vif
->chanctx_conf
);
663 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
664 struct ieee80211_chanctx_conf
*conf
,
672 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
676 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
677 ath10k_mac_num_chanctxs_iter
,
684 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
685 struct ieee80211_chanctx_conf
*conf
,
688 struct cfg80211_chan_def
**def
= data
;
693 static void ath10k_wait_for_peer_delete_done(struct ath10k
*ar
, u32 vdev_id
,
696 unsigned long time_left
;
699 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
700 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
702 ath10k_warn(ar
, "failed wait for peer deleted");
706 time_left
= wait_for_completion_timeout(&ar
->peer_delete_done
,
709 ath10k_warn(ar
, "Timeout in receiving peer delete response\n");
713 static int ath10k_peer_create(struct ath10k
*ar
,
714 struct ieee80211_vif
*vif
,
715 struct ieee80211_sta
*sta
,
718 enum wmi_peer_type peer_type
)
720 struct ath10k_vif
*arvif
;
721 struct ath10k_peer
*peer
;
725 lockdep_assert_held(&ar
->conf_mutex
);
727 num_peers
= ar
->num_peers
;
729 /* Each vdev consumes a peer entry as well */
730 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
733 if (num_peers
>= ar
->max_num_peers
)
736 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
738 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
743 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
745 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
750 spin_lock_bh(&ar
->data_lock
);
752 peer
= ath10k_peer_find(ar
, vdev_id
, addr
);
754 spin_unlock_bh(&ar
->data_lock
);
755 ath10k_warn(ar
, "failed to find peer %pM on vdev %i after creation\n",
757 ath10k_wait_for_peer_delete_done(ar
, vdev_id
, addr
);
764 spin_unlock_bh(&ar
->data_lock
);
771 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
773 struct ath10k
*ar
= arvif
->ar
;
777 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
778 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
779 ATH10K_KICKOUT_THRESHOLD
);
781 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
782 arvif
->vdev_id
, ret
);
786 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
787 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
788 ATH10K_KEEPALIVE_MIN_IDLE
);
790 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
791 arvif
->vdev_id
, ret
);
795 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
796 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
797 ATH10K_KEEPALIVE_MAX_IDLE
);
799 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
800 arvif
->vdev_id
, ret
);
804 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
805 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
806 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
808 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
809 arvif
->vdev_id
, ret
);
816 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
818 struct ath10k
*ar
= arvif
->ar
;
821 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
822 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
825 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
829 lockdep_assert_held(&ar
->conf_mutex
);
831 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
835 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
839 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
840 unsigned long time_left
;
842 time_left
= wait_for_completion_timeout
843 (&ar
->peer_delete_done
, 5 * HZ
);
846 ath10k_warn(ar
, "Timeout in receiving peer delete response\n");
856 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
858 struct ath10k_peer
*peer
, *tmp
;
862 lockdep_assert_held(&ar
->conf_mutex
);
864 spin_lock_bh(&ar
->data_lock
);
865 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
866 if (peer
->vdev_id
!= vdev_id
)
869 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
870 peer
->addr
, vdev_id
);
872 for_each_set_bit(peer_id
, peer
->peer_ids
,
873 ATH10K_MAX_NUM_PEER_IDS
) {
874 ar
->peer_map
[peer_id
] = NULL
;
877 /* Double check that peer is properly un-referenced from
880 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
881 if (ar
->peer_map
[i
] == peer
) {
882 ath10k_warn(ar
, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
883 peer
->addr
, peer
, i
);
884 ar
->peer_map
[i
] = NULL
;
888 list_del(&peer
->list
);
892 spin_unlock_bh(&ar
->data_lock
);
895 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
897 struct ath10k_peer
*peer
, *tmp
;
900 lockdep_assert_held(&ar
->conf_mutex
);
902 spin_lock_bh(&ar
->data_lock
);
903 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
904 list_del(&peer
->list
);
908 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++)
909 ar
->peer_map
[i
] = NULL
;
911 spin_unlock_bh(&ar
->data_lock
);
914 ar
->num_stations
= 0;
917 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
918 struct ieee80211_sta
*sta
,
919 enum wmi_tdls_peer_state state
)
922 struct wmi_tdls_peer_update_cmd_arg arg
= {};
923 struct wmi_tdls_peer_capab_arg cap
= {};
924 struct wmi_channel_arg chan_arg
= {};
926 lockdep_assert_held(&ar
->conf_mutex
);
928 arg
.vdev_id
= vdev_id
;
929 arg
.peer_state
= state
;
930 ether_addr_copy(arg
.addr
, sta
->addr
);
932 cap
.peer_max_sp
= sta
->max_sp
;
933 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
935 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
936 !sta
->tdls_initiator
)
937 cap
.is_peer_responder
= 1;
939 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
941 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
942 arg
.addr
, vdev_id
, ret
);
949 /************************/
950 /* Interface management */
951 /************************/
953 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
955 struct ath10k
*ar
= arvif
->ar
;
957 lockdep_assert_held(&ar
->data_lock
);
962 if (!arvif
->beacon_buf
)
963 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
964 arvif
->beacon
->len
, DMA_TO_DEVICE
);
966 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
967 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
970 dev_kfree_skb_any(arvif
->beacon
);
972 arvif
->beacon
= NULL
;
973 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
976 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
978 struct ath10k
*ar
= arvif
->ar
;
980 lockdep_assert_held(&ar
->data_lock
);
982 ath10k_mac_vif_beacon_free(arvif
);
984 if (arvif
->beacon_buf
) {
985 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
986 arvif
->beacon_buf
, arvif
->beacon_paddr
);
987 arvif
->beacon_buf
= NULL
;
991 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
993 unsigned long time_left
;
995 lockdep_assert_held(&ar
->conf_mutex
);
997 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
1000 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
1001 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
1005 return ar
->last_wmi_vdev_start_status
;
1008 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
1010 struct cfg80211_chan_def
*chandef
= NULL
;
1011 struct ieee80211_channel
*channel
= NULL
;
1012 struct wmi_vdev_start_request_arg arg
= {};
1015 lockdep_assert_held(&ar
->conf_mutex
);
1017 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1018 ath10k_mac_get_any_chandef_iter
,
1020 if (WARN_ON_ONCE(!chandef
))
1023 channel
= chandef
->chan
;
1025 arg
.vdev_id
= vdev_id
;
1026 arg
.channel
.freq
= channel
->center_freq
;
1027 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1028 arg
.channel
.band_center_freq2
= chandef
->center_freq2
;
1030 /* TODO setup this dynamically, what in case we
1031 * don't have any vifs?
1033 arg
.channel
.mode
= chan_to_phymode(chandef
);
1034 arg
.channel
.chan_radar
=
1035 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
1037 arg
.channel
.min_power
= 0;
1038 arg
.channel
.max_power
= channel
->max_power
* 2;
1039 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
1040 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
1042 reinit_completion(&ar
->vdev_setup_done
);
1043 reinit_completion(&ar
->vdev_delete_done
);
1045 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1047 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
1052 ret
= ath10k_vdev_setup_sync(ar
);
1054 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
1059 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
1061 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
1066 ar
->monitor_vdev_id
= vdev_id
;
1068 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
1069 ar
->monitor_vdev_id
);
1073 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
1075 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
1076 ar
->monitor_vdev_id
, ret
);
1081 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
1085 lockdep_assert_held(&ar
->conf_mutex
);
1087 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
1089 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
1090 ar
->monitor_vdev_id
, ret
);
1092 reinit_completion(&ar
->vdev_setup_done
);
1093 reinit_completion(&ar
->vdev_delete_done
);
1095 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
1097 ath10k_warn(ar
, "failed to request monitor vdev %i stop: %d\n",
1098 ar
->monitor_vdev_id
, ret
);
1100 ret
= ath10k_vdev_setup_sync(ar
);
1102 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
1103 ar
->monitor_vdev_id
, ret
);
1105 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
1106 ar
->monitor_vdev_id
);
1110 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
1114 lockdep_assert_held(&ar
->conf_mutex
);
1116 if (ar
->free_vdev_map
== 0) {
1117 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
1121 bit
= __ffs64(ar
->free_vdev_map
);
1123 ar
->monitor_vdev_id
= bit
;
1125 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
1126 WMI_VDEV_TYPE_MONITOR
,
1129 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
1130 ar
->monitor_vdev_id
, ret
);
1134 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
1135 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
1136 ar
->monitor_vdev_id
);
1141 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
1145 lockdep_assert_held(&ar
->conf_mutex
);
1147 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
1149 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
1150 ar
->monitor_vdev_id
, ret
);
1154 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
1156 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
1157 ar
->monitor_vdev_id
);
1161 static int ath10k_monitor_start(struct ath10k
*ar
)
1165 lockdep_assert_held(&ar
->conf_mutex
);
1167 ret
= ath10k_monitor_vdev_create(ar
);
1169 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
1173 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
1175 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
1176 ath10k_monitor_vdev_delete(ar
);
1180 ar
->monitor_started
= true;
1181 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
1186 static int ath10k_monitor_stop(struct ath10k
*ar
)
1190 lockdep_assert_held(&ar
->conf_mutex
);
1192 ret
= ath10k_monitor_vdev_stop(ar
);
1194 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1198 ret
= ath10k_monitor_vdev_delete(ar
);
1200 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1204 ar
->monitor_started
= false;
1205 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1210 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1214 /* At least one chanctx is required to derive a channel to start
1217 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1221 /* If there's already an existing special monitor interface then don't
1222 * bother creating another monitor vdev.
1224 if (ar
->monitor_arvif
)
1227 return ar
->monitor
||
1228 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST
,
1229 ar
->running_fw
->fw_file
.fw_features
) &&
1230 (ar
->filter_flags
& FIF_OTHER_BSS
)) ||
1231 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1234 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1238 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1240 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1241 * shouldn't allow this but make sure to prevent handling the following
1242 * case anyway since multi-channel DFS hasn't been tested at all.
1244 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1250 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1256 lockdep_assert_held(&ar
->conf_mutex
);
1258 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1259 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1261 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1262 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1263 ar
->monitor_started
, needed
, allowed
);
1265 if (WARN_ON(needed
&& !allowed
)) {
1266 if (ar
->monitor_started
) {
1267 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1269 ret
= ath10k_monitor_stop(ar
);
1271 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n",
1279 if (needed
== ar
->monitor_started
)
1283 return ath10k_monitor_start(ar
);
1285 return ath10k_monitor_stop(ar
);
1288 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif
*arvif
)
1290 struct ath10k
*ar
= arvif
->ar
;
1292 lockdep_assert_held(&ar
->conf_mutex
);
1294 if (!arvif
->is_started
) {
1295 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "defer cts setup, vdev is not ready yet\n");
1302 static int ath10k_mac_set_cts_prot(struct ath10k_vif
*arvif
)
1304 struct ath10k
*ar
= arvif
->ar
;
1307 lockdep_assert_held(&ar
->conf_mutex
);
1309 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
1311 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_protection %d\n",
1312 arvif
->vdev_id
, arvif
->use_cts_prot
);
1314 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1315 arvif
->use_cts_prot
? 1 : 0);
1318 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1320 struct ath10k
*ar
= arvif
->ar
;
1321 u32 vdev_param
, rts_cts
= 0;
1323 lockdep_assert_held(&ar
->conf_mutex
);
1325 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1327 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1329 if (arvif
->num_legacy_stations
> 0)
1330 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1331 WMI_RTSCTS_PROFILE
);
1333 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1334 WMI_RTSCTS_PROFILE
);
1336 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d recalc rts/cts prot %d\n",
1337 arvif
->vdev_id
, rts_cts
);
1339 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1343 static int ath10k_start_cac(struct ath10k
*ar
)
1347 lockdep_assert_held(&ar
->conf_mutex
);
1349 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1351 ret
= ath10k_monitor_recalc(ar
);
1353 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1354 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1358 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1359 ar
->monitor_vdev_id
);
1364 static int ath10k_stop_cac(struct ath10k
*ar
)
1366 lockdep_assert_held(&ar
->conf_mutex
);
1368 /* CAC is not running - do nothing */
1369 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1372 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1373 ath10k_monitor_stop(ar
);
1375 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1380 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1381 struct ieee80211_chanctx_conf
*conf
,
1386 if (!*ret
&& conf
->radar_enabled
)
1390 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1392 bool has_radar
= false;
1394 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1395 ath10k_mac_has_radar_iter
,
1401 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1405 lockdep_assert_held(&ar
->conf_mutex
);
1407 ath10k_stop_cac(ar
);
1409 if (!ath10k_mac_has_radar_enabled(ar
))
1412 if (ar
->num_started_vdevs
> 0)
1415 ret
= ath10k_start_cac(ar
);
1418 * Not possible to start CAC on current channel so starting
1419 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1420 * by indicating that radar was detected.
1422 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1423 ieee80211_radar_detected(ar
->hw
);
1427 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1429 struct ath10k
*ar
= arvif
->ar
;
1432 lockdep_assert_held(&ar
->conf_mutex
);
1434 reinit_completion(&ar
->vdev_setup_done
);
1435 reinit_completion(&ar
->vdev_delete_done
);
1437 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1439 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1440 arvif
->vdev_id
, ret
);
1444 ret
= ath10k_vdev_setup_sync(ar
);
1446 ath10k_warn(ar
, "failed to synchronize setup for vdev %i: %d\n",
1447 arvif
->vdev_id
, ret
);
1451 WARN_ON(ar
->num_started_vdevs
== 0);
1453 if (ar
->num_started_vdevs
!= 0) {
1454 ar
->num_started_vdevs
--;
1455 ath10k_recalc_radar_detection(ar
);
1461 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1462 const struct cfg80211_chan_def
*chandef
,
1465 struct ath10k
*ar
= arvif
->ar
;
1466 struct wmi_vdev_start_request_arg arg
= {};
1469 lockdep_assert_held(&ar
->conf_mutex
);
1471 reinit_completion(&ar
->vdev_setup_done
);
1472 reinit_completion(&ar
->vdev_delete_done
);
1474 arg
.vdev_id
= arvif
->vdev_id
;
1475 arg
.dtim_period
= arvif
->dtim_period
;
1476 arg
.bcn_intval
= arvif
->beacon_interval
;
1478 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1479 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1480 arg
.channel
.band_center_freq2
= chandef
->center_freq2
;
1481 arg
.channel
.mode
= chan_to_phymode(chandef
);
1483 arg
.channel
.min_power
= 0;
1484 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1485 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1486 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1488 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1489 arg
.ssid
= arvif
->u
.ap
.ssid
;
1490 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1491 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1493 /* For now allow DFS for AP mode */
1494 arg
.channel
.chan_radar
=
1495 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1496 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1497 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1498 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1501 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1502 "mac vdev %d start center_freq %d phymode %s\n",
1503 arg
.vdev_id
, arg
.channel
.freq
,
1504 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1507 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1509 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1512 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1517 ret
= ath10k_vdev_setup_sync(ar
);
1520 "failed to synchronize setup for vdev %i restart %d: %d\n",
1521 arg
.vdev_id
, restart
, ret
);
1525 ar
->num_started_vdevs
++;
1526 ath10k_recalc_radar_detection(ar
);
1531 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1532 const struct cfg80211_chan_def
*def
)
1534 return ath10k_vdev_start_restart(arvif
, def
, false);
1537 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1538 const struct cfg80211_chan_def
*def
)
1540 return ath10k_vdev_start_restart(arvif
, def
, true);
1543 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1544 struct sk_buff
*bcn
)
1546 struct ath10k
*ar
= arvif
->ar
;
1547 struct ieee80211_mgmt
*mgmt
;
1551 if (arvif
->vif
->type
!= NL80211_IFTYPE_AP
|| !arvif
->vif
->p2p
)
1554 mgmt
= (void *)bcn
->data
;
1555 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1556 mgmt
->u
.beacon
.variable
,
1557 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1562 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1564 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1565 arvif
->vdev_id
, ret
);
1572 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1573 u8 oui_type
, size_t ie_offset
)
1580 if (WARN_ON(skb
->len
< ie_offset
))
1583 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1584 skb
->data
+ ie_offset
,
1585 skb
->len
- ie_offset
);
1590 end
= skb
->data
+ skb
->len
;
1593 if (WARN_ON(next
> end
))
1596 memmove(ie
, next
, end
- next
);
1597 skb_trim(skb
, skb
->len
- len
);
1602 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1604 struct ath10k
*ar
= arvif
->ar
;
1605 struct ieee80211_hw
*hw
= ar
->hw
;
1606 struct ieee80211_vif
*vif
= arvif
->vif
;
1607 struct ieee80211_mutable_offsets offs
= {};
1608 struct sk_buff
*bcn
;
1611 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1614 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1615 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1618 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1620 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1624 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1626 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1631 /* P2P IE is inserted by firmware automatically (as configured above)
1632 * so remove it from the base beacon template to avoid duplicate P2P
1633 * IEs in beacon frames.
1635 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1636 offsetof(struct ieee80211_mgmt
,
1637 u
.beacon
.variable
));
1639 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1644 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1652 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1654 struct ath10k
*ar
= arvif
->ar
;
1655 struct ieee80211_hw
*hw
= ar
->hw
;
1656 struct ieee80211_vif
*vif
= arvif
->vif
;
1657 struct sk_buff
*prb
;
1660 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1663 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1666 /* For mesh, probe response and beacon share the same template */
1667 if (ieee80211_vif_is_mesh(vif
))
1670 prb
= ieee80211_proberesp_get(hw
, vif
);
1672 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1676 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1680 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1688 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1690 struct ath10k
*ar
= arvif
->ar
;
1691 struct cfg80211_chan_def def
;
1694 /* When originally vdev is started during assign_vif_chanctx() some
1695 * information is missing, notably SSID. Firmware revisions with beacon
1696 * offloading require the SSID to be provided during vdev (re)start to
1697 * handle hidden SSID properly.
1699 * Vdev restart must be done after vdev has been both started and
1700 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1701 * deliver vdev restart response event causing timeouts during vdev
1702 * syncing in ath10k.
1704 * Note: The vdev down/up and template reinstallation could be skipped
1705 * since only wmi-tlv firmware are known to have beacon offload and
1706 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1707 * response delivery. It's probably more robust to keep it as is.
1709 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1712 if (WARN_ON(!arvif
->is_started
))
1715 if (WARN_ON(!arvif
->is_up
))
1718 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1721 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1723 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1724 arvif
->vdev_id
, ret
);
1728 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1729 * firmware will crash upon vdev up.
1732 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1734 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1738 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1740 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1744 ret
= ath10k_vdev_restart(arvif
, &def
);
1746 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1747 arvif
->vdev_id
, ret
);
1751 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1754 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1755 arvif
->vdev_id
, ret
);
1762 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1763 struct ieee80211_bss_conf
*info
)
1765 struct ath10k
*ar
= arvif
->ar
;
1768 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1770 if (!info
->enable_beacon
) {
1771 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1773 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1774 arvif
->vdev_id
, ret
);
1776 arvif
->is_up
= false;
1778 spin_lock_bh(&arvif
->ar
->data_lock
);
1779 ath10k_mac_vif_beacon_free(arvif
);
1780 spin_unlock_bh(&arvif
->ar
->data_lock
);
1785 arvif
->tx_seq_no
= 0x1000;
1788 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1790 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1793 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1794 arvif
->vdev_id
, ret
);
1798 arvif
->is_up
= true;
1800 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1802 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1803 arvif
->vdev_id
, ret
);
1807 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1810 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1811 struct ieee80211_bss_conf
*info
,
1812 const u8 self_peer
[ETH_ALEN
])
1814 struct ath10k
*ar
= arvif
->ar
;
1818 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1820 if (!info
->ibss_joined
) {
1821 if (is_zero_ether_addr(arvif
->bssid
))
1824 eth_zero_addr(arvif
->bssid
);
1829 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1830 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1831 ATH10K_DEFAULT_ATIM
);
1833 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1834 arvif
->vdev_id
, ret
);
1837 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1839 struct ath10k
*ar
= arvif
->ar
;
1844 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1846 if (arvif
->u
.sta
.uapsd
)
1847 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1849 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1851 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1852 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1854 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1855 value
, arvif
->vdev_id
, ret
);
1862 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1864 struct ath10k
*ar
= arvif
->ar
;
1869 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1871 if (arvif
->u
.sta
.uapsd
)
1872 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1874 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1876 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1877 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1880 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1881 value
, arvif
->vdev_id
, ret
);
1888 static int ath10k_mac_num_vifs_started(struct ath10k
*ar
)
1890 struct ath10k_vif
*arvif
;
1893 lockdep_assert_held(&ar
->conf_mutex
);
1895 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1896 if (arvif
->is_started
)
1902 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1904 struct ath10k
*ar
= arvif
->ar
;
1905 struct ieee80211_vif
*vif
= arvif
->vif
;
1906 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1907 enum wmi_sta_powersave_param param
;
1908 enum wmi_sta_ps_mode psmode
;
1913 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1915 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1918 enable_ps
= arvif
->ps
;
1920 if (enable_ps
&& ath10k_mac_num_vifs_started(ar
) > 1 &&
1921 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1922 ar
->running_fw
->fw_file
.fw_features
)) {
1923 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1928 if (!arvif
->is_started
) {
1929 /* mac80211 can update vif powersave state while disconnected.
1930 * Firmware doesn't behave nicely and consumes more power than
1931 * necessary if PS is disabled on a non-started vdev. Hence
1932 * force-enable PS for non-running vdevs.
1934 psmode
= WMI_STA_PS_MODE_ENABLED
;
1935 } else if (enable_ps
) {
1936 psmode
= WMI_STA_PS_MODE_ENABLED
;
1937 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1939 ps_timeout
= conf
->dynamic_ps_timeout
;
1940 if (ps_timeout
== 0) {
1941 /* Firmware doesn't like 0 */
1942 ps_timeout
= ieee80211_tu_to_usec(
1943 vif
->bss_conf
.beacon_int
) / 1000;
1946 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1949 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1950 arvif
->vdev_id
, ret
);
1954 psmode
= WMI_STA_PS_MODE_DISABLED
;
1957 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1958 arvif
->vdev_id
, psmode
? "enable" : "disable");
1960 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1962 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1963 psmode
, arvif
->vdev_id
, ret
);
1970 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1972 struct ath10k
*ar
= arvif
->ar
;
1973 struct wmi_sta_keepalive_arg arg
= {};
1976 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1978 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1981 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1984 /* Some firmware revisions have a bug and ignore the `enabled` field.
1985 * Instead use the interval to disable the keepalive.
1987 arg
.vdev_id
= arvif
->vdev_id
;
1989 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1990 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1992 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1994 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
1995 arvif
->vdev_id
, ret
);
2002 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
2004 struct ath10k
*ar
= arvif
->ar
;
2005 struct ieee80211_vif
*vif
= arvif
->vif
;
2008 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
2010 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
2013 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
2016 if (!vif
->csa_active
)
2022 if (!ieee80211_beacon_cntdwn_is_complete(vif
)) {
2023 ieee80211_beacon_update_cntdwn(vif
);
2025 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
2027 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
2030 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
2032 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
2035 ieee80211_csa_finish(vif
);
2039 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
2041 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
2043 struct ath10k
*ar
= arvif
->ar
;
2045 mutex_lock(&ar
->conf_mutex
);
2046 ath10k_mac_vif_ap_csa_count_down(arvif
);
2047 mutex_unlock(&ar
->conf_mutex
);
2050 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
2051 struct ieee80211_vif
*vif
)
2053 struct sk_buff
*skb
= data
;
2054 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
2055 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2057 if (vif
->type
!= NL80211_IFTYPE_STATION
)
2060 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
2063 cancel_delayed_work(&arvif
->connection_loss_work
);
2066 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
2068 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2069 ATH10K_ITER_NORMAL_FLAGS
,
2070 ath10k_mac_handle_beacon_iter
,
2074 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
2075 struct ieee80211_vif
*vif
)
2077 u32
*vdev_id
= data
;
2078 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2079 struct ath10k
*ar
= arvif
->ar
;
2080 struct ieee80211_hw
*hw
= ar
->hw
;
2082 if (arvif
->vdev_id
!= *vdev_id
)
2088 ieee80211_beacon_loss(vif
);
2090 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2091 * (done by mac80211) succeeds but beacons do not resume then it
2092 * doesn't make sense to continue operation. Queue connection loss work
2093 * which can be cancelled when beacon is received.
2095 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
2096 ATH10K_CONNECTION_LOSS_HZ
);
2099 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
2101 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2102 ATH10K_ITER_NORMAL_FLAGS
,
2103 ath10k_mac_handle_beacon_miss_iter
,
2107 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
2109 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
2110 connection_loss_work
.work
);
2111 struct ieee80211_vif
*vif
= arvif
->vif
;
2116 ieee80211_connection_loss(vif
);
2119 /**********************/
2120 /* Station management */
2121 /**********************/
2123 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
2124 struct ieee80211_vif
*vif
)
2126 /* Some firmware revisions have unstable STA powersave when listen
2127 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2128 * generate NullFunc frames properly even if buffered frames have been
2129 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2130 * buffered frames. Often pinging the device from AP would simply fail.
2132 * As a workaround set it to 1.
2134 if (vif
->type
== NL80211_IFTYPE_STATION
)
2137 return ar
->hw
->conf
.listen_interval
;
2140 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
2141 struct ieee80211_vif
*vif
,
2142 struct ieee80211_sta
*sta
,
2143 struct wmi_peer_assoc_complete_arg
*arg
)
2145 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2148 lockdep_assert_held(&ar
->conf_mutex
);
2150 if (vif
->type
== NL80211_IFTYPE_STATION
)
2151 aid
= vif
->bss_conf
.aid
;
2155 ether_addr_copy(arg
->addr
, sta
->addr
);
2156 arg
->vdev_id
= arvif
->vdev_id
;
2157 arg
->peer_aid
= aid
;
2158 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->auth
;
2159 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
2160 arg
->peer_num_spatial_streams
= 1;
2161 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
2164 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
2165 struct ieee80211_vif
*vif
,
2166 struct ieee80211_sta
*sta
,
2167 struct wmi_peer_assoc_complete_arg
*arg
)
2169 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
2170 struct cfg80211_chan_def def
;
2171 struct cfg80211_bss
*bss
;
2172 const u8
*rsnie
= NULL
;
2173 const u8
*wpaie
= NULL
;
2175 lockdep_assert_held(&ar
->conf_mutex
);
2177 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2180 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
, NULL
, 0,
2181 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
2183 const struct cfg80211_bss_ies
*ies
;
2186 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
2188 ies
= rcu_dereference(bss
->ies
);
2190 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
2191 WLAN_OUI_TYPE_MICROSOFT_WPA
,
2195 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
2198 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2199 if (rsnie
|| wpaie
) {
2200 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
2201 arg
->peer_flags
|= ar
->wmi
.peer_flags
->need_ptk_4_way
;
2205 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
2206 arg
->peer_flags
|= ar
->wmi
.peer_flags
->need_gtk_2_way
;
2210 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT
,
2211 ar
->running_fw
->fw_file
.fw_features
)) {
2212 arg
->peer_flags
|= ar
->wmi
.peer_flags
->pmf
;
2216 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
2217 struct ieee80211_vif
*vif
,
2218 struct ieee80211_sta
*sta
,
2219 struct wmi_peer_assoc_complete_arg
*arg
)
2221 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2222 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
2223 struct cfg80211_chan_def def
;
2224 const struct ieee80211_supported_band
*sband
;
2225 const struct ieee80211_rate
*rates
;
2226 enum nl80211_band band
;
2231 lockdep_assert_held(&ar
->conf_mutex
);
2233 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2236 band
= def
.chan
->band
;
2237 sband
= ar
->hw
->wiphy
->bands
[band
];
2238 ratemask
= sta
->supp_rates
[band
];
2239 ratemask
&= arvif
->bitrate_mask
.control
[band
].legacy
;
2240 rates
= sband
->bitrates
;
2242 rateset
->num_rates
= 0;
2244 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2245 if (!(ratemask
& 1))
2248 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2249 rateset
->rates
[rateset
->num_rates
] = rate
;
2250 rateset
->num_rates
++;
2255 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
2259 for (nss
= 0; nss
< IEEE80211_HT_MCS_MASK_LEN
; nss
++)
2260 if (ht_mcs_mask
[nss
])
2267 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
2271 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++)
2272 if (vht_mcs_mask
[nss
])
2278 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2279 struct ieee80211_vif
*vif
,
2280 struct ieee80211_sta
*sta
,
2281 struct wmi_peer_assoc_complete_arg
*arg
)
2283 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2284 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2285 struct cfg80211_chan_def def
;
2286 enum nl80211_band band
;
2287 const u8
*ht_mcs_mask
;
2288 const u16
*vht_mcs_mask
;
2293 lockdep_assert_held(&ar
->conf_mutex
);
2295 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2298 if (!ht_cap
->ht_supported
)
2301 band
= def
.chan
->band
;
2302 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2303 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2305 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
) &&
2306 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2309 arg
->peer_flags
|= ar
->wmi
.peer_flags
->ht
;
2310 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2311 ht_cap
->ampdu_factor
)) - 1;
2313 arg
->peer_mpdu_density
=
2314 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2316 arg
->peer_ht_caps
= ht_cap
->cap
;
2317 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2319 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2320 arg
->peer_flags
|= ar
->wmi
.peer_flags
->ldbc
;
2322 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2323 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw40
;
2324 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2327 if (arvif
->bitrate_mask
.control
[band
].gi
!= NL80211_TXRATE_FORCE_LGI
) {
2328 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2329 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2331 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2332 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2335 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2336 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2337 arg
->peer_flags
|= ar
->wmi
.peer_flags
->stbc
;
2340 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2341 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2342 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2343 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2344 arg
->peer_rate_caps
|= stbc
;
2345 arg
->peer_flags
|= ar
->wmi
.peer_flags
->stbc
;
2348 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2349 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2350 else if (ht_cap
->mcs
.rx_mask
[1])
2351 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2353 for (i
= 0, n
= 0, max_nss
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
* 8; i
++)
2354 if ((ht_cap
->mcs
.rx_mask
[i
/ 8] & BIT(i
% 8)) &&
2355 (ht_mcs_mask
[i
/ 8] & BIT(i
% 8))) {
2356 max_nss
= (i
/ 8) + 1;
2357 arg
->peer_ht_rates
.rates
[n
++] = i
;
2361 * This is a workaround for HT-enabled STAs which break the spec
2362 * and have no HT capabilities RX mask (no HT RX MCS map).
2364 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2365 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2367 * Firmware asserts if such situation occurs.
2370 arg
->peer_ht_rates
.num_rates
= 8;
2371 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2372 arg
->peer_ht_rates
.rates
[i
] = i
;
2374 arg
->peer_ht_rates
.num_rates
= n
;
2375 arg
->peer_num_spatial_streams
= min(sta
->rx_nss
, max_nss
);
2378 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2380 arg
->peer_ht_rates
.num_rates
,
2381 arg
->peer_num_spatial_streams
);
2384 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2385 struct ath10k_vif
*arvif
,
2386 struct ieee80211_sta
*sta
)
2392 lockdep_assert_held(&ar
->conf_mutex
);
2394 if (sta
->wme
&& sta
->uapsd_queues
) {
2395 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2396 sta
->uapsd_queues
, sta
->max_sp
);
2398 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2399 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2400 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2401 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2402 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2403 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2404 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2405 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2406 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2407 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2408 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2409 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2411 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2412 max_sp
= sta
->max_sp
;
2414 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2416 WMI_AP_PS_PEER_PARAM_UAPSD
,
2419 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2420 arvif
->vdev_id
, ret
);
2424 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2426 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2429 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2430 arvif
->vdev_id
, ret
);
2434 /* TODO setup this based on STA listen interval and
2435 * beacon interval. Currently we don't know
2436 * sta->listen_interval - mac80211 patch required.
2437 * Currently use 10 seconds
2439 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2440 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2443 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2444 arvif
->vdev_id
, ret
);
2453 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set
,
2454 const u16 vht_mcs_limit
[NL80211_VHT_NSS_MAX
])
2461 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
2462 mcs_map
= ath10k_mac_get_max_vht_mcs_map(tx_mcs_set
, nss
) &
2466 idx_limit
= fls(mcs_map
) - 1;
2470 switch (idx_limit
) {
2479 /* see ath10k_mac_can_set_bitrate_mask() */
2483 mcs
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
2486 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_7
;
2489 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_8
;
2492 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_9
;
2496 tx_mcs_set
&= ~(0x3 << (nss
* 2));
2497 tx_mcs_set
|= mcs
<< (nss
* 2);
2503 static u32
get_160mhz_nss_from_maxrate(int rate
)
2515 nss
= 3; /* not support MCS9 from spec*/
2527 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2528 struct ieee80211_vif
*vif
,
2529 struct ieee80211_sta
*sta
,
2530 struct wmi_peer_assoc_complete_arg
*arg
)
2532 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
2533 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2534 struct ath10k_hw_params
*hw
= &ar
->hw_params
;
2535 struct cfg80211_chan_def def
;
2536 enum nl80211_band band
;
2537 const u16
*vht_mcs_mask
;
2539 u8 max_nss
, vht_mcs
;
2542 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2545 if (!vht_cap
->vht_supported
)
2548 band
= def
.chan
->band
;
2549 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2551 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2554 arg
->peer_flags
|= ar
->wmi
.peer_flags
->vht
;
2556 if (def
.chan
->band
== NL80211_BAND_2GHZ
)
2557 arg
->peer_flags
|= ar
->wmi
.peer_flags
->vht_2g
;
2559 arg
->peer_vht_caps
= vht_cap
->cap
;
2561 ampdu_factor
= (vht_cap
->cap
&
2562 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2563 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2565 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2566 * zero in VHT IE. Using it would result in degraded throughput.
2567 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2568 * it if VHT max_mpdu is smaller.
2570 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2571 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2572 ampdu_factor
)) - 1);
2574 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2575 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw80
;
2577 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_160
)
2578 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw160
;
2580 /* Calculate peer NSS capability from VHT capabilities if STA
2583 for (i
= 0, max_nss
= 0, vht_mcs
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
2584 vht_mcs
= __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
) >>
2587 if ((vht_mcs
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
) &&
2591 arg
->peer_num_spatial_streams
= min(sta
->rx_nss
, max_nss
);
2592 arg
->peer_vht_rates
.rx_max_rate
=
2593 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2594 arg
->peer_vht_rates
.rx_mcs_set
=
2595 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2596 arg
->peer_vht_rates
.tx_max_rate
=
2597 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2598 arg
->peer_vht_rates
.tx_mcs_set
= ath10k_peer_assoc_h_vht_limit(
2599 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
), vht_mcs_mask
);
2601 /* Configure bandwidth-NSS mapping to FW
2602 * for the chip's tx chains setting on 160Mhz bw
2604 if (arg
->peer_phymode
== MODE_11AC_VHT160
||
2605 arg
->peer_phymode
== MODE_11AC_VHT80_80
) {
2609 max_rate
= arg
->peer_vht_rates
.rx_max_rate
;
2610 rx_nss
= get_160mhz_nss_from_maxrate(max_rate
);
2613 rx_nss
= arg
->peer_num_spatial_streams
;
2615 rx_nss
= min(arg
->peer_num_spatial_streams
, rx_nss
);
2617 max_rate
= hw
->vht160_mcs_tx_highest
;
2618 rx_nss
= min(rx_nss
, get_160mhz_nss_from_maxrate(max_rate
));
2620 arg
->peer_bw_rxnss_override
=
2621 FIELD_PREP(WMI_PEER_NSS_MAP_ENABLE
, 1) |
2622 FIELD_PREP(WMI_PEER_NSS_160MHZ_MASK
, (rx_nss
- 1));
2624 if (arg
->peer_phymode
== MODE_11AC_VHT80_80
) {
2625 arg
->peer_bw_rxnss_override
|=
2626 FIELD_PREP(WMI_PEER_NSS_80_80MHZ_MASK
, (rx_nss
- 1));
2629 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2630 "mac vht peer %pM max_mpdu %d flags 0x%x peer_rx_nss_override 0x%x\n",
2631 sta
->addr
, arg
->peer_max_mpdu
,
2632 arg
->peer_flags
, arg
->peer_bw_rxnss_override
);
2635 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2636 struct ieee80211_vif
*vif
,
2637 struct ieee80211_sta
*sta
,
2638 struct wmi_peer_assoc_complete_arg
*arg
)
2640 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2642 switch (arvif
->vdev_type
) {
2643 case WMI_VDEV_TYPE_AP
:
2645 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2647 if (sta
->wme
&& sta
->uapsd_queues
) {
2648 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->apsd
;
2649 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2652 case WMI_VDEV_TYPE_STA
:
2654 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2656 case WMI_VDEV_TYPE_IBSS
:
2658 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2664 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2665 sta
->addr
, !!(arg
->peer_flags
&
2666 arvif
->ar
->wmi
.peer_flags
->qos
));
2669 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2671 return sta
->supp_rates
[NL80211_BAND_2GHZ
] >>
2672 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2675 static enum wmi_phy_mode
ath10k_mac_get_phymode_vht(struct ath10k
*ar
,
2676 struct ieee80211_sta
*sta
)
2678 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_160
) {
2679 switch (sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) {
2680 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
:
2681 return MODE_11AC_VHT160
;
2682 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
:
2683 return MODE_11AC_VHT80_80
;
2685 /* not sure if this is a valid case? */
2686 return MODE_11AC_VHT160
;
2690 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2691 return MODE_11AC_VHT80
;
2693 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2694 return MODE_11AC_VHT40
;
2696 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2697 return MODE_11AC_VHT20
;
2699 return MODE_UNKNOWN
;
2702 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2703 struct ieee80211_vif
*vif
,
2704 struct ieee80211_sta
*sta
,
2705 struct wmi_peer_assoc_complete_arg
*arg
)
2707 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2708 struct cfg80211_chan_def def
;
2709 enum nl80211_band band
;
2710 const u8
*ht_mcs_mask
;
2711 const u16
*vht_mcs_mask
;
2712 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2714 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2717 band
= def
.chan
->band
;
2718 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2719 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2722 case NL80211_BAND_2GHZ
:
2723 if (sta
->vht_cap
.vht_supported
&&
2724 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2725 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2726 phymode
= MODE_11AC_VHT40
;
2728 phymode
= MODE_11AC_VHT20
;
2729 } else if (sta
->ht_cap
.ht_supported
&&
2730 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2731 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2732 phymode
= MODE_11NG_HT40
;
2734 phymode
= MODE_11NG_HT20
;
2735 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2742 case NL80211_BAND_5GHZ
:
2746 if (sta
->vht_cap
.vht_supported
&&
2747 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2748 phymode
= ath10k_mac_get_phymode_vht(ar
, sta
);
2749 } else if (sta
->ht_cap
.ht_supported
&&
2750 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2751 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
)
2752 phymode
= MODE_11NA_HT40
;
2754 phymode
= MODE_11NA_HT20
;
2764 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2765 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2767 arg
->peer_phymode
= phymode
;
2768 WARN_ON(phymode
== MODE_UNKNOWN
);
2771 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2772 struct ieee80211_vif
*vif
,
2773 struct ieee80211_sta
*sta
,
2774 struct wmi_peer_assoc_complete_arg
*arg
)
2776 lockdep_assert_held(&ar
->conf_mutex
);
2778 memset(arg
, 0, sizeof(*arg
));
2780 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2781 ath10k_peer_assoc_h_crypto(ar
, vif
, sta
, arg
);
2782 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2783 ath10k_peer_assoc_h_ht(ar
, vif
, sta
, arg
);
2784 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2785 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2786 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2791 static const u32 ath10k_smps_map
[] = {
2792 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2793 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2794 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2795 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2798 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2800 const struct ieee80211_sta_ht_cap
*ht_cap
)
2804 if (!ht_cap
->ht_supported
)
2807 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2808 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2810 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2813 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2814 ar
->wmi
.peer_param
->smps_state
,
2815 ath10k_smps_map
[smps
]);
2818 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2819 struct ieee80211_vif
*vif
,
2820 struct ieee80211_sta_vht_cap vht_cap
)
2822 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2827 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_AFTER_ASSOC
)
2830 if (!(ar
->vht_cap_info
&
2831 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2832 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2833 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2834 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2837 param
= ar
->wmi
.vdev_param
->txbf
;
2840 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2843 /* The following logic is correct. If a remote STA advertises support
2844 * for being a beamformer then we should enable us being a beamformee.
2847 if (ar
->vht_cap_info
&
2848 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2849 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2850 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2851 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2853 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2854 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2857 if (ar
->vht_cap_info
&
2858 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2859 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2860 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2861 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2863 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2864 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2867 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2868 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2870 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2871 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2873 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2875 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2883 /* can be called only in mac80211 callbacks due to `key_count` usage */
2884 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2885 struct ieee80211_vif
*vif
,
2886 struct ieee80211_bss_conf
*bss_conf
)
2888 struct ath10k
*ar
= hw
->priv
;
2889 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2890 struct ieee80211_sta_ht_cap ht_cap
;
2891 struct ieee80211_sta_vht_cap vht_cap
;
2892 struct wmi_peer_assoc_complete_arg peer_arg
;
2893 struct ieee80211_sta
*ap_sta
;
2896 lockdep_assert_held(&ar
->conf_mutex
);
2898 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2899 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2903 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2905 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2906 bss_conf
->bssid
, arvif
->vdev_id
);
2911 /* ap_sta must be accessed only within rcu section which must be left
2912 * before calling ath10k_setup_peer_smps() which might sleep.
2914 ht_cap
= ap_sta
->ht_cap
;
2915 vht_cap
= ap_sta
->vht_cap
;
2917 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2919 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2920 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2927 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2929 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2930 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2934 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2936 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2937 arvif
->vdev_id
, ret
);
2941 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2943 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2944 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2948 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2949 "mac vdev %d up (associated) bssid %pM aid %d\n",
2950 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2952 WARN_ON(arvif
->is_up
);
2954 arvif
->aid
= bss_conf
->aid
;
2955 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2957 ret
= ath10k_wmi_pdev_set_param(ar
,
2958 ar
->wmi
.pdev_param
->peer_stats_info_enable
, 1);
2960 ath10k_warn(ar
, "failed to enable peer stats info: %d\n", ret
);
2962 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2964 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2965 arvif
->vdev_id
, ret
);
2969 arvif
->is_up
= true;
2971 /* Workaround: Some firmware revisions (tested with qca6174
2972 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2973 * poked with peer param command.
2975 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2976 ar
->wmi
.peer_param
->dummy_var
, 1);
2978 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2979 arvif
->bssid
, arvif
->vdev_id
, ret
);
2984 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2985 struct ieee80211_vif
*vif
)
2987 struct ath10k
*ar
= hw
->priv
;
2988 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2989 struct ieee80211_sta_vht_cap vht_cap
= {};
2992 lockdep_assert_held(&ar
->conf_mutex
);
2994 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2995 arvif
->vdev_id
, arvif
->bssid
);
2997 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2999 ath10k_warn(ar
, "failed to down vdev %i: %d\n",
3000 arvif
->vdev_id
, ret
);
3002 arvif
->def_wep_key_idx
= -1;
3004 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
3006 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
3007 arvif
->vdev_id
, ret
);
3011 arvif
->is_up
= false;
3013 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
3016 static int ath10k_new_peer_tid_config(struct ath10k
*ar
,
3017 struct ieee80211_sta
*sta
,
3018 struct ath10k_vif
*arvif
)
3020 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
3021 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3025 for (i
= 0; i
< ATH10K_TID_MAX
; i
++) {
3026 config_apply
= false;
3027 if (arvif
->retry_long
[i
] || arvif
->ampdu
[i
] ||
3028 arvif
->rate_ctrl
[i
] || arvif
->rtscts
[i
]) {
3029 config_apply
= true;
3031 arg
.vdev_id
= arvif
->vdev_id
;
3032 arg
.retry_count
= arvif
->retry_long
[i
];
3033 arg
.aggr_control
= arvif
->ampdu
[i
];
3034 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
3035 arg
.rcode_flags
= arvif
->rate_code
[i
];
3037 if (arvif
->rtscts
[i
])
3038 arg
.ext_tid_cfg_bitmap
=
3039 WMI_EXT_TID_RTS_CTS_CONFIG
;
3041 arg
.ext_tid_cfg_bitmap
= 0;
3043 arg
.rtscts_ctrl
= arvif
->rtscts
[i
];
3046 if (arvif
->noack
[i
]) {
3047 arg
.ack_policy
= arvif
->noack
[i
];
3048 arg
.rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE
;
3049 arg
.aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
3050 config_apply
= true;
3053 /* Assign default value(-1) to newly connected station.
3054 * This is to identify station specific tid configuration not
3055 * configured for the station.
3057 arsta
->retry_long
[i
] = -1;
3058 arsta
->noack
[i
] = -1;
3059 arsta
->ampdu
[i
] = -1;
3064 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
3066 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
3068 ath10k_warn(ar
, "failed to set per tid retry/aggr config for sta %pM: %d\n",
3073 memset(&arg
, 0, sizeof(arg
));
3079 static int ath10k_station_assoc(struct ath10k
*ar
,
3080 struct ieee80211_vif
*vif
,
3081 struct ieee80211_sta
*sta
,
3084 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3085 struct wmi_peer_assoc_complete_arg peer_arg
;
3088 lockdep_assert_held(&ar
->conf_mutex
);
3090 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
3092 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
3093 sta
->addr
, arvif
->vdev_id
, ret
);
3097 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
3099 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
3100 sta
->addr
, arvif
->vdev_id
, ret
);
3104 /* Re-assoc is run only to update supported rates for given station. It
3105 * doesn't make much sense to reconfigure the peer completely.
3108 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
3111 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
3112 arvif
->vdev_id
, ret
);
3116 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
3118 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
3119 sta
->addr
, arvif
->vdev_id
, ret
);
3124 arvif
->num_legacy_stations
++;
3125 ret
= ath10k_recalc_rtscts_prot(arvif
);
3127 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3128 arvif
->vdev_id
, ret
);
3133 /* Plumb cached keys only for static WEP */
3134 if ((arvif
->def_wep_key_idx
!= -1) && (!sta
->tdls
)) {
3135 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
3137 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
3138 arvif
->vdev_id
, ret
);
3144 if (!test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT
, ar
->wmi
.svc_map
))
3147 return ath10k_new_peer_tid_config(ar
, sta
, arvif
);
3150 static int ath10k_station_disassoc(struct ath10k
*ar
,
3151 struct ieee80211_vif
*vif
,
3152 struct ieee80211_sta
*sta
)
3154 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3157 lockdep_assert_held(&ar
->conf_mutex
);
3160 arvif
->num_legacy_stations
--;
3161 ret
= ath10k_recalc_rtscts_prot(arvif
);
3163 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3164 arvif
->vdev_id
, ret
);
3169 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
3171 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
3172 arvif
->vdev_id
, ret
);
3183 static int ath10k_update_channel_list(struct ath10k
*ar
)
3185 struct ieee80211_hw
*hw
= ar
->hw
;
3186 struct ieee80211_supported_band
**bands
;
3187 enum nl80211_band band
;
3188 struct ieee80211_channel
*channel
;
3189 struct wmi_scan_chan_list_arg arg
= {0};
3190 struct wmi_channel_arg
*ch
;
3196 lockdep_assert_held(&ar
->conf_mutex
);
3198 bands
= hw
->wiphy
->bands
;
3199 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
3203 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
3204 if (bands
[band
]->channels
[i
].flags
&
3205 IEEE80211_CHAN_DISABLED
)
3212 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
3213 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
3218 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
3222 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
3223 channel
= &bands
[band
]->channels
[i
];
3225 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
3228 ch
->allow_ht
= true;
3230 /* FIXME: when should we really allow VHT? */
3231 ch
->allow_vht
= true;
3234 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
3237 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
3240 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
3242 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
3243 ch
->passive
= passive
;
3245 /* the firmware is ignoring the "radar" flag of the
3246 * channel and is scanning actively using Probe Requests
3247 * on "Radar detection"/DFS channels which are not
3248 * marked as "available"
3250 ch
->passive
|= ch
->chan_radar
;
3252 ch
->freq
= channel
->center_freq
;
3253 ch
->band_center_freq1
= channel
->center_freq
;
3255 ch
->max_power
= channel
->max_power
* 2;
3256 ch
->max_reg_power
= channel
->max_reg_power
* 2;
3257 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
3258 ch
->reg_class_id
= 0; /* FIXME */
3260 /* FIXME: why use only legacy modes, why not any
3261 * HT/VHT modes? Would that even make any
3264 if (channel
->band
== NL80211_BAND_2GHZ
)
3265 ch
->mode
= MODE_11G
;
3267 ch
->mode
= MODE_11A
;
3269 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
3272 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
3273 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3274 ch
- arg
.channels
, arg
.n_channels
,
3275 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
3276 ch
->max_antenna_gain
, ch
->mode
);
3282 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
3283 kfree(arg
.channels
);
3288 static enum wmi_dfs_region
3289 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
3291 switch (dfs_region
) {
3292 case NL80211_DFS_UNSET
:
3293 return WMI_UNINIT_DFS_DOMAIN
;
3294 case NL80211_DFS_FCC
:
3295 return WMI_FCC_DFS_DOMAIN
;
3296 case NL80211_DFS_ETSI
:
3297 return WMI_ETSI_DFS_DOMAIN
;
3298 case NL80211_DFS_JP
:
3299 return WMI_MKK4_DFS_DOMAIN
;
3301 return WMI_UNINIT_DFS_DOMAIN
;
3304 static void ath10k_regd_update(struct ath10k
*ar
)
3306 struct reg_dmn_pair_mapping
*regpair
;
3308 enum wmi_dfs_region wmi_dfs_reg
;
3309 enum nl80211_dfs_regions nl_dfs_reg
;
3311 lockdep_assert_held(&ar
->conf_mutex
);
3313 ret
= ath10k_update_channel_list(ar
);
3315 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
3317 regpair
= ar
->ath_common
.regulatory
.regpair
;
3319 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3320 nl_dfs_reg
= ar
->dfs_detector
->region
;
3321 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
3323 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
3326 /* Target allows setting up per-band regdomain but ath_common provides
3327 * a combined one only
3329 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
3330 regpair
->reg_domain
,
3331 regpair
->reg_domain
, /* 2ghz */
3332 regpair
->reg_domain
, /* 5ghz */
3333 regpair
->reg_2ghz_ctl
,
3334 regpair
->reg_5ghz_ctl
,
3337 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
3340 static void ath10k_mac_update_channel_list(struct ath10k
*ar
,
3341 struct ieee80211_supported_band
*band
)
3345 if (ar
->low_5ghz_chan
&& ar
->high_5ghz_chan
) {
3346 for (i
= 0; i
< band
->n_channels
; i
++) {
3347 if (band
->channels
[i
].center_freq
< ar
->low_5ghz_chan
||
3348 band
->channels
[i
].center_freq
> ar
->high_5ghz_chan
)
3349 band
->channels
[i
].flags
|=
3350 IEEE80211_CHAN_DISABLED
;
3355 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
3356 struct regulatory_request
*request
)
3358 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
3359 struct ath10k
*ar
= hw
->priv
;
3362 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
3364 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3365 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
3366 request
->dfs_region
);
3367 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
3368 request
->dfs_region
);
3370 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3371 request
->dfs_region
);
3374 mutex_lock(&ar
->conf_mutex
);
3375 if (ar
->state
== ATH10K_STATE_ON
)
3376 ath10k_regd_update(ar
);
3377 mutex_unlock(&ar
->conf_mutex
);
3379 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
3380 ath10k_mac_update_channel_list(ar
,
3381 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
]);
3384 static void ath10k_stop_radar_confirmation(struct ath10k
*ar
)
3386 spin_lock_bh(&ar
->data_lock
);
3387 ar
->radar_conf_state
= ATH10K_RADAR_CONFIRMATION_STOPPED
;
3388 spin_unlock_bh(&ar
->data_lock
);
3390 cancel_work_sync(&ar
->radar_confirmation_work
);
3397 enum ath10k_mac_tx_path
{
3399 ATH10K_MAC_TX_HTT_MGMT
,
3400 ATH10K_MAC_TX_WMI_MGMT
,
3401 ATH10K_MAC_TX_UNKNOWN
,
3404 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
3406 lockdep_assert_held(&ar
->htt
.tx_lock
);
3408 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3409 ar
->tx_paused
|= BIT(reason
);
3410 ieee80211_stop_queues(ar
->hw
);
3413 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
3414 struct ieee80211_vif
*vif
)
3416 struct ath10k
*ar
= data
;
3417 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3419 if (arvif
->tx_paused
)
3422 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3425 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
3427 lockdep_assert_held(&ar
->htt
.tx_lock
);
3429 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3430 ar
->tx_paused
&= ~BIT(reason
);
3435 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3436 ATH10K_ITER_RESUME_FLAGS
,
3437 ath10k_mac_tx_unlock_iter
,
3440 ieee80211_wake_queue(ar
->hw
, ar
->hw
->offchannel_tx_hw_queue
);
3443 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
3445 struct ath10k
*ar
= arvif
->ar
;
3447 lockdep_assert_held(&ar
->htt
.tx_lock
);
3449 WARN_ON(reason
>= BITS_PER_LONG
);
3450 arvif
->tx_paused
|= BIT(reason
);
3451 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
3454 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
3456 struct ath10k
*ar
= arvif
->ar
;
3458 lockdep_assert_held(&ar
->htt
.tx_lock
);
3460 WARN_ON(reason
>= BITS_PER_LONG
);
3461 arvif
->tx_paused
&= ~BIT(reason
);
3466 if (arvif
->tx_paused
)
3469 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3472 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
3473 enum wmi_tlv_tx_pause_id pause_id
,
3474 enum wmi_tlv_tx_pause_action action
)
3476 struct ath10k
*ar
= arvif
->ar
;
3478 lockdep_assert_held(&ar
->htt
.tx_lock
);
3481 case WMI_TLV_TX_PAUSE_ACTION_STOP
:
3482 ath10k_mac_vif_tx_lock(arvif
, pause_id
);
3484 case WMI_TLV_TX_PAUSE_ACTION_WAKE
:
3485 ath10k_mac_vif_tx_unlock(arvif
, pause_id
);
3488 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
3489 "received unknown tx pause action %d on vdev %i, ignoring\n",
3490 action
, arvif
->vdev_id
);
3495 struct ath10k_mac_tx_pause
{
3497 enum wmi_tlv_tx_pause_id pause_id
;
3498 enum wmi_tlv_tx_pause_action action
;
3501 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
3502 struct ieee80211_vif
*vif
)
3504 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3505 struct ath10k_mac_tx_pause
*arg
= data
;
3507 if (arvif
->vdev_id
!= arg
->vdev_id
)
3510 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
3513 void ath10k_mac_handle_tx_pause_vdev(struct ath10k
*ar
, u32 vdev_id
,
3514 enum wmi_tlv_tx_pause_id pause_id
,
3515 enum wmi_tlv_tx_pause_action action
)
3517 struct ath10k_mac_tx_pause arg
= {
3519 .pause_id
= pause_id
,
3523 spin_lock_bh(&ar
->htt
.tx_lock
);
3524 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3525 ATH10K_ITER_RESUME_FLAGS
,
3526 ath10k_mac_handle_tx_pause_iter
,
3528 spin_unlock_bh(&ar
->htt
.tx_lock
);
3531 static enum ath10k_hw_txrx_mode
3532 ath10k_mac_tx_h_get_txmode(struct ath10k
*ar
,
3533 struct ieee80211_vif
*vif
,
3534 struct ieee80211_sta
*sta
,
3535 struct sk_buff
*skb
)
3537 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3538 const struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
3539 __le16 fc
= hdr
->frame_control
;
3541 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3542 return ATH10K_HW_TXRX_RAW
;
3544 if (ieee80211_is_mgmt(fc
))
3545 return ATH10K_HW_TXRX_MGMT
;
3549 * NullFunc frames are mostly used to ping if a client or AP are still
3550 * reachable and responsive. This implies tx status reports must be
3551 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3552 * come to a conclusion that the other end disappeared and tear down
3553 * BSS connection or it can never disconnect from BSS/client (which is
3556 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3557 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3558 * which seems to deliver correct tx reports for NullFunc frames. The
3559 * downside of using it is it ignores client powersave state so it can
3560 * end up disconnecting sleeping clients in AP mode. It should fix STA
3561 * mode though because AP don't sleep.
3563 if (ar
->htt
.target_version_major
< 3 &&
3564 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3565 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3566 ar
->running_fw
->fw_file
.fw_features
))
3567 return ATH10K_HW_TXRX_MGMT
;
3571 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3572 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3573 * to work with Ethernet txmode so use it.
3575 * FIXME: Check if raw mode works with TDLS.
3577 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3578 return ATH10K_HW_TXRX_ETHERNET
;
3580 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
) ||
3581 skb_cb
->flags
& ATH10K_SKB_F_RAW_TX
)
3582 return ATH10K_HW_TXRX_RAW
;
3584 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3587 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif
*vif
,
3588 struct sk_buff
*skb
)
3590 const struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3591 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3592 const u32 mask
= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
3593 IEEE80211_TX_CTL_INJECTED
;
3595 if (!ieee80211_has_protected(hdr
->frame_control
))
3598 if ((info
->flags
& mask
) == mask
)
3602 return !((struct ath10k_vif
*)vif
->drv_priv
)->nohwcrypt
;
3607 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3608 * Control in the header.
3610 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3612 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3613 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3616 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3619 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3620 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3621 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3622 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3624 /* Some firmware revisions don't handle sending QoS NullFunc well.
3625 * These frames are mainly used for CQM purposes so it doesn't really
3626 * matter whether QoS NullFunc or NullFunc are sent.
3628 hdr
= (void *)skb
->data
;
3629 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3630 cb
->flags
&= ~ATH10K_SKB_F_QOS
;
3632 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3635 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3637 struct ieee80211_hdr
*hdr
;
3638 struct rfc1042_hdr
*rfc1042
;
3645 hdr
= (void *)skb
->data
;
3646 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3647 rfc1042
= (void *)skb
->data
+ hdrlen
;
3649 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3650 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3651 type
= rfc1042
->snap_type
;
3653 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3654 skb_push(skb
, sizeof(*eth
));
3656 eth
= (void *)skb
->data
;
3657 ether_addr_copy(eth
->h_dest
, da
);
3658 ether_addr_copy(eth
->h_source
, sa
);
3659 eth
->h_proto
= type
;
3662 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3663 struct ieee80211_vif
*vif
,
3664 struct sk_buff
*skb
)
3666 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3667 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3669 /* This is case only for P2P_GO */
3670 if (vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
)
3673 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3674 spin_lock_bh(&ar
->data_lock
);
3675 if (arvif
->u
.ap
.noa_data
)
3676 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3678 skb_put_data(skb
, arvif
->u
.ap
.noa_data
,
3679 arvif
->u
.ap
.noa_len
);
3680 spin_unlock_bh(&ar
->data_lock
);
3684 static void ath10k_mac_tx_h_fill_cb(struct ath10k
*ar
,
3685 struct ieee80211_vif
*vif
,
3686 struct ieee80211_txq
*txq
,
3687 struct ieee80211_sta
*sta
,
3688 struct sk_buff
*skb
, u16 airtime
)
3690 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3691 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3692 const struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3693 bool is_data
= ieee80211_is_data(hdr
->frame_control
) ||
3694 ieee80211_is_data_qos(hdr
->frame_control
);
3695 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3696 struct ath10k_sta
*arsta
;
3701 if (!ath10k_tx_h_use_hwcrypto(vif
, skb
))
3702 cb
->flags
|= ATH10K_SKB_F_NO_HWCRYPT
;
3704 if (ieee80211_is_mgmt(hdr
->frame_control
))
3705 cb
->flags
|= ATH10K_SKB_F_MGMT
;
3707 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
3708 cb
->flags
|= ATH10K_SKB_F_QOS
;
3709 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3710 tid
= (*qos_ctl
) & IEEE80211_QOS_CTL_TID_MASK
;
3712 if (arvif
->noack
[tid
] == WMI_PEER_TID_CONFIG_NOACK
)
3716 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3718 if (arsta
->noack
[tid
] == WMI_PEER_TID_CONFIG_NOACK
)
3721 if (arsta
->noack
[tid
] == WMI_PEER_TID_CONFIG_ACK
)
3726 cb
->flags
|= ATH10K_SKB_F_NOACK_TID
;
3729 /* Data frames encrypted in software will be posted to firmware
3730 * with tx encap mode set to RAW. Ex: Multicast traffic generated
3731 * for a specific VLAN group will always be encrypted in software.
3733 if (is_data
&& ieee80211_has_protected(hdr
->frame_control
) &&
3734 !info
->control
.hw_key
) {
3735 cb
->flags
|= ATH10K_SKB_F_NO_HWCRYPT
;
3736 cb
->flags
|= ATH10K_SKB_F_RAW_TX
;
3741 cb
->airtime_est
= airtime
;
3743 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3744 spin_lock_bh(&ar
->data_lock
);
3745 cb
->ucast_cipher
= arsta
->ucast_cipher
;
3746 spin_unlock_bh(&ar
->data_lock
);
3750 bool ath10k_mac_tx_frm_has_freq(struct ath10k
*ar
)
3752 /* FIXME: Not really sure since when the behaviour changed. At some
3753 * point new firmware stopped requiring creation of peer entries for
3754 * offchannel tx (and actually creating them causes issues with wmi-htc
3755 * tx credit replenishment and reliability). Assuming it's at least 3.4
3756 * because that's when the `freq` was introduced to TX_FRM HTT command.
3758 return (ar
->htt
.target_version_major
>= 3 &&
3759 ar
->htt
.target_version_minor
>= 4 &&
3760 ar
->running_fw
->fw_file
.htt_op_version
== ATH10K_FW_HTT_OP_VERSION_TLV
);
3763 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3765 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3768 spin_lock_bh(&ar
->data_lock
);
3770 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
3771 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3776 __skb_queue_tail(q
, skb
);
3777 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3780 spin_unlock_bh(&ar
->data_lock
);
3785 static enum ath10k_mac_tx_path
3786 ath10k_mac_tx_h_get_txpath(struct ath10k
*ar
,
3787 struct sk_buff
*skb
,
3788 enum ath10k_hw_txrx_mode txmode
)
3791 case ATH10K_HW_TXRX_RAW
:
3792 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3793 case ATH10K_HW_TXRX_ETHERNET
:
3794 return ATH10K_MAC_TX_HTT
;
3795 case ATH10K_HW_TXRX_MGMT
:
3796 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3797 ar
->running_fw
->fw_file
.fw_features
) ||
3798 test_bit(WMI_SERVICE_MGMT_TX_WMI
,
3800 return ATH10K_MAC_TX_WMI_MGMT
;
3801 else if (ar
->htt
.target_version_major
>= 3)
3802 return ATH10K_MAC_TX_HTT
;
3804 return ATH10K_MAC_TX_HTT_MGMT
;
3807 return ATH10K_MAC_TX_UNKNOWN
;
3810 static int ath10k_mac_tx_submit(struct ath10k
*ar
,
3811 enum ath10k_hw_txrx_mode txmode
,
3812 enum ath10k_mac_tx_path txpath
,
3813 struct sk_buff
*skb
)
3815 struct ath10k_htt
*htt
= &ar
->htt
;
3819 case ATH10K_MAC_TX_HTT
:
3820 ret
= ath10k_htt_tx(htt
, txmode
, skb
);
3822 case ATH10K_MAC_TX_HTT_MGMT
:
3823 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
3825 case ATH10K_MAC_TX_WMI_MGMT
:
3826 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
3828 case ATH10K_MAC_TX_UNKNOWN
:
3835 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
3837 ieee80211_free_txskb(ar
->hw
, skb
);
3843 /* This function consumes the sk_buff regardless of return value as far as
3844 * caller is concerned so no freeing is necessary afterwards.
3846 static int ath10k_mac_tx(struct ath10k
*ar
,
3847 struct ieee80211_vif
*vif
,
3848 enum ath10k_hw_txrx_mode txmode
,
3849 enum ath10k_mac_tx_path txpath
,
3850 struct sk_buff
*skb
, bool noque_offchan
)
3852 struct ieee80211_hw
*hw
= ar
->hw
;
3853 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3854 const struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
3857 /* We should disable CCK RATE due to P2P */
3858 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3859 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3862 case ATH10K_HW_TXRX_MGMT
:
3863 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3864 ath10k_tx_h_nwifi(hw
, skb
);
3865 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3866 ath10k_tx_h_seq_no(vif
, skb
);
3868 case ATH10K_HW_TXRX_ETHERNET
:
3869 ath10k_tx_h_8023(skb
);
3871 case ATH10K_HW_TXRX_RAW
:
3872 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
) &&
3873 !(skb_cb
->flags
& ATH10K_SKB_F_RAW_TX
)) {
3875 ieee80211_free_txskb(hw
, skb
);
3880 if (!noque_offchan
&& info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3881 if (!ath10k_mac_tx_frm_has_freq(ar
)) {
3882 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac queued offchannel skb %pK len %d\n",
3885 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3886 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3891 ret
= ath10k_mac_tx_submit(ar
, txmode
, txpath
, skb
);
3893 ath10k_warn(ar
, "failed to submit frame: %d\n", ret
);
3900 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
3902 struct sk_buff
*skb
;
3905 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3909 ieee80211_free_txskb(ar
->hw
, skb
);
3913 void ath10k_offchan_tx_work(struct work_struct
*work
)
3915 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
3916 struct ath10k_peer
*peer
;
3917 struct ath10k_vif
*arvif
;
3918 enum ath10k_hw_txrx_mode txmode
;
3919 enum ath10k_mac_tx_path txpath
;
3920 struct ieee80211_hdr
*hdr
;
3921 struct ieee80211_vif
*vif
;
3922 struct ieee80211_sta
*sta
;
3923 struct sk_buff
*skb
;
3924 const u8
*peer_addr
;
3927 unsigned long time_left
;
3928 bool tmp_peer_created
= false;
3930 /* FW requirement: We must create a peer before FW will send out
3931 * an offchannel frame. Otherwise the frame will be stuck and
3932 * never transmitted. We delete the peer upon tx completion.
3933 * It is unlikely that a peer for offchannel tx will already be
3934 * present. However it may be in some rare cases so account for that.
3935 * Otherwise we might remove a legitimate peer and break stuff.
3939 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3943 mutex_lock(&ar
->conf_mutex
);
3945 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %pK len %d\n",
3948 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3949 peer_addr
= ieee80211_get_DA(hdr
);
3951 spin_lock_bh(&ar
->data_lock
);
3952 vdev_id
= ar
->scan
.vdev_id
;
3953 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
3954 spin_unlock_bh(&ar
->data_lock
);
3957 /* FIXME: should this use ath10k_warn()? */
3958 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
3959 peer_addr
, vdev_id
);
3962 ret
= ath10k_peer_create(ar
, NULL
, NULL
, vdev_id
,
3964 WMI_PEER_TYPE_DEFAULT
);
3966 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
3967 peer_addr
, vdev_id
, ret
);
3968 tmp_peer_created
= (ret
== 0);
3971 spin_lock_bh(&ar
->data_lock
);
3972 reinit_completion(&ar
->offchan_tx_completed
);
3973 ar
->offchan_tx_skb
= skb
;
3974 spin_unlock_bh(&ar
->data_lock
);
3976 /* It's safe to access vif and sta - conf_mutex guarantees that
3977 * sta_state() and remove_interface() are locked exclusively
3978 * out wrt to this offchannel worker.
3980 arvif
= ath10k_get_arvif(ar
, vdev_id
);
3983 sta
= ieee80211_find_sta(vif
, peer_addr
);
3989 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3990 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
3992 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, true);
3994 ath10k_warn(ar
, "failed to transmit offchannel frame: %d\n",
4000 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
4002 ath10k_warn(ar
, "timed out waiting for offchannel skb %pK, len: %d\n",
4005 if (!peer
&& tmp_peer_created
) {
4006 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
4008 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
4009 peer_addr
, vdev_id
, ret
);
4012 mutex_unlock(&ar
->conf_mutex
);
4016 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
4018 struct sk_buff
*skb
;
4021 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
4025 ieee80211_free_txskb(ar
->hw
, skb
);
4029 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
4031 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
4032 struct sk_buff
*skb
;
4037 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
4041 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF
,
4042 ar
->running_fw
->fw_file
.fw_features
)) {
4043 paddr
= dma_map_single(ar
->dev
, skb
->data
,
4044 skb
->len
, DMA_TO_DEVICE
);
4045 if (dma_mapping_error(ar
->dev
, paddr
)) {
4046 ieee80211_free_txskb(ar
->hw
, skb
);
4049 ret
= ath10k_wmi_mgmt_tx_send(ar
, skb
, paddr
);
4051 ath10k_warn(ar
, "failed to transmit management frame by ref via WMI: %d\n",
4053 /* remove this msdu from idr tracking */
4054 ath10k_wmi_cleanup_mgmt_tx_send(ar
, skb
);
4056 dma_unmap_single(ar
->dev
, paddr
, skb
->len
,
4058 ieee80211_free_txskb(ar
->hw
, skb
);
4061 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
4063 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
4065 ieee80211_free_txskb(ar
->hw
, skb
);
4071 static void ath10k_mac_txq_init(struct ieee80211_txq
*txq
)
4073 struct ath10k_txq
*artxq
;
4078 artxq
= (void *)txq
->drv_priv
;
4079 INIT_LIST_HEAD(&artxq
->list
);
4082 static void ath10k_mac_txq_unref(struct ath10k
*ar
, struct ieee80211_txq
*txq
)
4084 struct ath10k_skb_cb
*cb
;
4085 struct sk_buff
*msdu
;
4091 spin_lock_bh(&ar
->htt
.tx_lock
);
4092 idr_for_each_entry(&ar
->htt
.pending_tx
, msdu
, msdu_id
) {
4093 cb
= ATH10K_SKB_CB(msdu
);
4097 spin_unlock_bh(&ar
->htt
.tx_lock
);
4100 struct ieee80211_txq
*ath10k_mac_txq_lookup(struct ath10k
*ar
,
4104 struct ath10k_peer
*peer
;
4106 lockdep_assert_held(&ar
->data_lock
);
4108 peer
= ar
->peer_map
[peer_id
];
4116 return peer
->sta
->txq
[tid
];
4118 return peer
->vif
->txq
;
4123 static bool ath10k_mac_tx_can_push(struct ieee80211_hw
*hw
,
4124 struct ieee80211_txq
*txq
)
4126 struct ath10k
*ar
= hw
->priv
;
4127 struct ath10k_txq
*artxq
= (void *)txq
->drv_priv
;
4129 /* No need to get locks */
4130 if (ar
->htt
.tx_q_state
.mode
== HTT_TX_MODE_SWITCH_PUSH
)
4133 if (ar
->htt
.num_pending_tx
< ar
->htt
.tx_q_state
.num_push_allowed
)
4136 if (artxq
->num_fw_queued
< artxq
->num_push_allowed
)
4142 /* Return estimated airtime in microsecond, which is calculated using last
4143 * reported TX rate. This is just a rough estimation because host driver has no
4144 * knowledge of the actual transmit rate, retries or aggregation. If actual
4145 * airtime can be reported by firmware, then delta between estimated and actual
4146 * airtime can be adjusted from deficit.
4148 #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
4149 #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
4150 static u16
ath10k_mac_update_airtime(struct ath10k
*ar
,
4151 struct ieee80211_txq
*txq
,
4152 struct sk_buff
*skb
)
4154 struct ath10k_sta
*arsta
;
4158 if (!txq
|| !txq
->sta
)
4161 if (test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
4164 spin_lock_bh(&ar
->data_lock
);
4165 arsta
= (struct ath10k_sta
*)txq
->sta
->drv_priv
;
4167 pktlen
= skb
->len
+ 38; /* Assume MAC header 30, SNAP 8 for most case */
4168 if (arsta
->last_tx_bitrate
) {
4169 /* airtime in us, last_tx_bitrate in 100kbps */
4170 airtime
= (pktlen
* 8 * (1000 / 100))
4171 / arsta
->last_tx_bitrate
;
4172 /* overhead for media access time and IFS */
4173 airtime
+= IEEE80211_ATF_OVERHEAD_IFS
;
4175 /* This is mostly for throttle excessive BC/MC frames, and the
4176 * airtime/rate doesn't need be exact. Airtime of BC/MC frames
4177 * in 2G get some discount, which helps prevent very low rate
4178 * frames from being blocked for too long.
4180 airtime
= (pktlen
* 8 * (1000 / 100)) / 60; /* 6M */
4181 airtime
+= IEEE80211_ATF_OVERHEAD
;
4183 spin_unlock_bh(&ar
->data_lock
);
4188 int ath10k_mac_tx_push_txq(struct ieee80211_hw
*hw
,
4189 struct ieee80211_txq
*txq
)
4191 struct ath10k
*ar
= hw
->priv
;
4192 struct ath10k_htt
*htt
= &ar
->htt
;
4193 struct ath10k_txq
*artxq
= (void *)txq
->drv_priv
;
4194 struct ieee80211_vif
*vif
= txq
->vif
;
4195 struct ieee80211_sta
*sta
= txq
->sta
;
4196 enum ath10k_hw_txrx_mode txmode
;
4197 enum ath10k_mac_tx_path txpath
;
4198 struct sk_buff
*skb
;
4199 struct ieee80211_hdr
*hdr
;
4201 bool is_mgmt
, is_presp
;
4205 spin_lock_bh(&ar
->htt
.tx_lock
);
4206 ret
= ath10k_htt_tx_inc_pending(htt
);
4207 spin_unlock_bh(&ar
->htt
.tx_lock
);
4212 skb
= ieee80211_tx_dequeue_ni(hw
, txq
);
4214 spin_lock_bh(&ar
->htt
.tx_lock
);
4215 ath10k_htt_tx_dec_pending(htt
);
4216 spin_unlock_bh(&ar
->htt
.tx_lock
);
4221 airtime
= ath10k_mac_update_airtime(ar
, txq
, skb
);
4222 ath10k_mac_tx_h_fill_cb(ar
, vif
, txq
, sta
, skb
, airtime
);
4225 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4226 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4227 is_mgmt
= (txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4230 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4231 is_presp
= ieee80211_is_probe_resp(hdr
->frame_control
);
4233 spin_lock_bh(&ar
->htt
.tx_lock
);
4234 ret
= ath10k_htt_tx_mgmt_inc_pending(htt
, is_mgmt
, is_presp
);
4237 ath10k_htt_tx_dec_pending(htt
);
4238 spin_unlock_bh(&ar
->htt
.tx_lock
);
4241 spin_unlock_bh(&ar
->htt
.tx_lock
);
4244 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, false);
4245 if (unlikely(ret
)) {
4246 ath10k_warn(ar
, "failed to push frame: %d\n", ret
);
4248 spin_lock_bh(&ar
->htt
.tx_lock
);
4249 ath10k_htt_tx_dec_pending(htt
);
4251 ath10k_htt_tx_mgmt_dec_pending(htt
);
4252 spin_unlock_bh(&ar
->htt
.tx_lock
);
4257 spin_lock_bh(&ar
->htt
.tx_lock
);
4258 artxq
->num_fw_queued
++;
4259 spin_unlock_bh(&ar
->htt
.tx_lock
);
4264 static int ath10k_mac_schedule_txq(struct ieee80211_hw
*hw
, u32 ac
)
4266 struct ieee80211_txq
*txq
;
4269 ieee80211_txq_schedule_start(hw
, ac
);
4270 while ((txq
= ieee80211_next_txq(hw
, ac
))) {
4271 while (ath10k_mac_tx_can_push(hw
, txq
)) {
4272 ret
= ath10k_mac_tx_push_txq(hw
, txq
);
4276 ieee80211_return_txq(hw
, txq
, false);
4277 ath10k_htt_tx_txq_update(hw
, txq
);
4281 ieee80211_txq_schedule_end(hw
, ac
);
4286 void ath10k_mac_tx_push_pending(struct ath10k
*ar
)
4288 struct ieee80211_hw
*hw
= ar
->hw
;
4291 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH
)
4294 if (ar
->htt
.num_pending_tx
>= (ar
->htt
.max_num_pending_tx
/ 2))
4298 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
4299 if (ath10k_mac_schedule_txq(hw
, ac
) == -EBUSY
)
4304 EXPORT_SYMBOL(ath10k_mac_tx_push_pending
);
4310 void __ath10k_scan_finish(struct ath10k
*ar
)
4312 lockdep_assert_held(&ar
->data_lock
);
4314 switch (ar
->scan
.state
) {
4315 case ATH10K_SCAN_IDLE
:
4317 case ATH10K_SCAN_RUNNING
:
4318 case ATH10K_SCAN_ABORTING
:
4319 if (!ar
->scan
.is_roc
) {
4320 struct cfg80211_scan_info info
= {
4321 .aborted
= (ar
->scan
.state
==
4322 ATH10K_SCAN_ABORTING
),
4325 ieee80211_scan_completed(ar
->hw
, &info
);
4326 } else if (ar
->scan
.roc_notify
) {
4327 ieee80211_remain_on_channel_expired(ar
->hw
);
4330 case ATH10K_SCAN_STARTING
:
4331 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4332 ar
->scan_channel
= NULL
;
4333 ar
->scan
.roc_freq
= 0;
4334 ath10k_offchan_tx_purge(ar
);
4335 cancel_delayed_work(&ar
->scan
.timeout
);
4336 complete(&ar
->scan
.completed
);
4341 void ath10k_scan_finish(struct ath10k
*ar
)
4343 spin_lock_bh(&ar
->data_lock
);
4344 __ath10k_scan_finish(ar
);
4345 spin_unlock_bh(&ar
->data_lock
);
4348 static int ath10k_scan_stop(struct ath10k
*ar
)
4350 struct wmi_stop_scan_arg arg
= {
4351 .req_id
= 1, /* FIXME */
4352 .req_type
= WMI_SCAN_STOP_ONE
,
4353 .u
.scan_id
= ATH10K_SCAN_ID
,
4357 lockdep_assert_held(&ar
->conf_mutex
);
4359 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
4361 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
4365 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3 * HZ
);
4367 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
4369 } else if (ret
> 0) {
4374 /* Scan state should be updated upon scan completion but in case
4375 * firmware fails to deliver the event (for whatever reason) it is
4376 * desired to clean up scan state anyway. Firmware may have just
4377 * dropped the scan completion event delivery due to transport pipe
4378 * being overflown with data and/or it can recover on its own before
4379 * next scan request is submitted.
4381 spin_lock_bh(&ar
->data_lock
);
4382 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
4383 __ath10k_scan_finish(ar
);
4384 spin_unlock_bh(&ar
->data_lock
);
4389 static void ath10k_scan_abort(struct ath10k
*ar
)
4393 lockdep_assert_held(&ar
->conf_mutex
);
4395 spin_lock_bh(&ar
->data_lock
);
4397 switch (ar
->scan
.state
) {
4398 case ATH10K_SCAN_IDLE
:
4399 /* This can happen if timeout worker kicked in and called
4400 * abortion while scan completion was being processed.
4403 case ATH10K_SCAN_STARTING
:
4404 case ATH10K_SCAN_ABORTING
:
4405 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4406 ath10k_scan_state_str(ar
->scan
.state
),
4409 case ATH10K_SCAN_RUNNING
:
4410 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
4411 spin_unlock_bh(&ar
->data_lock
);
4413 ret
= ath10k_scan_stop(ar
);
4415 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
4417 spin_lock_bh(&ar
->data_lock
);
4421 spin_unlock_bh(&ar
->data_lock
);
4424 void ath10k_scan_timeout_work(struct work_struct
*work
)
4426 struct ath10k
*ar
= container_of(work
, struct ath10k
,
4429 mutex_lock(&ar
->conf_mutex
);
4430 ath10k_scan_abort(ar
);
4431 mutex_unlock(&ar
->conf_mutex
);
4434 static int ath10k_start_scan(struct ath10k
*ar
,
4435 const struct wmi_start_scan_arg
*arg
)
4439 lockdep_assert_held(&ar
->conf_mutex
);
4441 ret
= ath10k_wmi_start_scan(ar
, arg
);
4445 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1 * HZ
);
4447 ret
= ath10k_scan_stop(ar
);
4449 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
4454 /* If we failed to start the scan, return error code at
4455 * this point. This is probably due to some issue in the
4456 * firmware, but no need to wedge the driver due to that...
4458 spin_lock_bh(&ar
->data_lock
);
4459 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
4460 spin_unlock_bh(&ar
->data_lock
);
4463 spin_unlock_bh(&ar
->data_lock
);
4468 /**********************/
4469 /* mac80211 callbacks */
4470 /**********************/
4472 static void ath10k_mac_op_tx(struct ieee80211_hw
*hw
,
4473 struct ieee80211_tx_control
*control
,
4474 struct sk_buff
*skb
)
4476 struct ath10k
*ar
= hw
->priv
;
4477 struct ath10k_htt
*htt
= &ar
->htt
;
4478 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
4479 struct ieee80211_vif
*vif
= info
->control
.vif
;
4480 struct ieee80211_sta
*sta
= control
->sta
;
4481 struct ieee80211_txq
*txq
= NULL
;
4482 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
4483 enum ath10k_hw_txrx_mode txmode
;
4484 enum ath10k_mac_tx_path txpath
;
4491 airtime
= ath10k_mac_update_airtime(ar
, txq
, skb
);
4492 ath10k_mac_tx_h_fill_cb(ar
, vif
, txq
, sta
, skb
, airtime
);
4494 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4495 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4496 is_htt
= (txpath
== ATH10K_MAC_TX_HTT
||
4497 txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4498 is_mgmt
= (txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4501 spin_lock_bh(&ar
->htt
.tx_lock
);
4502 is_presp
= ieee80211_is_probe_resp(hdr
->frame_control
);
4504 ret
= ath10k_htt_tx_inc_pending(htt
);
4506 ath10k_warn(ar
, "failed to increase tx pending count: %d, dropping\n",
4508 spin_unlock_bh(&ar
->htt
.tx_lock
);
4509 ieee80211_free_txskb(ar
->hw
, skb
);
4513 ret
= ath10k_htt_tx_mgmt_inc_pending(htt
, is_mgmt
, is_presp
);
4515 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "failed to increase tx mgmt pending count: %d, dropping\n",
4517 ath10k_htt_tx_dec_pending(htt
);
4518 spin_unlock_bh(&ar
->htt
.tx_lock
);
4519 ieee80211_free_txskb(ar
->hw
, skb
);
4522 spin_unlock_bh(&ar
->htt
.tx_lock
);
4525 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, false);
4527 ath10k_warn(ar
, "failed to transmit frame: %d\n", ret
);
4529 spin_lock_bh(&ar
->htt
.tx_lock
);
4530 ath10k_htt_tx_dec_pending(htt
);
4532 ath10k_htt_tx_mgmt_dec_pending(htt
);
4533 spin_unlock_bh(&ar
->htt
.tx_lock
);
4539 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw
*hw
,
4540 struct ieee80211_txq
*txq
)
4542 struct ath10k
*ar
= hw
->priv
;
4546 ath10k_htt_tx_txq_update(hw
, txq
);
4547 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH
)
4551 ieee80211_txq_schedule_start(hw
, ac
);
4552 txq
= ieee80211_next_txq(hw
, ac
);
4556 while (ath10k_mac_tx_can_push(hw
, txq
)) {
4557 ret
= ath10k_mac_tx_push_txq(hw
, txq
);
4561 ieee80211_return_txq(hw
, txq
, false);
4562 ath10k_htt_tx_txq_update(hw
, txq
);
4564 ieee80211_txq_schedule_end(hw
, ac
);
4567 /* Must not be called with conf_mutex held as workers can use that also. */
4568 void ath10k_drain_tx(struct ath10k
*ar
)
4570 /* make sure rcu-protected mac80211 tx path itself is drained */
4573 ath10k_offchan_tx_purge(ar
);
4574 ath10k_mgmt_over_wmi_tx_purge(ar
);
4576 cancel_work_sync(&ar
->offchan_tx_work
);
4577 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
4580 void ath10k_halt(struct ath10k
*ar
)
4582 struct ath10k_vif
*arvif
;
4584 lockdep_assert_held(&ar
->conf_mutex
);
4586 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
4587 ar
->filter_flags
= 0;
4588 ar
->monitor
= false;
4589 ar
->monitor_arvif
= NULL
;
4591 if (ar
->monitor_started
)
4592 ath10k_monitor_stop(ar
);
4594 ar
->monitor_started
= false;
4597 ath10k_scan_finish(ar
);
4598 ath10k_peer_cleanup_all(ar
);
4599 ath10k_stop_radar_confirmation(ar
);
4600 ath10k_core_stop(ar
);
4601 ath10k_hif_power_down(ar
);
4603 spin_lock_bh(&ar
->data_lock
);
4604 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
4605 ath10k_mac_vif_beacon_cleanup(arvif
);
4606 spin_unlock_bh(&ar
->data_lock
);
4609 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
4611 struct ath10k
*ar
= hw
->priv
;
4613 mutex_lock(&ar
->conf_mutex
);
4615 *tx_ant
= ar
->cfg_tx_chainmask
;
4616 *rx_ant
= ar
->cfg_rx_chainmask
;
4618 mutex_unlock(&ar
->conf_mutex
);
4623 static bool ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
4625 /* It is not clear that allowing gaps in chainmask
4626 * is helpful. Probably it will not do what user
4627 * is hoping for, so warn in that case.
4629 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
4632 ath10k_warn(ar
, "mac %s antenna chainmask is invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4637 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k
*ar
)
4639 int nsts
= ar
->vht_cap_info
;
4641 nsts
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
4642 nsts
>>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
4644 /* If firmware does not deliver to host number of space-time
4645 * streams supported, assume it support up to 4 BF STS and return
4646 * the value for VHT CAP: nsts-1)
4654 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k
*ar
)
4656 int sound_dim
= ar
->vht_cap_info
;
4658 sound_dim
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
4659 sound_dim
>>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
4661 /* If the sounding dimension is not advertised by the firmware,
4662 * let's use a default value of 1
4670 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
4672 struct ieee80211_sta_vht_cap vht_cap
= {0};
4673 struct ath10k_hw_params
*hw
= &ar
->hw_params
;
4678 vht_cap
.vht_supported
= 1;
4679 vht_cap
.cap
= ar
->vht_cap_info
;
4681 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
4682 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
4683 val
= ath10k_mac_get_vht_cap_bf_sts(ar
);
4684 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
4685 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
4690 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
4691 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
4692 val
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
4693 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
4694 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
4700 for (i
= 0; i
< 8; i
++) {
4701 if ((i
< ar
->num_rf_chains
) && (ar
->cfg_tx_chainmask
& BIT(i
)))
4702 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
* 2);
4704 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
* 2);
4707 if (ar
->cfg_tx_chainmask
<= 1)
4708 vht_cap
.cap
&= ~IEEE80211_VHT_CAP_TXSTBC
;
4710 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
4711 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
4713 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4714 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4715 * user-space a clue if that is the case.
4717 if ((vht_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) &&
4718 (hw
->vht160_mcs_rx_highest
!= 0 ||
4719 hw
->vht160_mcs_tx_highest
!= 0)) {
4720 vht_cap
.vht_mcs
.rx_highest
= cpu_to_le16(hw
->vht160_mcs_rx_highest
);
4721 vht_cap
.vht_mcs
.tx_highest
= cpu_to_le16(hw
->vht160_mcs_tx_highest
);
4727 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
4730 struct ieee80211_sta_ht_cap ht_cap
= {0};
4732 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
4735 ht_cap
.ht_supported
= 1;
4736 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
4737 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
4738 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
4739 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
4741 WLAN_HT_CAP_SM_PS_DISABLED
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
4743 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
4744 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
4746 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
4747 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
4749 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
4752 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
4753 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
4758 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
&& (ar
->cfg_tx_chainmask
> 1))
4759 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
4761 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
4764 stbc
= ar
->ht_cap_info
;
4765 stbc
&= WMI_HT_CAP_RX_STBC
;
4766 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
4767 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
4768 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
4773 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
|| (ar
->ht_cap_info
&
4774 WMI_HT_CAP_RX_LDPC
&& (ar
->ht_cap_info
& WMI_HT_CAP_TX_LDPC
)))
4775 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
4777 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
4778 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
4780 /* max AMSDU is implicitly taken from vht_cap_info */
4781 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
4782 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
4784 for (i
= 0; i
< ar
->num_rf_chains
; i
++) {
4785 if (ar
->cfg_rx_chainmask
& BIT(i
))
4786 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
4789 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
4794 static void ath10k_mac_setup_ht_vht_cap(struct ath10k
*ar
)
4796 struct ieee80211_supported_band
*band
;
4797 struct ieee80211_sta_vht_cap vht_cap
;
4798 struct ieee80211_sta_ht_cap ht_cap
;
4800 ht_cap
= ath10k_get_ht_cap(ar
);
4801 vht_cap
= ath10k_create_vht_cap(ar
);
4803 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
4804 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
4805 band
->ht_cap
= ht_cap
;
4807 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
4808 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
4809 band
->ht_cap
= ht_cap
;
4810 band
->vht_cap
= vht_cap
;
4814 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
4817 bool is_valid_tx_chain_mask
, is_valid_rx_chain_mask
;
4819 lockdep_assert_held(&ar
->conf_mutex
);
4821 is_valid_tx_chain_mask
= ath10k_check_chain_mask(ar
, tx_ant
, "tx");
4822 is_valid_rx_chain_mask
= ath10k_check_chain_mask(ar
, rx_ant
, "rx");
4824 if (!is_valid_tx_chain_mask
|| !is_valid_rx_chain_mask
)
4827 ar
->cfg_tx_chainmask
= tx_ant
;
4828 ar
->cfg_rx_chainmask
= rx_ant
;
4830 if ((ar
->state
!= ATH10K_STATE_ON
) &&
4831 (ar
->state
!= ATH10K_STATE_RESTARTED
))
4834 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
4837 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
4842 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
4845 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
4850 /* Reload HT/VHT capability */
4851 ath10k_mac_setup_ht_vht_cap(ar
);
4856 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
4858 struct ath10k
*ar
= hw
->priv
;
4861 mutex_lock(&ar
->conf_mutex
);
4862 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
4863 mutex_unlock(&ar
->conf_mutex
);
4867 static int __ath10k_fetch_bb_timing_dt(struct ath10k
*ar
,
4868 struct wmi_bb_timing_cfg_arg
*bb_timing
)
4870 struct device_node
*node
;
4871 const char *fem_name
;
4874 node
= ar
->dev
->of_node
;
4878 ret
= of_property_read_string_index(node
, "ext-fem-name", 0, &fem_name
);
4883 * If external Front End module used in hardware, then default base band timing
4884 * parameter cannot be used since they were fine tuned for reference hardware,
4885 * so choosing different value suitable for that external FEM.
4887 if (!strcmp("microsemi-lx5586", fem_name
)) {
4888 bb_timing
->bb_tx_timing
= 0x00;
4889 bb_timing
->bb_xpa_timing
= 0x0101;
4894 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
4895 bb_timing
->bb_tx_timing
, bb_timing
->bb_xpa_timing
);
4899 static int ath10k_mac_rfkill_config(struct ath10k
*ar
)
4904 if (ar
->hw_values
->rfkill_pin
== 0) {
4905 ath10k_warn(ar
, "ath10k does not support hardware rfkill with this device\n");
4909 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4910 "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
4911 ar
->hw_values
->rfkill_pin
, ar
->hw_values
->rfkill_cfg
,
4912 ar
->hw_values
->rfkill_on_level
);
4914 param
= FIELD_PREP(WMI_TLV_RFKILL_CFG_RADIO_LEVEL
,
4915 ar
->hw_values
->rfkill_on_level
) |
4916 FIELD_PREP(WMI_TLV_RFKILL_CFG_GPIO_PIN_NUM
,
4917 ar
->hw_values
->rfkill_pin
) |
4918 FIELD_PREP(WMI_TLV_RFKILL_CFG_PIN_AS_GPIO
,
4919 ar
->hw_values
->rfkill_cfg
);
4921 ret
= ath10k_wmi_pdev_set_param(ar
,
4922 ar
->wmi
.pdev_param
->rfkill_config
,
4926 "failed to set rfkill config 0x%x: %d\n",
4933 int ath10k_mac_rfkill_enable_radio(struct ath10k
*ar
, bool enable
)
4935 enum wmi_tlv_rfkill_enable_radio param
;
4939 param
= WMI_TLV_RFKILL_ENABLE_RADIO_ON
;
4941 param
= WMI_TLV_RFKILL_ENABLE_RADIO_OFF
;
4943 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac rfkill enable %d", param
);
4945 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rfkill_enable
,
4948 ath10k_warn(ar
, "failed to set rfkill enable param %d: %d\n",
4956 static int ath10k_start(struct ieee80211_hw
*hw
)
4958 struct ath10k
*ar
= hw
->priv
;
4961 struct wmi_bb_timing_cfg_arg bb_timing
= {0};
4964 * This makes sense only when restarting hw. It is harmless to call
4965 * unconditionally. This is necessary to make sure no HTT/WMI tx
4966 * commands will be submitted while restarting.
4968 ath10k_drain_tx(ar
);
4970 mutex_lock(&ar
->conf_mutex
);
4972 switch (ar
->state
) {
4973 case ATH10K_STATE_OFF
:
4974 ar
->state
= ATH10K_STATE_ON
;
4976 case ATH10K_STATE_RESTARTING
:
4977 ar
->state
= ATH10K_STATE_RESTARTED
;
4979 case ATH10K_STATE_ON
:
4980 case ATH10K_STATE_RESTARTED
:
4981 case ATH10K_STATE_WEDGED
:
4985 case ATH10K_STATE_UTF
:
4990 spin_lock_bh(&ar
->data_lock
);
4992 if (ar
->hw_rfkill_on
) {
4993 ar
->hw_rfkill_on
= false;
4994 spin_unlock_bh(&ar
->data_lock
);
4998 spin_unlock_bh(&ar
->data_lock
);
5000 ret
= ath10k_hif_power_up(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
5002 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
5006 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
,
5007 &ar
->normal_mode_fw
);
5009 ath10k_err(ar
, "Could not init core: %d\n", ret
);
5010 goto err_power_down
;
5013 if (ar
->sys_cap_info
& WMI_TLV_SYS_CAP_INFO_RFKILL
) {
5014 ret
= ath10k_mac_rfkill_config(ar
);
5015 if (ret
&& ret
!= -EOPNOTSUPP
) {
5016 ath10k_warn(ar
, "failed to configure rfkill: %d", ret
);
5021 param
= ar
->wmi
.pdev_param
->pmf_qos
;
5022 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5024 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
5028 param
= ar
->wmi
.pdev_param
->dynamic_bw
;
5029 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5031 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
5035 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
5036 ret
= ath10k_wmi_scan_prob_req_oui(ar
, ar
->mac_addr
);
5038 ath10k_err(ar
, "failed to set prob req oui: %i\n", ret
);
5043 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
5044 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
5046 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
5052 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
5053 param
= ar
->wmi
.pdev_param
->burst_enable
;
5054 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
5056 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
5061 param
= ar
->wmi
.pdev_param
->idle_ps_config
;
5062 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5063 if (ret
&& ret
!= -EOPNOTSUPP
) {
5064 ath10k_warn(ar
, "failed to enable idle_ps_config: %d\n", ret
);
5068 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
, ar
->cfg_rx_chainmask
);
5071 * By default FW set ARP frames ac to voice (6). In that case ARP
5072 * exchange is not working properly for UAPSD enabled AP. ARP requests
5073 * which arrives with access category 0 are processed by network stack
5074 * and send back with access category 0, but FW changes access category
5075 * to 6. Set ARP frames access category to best effort (0) solves
5079 param
= ar
->wmi
.pdev_param
->arp_ac_override
;
5080 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
5082 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
5087 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA
,
5088 ar
->running_fw
->fw_file
.fw_features
)) {
5089 ret
= ath10k_wmi_pdev_enable_adaptive_cca(ar
, 1,
5090 WMI_CCA_DETECT_LEVEL_AUTO
,
5091 WMI_CCA_DETECT_MARGIN_AUTO
);
5093 ath10k_warn(ar
, "failed to enable adaptive cca: %d\n",
5099 param
= ar
->wmi
.pdev_param
->ani_enable
;
5100 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
5102 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
5107 ar
->ani_enabled
= true;
5109 if (ath10k_peer_stats_enabled(ar
)) {
5110 param
= ar
->wmi
.pdev_param
->peer_stats_update_period
;
5111 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
5112 PEER_DEFAULT_STATS_UPDATE_PERIOD
);
5115 "failed to set peer stats period : %d\n",
5121 param
= ar
->wmi
.pdev_param
->enable_btcoex
;
5122 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
) &&
5123 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM
,
5124 ar
->running_fw
->fw_file
.fw_features
) &&
5126 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
5129 "failed to set btcoex param: %d\n", ret
);
5132 clear_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
5135 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT
, ar
->wmi
.svc_map
)) {
5136 ret
= __ath10k_fetch_bb_timing_dt(ar
, &bb_timing
);
5138 ret
= ath10k_wmi_pdev_bb_timing(ar
, &bb_timing
);
5141 "failed to set bb timings: %d\n",
5148 ar
->num_started_vdevs
= 0;
5149 ath10k_regd_update(ar
);
5151 ath10k_spectral_start(ar
);
5152 ath10k_thermal_set_throttling(ar
);
5154 ar
->radar_conf_state
= ATH10K_RADAR_CONFIRMATION_IDLE
;
5156 mutex_unlock(&ar
->conf_mutex
);
5160 ath10k_core_stop(ar
);
5163 ath10k_hif_power_down(ar
);
5166 ar
->state
= ATH10K_STATE_OFF
;
5169 mutex_unlock(&ar
->conf_mutex
);
5173 static void ath10k_stop(struct ieee80211_hw
*hw
)
5175 struct ath10k
*ar
= hw
->priv
;
5177 ath10k_drain_tx(ar
);
5179 mutex_lock(&ar
->conf_mutex
);
5180 if (ar
->state
!= ATH10K_STATE_OFF
) {
5181 if (!ar
->hw_rfkill_on
)
5183 ar
->state
= ATH10K_STATE_OFF
;
5185 mutex_unlock(&ar
->conf_mutex
);
5187 cancel_work_sync(&ar
->set_coverage_class_work
);
5188 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5189 cancel_work_sync(&ar
->restart_work
);
5192 static int ath10k_config_ps(struct ath10k
*ar
)
5194 struct ath10k_vif
*arvif
;
5197 lockdep_assert_held(&ar
->conf_mutex
);
5199 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5200 ret
= ath10k_mac_vif_setup_ps(arvif
);
5202 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
5210 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
5215 lockdep_assert_held(&ar
->conf_mutex
);
5217 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
5219 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
5220 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
5222 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
5227 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
5228 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
5230 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
5238 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
5240 struct ath10k_vif
*arvif
;
5241 int ret
, txpower
= -1;
5243 lockdep_assert_held(&ar
->conf_mutex
);
5245 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5246 /* txpower not initialized yet? */
5247 if (arvif
->txpower
== INT_MIN
)
5251 txpower
= arvif
->txpower
;
5253 txpower
= min(txpower
, arvif
->txpower
);
5259 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
5261 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
5269 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
5271 struct ath10k
*ar
= hw
->priv
;
5272 struct ieee80211_conf
*conf
= &hw
->conf
;
5275 mutex_lock(&ar
->conf_mutex
);
5277 if (changed
& IEEE80211_CONF_CHANGE_PS
)
5278 ath10k_config_ps(ar
);
5280 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
5281 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
5282 ret
= ath10k_monitor_recalc(ar
);
5284 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5287 mutex_unlock(&ar
->conf_mutex
);
5291 static u32
get_nss_from_chainmask(u16 chain_mask
)
5293 if ((chain_mask
& 0xf) == 0xf)
5295 else if ((chain_mask
& 0x7) == 0x7)
5297 else if ((chain_mask
& 0x3) == 0x3)
5302 static int ath10k_mac_set_txbf_conf(struct ath10k_vif
*arvif
)
5305 struct ath10k
*ar
= arvif
->ar
;
5309 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_BEFORE_ASSOC
)
5312 nsts
= ath10k_mac_get_vht_cap_bf_sts(ar
);
5313 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
5314 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
))
5315 value
|= SM(nsts
, WMI_TXBF_STS_CAP_OFFSET
);
5317 sound_dim
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
5318 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
5319 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
))
5320 value
|= SM(sound_dim
, WMI_BF_SOUND_DIM_OFFSET
);
5325 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
5326 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
5328 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
5329 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER
|
5330 WMI_VDEV_PARAM_TXBF_SU_TX_BFER
);
5332 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
5333 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
5335 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
5336 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
|
5337 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
);
5339 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5340 ar
->wmi
.vdev_param
->txbf
, value
);
5345 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5346 * because we will send mgmt frames without CCK. This requirement
5347 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5350 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
5351 struct ieee80211_vif
*vif
)
5353 struct ath10k
*ar
= hw
->priv
;
5354 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5355 struct ath10k_peer
*peer
;
5356 enum wmi_sta_powersave_param param
;
5363 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
5365 mutex_lock(&ar
->conf_mutex
);
5367 memset(arvif
, 0, sizeof(*arvif
));
5368 ath10k_mac_txq_init(vif
->txq
);
5373 INIT_LIST_HEAD(&arvif
->list
);
5374 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
5375 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
5376 ath10k_mac_vif_sta_connection_loss_work
);
5378 for (i
= 0; i
< ARRAY_SIZE(arvif
->bitrate_mask
.control
); i
++) {
5379 arvif
->bitrate_mask
.control
[i
].legacy
= 0xffffffff;
5380 memset(arvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
5381 sizeof(arvif
->bitrate_mask
.control
[i
].ht_mcs
));
5382 memset(arvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
5383 sizeof(arvif
->bitrate_mask
.control
[i
].vht_mcs
));
5386 if (ar
->num_peers
>= ar
->max_num_peers
) {
5387 ath10k_warn(ar
, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5392 if (ar
->free_vdev_map
== 0) {
5393 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
5397 bit
= __ffs64(ar
->free_vdev_map
);
5399 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
5400 bit
, ar
->free_vdev_map
);
5402 arvif
->vdev_id
= bit
;
5403 arvif
->vdev_subtype
=
5404 ath10k_wmi_get_vdev_subtype(ar
, WMI_VDEV_SUBTYPE_NONE
);
5406 switch (vif
->type
) {
5407 case NL80211_IFTYPE_P2P_DEVICE
:
5408 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
5409 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5410 (ar
, WMI_VDEV_SUBTYPE_P2P_DEVICE
);
5412 case NL80211_IFTYPE_UNSPECIFIED
:
5413 case NL80211_IFTYPE_STATION
:
5414 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
5416 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5417 (ar
, WMI_VDEV_SUBTYPE_P2P_CLIENT
);
5419 case NL80211_IFTYPE_ADHOC
:
5420 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
5422 case NL80211_IFTYPE_MESH_POINT
:
5423 if (test_bit(WMI_SERVICE_MESH_11S
, ar
->wmi
.svc_map
)) {
5424 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5425 (ar
, WMI_VDEV_SUBTYPE_MESH_11S
);
5426 } else if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
5428 ath10k_warn(ar
, "must load driver with rawmode=1 to add mesh interfaces\n");
5431 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
5433 case NL80211_IFTYPE_AP
:
5434 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
5437 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5438 (ar
, WMI_VDEV_SUBTYPE_P2P_GO
);
5440 case NL80211_IFTYPE_MONITOR
:
5441 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
5448 /* Using vdev_id as queue number will make it very easy to do per-vif
5449 * tx queue locking. This shouldn't wrap due to interface combinations
5450 * but do a modulo for correctness sake and prevent using offchannel tx
5451 * queues for regular vif tx.
5453 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
5454 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
5455 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
5457 /* Some firmware revisions don't wait for beacon tx completion before
5458 * sending another SWBA event. This could lead to hardware using old
5459 * (freed) beacon data in some cases, e.g. tx credit starvation
5460 * combined with missed TBTT. This is very rare.
5462 * On non-IOMMU-enabled hosts this could be a possible security issue
5463 * because hw could beacon some random data on the air. On
5464 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5465 * device would crash.
5467 * Since there are no beacon tx completions (implicit nor explicit)
5468 * propagated to host the only workaround for this is to allocate a
5469 * DMA-coherent buffer for a lifetime of a vif and use it for all
5470 * beacon tx commands. Worst case for this approach is some beacons may
5471 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5473 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
5474 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
5475 vif
->type
== NL80211_IFTYPE_AP
) {
5476 arvif
->beacon_buf
= dma_alloc_coherent(ar
->dev
,
5477 IEEE80211_MAX_FRAME_LEN
,
5478 &arvif
->beacon_paddr
,
5480 if (!arvif
->beacon_buf
) {
5482 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
5487 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
))
5488 arvif
->nohwcrypt
= true;
5490 if (arvif
->nohwcrypt
&&
5491 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
5492 ath10k_warn(ar
, "cryptmode module param needed for sw crypto\n");
5496 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5497 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
5498 arvif
->beacon_buf
? "single-buf" : "per-skb");
5500 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
5501 arvif
->vdev_subtype
, vif
->addr
);
5503 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
5504 arvif
->vdev_id
, ret
);
5508 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT
,
5510 vdev_param
= ar
->wmi
.vdev_param
->disable_4addr_src_lrn
;
5511 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5512 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN
);
5513 if (ret
&& ret
!= -EOPNOTSUPP
) {
5514 ath10k_warn(ar
, "failed to disable 4addr src lrn vdev %i: %d\n",
5515 arvif
->vdev_id
, ret
);
5519 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
5520 spin_lock_bh(&ar
->data_lock
);
5521 list_add(&arvif
->list
, &ar
->arvifs
);
5522 spin_unlock_bh(&ar
->data_lock
);
5524 /* It makes no sense to have firmware do keepalives. mac80211 already
5525 * takes care of this with idle connection polling.
5527 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
5529 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
5530 arvif
->vdev_id
, ret
);
5531 goto err_vdev_delete
;
5534 arvif
->def_wep_key_idx
= -1;
5536 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
5537 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5538 ATH10K_HW_TXRX_NATIVE_WIFI
);
5539 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5540 if (ret
&& ret
!= -EOPNOTSUPP
) {
5541 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
5542 arvif
->vdev_id
, ret
);
5543 goto err_vdev_delete
;
5546 /* Configuring number of spatial stream for monitor interface is causing
5547 * target assert in qca9888 and qca6174.
5549 if (ar
->cfg_tx_chainmask
&& (vif
->type
!= NL80211_IFTYPE_MONITOR
)) {
5550 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
5552 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5553 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5556 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5557 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
5559 goto err_vdev_delete
;
5563 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5564 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5565 ret
= ath10k_peer_create(ar
, vif
, NULL
, arvif
->vdev_id
,
5566 vif
->addr
, WMI_PEER_TYPE_DEFAULT
);
5568 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
5569 arvif
->vdev_id
, ret
);
5570 goto err_vdev_delete
;
5573 spin_lock_bh(&ar
->data_lock
);
5575 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, vif
->addr
);
5577 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
5578 vif
->addr
, arvif
->vdev_id
);
5579 spin_unlock_bh(&ar
->data_lock
);
5581 goto err_peer_delete
;
5584 arvif
->peer_id
= find_first_bit(peer
->peer_ids
,
5585 ATH10K_MAX_NUM_PEER_IDS
);
5587 spin_unlock_bh(&ar
->data_lock
);
5589 arvif
->peer_id
= HTT_INVALID_PEERID
;
5592 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
5593 ret
= ath10k_mac_set_kickout(arvif
);
5595 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
5596 arvif
->vdev_id
, ret
);
5597 goto err_peer_delete
;
5601 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
5602 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
5603 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5604 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5607 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
5608 arvif
->vdev_id
, ret
);
5609 goto err_peer_delete
;
5612 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5614 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5615 arvif
->vdev_id
, ret
);
5616 goto err_peer_delete
;
5619 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5621 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5622 arvif
->vdev_id
, ret
);
5623 goto err_peer_delete
;
5627 ret
= ath10k_mac_set_txbf_conf(arvif
);
5629 ath10k_warn(ar
, "failed to set txbf for vdev %d: %d\n",
5630 arvif
->vdev_id
, ret
);
5631 goto err_peer_delete
;
5634 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
5636 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5637 arvif
->vdev_id
, ret
);
5638 goto err_peer_delete
;
5641 arvif
->txpower
= vif
->bss_conf
.txpower
;
5642 ret
= ath10k_mac_txpower_recalc(ar
);
5644 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
5645 goto err_peer_delete
;
5648 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
)) {
5649 vdev_param
= ar
->wmi
.vdev_param
->rtt_responder_role
;
5650 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5651 arvif
->ftm_responder
);
5653 /* It is harmless to not set FTM role. Do not warn */
5654 if (ret
&& ret
!= -EOPNOTSUPP
)
5655 ath10k_warn(ar
, "failed to set vdev %i FTM Responder: %d\n",
5656 arvif
->vdev_id
, ret
);
5659 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
5660 ar
->monitor_arvif
= arvif
;
5661 ret
= ath10k_monitor_recalc(ar
);
5663 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5664 goto err_peer_delete
;
5668 spin_lock_bh(&ar
->htt
.tx_lock
);
5670 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
5671 spin_unlock_bh(&ar
->htt
.tx_lock
);
5673 mutex_unlock(&ar
->conf_mutex
);
5677 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5678 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5679 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
5680 ath10k_wait_for_peer_delete_done(ar
, arvif
->vdev_id
,
5685 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
5686 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
5687 spin_lock_bh(&ar
->data_lock
);
5688 list_del(&arvif
->list
);
5689 spin_unlock_bh(&ar
->data_lock
);
5692 if (arvif
->beacon_buf
) {
5693 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
5694 arvif
->beacon_buf
, arvif
->beacon_paddr
);
5695 arvif
->beacon_buf
= NULL
;
5698 mutex_unlock(&ar
->conf_mutex
);
5703 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
5707 for (i
= 0; i
< BITS_PER_LONG
; i
++)
5708 ath10k_mac_vif_tx_unlock(arvif
, i
);
5711 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
5712 struct ieee80211_vif
*vif
)
5714 struct ath10k
*ar
= hw
->priv
;
5715 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5716 struct ath10k_peer
*peer
;
5717 unsigned long time_left
;
5721 cancel_work_sync(&arvif
->ap_csa_work
);
5722 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
5724 mutex_lock(&ar
->conf_mutex
);
5726 ret
= ath10k_spectral_vif_stop(arvif
);
5728 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
5729 arvif
->vdev_id
, ret
);
5731 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
5732 spin_lock_bh(&ar
->data_lock
);
5733 list_del(&arvif
->list
);
5734 spin_unlock_bh(&ar
->data_lock
);
5736 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5737 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5738 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
5741 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5742 arvif
->vdev_id
, ret
);
5744 ath10k_wait_for_peer_delete_done(ar
, arvif
->vdev_id
,
5746 kfree(arvif
->u
.ap
.noa_data
);
5749 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
5752 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
5754 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
5755 arvif
->vdev_id
, ret
);
5757 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
5758 time_left
= wait_for_completion_timeout(&ar
->vdev_delete_done
,
5759 ATH10K_VDEV_DELETE_TIMEOUT_HZ
);
5760 if (time_left
== 0) {
5761 ath10k_warn(ar
, "Timeout in receiving vdev delete response\n");
5766 /* Some firmware revisions don't notify host about self-peer removal
5767 * until after associated vdev is deleted.
5769 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5770 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5771 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
5774 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
5775 arvif
->vdev_id
, ret
);
5777 spin_lock_bh(&ar
->data_lock
);
5779 spin_unlock_bh(&ar
->data_lock
);
5782 spin_lock_bh(&ar
->data_lock
);
5783 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
5784 peer
= ar
->peer_map
[i
];
5788 if (peer
->vif
== vif
) {
5789 ath10k_warn(ar
, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5790 vif
->addr
, arvif
->vdev_id
);
5795 /* Clean this up late, less opportunity for firmware to access
5796 * DMA memory we have deleted.
5798 ath10k_mac_vif_beacon_cleanup(arvif
);
5799 spin_unlock_bh(&ar
->data_lock
);
5801 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
5802 ath10k_mac_txq_unref(ar
, vif
->txq
);
5804 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
5805 ar
->monitor_arvif
= NULL
;
5806 ret
= ath10k_monitor_recalc(ar
);
5808 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5811 ret
= ath10k_mac_txpower_recalc(ar
);
5813 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
5815 spin_lock_bh(&ar
->htt
.tx_lock
);
5816 ath10k_mac_vif_tx_unlock_all(arvif
);
5817 spin_unlock_bh(&ar
->htt
.tx_lock
);
5819 ath10k_mac_txq_unref(ar
, vif
->txq
);
5822 mutex_unlock(&ar
->conf_mutex
);
5826 * FIXME: Has to be verified.
5828 #define SUPPORTED_FILTERS \
5833 FIF_BCN_PRBRESP_PROMISC | \
5837 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
5838 unsigned int changed_flags
,
5839 unsigned int *total_flags
,
5842 struct ath10k
*ar
= hw
->priv
;
5845 mutex_lock(&ar
->conf_mutex
);
5847 changed_flags
&= SUPPORTED_FILTERS
;
5848 *total_flags
&= SUPPORTED_FILTERS
;
5849 ar
->filter_flags
= *total_flags
;
5851 ret
= ath10k_monitor_recalc(ar
);
5853 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5855 mutex_unlock(&ar
->conf_mutex
);
5858 static void ath10k_recalculate_mgmt_rate(struct ath10k
*ar
,
5859 struct ieee80211_vif
*vif
,
5860 struct cfg80211_chan_def
*def
)
5862 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5863 const struct ieee80211_supported_band
*sband
;
5870 lockdep_assert_held(&ar
->conf_mutex
);
5872 sband
= ar
->hw
->wiphy
->bands
[def
->chan
->band
];
5873 basic_rate_idx
= ffs(vif
->bss_conf
.basic_rates
) - 1;
5874 bitrate
= sband
->bitrates
[basic_rate_idx
].bitrate
;
5876 hw_rate_code
= ath10k_mac_get_rate_hw_value(bitrate
);
5877 if (hw_rate_code
< 0) {
5878 ath10k_warn(ar
, "bitrate not supported %d\n", bitrate
);
5882 vdev_param
= ar
->wmi
.vdev_param
->mgmt_rate
;
5883 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5886 ath10k_warn(ar
, "failed to set mgmt tx rate %d\n", ret
);
5889 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
5890 struct ieee80211_vif
*vif
,
5891 struct ieee80211_bss_conf
*info
,
5894 struct ath10k
*ar
= hw
->priv
;
5895 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5896 struct cfg80211_chan_def def
;
5897 u32 vdev_param
, pdev_param
, slottime
, preamble
;
5898 u16 bitrate
, hw_value
;
5900 int ret
= 0, mcast_rate
;
5901 enum nl80211_band band
;
5903 mutex_lock(&ar
->conf_mutex
);
5905 if (changed
& BSS_CHANGED_IBSS
)
5906 ath10k_control_ibss(arvif
, info
, vif
->addr
);
5908 if (changed
& BSS_CHANGED_BEACON_INT
) {
5909 arvif
->beacon_interval
= info
->beacon_int
;
5910 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
5911 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5912 arvif
->beacon_interval
);
5913 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5914 "mac vdev %d beacon_interval %d\n",
5915 arvif
->vdev_id
, arvif
->beacon_interval
);
5918 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
5919 arvif
->vdev_id
, ret
);
5922 if (changed
& BSS_CHANGED_BEACON
) {
5923 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5924 "vdev %d set beacon tx mode to staggered\n",
5927 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
5928 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
5929 WMI_BEACON_STAGGERED_MODE
);
5931 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
5932 arvif
->vdev_id
, ret
);
5934 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
5936 ath10k_warn(ar
, "failed to update beacon template: %d\n",
5939 if (ieee80211_vif_is_mesh(vif
)) {
5940 /* mesh doesn't use SSID but firmware needs it */
5941 strncpy(arvif
->u
.ap
.ssid
, "mesh",
5942 sizeof(arvif
->u
.ap
.ssid
));
5943 arvif
->u
.ap
.ssid_len
= 4;
5947 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
5948 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
5950 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
5951 arvif
->vdev_id
, ret
);
5954 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
5955 arvif
->dtim_period
= info
->dtim_period
;
5957 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5958 "mac vdev %d dtim_period %d\n",
5959 arvif
->vdev_id
, arvif
->dtim_period
);
5961 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
5962 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5963 arvif
->dtim_period
);
5965 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
5966 arvif
->vdev_id
, ret
);
5969 if (changed
& BSS_CHANGED_SSID
&&
5970 vif
->type
== NL80211_IFTYPE_AP
) {
5971 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
5973 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
5974 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
5977 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
5978 ether_addr_copy(arvif
->bssid
, info
->bssid
);
5980 if (changed
& BSS_CHANGED_FTM_RESPONDER
&&
5981 arvif
->ftm_responder
!= info
->ftm_responder
&&
5982 test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
)) {
5983 arvif
->ftm_responder
= info
->ftm_responder
;
5985 vdev_param
= ar
->wmi
.vdev_param
->rtt_responder_role
;
5986 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5987 arvif
->ftm_responder
);
5989 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5990 "mac vdev %d ftm_responder %d:ret %d\n",
5991 arvif
->vdev_id
, arvif
->ftm_responder
, ret
);
5994 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
5995 ath10k_control_beaconing(arvif
, info
);
5997 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
5998 arvif
->use_cts_prot
= info
->use_cts_prot
;
6000 ret
= ath10k_recalc_rtscts_prot(arvif
);
6002 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
6003 arvif
->vdev_id
, ret
);
6005 if (ath10k_mac_can_set_cts_prot(arvif
)) {
6006 ret
= ath10k_mac_set_cts_prot(arvif
);
6008 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
6009 arvif
->vdev_id
, ret
);
6013 if (changed
& BSS_CHANGED_ERP_SLOT
) {
6014 if (info
->use_short_slot
)
6015 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
6018 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
6020 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
6021 arvif
->vdev_id
, slottime
);
6023 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
6024 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6027 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
6028 arvif
->vdev_id
, ret
);
6031 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
6032 if (info
->use_short_preamble
)
6033 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
6035 preamble
= WMI_VDEV_PREAMBLE_LONG
;
6037 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6038 "mac vdev %d preamble %dn",
6039 arvif
->vdev_id
, preamble
);
6041 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
6042 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6045 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
6046 arvif
->vdev_id
, ret
);
6049 if (changed
& BSS_CHANGED_ASSOC
) {
6051 /* Workaround: Make sure monitor vdev is not running
6052 * when associating to prevent some firmware revisions
6053 * (e.g. 10.1 and 10.2) from crashing.
6055 if (ar
->monitor_started
)
6056 ath10k_monitor_stop(ar
);
6057 ath10k_bss_assoc(hw
, vif
, info
);
6058 ath10k_monitor_recalc(ar
);
6060 ath10k_bss_disassoc(hw
, vif
);
6064 if (changed
& BSS_CHANGED_TXPOWER
) {
6065 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
6066 arvif
->vdev_id
, info
->txpower
);
6068 arvif
->txpower
= info
->txpower
;
6069 ret
= ath10k_mac_txpower_recalc(ar
);
6071 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
6074 if (changed
& BSS_CHANGED_PS
) {
6075 arvif
->ps
= vif
->bss_conf
.ps
;
6077 ret
= ath10k_config_ps(ar
);
6079 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
6080 arvif
->vdev_id
, ret
);
6083 if (changed
& BSS_CHANGED_MCAST_RATE
&&
6084 !ath10k_mac_vif_chan(arvif
->vif
, &def
)) {
6085 band
= def
.chan
->band
;
6086 mcast_rate
= vif
->bss_conf
.mcast_rate
[band
];
6088 rateidx
= mcast_rate
- 1;
6090 rateidx
= ffs(vif
->bss_conf
.basic_rates
) - 1;
6092 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
6093 rateidx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
6095 bitrate
= ath10k_wmi_legacy_rates
[rateidx
].bitrate
;
6096 hw_value
= ath10k_wmi_legacy_rates
[rateidx
].hw_value
;
6097 if (ath10k_mac_bitrate_is_cck(bitrate
))
6098 preamble
= WMI_RATE_PREAMBLE_CCK
;
6100 preamble
= WMI_RATE_PREAMBLE_OFDM
;
6102 rate
= ATH10K_HW_RATECODE(hw_value
, 0, preamble
);
6104 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6105 "mac vdev %d mcast_rate %x\n",
6106 arvif
->vdev_id
, rate
);
6108 vdev_param
= ar
->wmi
.vdev_param
->mcast_data_rate
;
6109 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
6113 "failed to set mcast rate on vdev %i: %d\n",
6114 arvif
->vdev_id
, ret
);
6116 vdev_param
= ar
->wmi
.vdev_param
->bcast_data_rate
;
6117 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
6121 "failed to set bcast rate on vdev %i: %d\n",
6122 arvif
->vdev_id
, ret
);
6125 if (changed
& BSS_CHANGED_BASIC_RATES
&&
6126 !ath10k_mac_vif_chan(arvif
->vif
, &def
))
6127 ath10k_recalculate_mgmt_rate(ar
, vif
, &def
);
6129 mutex_unlock(&ar
->conf_mutex
);
6132 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw
*hw
, s16 value
)
6134 struct ath10k
*ar
= hw
->priv
;
6136 /* This function should never be called if setting the coverage class
6137 * is not supported on this hardware.
6139 if (!ar
->hw_params
.hw_ops
->set_coverage_class
) {
6143 ar
->hw_params
.hw_ops
->set_coverage_class(ar
, value
);
6146 struct ath10k_mac_tdls_iter_data
{
6147 u32 num_tdls_stations
;
6148 struct ieee80211_vif
*curr_vif
;
6151 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
6152 struct ieee80211_sta
*sta
)
6154 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
6155 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6156 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
6158 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
6159 iter_data
->num_tdls_stations
++;
6162 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
6163 struct ieee80211_vif
*vif
)
6165 struct ath10k_mac_tdls_iter_data data
= {};
6167 data
.curr_vif
= vif
;
6169 ieee80211_iterate_stations_atomic(hw
,
6170 ath10k_mac_tdls_vif_stations_count_iter
,
6172 return data
.num_tdls_stations
;
6175 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
6176 struct ieee80211_vif
*vif
,
6177 struct ieee80211_scan_request
*hw_req
)
6179 struct ath10k
*ar
= hw
->priv
;
6180 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6181 struct cfg80211_scan_request
*req
= &hw_req
->req
;
6182 struct wmi_start_scan_arg arg
;
6187 mutex_lock(&ar
->conf_mutex
);
6189 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
6194 spin_lock_bh(&ar
->data_lock
);
6195 switch (ar
->scan
.state
) {
6196 case ATH10K_SCAN_IDLE
:
6197 reinit_completion(&ar
->scan
.started
);
6198 reinit_completion(&ar
->scan
.completed
);
6199 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
6200 ar
->scan
.is_roc
= false;
6201 ar
->scan
.vdev_id
= arvif
->vdev_id
;
6204 case ATH10K_SCAN_STARTING
:
6205 case ATH10K_SCAN_RUNNING
:
6206 case ATH10K_SCAN_ABORTING
:
6210 spin_unlock_bh(&ar
->data_lock
);
6215 memset(&arg
, 0, sizeof(arg
));
6216 ath10k_wmi_start_scan_init(ar
, &arg
);
6217 arg
.vdev_id
= arvif
->vdev_id
;
6218 arg
.scan_id
= ATH10K_SCAN_ID
;
6221 arg
.ie_len
= req
->ie_len
;
6222 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
6226 arg
.n_ssids
= req
->n_ssids
;
6227 for (i
= 0; i
< arg
.n_ssids
; i
++) {
6228 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
6229 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
6232 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
6235 if (req
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6236 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ
;
6237 ether_addr_copy(arg
.mac_addr
.addr
, req
->mac_addr
);
6238 ether_addr_copy(arg
.mac_mask
.addr
, req
->mac_addr_mask
);
6241 if (req
->n_channels
) {
6242 arg
.n_channels
= req
->n_channels
;
6243 for (i
= 0; i
< arg
.n_channels
; i
++)
6244 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
6247 /* if duration is set, default dwell times will be overwritten */
6248 if (req
->duration
) {
6249 arg
.dwell_time_active
= req
->duration
;
6250 arg
.dwell_time_passive
= req
->duration
;
6251 arg
.burst_duration_ms
= req
->duration
;
6253 scan_timeout
= min_t(u32
, arg
.max_rest_time
*
6254 (arg
.n_channels
- 1) + (req
->duration
+
6255 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD
) *
6256 arg
.n_channels
, arg
.max_scan_time
+ 200);
6259 /* Add a 200ms margin to account for event/command processing */
6260 scan_timeout
= arg
.max_scan_time
+ 200;
6263 ret
= ath10k_start_scan(ar
, &arg
);
6265 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
6266 spin_lock_bh(&ar
->data_lock
);
6267 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
6268 spin_unlock_bh(&ar
->data_lock
);
6271 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
6272 msecs_to_jiffies(scan_timeout
));
6275 mutex_unlock(&ar
->conf_mutex
);
6279 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
6280 struct ieee80211_vif
*vif
)
6282 struct ath10k
*ar
= hw
->priv
;
6284 mutex_lock(&ar
->conf_mutex
);
6285 ath10k_scan_abort(ar
);
6286 mutex_unlock(&ar
->conf_mutex
);
6288 cancel_delayed_work_sync(&ar
->scan
.timeout
);
6291 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
6292 struct ath10k_vif
*arvif
,
6293 enum set_key_cmd cmd
,
6294 struct ieee80211_key_conf
*key
)
6296 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
6299 /* 10.1 firmware branch requires default key index to be set to group
6300 * key index after installing it. Otherwise FW/HW Txes corrupted
6301 * frames with multi-vif APs. This is not required for main firmware
6302 * branch (e.g. 636).
6304 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6306 * FIXME: It remains unknown if this is required for multi-vif STA
6307 * interfaces on 10.1.
6310 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
6311 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
6314 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
6317 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
6320 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6326 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6329 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
6330 arvif
->vdev_id
, ret
);
6333 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6334 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
6335 struct ieee80211_key_conf
*key
)
6337 struct ath10k
*ar
= hw
->priv
;
6338 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6339 struct ath10k_sta
*arsta
;
6340 struct ath10k_peer
*peer
;
6341 const u8
*peer_addr
;
6342 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
6343 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
6349 /* this one needs to be done in software */
6350 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
6351 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
6352 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
||
6353 key
->cipher
== WLAN_CIPHER_SUITE_BIP_CMAC_256
)
6356 if (arvif
->nohwcrypt
)
6359 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
6362 mutex_lock(&ar
->conf_mutex
);
6365 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6366 peer_addr
= sta
->addr
;
6367 spin_lock_bh(&ar
->data_lock
);
6368 arsta
->ucast_cipher
= key
->cipher
;
6369 spin_unlock_bh(&ar
->data_lock
);
6370 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
6371 peer_addr
= vif
->bss_conf
.bssid
;
6373 peer_addr
= vif
->addr
;
6376 key
->hw_key_idx
= key
->keyidx
;
6380 arvif
->wep_keys
[key
->keyidx
] = key
;
6382 arvif
->wep_keys
[key
->keyidx
] = NULL
;
6385 /* the peer should not disappear in mid-way (unless FW goes awry) since
6386 * we already hold conf_mutex. we just make sure its there now.
6388 spin_lock_bh(&ar
->data_lock
);
6389 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6390 spin_unlock_bh(&ar
->data_lock
);
6393 if (cmd
== SET_KEY
) {
6394 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
6399 /* if the peer doesn't exist there is no key to disable anymore */
6404 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6405 flags
|= WMI_KEY_PAIRWISE
;
6407 flags
|= WMI_KEY_GROUP
;
6410 if (cmd
== DISABLE_KEY
)
6411 ath10k_clear_vdev_key(arvif
, key
);
6413 /* When WEP keys are uploaded it's possible that there are
6414 * stations associated already (e.g. when merging) without any
6415 * keys. Static WEP needs an explicit per-peer key upload.
6417 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
6419 ath10k_mac_vif_update_wep_key(arvif
, key
);
6421 /* 802.1x never sets the def_wep_key_idx so each set_key()
6422 * call changes default tx key.
6424 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6425 * after first set_key().
6427 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
6428 flags
|= WMI_KEY_TX_USAGE
;
6431 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
6434 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
6435 arvif
->vdev_id
, peer_addr
, ret
);
6439 /* mac80211 sets static WEP keys as groupwise while firmware requires
6440 * them to be installed twice as both pairwise and groupwise.
6442 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
6444 flags2
&= ~WMI_KEY_GROUP
;
6445 flags2
|= WMI_KEY_PAIRWISE
;
6447 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
6450 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6451 arvif
->vdev_id
, peer_addr
, ret
);
6452 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
6456 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6457 arvif
->vdev_id
, peer_addr
, ret2
);
6463 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
6465 spin_lock_bh(&ar
->data_lock
);
6466 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6467 if (peer
&& cmd
== SET_KEY
)
6468 peer
->keys
[key
->keyidx
] = key
;
6469 else if (peer
&& cmd
== DISABLE_KEY
)
6470 peer
->keys
[key
->keyidx
] = NULL
;
6471 else if (peer
== NULL
)
6472 /* impossible unless FW goes crazy */
6473 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
6474 spin_unlock_bh(&ar
->data_lock
);
6476 if (sta
&& sta
->tdls
)
6477 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6478 ar
->wmi
.peer_param
->authorize
, 1);
6479 else if (sta
&& cmd
== SET_KEY
&& (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
6480 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, peer_addr
,
6481 ar
->wmi
.peer_param
->authorize
, 1);
6484 mutex_unlock(&ar
->conf_mutex
);
6488 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
6489 struct ieee80211_vif
*vif
,
6492 struct ath10k
*ar
= hw
->priv
;
6493 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6496 mutex_lock(&arvif
->ar
->conf_mutex
);
6498 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
6501 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
6502 arvif
->vdev_id
, keyidx
);
6504 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
6506 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
6510 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
6516 arvif
->def_wep_key_idx
= keyidx
;
6519 mutex_unlock(&arvif
->ar
->conf_mutex
);
6522 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
6525 struct ath10k_vif
*arvif
;
6526 struct ath10k_sta
*arsta
;
6527 struct ieee80211_sta
*sta
;
6528 struct cfg80211_chan_def def
;
6529 enum nl80211_band band
;
6530 const u8
*ht_mcs_mask
;
6531 const u16
*vht_mcs_mask
;
6532 u32 changed
, bw
, nss
, smps
;
6535 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
6536 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
6537 arvif
= arsta
->arvif
;
6540 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
6543 band
= def
.chan
->band
;
6544 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
6545 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
6547 spin_lock_bh(&ar
->data_lock
);
6549 changed
= arsta
->changed
;
6556 spin_unlock_bh(&ar
->data_lock
);
6558 mutex_lock(&ar
->conf_mutex
);
6560 nss
= max_t(u32
, 1, nss
);
6561 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6562 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6564 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6565 enum wmi_phy_mode mode
;
6567 mode
= chan_to_phymode(&def
);
6568 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d phymode %d\n",
6569 sta
->addr
, bw
, mode
);
6571 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6572 ar
->wmi
.peer_param
->phymode
, mode
);
6574 ath10k_warn(ar
, "failed to update STA %pM peer phymode %d: %d\n",
6575 sta
->addr
, mode
, err
);
6579 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6580 ar
->wmi
.peer_param
->chan_width
, bw
);
6582 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
6583 sta
->addr
, bw
, err
);
6586 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
6587 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
6590 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6591 ar
->wmi
.peer_param
->nss
, nss
);
6593 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
6594 sta
->addr
, nss
, err
);
6597 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6598 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
6601 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6602 ar
->wmi
.peer_param
->smps_state
, smps
);
6604 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
6605 sta
->addr
, smps
, err
);
6608 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
6609 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates\n",
6612 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
6614 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
6619 mutex_unlock(&ar
->conf_mutex
);
6622 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
6623 struct ieee80211_sta
*sta
)
6625 struct ath10k
*ar
= arvif
->ar
;
6627 lockdep_assert_held(&ar
->conf_mutex
);
6629 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6632 if (ar
->num_stations
>= ar
->max_num_stations
)
6640 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
6641 struct ieee80211_sta
*sta
)
6643 struct ath10k
*ar
= arvif
->ar
;
6645 lockdep_assert_held(&ar
->conf_mutex
);
6647 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6653 static int ath10k_sta_set_txpwr(struct ieee80211_hw
*hw
,
6654 struct ieee80211_vif
*vif
,
6655 struct ieee80211_sta
*sta
)
6657 struct ath10k
*ar
= hw
->priv
;
6658 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6662 if (sta
->txpwr
.type
== NL80211_TX_POWER_AUTOMATIC
) {
6665 txpwr
= sta
->txpwr
.power
;
6670 if (txpwr
> ATH10K_TX_POWER_MAX_VAL
|| txpwr
< ATH10K_TX_POWER_MIN_VAL
)
6673 mutex_lock(&ar
->conf_mutex
);
6675 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6676 ar
->wmi
.peer_param
->use_fixed_power
, txpwr
);
6678 ath10k_warn(ar
, "failed to set tx power for station ret: %d\n",
6684 mutex_unlock(&ar
->conf_mutex
);
6688 struct ath10k_mac_iter_tid_conf_data
{
6689 struct ieee80211_vif
*curr_vif
;
6695 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
6696 enum nl80211_band band
,
6697 const struct cfg80211_bitrate_mask
*mask
,
6703 num_rates
+= hweight32(mask
->control
[band
].legacy
);
6705 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
6706 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
6709 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6710 tmp
= hweight16(mask
->control
[band
].vht_mcs
[i
]);
6712 *vht_num_rates
+= tmp
;
6715 return num_rates
== 1;
6719 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
6720 enum nl80211_band band
,
6721 const struct cfg80211_bitrate_mask
*mask
,
6722 u8
*rate
, u8
*nss
, bool vht_only
)
6733 if (hweight32(mask
->control
[band
].legacy
) == 1) {
6734 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
6736 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
6737 rate_idx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
6739 hw_rate
= ath10k_wmi_legacy_rates
[rate_idx
].hw_value
;
6740 bitrate
= ath10k_wmi_legacy_rates
[rate_idx
].bitrate
;
6742 if (ath10k_mac_bitrate_is_cck(bitrate
))
6743 preamble
= WMI_RATE_PREAMBLE_CCK
;
6745 preamble
= WMI_RATE_PREAMBLE_OFDM
;
6748 *rate
= preamble
<< 6 |
6755 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
6756 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
6758 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
6760 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
6767 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
6768 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
6770 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
6772 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
6781 static int ath10k_mac_validate_rate_mask(struct ath10k
*ar
,
6782 struct ieee80211_sta
*sta
,
6783 u32 rate_ctrl_flag
, u8 nss
)
6785 if (nss
> sta
->rx_nss
) {
6786 ath10k_warn(ar
, "Invalid nss field, configured %u limit %u\n",
6791 if (ATH10K_HW_PREAMBLE(rate_ctrl_flag
) == WMI_RATE_PREAMBLE_VHT
) {
6792 if (!sta
->vht_cap
.vht_supported
) {
6793 ath10k_warn(ar
, "Invalid VHT rate for sta %pM\n",
6797 } else if (ATH10K_HW_PREAMBLE(rate_ctrl_flag
) == WMI_RATE_PREAMBLE_HT
) {
6798 if (!sta
->ht_cap
.ht_supported
|| sta
->vht_cap
.vht_supported
) {
6799 ath10k_warn(ar
, "Invalid HT rate for sta %pM\n",
6804 if (sta
->ht_cap
.ht_supported
|| sta
->vht_cap
.vht_supported
)
6812 ath10k_mac_tid_bitrate_config(struct ath10k
*ar
,
6813 struct ieee80211_vif
*vif
,
6814 struct ieee80211_sta
*sta
,
6815 u32
*rate_ctrl_flag
, u8
*rate_ctrl
,
6816 enum nl80211_tx_rate_setting txrate_type
,
6817 const struct cfg80211_bitrate_mask
*mask
)
6819 struct cfg80211_chan_def def
;
6820 enum nl80211_band band
;
6822 int vht_num_rates
, ret
;
6824 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
6827 if (txrate_type
== NL80211_TX_RATE_AUTOMATIC
) {
6828 *rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
6829 *rate_ctrl_flag
= 0;
6833 band
= def
.chan
->band
;
6835 if (!ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
6840 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
6841 &rate
, &nss
, false);
6843 ath10k_warn(ar
, "failed to get single rate: %d\n",
6848 *rate_ctrl_flag
= rate
;
6850 if (sta
&& ath10k_mac_validate_rate_mask(ar
, sta
, *rate_ctrl_flag
, nss
))
6853 if (txrate_type
== NL80211_TX_RATE_FIXED
)
6854 *rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_FIXED_RATE
;
6855 else if (txrate_type
== NL80211_TX_RATE_LIMITED
&&
6856 (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT
,
6858 *rate_ctrl
= WMI_PEER_TID_CONFIG_RATE_UPPER_CAP
;
6865 static int ath10k_mac_set_tid_config(struct ath10k
*ar
, struct ieee80211_sta
*sta
,
6866 struct ieee80211_vif
*vif
, u32 changed
,
6867 struct wmi_per_peer_per_tid_cfg_arg
*arg
)
6869 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6870 struct ath10k_sta
*arsta
;
6877 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6879 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
6880 if ((arsta
->retry_long
[arg
->tid
] > 0 ||
6881 arsta
->rate_code
[arg
->tid
] > 0 ||
6882 arsta
->ampdu
[arg
->tid
] ==
6883 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
) &&
6884 arg
->ack_policy
== WMI_PEER_TID_CONFIG_NOACK
) {
6885 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
6886 arg
->ack_policy
= 0;
6887 arg
->aggr_control
= 0;
6889 arg
->rcode_flags
= 0;
6893 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
6894 if (arsta
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
||
6895 arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
6896 arg
->aggr_control
= 0;
6897 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
6901 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
6902 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
6903 if (arsta
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
||
6904 arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
6906 arg
->rcode_flags
= 0;
6910 ether_addr_copy(arg
->peer_macaddr
.addr
, sta
->addr
);
6912 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, arg
);
6916 /* Store the configured parameters in success case */
6917 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
6918 arsta
->noack
[arg
->tid
] = arg
->ack_policy
;
6919 arg
->ack_policy
= 0;
6920 arg
->aggr_control
= 0;
6922 arg
->rcode_flags
= 0;
6925 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
6926 arsta
->retry_long
[arg
->tid
] = arg
->retry_count
;
6927 arg
->retry_count
= 0;
6930 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
6931 arsta
->ampdu
[arg
->tid
] = arg
->aggr_control
;
6932 arg
->aggr_control
= 0;
6935 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
6936 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
6937 arsta
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
6939 arg
->rcode_flags
= 0;
6942 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
6943 arsta
->rtscts
[arg
->tid
] = arg
->rtscts_ctrl
;
6944 arg
->ext_tid_cfg_bitmap
= 0;
6947 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
6948 if ((arvif
->retry_long
[arg
->tid
] ||
6949 arvif
->rate_code
[arg
->tid
] ||
6950 arvif
->ampdu
[arg
->tid
] ==
6951 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
) &&
6952 arg
->ack_policy
== WMI_PEER_TID_CONFIG_NOACK
) {
6953 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK
);
6955 arvif
->noack
[arg
->tid
] = arg
->ack_policy
;
6956 arvif
->ampdu
[arg
->tid
] = arg
->aggr_control
;
6957 arvif
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
6961 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
6962 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
)
6963 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
);
6965 arvif
->retry_long
[arg
->tid
] = arg
->retry_count
;
6968 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
6969 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
)
6970 changed
&= ~BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
);
6972 arvif
->ampdu
[arg
->tid
] = arg
->aggr_control
;
6975 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
6976 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
6977 if (arvif
->noack
[arg
->tid
] == WMI_PEER_TID_CONFIG_NOACK
) {
6978 changed
&= ~(BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
6979 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
));
6981 arvif
->rate_ctrl
[arg
->tid
] = arg
->rate_ctrl
;
6982 arvif
->rate_code
[arg
->tid
] = arg
->rcode_flags
;
6986 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
6987 arvif
->rtscts
[arg
->tid
] = arg
->rtscts_ctrl
;
6988 arg
->ext_tid_cfg_bitmap
= 0;
6992 arvif
->tid_conf_changed
[arg
->tid
] |= changed
;
6999 ath10k_mac_parse_tid_config(struct ath10k
*ar
,
7000 struct ieee80211_sta
*sta
,
7001 struct ieee80211_vif
*vif
,
7002 struct cfg80211_tid_cfg
*tid_conf
,
7003 struct wmi_per_peer_per_tid_cfg_arg
*arg
)
7005 u32 changed
= tid_conf
->mask
;
7011 while (i
< ATH10K_TID_MAX
) {
7012 if (!(tid_conf
->tids
& BIT(i
))) {
7019 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7020 if (tid_conf
->noack
== NL80211_TID_CONFIG_ENABLE
) {
7021 arg
->ack_policy
= WMI_PEER_TID_CONFIG_NOACK
;
7023 WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE
;
7025 WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
7028 WMI_PEER_TID_CONFIG_ACK
;
7030 WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7032 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7036 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
))
7037 arg
->retry_count
= tid_conf
->retry_long
;
7039 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7040 if (tid_conf
->noack
== NL80211_TID_CONFIG_ENABLE
)
7041 arg
->aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7043 arg
->aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_DISABLE
;
7046 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7047 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7048 ret
= ath10k_mac_tid_bitrate_config(ar
, vif
, sta
,
7051 tid_conf
->txrate_type
,
7052 &tid_conf
->txrate_mask
);
7054 ath10k_warn(ar
, "failed to configure bitrate mask %d\n",
7056 arg
->rcode_flags
= 0;
7061 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7062 if (tid_conf
->rtscts
)
7063 arg
->rtscts_ctrl
= tid_conf
->rtscts
;
7065 arg
->ext_tid_cfg_bitmap
= WMI_EXT_TID_RTS_CTS_CONFIG
;
7068 ret
= ath10k_mac_set_tid_config(ar
, sta
, vif
, changed
, arg
);
7077 static int ath10k_mac_reset_tid_config(struct ath10k
*ar
,
7078 struct ieee80211_sta
*sta
,
7079 struct ath10k_vif
*arvif
,
7082 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7083 struct wmi_per_peer_per_tid_cfg_arg arg
;
7086 arg
.vdev_id
= arvif
->vdev_id
;
7087 while (i
< ATH10K_TID_MAX
) {
7088 if (!(tids
& BIT(i
))) {
7094 arg
.ack_policy
= WMI_PEER_TID_CONFIG_ACK
;
7095 arg
.retry_count
= ATH10K_MAX_RETRY_COUNT
;
7096 arg
.rate_ctrl
= WMI_TID_CONFIG_RATE_CONTROL_AUTO
;
7097 arg
.aggr_control
= WMI_TID_CONFIG_AGGR_CONTROL_ENABLE
;
7098 arg
.rtscts_ctrl
= WMI_TID_CONFIG_RTSCTS_CONTROL_ENABLE
;
7099 arg
.ext_tid_cfg_bitmap
= WMI_EXT_TID_RTS_CTS_CONFIG
;
7101 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
7103 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
7107 if (!arvif
->tids_rst
) {
7108 arsta
->retry_long
[i
] = -1;
7109 arsta
->noack
[i
] = -1;
7110 arsta
->ampdu
[i
] = -1;
7111 arsta
->rate_code
[i
] = -1;
7112 arsta
->rate_ctrl
[i
] = 0;
7113 arsta
->rtscts
[i
] = -1;
7115 arvif
->retry_long
[i
] = 0;
7116 arvif
->noack
[i
] = 0;
7117 arvif
->ampdu
[i
] = 0;
7118 arvif
->rate_code
[i
] = 0;
7119 arvif
->rate_ctrl
[i
] = 0;
7120 arvif
->rtscts
[i
] = 0;
7129 static void ath10k_sta_tid_cfg_wk(struct work_struct
*wk
)
7131 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
7132 struct ieee80211_sta
*sta
;
7133 struct ath10k_sta
*arsta
;
7134 struct ath10k_vif
*arvif
;
7141 arsta
= container_of(wk
, struct ath10k_sta
, tid_config_wk
);
7142 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
7143 arvif
= arsta
->arvif
;
7146 mutex_lock(&ar
->conf_mutex
);
7148 if (arvif
->tids_rst
) {
7149 ret
= ath10k_mac_reset_tid_config(ar
, sta
, arvif
,
7154 ether_addr_copy(arg
.peer_macaddr
.addr
, sta
->addr
);
7156 for (i
= 0; i
< ATH10K_TID_MAX
; i
++) {
7157 config_apply
= false;
7158 changed
= arvif
->tid_conf_changed
[i
];
7160 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_NOACK
)) {
7161 if (arsta
->noack
[i
] != -1) {
7164 config_apply
= true;
7165 arg
.ack_policy
= arvif
->noack
[i
];
7166 arg
.aggr_control
= arvif
->ampdu
[i
];
7167 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
7171 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
)) {
7172 if (arsta
->retry_long
[i
] != -1 ||
7173 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7174 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7175 arg
.retry_count
= 0;
7177 arg
.retry_count
= arvif
->retry_long
[i
];
7178 config_apply
= true;
7182 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
)) {
7183 if (arsta
->ampdu
[i
] != -1 ||
7184 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7185 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7186 arg
.aggr_control
= 0;
7188 arg
.aggr_control
= arvif
->ampdu
[i
];
7189 config_apply
= true;
7193 if (changed
& (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
7194 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
))) {
7195 nss
= ATH10K_HW_NSS(arvif
->rate_code
[i
]);
7196 ret
= ath10k_mac_validate_rate_mask(ar
, sta
,
7197 arvif
->rate_code
[i
],
7200 arvif
->rate_ctrl
[i
] > WMI_TID_CONFIG_RATE_CONTROL_AUTO
) {
7202 arg
.rcode_flags
= 0;
7205 if (arsta
->rate_ctrl
[i
] >
7206 WMI_TID_CONFIG_RATE_CONTROL_AUTO
||
7207 arsta
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
||
7208 arvif
->noack
[i
] == WMI_PEER_TID_CONFIG_NOACK
) {
7210 arg
.rcode_flags
= 0;
7212 arg
.rate_ctrl
= arvif
->rate_ctrl
[i
];
7213 arg
.rcode_flags
= arvif
->rate_code
[i
];
7214 config_apply
= true;
7218 if (changed
& BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
)) {
7219 if (arsta
->rtscts
[i
]) {
7220 arg
.rtscts_ctrl
= 0;
7221 arg
.ext_tid_cfg_bitmap
= 0;
7223 arg
.rtscts_ctrl
= arvif
->rtscts
[i
] - 1;
7224 arg
.ext_tid_cfg_bitmap
=
7225 WMI_EXT_TID_RTS_CTS_CONFIG
;
7226 config_apply
= true;
7233 ret
= ath10k_wmi_set_per_peer_per_tid_cfg(ar
, &arg
);
7235 ath10k_warn(ar
, "failed to set per tid config for sta %pM: %d\n",
7240 arg
.retry_count
= 0;
7241 arg
.aggr_control
= 0;
7243 arg
.rcode_flags
= 0;
7247 mutex_unlock(&ar
->conf_mutex
);
7250 static void ath10k_mac_vif_stations_tid_conf(void *data
,
7251 struct ieee80211_sta
*sta
)
7253 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7254 struct ath10k_mac_iter_tid_conf_data
*iter_data
= data
;
7255 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
7257 if (sta_vif
!= iter_data
->curr_vif
|| !sta
->wme
)
7260 ieee80211_queue_work(iter_data
->ar
->hw
, &arsta
->tid_config_wk
);
7263 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
7264 struct ieee80211_vif
*vif
,
7265 struct ieee80211_sta
*sta
,
7266 enum ieee80211_sta_state old_state
,
7267 enum ieee80211_sta_state new_state
)
7269 struct ath10k
*ar
= hw
->priv
;
7270 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7271 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7272 struct ath10k_peer
*peer
;
7276 if (old_state
== IEEE80211_STA_NOTEXIST
&&
7277 new_state
== IEEE80211_STA_NONE
) {
7278 memset(arsta
, 0, sizeof(*arsta
));
7279 arsta
->arvif
= arvif
;
7280 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
7281 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
7282 INIT_WORK(&arsta
->tid_config_wk
, ath10k_sta_tid_cfg_wk
);
7284 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
7285 ath10k_mac_txq_init(sta
->txq
[i
]);
7288 /* cancel must be done outside the mutex to avoid deadlock */
7289 if ((old_state
== IEEE80211_STA_NONE
&&
7290 new_state
== IEEE80211_STA_NOTEXIST
)) {
7291 cancel_work_sync(&arsta
->update_wk
);
7292 cancel_work_sync(&arsta
->tid_config_wk
);
7295 mutex_lock(&ar
->conf_mutex
);
7297 if (old_state
== IEEE80211_STA_NOTEXIST
&&
7298 new_state
== IEEE80211_STA_NONE
) {
7300 * New station addition.
7302 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
7303 u32 num_tdls_stations
;
7305 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
7306 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
7307 arvif
->vdev_id
, sta
->addr
,
7308 ar
->num_stations
+ 1, ar
->max_num_stations
,
7309 ar
->num_peers
+ 1, ar
->max_num_peers
);
7311 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
7314 if (num_tdls_stations
>= ar
->max_num_tdls_vdevs
) {
7315 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
7317 ar
->max_num_tdls_vdevs
);
7321 peer_type
= WMI_PEER_TYPE_TDLS
;
7324 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
7326 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
7327 ar
->max_num_stations
);
7331 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
7332 arsta
->tx_stats
= kzalloc(sizeof(*arsta
->tx_stats
),
7334 if (!arsta
->tx_stats
) {
7335 ath10k_mac_dec_num_stations(arvif
, sta
);
7341 ret
= ath10k_peer_create(ar
, vif
, sta
, arvif
->vdev_id
,
7342 sta
->addr
, peer_type
);
7344 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
7345 sta
->addr
, arvif
->vdev_id
, ret
);
7346 ath10k_mac_dec_num_stations(arvif
, sta
);
7347 kfree(arsta
->tx_stats
);
7351 spin_lock_bh(&ar
->data_lock
);
7353 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
7355 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
7356 vif
->addr
, arvif
->vdev_id
);
7357 spin_unlock_bh(&ar
->data_lock
);
7358 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7359 ath10k_mac_dec_num_stations(arvif
, sta
);
7360 kfree(arsta
->tx_stats
);
7365 arsta
->peer_id
= find_first_bit(peer
->peer_ids
,
7366 ATH10K_MAX_NUM_PEER_IDS
);
7368 spin_unlock_bh(&ar
->data_lock
);
7373 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7374 WMI_TDLS_ENABLE_ACTIVE
);
7376 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
7377 arvif
->vdev_id
, ret
);
7378 ath10k_peer_delete(ar
, arvif
->vdev_id
,
7380 ath10k_mac_dec_num_stations(arvif
, sta
);
7381 kfree(arsta
->tx_stats
);
7385 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
7386 WMI_TDLS_PEER_STATE_PEERING
);
7389 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
7390 sta
->addr
, arvif
->vdev_id
, ret
);
7391 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7392 ath10k_mac_dec_num_stations(arvif
, sta
);
7393 kfree(arsta
->tx_stats
);
7395 if (num_tdls_stations
!= 0)
7397 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7400 } else if ((old_state
== IEEE80211_STA_NONE
&&
7401 new_state
== IEEE80211_STA_NOTEXIST
)) {
7403 * Existing station deletion.
7405 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
7406 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
7407 arvif
->vdev_id
, sta
->addr
, sta
);
7410 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
,
7412 WMI_TDLS_PEER_STATE_TEARDOWN
);
7414 ath10k_warn(ar
, "failed to update tdls peer state for %pM state %d: %i\n",
7416 WMI_TDLS_PEER_STATE_TEARDOWN
, ret
);
7419 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
7421 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
7422 sta
->addr
, arvif
->vdev_id
, ret
);
7424 ath10k_mac_dec_num_stations(arvif
, sta
);
7426 spin_lock_bh(&ar
->data_lock
);
7427 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
7428 peer
= ar
->peer_map
[i
];
7432 if (peer
->sta
== sta
) {
7433 ath10k_warn(ar
, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
7434 sta
->addr
, peer
, i
, arvif
->vdev_id
);
7437 /* Clean up the peer object as well since we
7438 * must have failed to do this above.
7440 list_del(&peer
->list
);
7441 ar
->peer_map
[i
] = NULL
;
7446 spin_unlock_bh(&ar
->data_lock
);
7448 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
7449 kfree(arsta
->tx_stats
);
7450 arsta
->tx_stats
= NULL
;
7453 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
7454 ath10k_mac_txq_unref(ar
, sta
->txq
[i
]);
7459 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
7462 /* This was the last tdls peer in current vif */
7463 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
7466 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
7467 arvif
->vdev_id
, ret
);
7469 } else if (old_state
== IEEE80211_STA_AUTH
&&
7470 new_state
== IEEE80211_STA_ASSOC
&&
7471 (vif
->type
== NL80211_IFTYPE_AP
||
7472 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
7473 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
7477 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
7480 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
7482 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
7483 sta
->addr
, arvif
->vdev_id
, ret
);
7484 } else if (old_state
== IEEE80211_STA_ASSOC
&&
7485 new_state
== IEEE80211_STA_AUTHORIZED
&&
7488 * Tdls station authorized.
7490 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
7493 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
7495 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
7496 sta
->addr
, arvif
->vdev_id
, ret
);
7500 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
7501 WMI_TDLS_PEER_STATE_CONNECTED
);
7503 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
7504 sta
->addr
, arvif
->vdev_id
, ret
);
7505 } else if (old_state
== IEEE80211_STA_ASSOC
&&
7506 new_state
== IEEE80211_STA_AUTH
&&
7507 (vif
->type
== NL80211_IFTYPE_AP
||
7508 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
7509 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
7513 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
7516 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
7518 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
7519 sta
->addr
, arvif
->vdev_id
, ret
);
7522 mutex_unlock(&ar
->conf_mutex
);
7526 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
7527 u16 ac
, bool enable
)
7529 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7530 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
7531 u32 prio
= 0, acc
= 0;
7535 lockdep_assert_held(&ar
->conf_mutex
);
7537 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
7541 case IEEE80211_AC_VO
:
7542 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
7543 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
7547 case IEEE80211_AC_VI
:
7548 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
7549 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
7553 case IEEE80211_AC_BE
:
7554 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
7555 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
7559 case IEEE80211_AC_BK
:
7560 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
7561 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
7568 arvif
->u
.sta
.uapsd
|= value
;
7570 arvif
->u
.sta
.uapsd
&= ~value
;
7572 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
7573 WMI_STA_PS_PARAM_UAPSD
,
7574 arvif
->u
.sta
.uapsd
);
7576 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
7580 if (arvif
->u
.sta
.uapsd
)
7581 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
7583 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
7585 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
7586 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
7589 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
7591 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
7593 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
7594 arvif
->vdev_id
, ret
);
7598 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
7600 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
7601 arvif
->vdev_id
, ret
);
7605 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
7606 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
7607 /* Only userspace can make an educated decision when to send
7608 * trigger frame. The following effectively disables u-UAPSD
7609 * autotrigger in firmware (which is enabled by default
7610 * provided the autotrigger service is available).
7614 arg
.user_priority
= prio
;
7615 arg
.service_interval
= 0;
7616 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
7617 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
7619 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
7620 arvif
->bssid
, &arg
, 1);
7622 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
7632 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
7633 struct ieee80211_vif
*vif
, u16 ac
,
7634 const struct ieee80211_tx_queue_params
*params
)
7636 struct ath10k
*ar
= hw
->priv
;
7637 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7638 struct wmi_wmm_params_arg
*p
= NULL
;
7641 mutex_lock(&ar
->conf_mutex
);
7644 case IEEE80211_AC_VO
:
7645 p
= &arvif
->wmm_params
.ac_vo
;
7647 case IEEE80211_AC_VI
:
7648 p
= &arvif
->wmm_params
.ac_vi
;
7650 case IEEE80211_AC_BE
:
7651 p
= &arvif
->wmm_params
.ac_be
;
7653 case IEEE80211_AC_BK
:
7654 p
= &arvif
->wmm_params
.ac_bk
;
7663 p
->cwmin
= params
->cw_min
;
7664 p
->cwmax
= params
->cw_max
;
7665 p
->aifs
= params
->aifs
;
7668 * The channel time duration programmed in the HW is in absolute
7669 * microseconds, while mac80211 gives the txop in units of
7672 p
->txop
= params
->txop
* 32;
7674 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
7675 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
7676 &arvif
->wmm_params
);
7678 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
7679 arvif
->vdev_id
, ret
);
7683 /* This won't work well with multi-interface cases but it's
7684 * better than nothing.
7686 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
7688 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
7693 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
7695 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
7698 mutex_unlock(&ar
->conf_mutex
);
7702 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
7703 struct ieee80211_vif
*vif
,
7704 struct ieee80211_channel
*chan
,
7706 enum ieee80211_roc_type type
)
7708 struct ath10k
*ar
= hw
->priv
;
7709 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7710 struct wmi_start_scan_arg arg
;
7714 mutex_lock(&ar
->conf_mutex
);
7716 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
7721 spin_lock_bh(&ar
->data_lock
);
7722 switch (ar
->scan
.state
) {
7723 case ATH10K_SCAN_IDLE
:
7724 reinit_completion(&ar
->scan
.started
);
7725 reinit_completion(&ar
->scan
.completed
);
7726 reinit_completion(&ar
->scan
.on_channel
);
7727 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
7728 ar
->scan
.is_roc
= true;
7729 ar
->scan
.vdev_id
= arvif
->vdev_id
;
7730 ar
->scan
.roc_freq
= chan
->center_freq
;
7731 ar
->scan
.roc_notify
= true;
7734 case ATH10K_SCAN_STARTING
:
7735 case ATH10K_SCAN_RUNNING
:
7736 case ATH10K_SCAN_ABORTING
:
7740 spin_unlock_bh(&ar
->data_lock
);
7745 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
7747 memset(&arg
, 0, sizeof(arg
));
7748 ath10k_wmi_start_scan_init(ar
, &arg
);
7749 arg
.vdev_id
= arvif
->vdev_id
;
7750 arg
.scan_id
= ATH10K_SCAN_ID
;
7752 arg
.channels
[0] = chan
->center_freq
;
7753 arg
.dwell_time_active
= scan_time_msec
;
7754 arg
.dwell_time_passive
= scan_time_msec
;
7755 arg
.max_scan_time
= scan_time_msec
;
7756 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
7757 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
7758 arg
.burst_duration_ms
= duration
;
7760 ret
= ath10k_start_scan(ar
, &arg
);
7762 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
7763 spin_lock_bh(&ar
->data_lock
);
7764 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
7765 spin_unlock_bh(&ar
->data_lock
);
7769 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3 * HZ
);
7771 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
7773 ret
= ath10k_scan_stop(ar
);
7775 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
7781 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
7782 msecs_to_jiffies(duration
));
7786 mutex_unlock(&ar
->conf_mutex
);
7790 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
,
7791 struct ieee80211_vif
*vif
)
7793 struct ath10k
*ar
= hw
->priv
;
7795 mutex_lock(&ar
->conf_mutex
);
7797 spin_lock_bh(&ar
->data_lock
);
7798 ar
->scan
.roc_notify
= false;
7799 spin_unlock_bh(&ar
->data_lock
);
7801 ath10k_scan_abort(ar
);
7803 mutex_unlock(&ar
->conf_mutex
);
7805 cancel_delayed_work_sync(&ar
->scan
.timeout
);
7811 * Both RTS and Fragmentation threshold are interface-specific
7812 * in ath10k, but device-specific in mac80211.
7815 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
7817 struct ath10k
*ar
= hw
->priv
;
7818 struct ath10k_vif
*arvif
;
7821 mutex_lock(&ar
->conf_mutex
);
7822 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
7823 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
7824 arvif
->vdev_id
, value
);
7826 ret
= ath10k_mac_set_rts(arvif
, value
);
7828 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
7829 arvif
->vdev_id
, ret
);
7833 mutex_unlock(&ar
->conf_mutex
);
7838 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
7840 /* Even though there's a WMI enum for fragmentation threshold no known
7841 * firmware actually implements it. Moreover it is not possible to rely
7842 * frame fragmentation to mac80211 because firmware clears the "more
7843 * fragments" bit in frame control making it impossible for remote
7844 * devices to reassemble frames.
7846 * Hence implement a dummy callback just to say fragmentation isn't
7847 * supported. This effectively prevents mac80211 from doing frame
7848 * fragmentation in software.
7853 void ath10k_mac_wait_tx_complete(struct ath10k
*ar
)
7858 /* mac80211 doesn't care if we really xmit queued frames or not
7859 * we'll collect those frames either way if we stop/delete vdevs
7862 if (ar
->state
== ATH10K_STATE_WEDGED
)
7865 time_left
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
7868 spin_lock_bh(&ar
->htt
.tx_lock
);
7869 empty
= (ar
->htt
.num_pending_tx
== 0);
7870 spin_unlock_bh(&ar
->htt
.tx_lock
);
7872 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
7873 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
7877 }), ATH10K_FLUSH_TIMEOUT_HZ
);
7879 if (time_left
== 0 || skip
)
7880 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
7881 skip
, ar
->state
, time_left
);
7884 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
7885 u32 queues
, bool drop
)
7887 struct ath10k
*ar
= hw
->priv
;
7888 struct ath10k_vif
*arvif
;
7892 if (vif
&& vif
->type
== NL80211_IFTYPE_STATION
) {
7893 bitmap
= ~(1 << WMI_MGMT_TID
);
7894 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
7895 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
7896 ath10k_wmi_peer_flush(ar
, arvif
->vdev_id
,
7897 arvif
->bssid
, bitmap
);
7899 ath10k_htt_flush_tx(&ar
->htt
);
7904 mutex_lock(&ar
->conf_mutex
);
7905 ath10k_mac_wait_tx_complete(ar
);
7906 mutex_unlock(&ar
->conf_mutex
);
7909 /* TODO: Implement this function properly
7910 * For now it is needed to reply to Probe Requests in IBSS mode.
7911 * Propably we need this information from FW.
7913 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
7918 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
7919 enum ieee80211_reconfig_type reconfig_type
)
7921 struct ath10k
*ar
= hw
->priv
;
7923 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
7926 mutex_lock(&ar
->conf_mutex
);
7928 /* If device failed to restart it will be in a different state, e.g.
7929 * ATH10K_STATE_WEDGED
7931 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
7932 ath10k_info(ar
, "device successfully recovered\n");
7933 ar
->state
= ATH10K_STATE_ON
;
7934 ieee80211_wake_queues(ar
->hw
);
7935 clear_bit(ATH10K_FLAG_RESTARTING
, &ar
->dev_flags
);
7938 mutex_unlock(&ar
->conf_mutex
);
7942 ath10k_mac_update_bss_chan_survey(struct ath10k
*ar
,
7943 struct ieee80211_channel
*channel
)
7946 enum wmi_bss_survey_req_type type
= WMI_BSS_SURVEY_REQ_TYPE_READ
;
7948 lockdep_assert_held(&ar
->conf_mutex
);
7950 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64
, ar
->wmi
.svc_map
) ||
7951 (ar
->rx_channel
!= channel
))
7954 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
) {
7955 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "ignoring bss chan info request while scanning..\n");
7959 reinit_completion(&ar
->bss_survey_done
);
7961 ret
= ath10k_wmi_pdev_bss_chan_info_request(ar
, type
);
7963 ath10k_warn(ar
, "failed to send pdev bss chan info request\n");
7967 ret
= wait_for_completion_timeout(&ar
->bss_survey_done
, 3 * HZ
);
7969 ath10k_warn(ar
, "bss channel survey timed out\n");
7974 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
7975 struct survey_info
*survey
)
7977 struct ath10k
*ar
= hw
->priv
;
7978 struct ieee80211_supported_band
*sband
;
7979 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
7982 mutex_lock(&ar
->conf_mutex
);
7984 sband
= hw
->wiphy
->bands
[NL80211_BAND_2GHZ
];
7985 if (sband
&& idx
>= sband
->n_channels
) {
7986 idx
-= sband
->n_channels
;
7991 sband
= hw
->wiphy
->bands
[NL80211_BAND_5GHZ
];
7993 if (!sband
|| idx
>= sband
->n_channels
) {
7998 ath10k_mac_update_bss_chan_survey(ar
, &sband
->channels
[idx
]);
8000 spin_lock_bh(&ar
->data_lock
);
8001 memcpy(survey
, ar_survey
, sizeof(*survey
));
8002 spin_unlock_bh(&ar
->data_lock
);
8004 survey
->channel
= &sband
->channels
[idx
];
8006 if (ar
->rx_channel
== survey
->channel
)
8007 survey
->filled
|= SURVEY_INFO_IN_USE
;
8010 mutex_unlock(&ar
->conf_mutex
);
8015 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
8016 enum nl80211_band band
,
8017 const struct cfg80211_bitrate_mask
*mask
,
8020 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
8021 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8023 u8 vht_nss_mask
= 0;
8026 if (mask
->control
[band
].legacy
)
8029 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
8030 if (mask
->control
[band
].ht_mcs
[i
] == 0)
8032 else if (mask
->control
[band
].ht_mcs
[i
] ==
8033 sband
->ht_cap
.mcs
.rx_mask
[i
])
8034 ht_nss_mask
|= BIT(i
);
8039 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
8040 if (mask
->control
[band
].vht_mcs
[i
] == 0)
8042 else if (mask
->control
[band
].vht_mcs
[i
] ==
8043 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
8044 vht_nss_mask
|= BIT(i
);
8049 if (ht_nss_mask
!= vht_nss_mask
)
8052 if (ht_nss_mask
== 0)
8055 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
8058 *nss
= fls(ht_nss_mask
);
8063 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
8064 u8 rate
, u8 nss
, u8 sgi
, u8 ldpc
)
8066 struct ath10k
*ar
= arvif
->ar
;
8070 lockdep_assert_held(&ar
->conf_mutex
);
8072 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
8073 arvif
->vdev_id
, rate
, nss
, sgi
);
8075 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
8076 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
8078 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
8083 vdev_param
= ar
->wmi
.vdev_param
->nss
;
8084 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
8086 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
8090 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
8091 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
8093 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
8097 vdev_param
= ar
->wmi
.vdev_param
->ldpc
;
8098 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, ldpc
);
8100 ath10k_warn(ar
, "failed to set ldpc param %d: %d\n", ldpc
, ret
);
8108 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
8109 enum nl80211_band band
,
8110 const struct cfg80211_bitrate_mask
*mask
,
8116 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
8117 * to express all VHT MCS rate masks. Effectively only the following
8118 * ranges can be used: none, 0-7, 0-8 and 0-9.
8120 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8121 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
8131 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
8139 static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k
*ar
,
8140 struct ath10k_vif
*arvif
,
8141 struct ieee80211_sta
*sta
)
8144 u8 rate
= arvif
->vht_pfr
;
8146 /* skip non vht and multiple rate peers */
8147 if (!sta
->vht_cap
.vht_supported
|| arvif
->vht_num_rates
!= 1)
8150 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
8151 WMI_PEER_PARAM_FIXED_RATE
, rate
);
8153 ath10k_warn(ar
, "failed to enable STA %pM peer fixed rate: %d\n",
8159 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
8160 struct ieee80211_sta
*sta
)
8162 struct ath10k_vif
*arvif
= data
;
8163 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8164 struct ath10k
*ar
= arvif
->ar
;
8166 if (arsta
->arvif
!= arvif
)
8169 if (ath10k_mac_set_vht_bitrate_mask_fixup(ar
, arvif
, sta
))
8172 spin_lock_bh(&ar
->data_lock
);
8173 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
8174 spin_unlock_bh(&ar
->data_lock
);
8176 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
8179 static void ath10k_mac_clr_bitrate_mask_iter(void *data
,
8180 struct ieee80211_sta
*sta
)
8182 struct ath10k_vif
*arvif
= data
;
8183 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8184 struct ath10k
*ar
= arvif
->ar
;
8187 /* clear vht peers only */
8188 if (arsta
->arvif
!= arvif
|| !sta
->vht_cap
.vht_supported
)
8191 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
8192 WMI_PEER_PARAM_FIXED_RATE
,
8193 WMI_FIXED_RATE_NONE
);
8195 ath10k_warn(ar
, "failed to clear STA %pM peer fixed rate: %d\n",
8199 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
8200 struct ieee80211_vif
*vif
,
8201 const struct cfg80211_bitrate_mask
*mask
)
8203 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8204 struct cfg80211_chan_def def
;
8205 struct ath10k
*ar
= arvif
->ar
;
8206 enum nl80211_band band
;
8207 const u8
*ht_mcs_mask
;
8208 const u16
*vht_mcs_mask
;
8215 int vht_num_rates
, allow_pfr
;
8217 bool update_bitrate_mask
= true;
8219 if (ath10k_mac_vif_chan(vif
, &def
))
8222 band
= def
.chan
->band
;
8223 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
8224 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
8225 ldpc
= !!(ar
->ht_cap_info
& WMI_HT_CAP_LDPC
);
8227 sgi
= mask
->control
[band
].gi
;
8228 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
8231 allow_pfr
= test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE
,
8232 ar
->normal_mode_fw
.fw_file
.fw_features
);
8234 mutex_lock(&ar
->conf_mutex
);
8235 ieee80211_iterate_stations_atomic(ar
->hw
,
8236 ath10k_mac_clr_bitrate_mask_iter
,
8238 mutex_unlock(&ar
->conf_mutex
);
8241 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
8243 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
8247 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
8248 arvif
->vdev_id
, ret
);
8251 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
8253 rate
= WMI_FIXED_RATE_NONE
;
8256 rate
= WMI_FIXED_RATE_NONE
;
8257 nss
= min(ar
->num_rf_chains
,
8258 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
8259 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
8261 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
,
8265 if (!allow_pfr
|| vht_num_rates
!= 1)
8268 /* Reach here, firmware supports peer fixed rate and has
8269 * single vht rate, and don't update vif birate_mask, as
8270 * the rate only for specific peer.
8272 ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
8276 update_bitrate_mask
= false;
8281 mutex_lock(&ar
->conf_mutex
);
8283 if (update_bitrate_mask
)
8284 arvif
->bitrate_mask
= *mask
;
8285 arvif
->vht_num_rates
= vht_num_rates
;
8286 arvif
->vht_pfr
= vht_pfr
;
8287 ieee80211_iterate_stations_atomic(ar
->hw
,
8288 ath10k_mac_set_bitrate_mask_iter
,
8291 mutex_unlock(&ar
->conf_mutex
);
8294 mutex_lock(&ar
->conf_mutex
);
8296 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
, ldpc
);
8298 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
8299 arvif
->vdev_id
, ret
);
8304 mutex_unlock(&ar
->conf_mutex
);
8309 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
8310 struct ieee80211_vif
*vif
,
8311 struct ieee80211_sta
*sta
,
8314 struct ath10k
*ar
= hw
->priv
;
8315 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8316 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8317 struct ath10k_peer
*peer
;
8320 spin_lock_bh(&ar
->data_lock
);
8322 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
8324 spin_unlock_bh(&ar
->data_lock
);
8325 ath10k_warn(ar
, "mac sta rc update failed to find peer %pM on vdev %i\n",
8326 sta
->addr
, arvif
->vdev_id
);
8330 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8331 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
8332 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
8335 if (changed
& IEEE80211_RC_BW_CHANGED
) {
8336 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8338 switch (sta
->bandwidth
) {
8339 case IEEE80211_STA_RX_BW_20
:
8340 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8342 case IEEE80211_STA_RX_BW_40
:
8343 bw
= WMI_PEER_CHWIDTH_40MHZ
;
8345 case IEEE80211_STA_RX_BW_80
:
8346 bw
= WMI_PEER_CHWIDTH_80MHZ
;
8348 case IEEE80211_STA_RX_BW_160
:
8349 bw
= WMI_PEER_CHWIDTH_160MHZ
;
8352 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
8353 sta
->bandwidth
, sta
->addr
);
8354 bw
= WMI_PEER_CHWIDTH_20MHZ
;
8361 if (changed
& IEEE80211_RC_NSS_CHANGED
)
8362 arsta
->nss
= sta
->rx_nss
;
8364 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
8365 smps
= WMI_PEER_SMPS_PS_NONE
;
8367 switch (sta
->smps_mode
) {
8368 case IEEE80211_SMPS_AUTOMATIC
:
8369 case IEEE80211_SMPS_OFF
:
8370 smps
= WMI_PEER_SMPS_PS_NONE
;
8372 case IEEE80211_SMPS_STATIC
:
8373 smps
= WMI_PEER_SMPS_STATIC
;
8375 case IEEE80211_SMPS_DYNAMIC
:
8376 smps
= WMI_PEER_SMPS_DYNAMIC
;
8378 case IEEE80211_SMPS_NUM_MODES
:
8379 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
8380 sta
->smps_mode
, sta
->addr
);
8381 smps
= WMI_PEER_SMPS_PS_NONE
;
8388 arsta
->changed
|= changed
;
8390 spin_unlock_bh(&ar
->data_lock
);
8392 ieee80211_queue_work(hw
, &arsta
->update_wk
);
8395 static void ath10k_offset_tsf(struct ieee80211_hw
*hw
,
8396 struct ieee80211_vif
*vif
, s64 tsf_offset
)
8398 struct ath10k
*ar
= hw
->priv
;
8399 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8400 u32 offset
, vdev_param
;
8403 if (tsf_offset
< 0) {
8404 vdev_param
= ar
->wmi
.vdev_param
->dec_tsf
;
8405 offset
= -tsf_offset
;
8407 vdev_param
= ar
->wmi
.vdev_param
->inc_tsf
;
8408 offset
= tsf_offset
;
8411 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
8412 vdev_param
, offset
);
8414 if (ret
&& ret
!= -EOPNOTSUPP
)
8415 ath10k_warn(ar
, "failed to set tsf offset %d cmd %d: %d\n",
8416 offset
, vdev_param
, ret
);
8419 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
8420 struct ieee80211_vif
*vif
,
8421 struct ieee80211_ampdu_params
*params
)
8423 struct ath10k
*ar
= hw
->priv
;
8424 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8425 struct ieee80211_sta
*sta
= params
->sta
;
8426 enum ieee80211_ampdu_mlme_action action
= params
->action
;
8427 u16 tid
= params
->tid
;
8429 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
8430 arvif
->vdev_id
, sta
->addr
, tid
, action
);
8433 case IEEE80211_AMPDU_RX_START
:
8434 case IEEE80211_AMPDU_RX_STOP
:
8435 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
8436 * creation/removal. Do we need to verify this?
8439 case IEEE80211_AMPDU_TX_START
:
8440 case IEEE80211_AMPDU_TX_STOP_CONT
:
8441 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
8442 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
8443 case IEEE80211_AMPDU_TX_OPERATIONAL
:
8444 /* Firmware offloads Tx aggregation entirely so deny mac80211
8445 * Tx aggregation requests.
8454 ath10k_mac_update_rx_channel(struct ath10k
*ar
,
8455 struct ieee80211_chanctx_conf
*ctx
,
8456 struct ieee80211_vif_chanctx_switch
*vifs
,
8459 struct cfg80211_chan_def
*def
= NULL
;
8461 /* Both locks are required because ar->rx_channel is modified. This
8462 * allows readers to hold either lock.
8464 lockdep_assert_held(&ar
->conf_mutex
);
8465 lockdep_assert_held(&ar
->data_lock
);
8467 WARN_ON(ctx
&& vifs
);
8468 WARN_ON(vifs
&& !n_vifs
);
8470 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
8471 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
8472 * ppdu on Rx may reduce performance on low-end systems. It should be
8473 * possible to make tables/hashmaps to speed the lookup up (be vary of
8474 * cpu data cache lines though regarding sizes) but to keep the initial
8475 * implementation simple and less intrusive fallback to the slow lookup
8476 * only for multi-channel cases. Single-channel cases will remain to
8477 * use the old channel derival and thus performance should not be
8481 if (!ctx
&& ath10k_mac_num_chanctxs(ar
) == 1) {
8482 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
8483 ath10k_mac_get_any_chandef_iter
,
8487 def
= &vifs
[0].new_ctx
->def
;
8489 ar
->rx_channel
= def
->chan
;
8490 } else if ((ctx
&& ath10k_mac_num_chanctxs(ar
) == 0) ||
8491 (ctx
&& (ar
->state
== ATH10K_STATE_RESTARTED
))) {
8492 /* During driver restart due to firmware assert, since mac80211
8493 * already has valid channel context for given radio, channel
8494 * context iteration return num_chanctx > 0. So fix rx_channel
8495 * when restart is in progress.
8497 ar
->rx_channel
= ctx
->def
.chan
;
8499 ar
->rx_channel
= NULL
;
8505 ath10k_mac_update_vif_chan(struct ath10k
*ar
,
8506 struct ieee80211_vif_chanctx_switch
*vifs
,
8509 struct ath10k_vif
*arvif
;
8513 lockdep_assert_held(&ar
->conf_mutex
);
8515 /* First stop monitor interface. Some FW versions crash if there's a
8516 * lone monitor interface.
8518 if (ar
->monitor_started
)
8519 ath10k_monitor_stop(ar
);
8521 for (i
= 0; i
< n_vifs
; i
++) {
8522 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
8524 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8525 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
8527 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
8528 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
8529 vifs
[i
].old_ctx
->def
.width
,
8530 vifs
[i
].new_ctx
->def
.width
);
8532 if (WARN_ON(!arvif
->is_started
))
8535 if (WARN_ON(!arvif
->is_up
))
8538 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
8540 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
8541 arvif
->vdev_id
, ret
);
8546 /* All relevant vdevs are downed and associated channel resources
8547 * should be available for the channel switch now.
8550 spin_lock_bh(&ar
->data_lock
);
8551 ath10k_mac_update_rx_channel(ar
, NULL
, vifs
, n_vifs
);
8552 spin_unlock_bh(&ar
->data_lock
);
8554 for (i
= 0; i
< n_vifs
; i
++) {
8555 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
8557 if (WARN_ON(!arvif
->is_started
))
8560 if (WARN_ON(!arvif
->is_up
))
8563 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
8565 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
8568 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
8570 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
8573 ret
= ath10k_vdev_restart(arvif
, &vifs
[i
].new_ctx
->def
);
8575 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
8576 arvif
->vdev_id
, ret
);
8580 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
8583 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
8584 arvif
->vdev_id
, ret
);
8589 ath10k_monitor_recalc(ar
);
8593 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
8594 struct ieee80211_chanctx_conf
*ctx
)
8596 struct ath10k
*ar
= hw
->priv
;
8598 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8599 "mac chanctx add freq %hu width %d ptr %pK\n",
8600 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8602 mutex_lock(&ar
->conf_mutex
);
8604 spin_lock_bh(&ar
->data_lock
);
8605 ath10k_mac_update_rx_channel(ar
, ctx
, NULL
, 0);
8606 spin_unlock_bh(&ar
->data_lock
);
8608 ath10k_recalc_radar_detection(ar
);
8609 ath10k_monitor_recalc(ar
);
8611 mutex_unlock(&ar
->conf_mutex
);
8617 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
8618 struct ieee80211_chanctx_conf
*ctx
)
8620 struct ath10k
*ar
= hw
->priv
;
8622 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8623 "mac chanctx remove freq %hu width %d ptr %pK\n",
8624 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8626 mutex_lock(&ar
->conf_mutex
);
8628 spin_lock_bh(&ar
->data_lock
);
8629 ath10k_mac_update_rx_channel(ar
, NULL
, NULL
, 0);
8630 spin_unlock_bh(&ar
->data_lock
);
8632 ath10k_recalc_radar_detection(ar
);
8633 ath10k_monitor_recalc(ar
);
8635 mutex_unlock(&ar
->conf_mutex
);
8638 struct ath10k_mac_change_chanctx_arg
{
8639 struct ieee80211_chanctx_conf
*ctx
;
8640 struct ieee80211_vif_chanctx_switch
*vifs
;
8646 ath10k_mac_change_chanctx_cnt_iter(void *data
, u8
*mac
,
8647 struct ieee80211_vif
*vif
)
8649 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8651 if (rcu_access_pointer(vif
->chanctx_conf
) != arg
->ctx
)
8658 ath10k_mac_change_chanctx_fill_iter(void *data
, u8
*mac
,
8659 struct ieee80211_vif
*vif
)
8661 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8662 struct ieee80211_chanctx_conf
*ctx
;
8664 ctx
= rcu_access_pointer(vif
->chanctx_conf
);
8665 if (ctx
!= arg
->ctx
)
8668 if (WARN_ON(arg
->next_vif
== arg
->n_vifs
))
8671 arg
->vifs
[arg
->next_vif
].vif
= vif
;
8672 arg
->vifs
[arg
->next_vif
].old_ctx
= ctx
;
8673 arg
->vifs
[arg
->next_vif
].new_ctx
= ctx
;
8678 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
8679 struct ieee80211_chanctx_conf
*ctx
,
8682 struct ath10k
*ar
= hw
->priv
;
8683 struct ath10k_mac_change_chanctx_arg arg
= { .ctx
= ctx
};
8685 mutex_lock(&ar
->conf_mutex
);
8687 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8688 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
8689 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
, changed
);
8691 /* This shouldn't really happen because channel switching should use
8692 * switch_vif_chanctx().
8694 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
8697 if (changed
& IEEE80211_CHANCTX_CHANGE_WIDTH
) {
8698 ieee80211_iterate_active_interfaces_atomic(
8700 ATH10K_ITER_NORMAL_FLAGS
,
8701 ath10k_mac_change_chanctx_cnt_iter
,
8703 if (arg
.n_vifs
== 0)
8706 arg
.vifs
= kcalloc(arg
.n_vifs
, sizeof(arg
.vifs
[0]),
8711 ieee80211_iterate_active_interfaces_atomic(
8713 ATH10K_ITER_NORMAL_FLAGS
,
8714 ath10k_mac_change_chanctx_fill_iter
,
8716 ath10k_mac_update_vif_chan(ar
, arg
.vifs
, arg
.n_vifs
);
8721 ath10k_recalc_radar_detection(ar
);
8723 /* FIXME: How to configure Rx chains properly? */
8725 /* No other actions are actually necessary. Firmware maintains channel
8726 * definitions per vdev internally and there's no host-side channel
8727 * context abstraction to configure, e.g. channel width.
8731 mutex_unlock(&ar
->conf_mutex
);
8735 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
8736 struct ieee80211_vif
*vif
,
8737 struct ieee80211_chanctx_conf
*ctx
)
8739 struct ath10k
*ar
= hw
->priv
;
8740 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8743 mutex_lock(&ar
->conf_mutex
);
8745 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8746 "mac chanctx assign ptr %pK vdev_id %i\n",
8747 ctx
, arvif
->vdev_id
);
8749 if (WARN_ON(arvif
->is_started
)) {
8750 mutex_unlock(&ar
->conf_mutex
);
8754 ret
= ath10k_vdev_start(arvif
, &ctx
->def
);
8756 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
8757 arvif
->vdev_id
, vif
->addr
,
8758 ctx
->def
.chan
->center_freq
, ret
);
8762 arvif
->is_started
= true;
8764 ret
= ath10k_mac_vif_setup_ps(arvif
);
8766 ath10k_warn(ar
, "failed to update vdev %i ps: %d\n",
8767 arvif
->vdev_id
, ret
);
8771 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
8772 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
8774 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
8775 arvif
->vdev_id
, ret
);
8779 arvif
->is_up
= true;
8782 if (ath10k_mac_can_set_cts_prot(arvif
)) {
8783 ret
= ath10k_mac_set_cts_prot(arvif
);
8785 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
8786 arvif
->vdev_id
, ret
);
8789 if (ath10k_peer_stats_enabled(ar
) &&
8790 ar
->hw_params
.tx_stats_over_pktlog
) {
8791 ar
->pktlog_filter
|= ATH10K_PKTLOG_PEER_STATS
;
8792 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
8795 ath10k_warn(ar
, "failed to enable pktlog %d\n", ret
);
8800 mutex_unlock(&ar
->conf_mutex
);
8804 ath10k_vdev_stop(arvif
);
8805 arvif
->is_started
= false;
8806 ath10k_mac_vif_setup_ps(arvif
);
8809 mutex_unlock(&ar
->conf_mutex
);
8814 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
8815 struct ieee80211_vif
*vif
,
8816 struct ieee80211_chanctx_conf
*ctx
)
8818 struct ath10k
*ar
= hw
->priv
;
8819 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8822 mutex_lock(&ar
->conf_mutex
);
8824 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8825 "mac chanctx unassign ptr %pK vdev_id %i\n",
8826 ctx
, arvif
->vdev_id
);
8828 WARN_ON(!arvif
->is_started
);
8830 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
8831 WARN_ON(!arvif
->is_up
);
8833 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
8835 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
8836 arvif
->vdev_id
, ret
);
8838 arvif
->is_up
= false;
8841 ret
= ath10k_vdev_stop(arvif
);
8843 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
8844 arvif
->vdev_id
, ret
);
8846 arvif
->is_started
= false;
8848 mutex_unlock(&ar
->conf_mutex
);
8852 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
8853 struct ieee80211_vif_chanctx_switch
*vifs
,
8855 enum ieee80211_chanctx_switch_mode mode
)
8857 struct ath10k
*ar
= hw
->priv
;
8859 mutex_lock(&ar
->conf_mutex
);
8861 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8862 "mac chanctx switch n_vifs %d mode %d\n",
8864 ath10k_mac_update_vif_chan(ar
, vifs
, n_vifs
);
8866 mutex_unlock(&ar
->conf_mutex
);
8870 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
8871 struct ieee80211_vif
*vif
,
8872 struct ieee80211_sta
*sta
)
8875 struct ath10k_peer
*peer
;
8879 list_for_each_entry(peer
, &ar
->peers
, list
)
8880 if (peer
->sta
== sta
)
8881 peer
->removed
= true;
8884 /* HT MCS parameters with Nss = 1 */
8885 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss1
[] = {
8886 /* MCS L20 L40 S20 S40 */
8887 {0, { 65, 135, 72, 150} },
8888 {1, { 130, 270, 144, 300} },
8889 {2, { 195, 405, 217, 450} },
8890 {3, { 260, 540, 289, 600} },
8891 {4, { 390, 810, 433, 900} },
8892 {5, { 520, 1080, 578, 1200} },
8893 {6, { 585, 1215, 650, 1350} },
8894 {7, { 650, 1350, 722, 1500} }
8897 /* HT MCS parameters with Nss = 2 */
8898 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss2
[] = {
8899 /* MCS L20 L40 S20 S40 */
8900 {0, {130, 270, 144, 300} },
8901 {1, {260, 540, 289, 600} },
8902 {2, {390, 810, 433, 900} },
8903 {3, {520, 1080, 578, 1200} },
8904 {4, {780, 1620, 867, 1800} },
8905 {5, {1040, 2160, 1156, 2400} },
8906 {6, {1170, 2430, 1300, 2700} },
8907 {7, {1300, 2700, 1444, 3000} }
8910 /* MCS parameters with Nss = 1 */
8911 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss1
[] = {
8912 /* MCS L80 S80 L40 S40 L20 S20 */
8913 {0, {293, 325}, {135, 150}, {65, 72} },
8914 {1, {585, 650}, {270, 300}, {130, 144} },
8915 {2, {878, 975}, {405, 450}, {195, 217} },
8916 {3, {1170, 1300}, {540, 600}, {260, 289} },
8917 {4, {1755, 1950}, {810, 900}, {390, 433} },
8918 {5, {2340, 2600}, {1080, 1200}, {520, 578} },
8919 {6, {2633, 2925}, {1215, 1350}, {585, 650} },
8920 {7, {2925, 3250}, {1350, 1500}, {650, 722} },
8921 {8, {3510, 3900}, {1620, 1800}, {780, 867} },
8922 {9, {3900, 4333}, {1800, 2000}, {780, 867} }
8925 /*MCS parameters with Nss = 2 */
8926 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss2
[] = {
8927 /* MCS L80 S80 L40 S40 L20 S20 */
8928 {0, {585, 650}, {270, 300}, {130, 144} },
8929 {1, {1170, 1300}, {540, 600}, {260, 289} },
8930 {2, {1755, 1950}, {810, 900}, {390, 433} },
8931 {3, {2340, 2600}, {1080, 1200}, {520, 578} },
8932 {4, {3510, 3900}, {1620, 1800}, {780, 867} },
8933 {5, {4680, 5200}, {2160, 2400}, {1040, 1156} },
8934 {6, {5265, 5850}, {2430, 2700}, {1170, 1300} },
8935 {7, {5850, 6500}, {2700, 3000}, {1300, 1444} },
8936 {8, {7020, 7800}, {3240, 3600}, {1560, 1733} },
8937 {9, {7800, 8667}, {3600, 4000}, {1560, 1733} }
8940 static void ath10k_mac_get_rate_flags_ht(struct ath10k
*ar
, u32 rate
, u8 nss
, u8 mcs
,
8943 struct ath10k_index_ht_data_rate_type
*mcs_rate
;
8945 size_t len_nss1
= ARRAY_SIZE(supported_ht_mcs_rate_nss1
);
8946 size_t len_nss2
= ARRAY_SIZE(supported_ht_mcs_rate_nss2
);
8948 if (mcs
>= (len_nss1
+ len_nss2
)) {
8949 ath10k_warn(ar
, "not supported mcs %d in current rate table", mcs
);
8953 mcs_rate
= (struct ath10k_index_ht_data_rate_type
*)
8954 ((nss
== 1) ? &supported_ht_mcs_rate_nss1
:
8955 &supported_ht_mcs_rate_nss2
);
8957 if (mcs
>= len_nss1
)
8958 index
= mcs
- len_nss1
;
8962 if (rate
== mcs_rate
[index
].supported_rate
[0]) {
8963 *bw
= RATE_INFO_BW_20
;
8964 } else if (rate
== mcs_rate
[index
].supported_rate
[1]) {
8965 *bw
|= RATE_INFO_BW_40
;
8966 } else if (rate
== mcs_rate
[index
].supported_rate
[2]) {
8967 *bw
|= RATE_INFO_BW_20
;
8968 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
8969 } else if (rate
== mcs_rate
[index
].supported_rate
[3]) {
8970 *bw
|= RATE_INFO_BW_40
;
8971 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
8973 ath10k_warn(ar
, "invalid ht params rate %d 100kbps nss %d mcs %d",
8978 static void ath10k_mac_get_rate_flags_vht(struct ath10k
*ar
, u32 rate
, u8 nss
, u8 mcs
,
8981 struct ath10k_index_vht_data_rate_type
*mcs_rate
;
8983 mcs_rate
= (struct ath10k_index_vht_data_rate_type
*)
8984 ((nss
== 1) ? &supported_vht_mcs_rate_nss1
:
8985 &supported_vht_mcs_rate_nss2
);
8987 if (rate
== mcs_rate
[mcs
].supported_VHT80_rate
[0]) {
8988 *bw
= RATE_INFO_BW_80
;
8989 } else if (rate
== mcs_rate
[mcs
].supported_VHT80_rate
[1]) {
8990 *bw
= RATE_INFO_BW_80
;
8991 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
8992 } else if (rate
== mcs_rate
[mcs
].supported_VHT40_rate
[0]) {
8993 *bw
= RATE_INFO_BW_40
;
8994 } else if (rate
== mcs_rate
[mcs
].supported_VHT40_rate
[1]) {
8995 *bw
= RATE_INFO_BW_40
;
8996 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
8997 } else if (rate
== mcs_rate
[mcs
].supported_VHT20_rate
[0]) {
8998 *bw
= RATE_INFO_BW_20
;
8999 } else if (rate
== mcs_rate
[mcs
].supported_VHT20_rate
[1]) {
9000 *bw
= RATE_INFO_BW_20
;
9001 *flags
|= RATE_INFO_FLAGS_SHORT_GI
;
9003 ath10k_warn(ar
, "invalid vht params rate %d 100kbps nss %d mcs %d",
9008 static void ath10k_mac_get_rate_flags(struct ath10k
*ar
, u32 rate
,
9009 enum ath10k_phy_mode mode
, u8 nss
, u8 mcs
,
9012 if (mode
== ATH10K_PHY_MODE_HT
) {
9013 *flags
= RATE_INFO_FLAGS_MCS
;
9014 ath10k_mac_get_rate_flags_ht(ar
, rate
, nss
, mcs
, flags
, bw
);
9015 } else if (mode
== ATH10K_PHY_MODE_VHT
) {
9016 *flags
= RATE_INFO_FLAGS_VHT_MCS
;
9017 ath10k_mac_get_rate_flags_vht(ar
, rate
, nss
, mcs
, flags
, bw
);
9021 static void ath10k_mac_parse_bitrate(struct ath10k
*ar
, u32 rate_code
,
9022 u32 bitrate_kbps
, struct rate_info
*rate
)
9024 enum ath10k_phy_mode mode
= ATH10K_PHY_MODE_LEGACY
;
9025 enum wmi_rate_preamble preamble
= WMI_TLV_GET_HW_RC_PREAM_V1(rate_code
);
9026 u8 nss
= WMI_TLV_GET_HW_RC_NSS_V1(rate_code
) + 1;
9027 u8 mcs
= WMI_TLV_GET_HW_RC_RATE_V1(rate_code
);
9028 u8 flags
= 0, bw
= 0;
9030 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac parse rate code 0x%x bitrate %d kbps\n",
9031 rate_code
, bitrate_kbps
);
9033 if (preamble
== WMI_RATE_PREAMBLE_HT
)
9034 mode
= ATH10K_PHY_MODE_HT
;
9035 else if (preamble
== WMI_RATE_PREAMBLE_VHT
)
9036 mode
= ATH10K_PHY_MODE_VHT
;
9038 ath10k_mac_get_rate_flags(ar
, bitrate_kbps
/ 100, mode
, nss
, mcs
, &flags
, &bw
);
9040 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
9041 "mac parse bitrate preamble %d mode %d nss %d mcs %d flags %x bw %d\n",
9042 preamble
, mode
, nss
, mcs
, flags
, bw
);
9044 rate
->flags
= flags
;
9046 rate
->legacy
= bitrate_kbps
/ 100;
9051 static void ath10k_mac_sta_get_peer_stats_info(struct ath10k
*ar
,
9052 struct ieee80211_sta
*sta
,
9053 struct station_info
*sinfo
)
9055 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
9056 struct ath10k_peer
*peer
;
9057 unsigned long time_left
;
9060 if (!(ar
->hw_params
.supports_peer_stats_info
&&
9061 arsta
->arvif
->vdev_type
== WMI_VDEV_TYPE_STA
))
9064 spin_lock_bh(&ar
->data_lock
);
9065 peer
= ath10k_peer_find(ar
, arsta
->arvif
->vdev_id
, sta
->addr
);
9066 spin_unlock_bh(&ar
->data_lock
);
9070 reinit_completion(&ar
->peer_stats_info_complete
);
9072 ret
= ath10k_wmi_request_peer_stats_info(ar
,
9073 arsta
->arvif
->vdev_id
,
9074 WMI_REQUEST_ONE_PEER_STATS_INFO
,
9075 arsta
->arvif
->bssid
,
9077 if (ret
&& ret
!= -EOPNOTSUPP
) {
9078 ath10k_warn(ar
, "could not request peer stats info: %d\n", ret
);
9082 time_left
= wait_for_completion_timeout(&ar
->peer_stats_info_complete
, 3 * HZ
);
9083 if (time_left
== 0) {
9084 ath10k_warn(ar
, "timed out waiting peer stats info\n");
9088 if (arsta
->rx_rate_code
!= 0 && arsta
->rx_bitrate_kbps
!= 0) {
9089 ath10k_mac_parse_bitrate(ar
, arsta
->rx_rate_code
,
9090 arsta
->rx_bitrate_kbps
,
9093 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_BITRATE
);
9094 arsta
->rx_rate_code
= 0;
9095 arsta
->rx_bitrate_kbps
= 0;
9098 if (arsta
->tx_rate_code
!= 0 && arsta
->tx_bitrate_kbps
!= 0) {
9099 ath10k_mac_parse_bitrate(ar
, arsta
->tx_rate_code
,
9100 arsta
->tx_bitrate_kbps
,
9103 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
9104 arsta
->tx_rate_code
= 0;
9105 arsta
->tx_bitrate_kbps
= 0;
9109 static void ath10k_sta_statistics(struct ieee80211_hw
*hw
,
9110 struct ieee80211_vif
*vif
,
9111 struct ieee80211_sta
*sta
,
9112 struct station_info
*sinfo
)
9114 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
9115 struct ath10k
*ar
= arsta
->arvif
->ar
;
9117 if (!ath10k_peer_stats_enabled(ar
))
9120 ath10k_debug_fw_stats_request(ar
);
9122 sinfo
->rx_duration
= arsta
->rx_duration
;
9123 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_DURATION
);
9125 if (arsta
->txrate
.legacy
|| arsta
->txrate
.nss
) {
9126 if (arsta
->txrate
.legacy
) {
9127 sinfo
->txrate
.legacy
= arsta
->txrate
.legacy
;
9129 sinfo
->txrate
.mcs
= arsta
->txrate
.mcs
;
9130 sinfo
->txrate
.nss
= arsta
->txrate
.nss
;
9131 sinfo
->txrate
.bw
= arsta
->txrate
.bw
;
9133 sinfo
->txrate
.flags
= arsta
->txrate
.flags
;
9134 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
9137 if (ar
->htt
.disable_tx_comp
) {
9138 sinfo
->tx_failed
= arsta
->tx_failed
;
9139 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_FAILED
);
9142 sinfo
->tx_retries
= arsta
->tx_retries
;
9143 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_RETRIES
);
9145 ath10k_mac_sta_get_peer_stats_info(ar
, sta
, sinfo
);
9148 static int ath10k_mac_op_set_tid_config(struct ieee80211_hw
*hw
,
9149 struct ieee80211_vif
*vif
,
9150 struct ieee80211_sta
*sta
,
9151 struct cfg80211_tid_config
*tid_config
)
9153 struct ath10k
*ar
= hw
->priv
;
9154 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9155 struct ath10k_mac_iter_tid_conf_data data
= {};
9156 struct wmi_per_peer_per_tid_cfg_arg arg
= {};
9159 mutex_lock(&ar
->conf_mutex
);
9160 arg
.vdev_id
= arvif
->vdev_id
;
9162 arvif
->tids_rst
= 0;
9163 memset(arvif
->tid_conf_changed
, 0, sizeof(arvif
->tid_conf_changed
));
9165 for (i
= 0; i
< tid_config
->n_tid_conf
; i
++) {
9166 ret
= ath10k_mac_parse_tid_config(ar
, sta
, vif
,
9167 &tid_config
->tid_conf
[i
],
9178 arvif
->tids_rst
= 0;
9179 data
.curr_vif
= vif
;
9182 ieee80211_iterate_stations_atomic(hw
, ath10k_mac_vif_stations_tid_conf
,
9186 mutex_unlock(&ar
->conf_mutex
);
9190 static int ath10k_mac_op_reset_tid_config(struct ieee80211_hw
*hw
,
9191 struct ieee80211_vif
*vif
,
9192 struct ieee80211_sta
*sta
,
9195 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9196 struct ath10k_mac_iter_tid_conf_data data
= {};
9197 struct ath10k
*ar
= hw
->priv
;
9200 mutex_lock(&ar
->conf_mutex
);
9203 arvif
->tids_rst
= 0;
9204 ret
= ath10k_mac_reset_tid_config(ar
, sta
, arvif
, tids
);
9208 arvif
->tids_rst
= tids
;
9209 data
.curr_vif
= vif
;
9211 ieee80211_iterate_stations_atomic(hw
, ath10k_mac_vif_stations_tid_conf
,
9215 mutex_unlock(&ar
->conf_mutex
);
9219 static const struct ieee80211_ops ath10k_ops
= {
9220 .tx
= ath10k_mac_op_tx
,
9221 .wake_tx_queue
= ath10k_mac_op_wake_tx_queue
,
9222 .start
= ath10k_start
,
9223 .stop
= ath10k_stop
,
9224 .config
= ath10k_config
,
9225 .add_interface
= ath10k_add_interface
,
9226 .remove_interface
= ath10k_remove_interface
,
9227 .configure_filter
= ath10k_configure_filter
,
9228 .bss_info_changed
= ath10k_bss_info_changed
,
9229 .set_coverage_class
= ath10k_mac_op_set_coverage_class
,
9230 .hw_scan
= ath10k_hw_scan
,
9231 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
9232 .set_key
= ath10k_set_key
,
9233 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
9234 .sta_state
= ath10k_sta_state
,
9235 .sta_set_txpwr
= ath10k_sta_set_txpwr
,
9236 .conf_tx
= ath10k_conf_tx
,
9237 .remain_on_channel
= ath10k_remain_on_channel
,
9238 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
9239 .set_rts_threshold
= ath10k_set_rts_threshold
,
9240 .set_frag_threshold
= ath10k_mac_op_set_frag_threshold
,
9241 .flush
= ath10k_flush
,
9242 .tx_last_beacon
= ath10k_tx_last_beacon
,
9243 .set_antenna
= ath10k_set_antenna
,
9244 .get_antenna
= ath10k_get_antenna
,
9245 .reconfig_complete
= ath10k_reconfig_complete
,
9246 .get_survey
= ath10k_get_survey
,
9247 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
9248 .sta_rc_update
= ath10k_sta_rc_update
,
9249 .offset_tsf
= ath10k_offset_tsf
,
9250 .ampdu_action
= ath10k_ampdu_action
,
9251 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
9252 .get_et_stats
= ath10k_debug_get_et_stats
,
9253 .get_et_strings
= ath10k_debug_get_et_strings
,
9254 .add_chanctx
= ath10k_mac_op_add_chanctx
,
9255 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
9256 .change_chanctx
= ath10k_mac_op_change_chanctx
,
9257 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
9258 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
9259 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
9260 .sta_pre_rcu_remove
= ath10k_mac_op_sta_pre_rcu_remove
,
9261 .sta_statistics
= ath10k_sta_statistics
,
9262 .set_tid_config
= ath10k_mac_op_set_tid_config
,
9263 .reset_tid_config
= ath10k_mac_op_reset_tid_config
,
9265 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
9268 .suspend
= ath10k_wow_op_suspend
,
9269 .resume
= ath10k_wow_op_resume
,
9270 .set_wakeup
= ath10k_wow_op_set_wakeup
,
9272 #ifdef CONFIG_MAC80211_DEBUGFS
9273 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
9277 #define CHAN2G(_channel, _freq, _flags) { \
9278 .band = NL80211_BAND_2GHZ, \
9279 .hw_value = (_channel), \
9280 .center_freq = (_freq), \
9281 .flags = (_flags), \
9282 .max_antenna_gain = 0, \
9286 #define CHAN5G(_channel, _freq, _flags) { \
9287 .band = NL80211_BAND_5GHZ, \
9288 .hw_value = (_channel), \
9289 .center_freq = (_freq), \
9290 .flags = (_flags), \
9291 .max_antenna_gain = 0, \
9295 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
9305 CHAN2G(10, 2457, 0),
9306 CHAN2G(11, 2462, 0),
9307 CHAN2G(12, 2467, 0),
9308 CHAN2G(13, 2472, 0),
9309 CHAN2G(14, 2484, 0),
9312 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
9313 CHAN5G(36, 5180, 0),
9314 CHAN5G(40, 5200, 0),
9315 CHAN5G(44, 5220, 0),
9316 CHAN5G(48, 5240, 0),
9317 CHAN5G(52, 5260, 0),
9318 CHAN5G(56, 5280, 0),
9319 CHAN5G(60, 5300, 0),
9320 CHAN5G(64, 5320, 0),
9321 CHAN5G(100, 5500, 0),
9322 CHAN5G(104, 5520, 0),
9323 CHAN5G(108, 5540, 0),
9324 CHAN5G(112, 5560, 0),
9325 CHAN5G(116, 5580, 0),
9326 CHAN5G(120, 5600, 0),
9327 CHAN5G(124, 5620, 0),
9328 CHAN5G(128, 5640, 0),
9329 CHAN5G(132, 5660, 0),
9330 CHAN5G(136, 5680, 0),
9331 CHAN5G(140, 5700, 0),
9332 CHAN5G(144, 5720, 0),
9333 CHAN5G(149, 5745, 0),
9334 CHAN5G(153, 5765, 0),
9335 CHAN5G(157, 5785, 0),
9336 CHAN5G(161, 5805, 0),
9337 CHAN5G(165, 5825, 0),
9338 CHAN5G(169, 5845, 0),
9339 CHAN5G(173, 5865, 0),
9340 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
9341 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
9344 struct ath10k
*ath10k_mac_create(size_t priv_size
)
9346 struct ieee80211_hw
*hw
;
9347 struct ieee80211_ops
*ops
;
9350 ops
= kmemdup(&ath10k_ops
, sizeof(ath10k_ops
), GFP_KERNEL
);
9354 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, ops
);
9367 void ath10k_mac_destroy(struct ath10k
*ar
)
9369 struct ieee80211_ops
*ops
= ar
->ops
;
9371 ieee80211_free_hw(ar
->hw
);
9375 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
9378 .types
= BIT(NL80211_IFTYPE_STATION
)
9379 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
9383 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
9387 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
9391 .types
= BIT(NL80211_IFTYPE_AP
)
9392 #ifdef CONFIG_MAC80211_MESH
9393 | BIT(NL80211_IFTYPE_MESH_POINT
)
9398 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
9401 .types
= BIT(NL80211_IFTYPE_AP
)
9402 #ifdef CONFIG_MAC80211_MESH
9403 | BIT(NL80211_IFTYPE_MESH_POINT
)
9408 .types
= BIT(NL80211_IFTYPE_STATION
)
9412 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
9414 .limits
= ath10k_if_limits
,
9415 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
9416 .max_interfaces
= 8,
9417 .num_different_channels
= 1,
9418 .beacon_int_infra_match
= true,
9422 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
9424 .limits
= ath10k_10x_if_limits
,
9425 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
9426 .max_interfaces
= 8,
9427 .num_different_channels
= 1,
9428 .beacon_int_infra_match
= true,
9429 .beacon_int_min_gcd
= 1,
9430 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9431 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9432 BIT(NL80211_CHAN_WIDTH_20
) |
9433 BIT(NL80211_CHAN_WIDTH_40
) |
9434 BIT(NL80211_CHAN_WIDTH_80
),
9439 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
9442 .types
= BIT(NL80211_IFTYPE_STATION
),
9446 .types
= BIT(NL80211_IFTYPE_AP
) |
9447 #ifdef CONFIG_MAC80211_MESH
9448 BIT(NL80211_IFTYPE_MESH_POINT
) |
9450 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
9451 BIT(NL80211_IFTYPE_P2P_GO
),
9455 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
9459 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit
[] = {
9462 .types
= BIT(NL80211_IFTYPE_STATION
),
9466 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
),
9470 .types
= BIT(NL80211_IFTYPE_AP
) |
9471 #ifdef CONFIG_MAC80211_MESH
9472 BIT(NL80211_IFTYPE_MESH_POINT
) |
9474 BIT(NL80211_IFTYPE_P2P_GO
),
9478 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
9482 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
9485 .types
= BIT(NL80211_IFTYPE_STATION
),
9489 .types
= BIT(NL80211_IFTYPE_ADHOC
),
9493 /* FIXME: This is not thouroughly tested. These combinations may over- or
9494 * underestimate hw/fw capabilities.
9496 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
9498 .limits
= ath10k_tlv_if_limit
,
9499 .num_different_channels
= 1,
9500 .max_interfaces
= 4,
9501 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
9504 .limits
= ath10k_tlv_if_limit_ibss
,
9505 .num_different_channels
= 1,
9506 .max_interfaces
= 2,
9507 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
9511 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
9513 .limits
= ath10k_tlv_if_limit
,
9514 .num_different_channels
= 1,
9515 .max_interfaces
= 4,
9516 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
9519 .limits
= ath10k_tlv_qcs_if_limit
,
9520 .num_different_channels
= 2,
9521 .max_interfaces
= 4,
9522 .n_limits
= ARRAY_SIZE(ath10k_tlv_qcs_if_limit
),
9525 .limits
= ath10k_tlv_if_limit_ibss
,
9526 .num_different_channels
= 1,
9527 .max_interfaces
= 2,
9528 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
9532 static const struct ieee80211_iface_limit ath10k_10_4_if_limits
[] = {
9535 .types
= BIT(NL80211_IFTYPE_STATION
),
9539 .types
= BIT(NL80211_IFTYPE_AP
)
9540 #ifdef CONFIG_MAC80211_MESH
9541 | BIT(NL80211_IFTYPE_MESH_POINT
)
9546 static const struct ieee80211_iface_combination ath10k_10_4_if_comb
[] = {
9548 .limits
= ath10k_10_4_if_limits
,
9549 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
9550 .max_interfaces
= 16,
9551 .num_different_channels
= 1,
9552 .beacon_int_infra_match
= true,
9553 .beacon_int_min_gcd
= 1,
9554 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9555 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9556 BIT(NL80211_CHAN_WIDTH_20
) |
9557 BIT(NL80211_CHAN_WIDTH_40
) |
9558 BIT(NL80211_CHAN_WIDTH_80
) |
9559 BIT(NL80211_CHAN_WIDTH_80P80
) |
9560 BIT(NL80211_CHAN_WIDTH_160
),
9566 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb
[] = {
9568 .limits
= ath10k_10_4_if_limits
,
9569 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
9570 .max_interfaces
= 16,
9571 .num_different_channels
= 1,
9572 .beacon_int_infra_match
= true,
9573 .beacon_int_min_gcd
= 100,
9574 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9575 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
9576 BIT(NL80211_CHAN_WIDTH_20
) |
9577 BIT(NL80211_CHAN_WIDTH_40
) |
9578 BIT(NL80211_CHAN_WIDTH_80
) |
9579 BIT(NL80211_CHAN_WIDTH_80P80
) |
9580 BIT(NL80211_CHAN_WIDTH_160
),
9585 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
9586 struct ieee80211_vif
*vif
)
9588 struct ath10k_vif_iter
*arvif_iter
= data
;
9589 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
9591 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
9592 arvif_iter
->arvif
= arvif
;
9595 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
9597 struct ath10k_vif_iter arvif_iter
;
9599 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
9600 arvif_iter
.vdev_id
= vdev_id
;
9602 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
9603 ATH10K_ITER_RESUME_FLAGS
,
9604 ath10k_get_arvif_iter
,
9606 if (!arvif_iter
.arvif
) {
9607 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
9611 return arvif_iter
.arvif
;
9614 #define WRD_METHOD "WRDD"
9615 #define WRDD_WIFI (0x07)
9617 static u32
ath10k_mac_wrdd_get_mcc(struct ath10k
*ar
, union acpi_object
*wrdd
)
9619 union acpi_object
*mcc_pkg
;
9620 union acpi_object
*domain_type
;
9621 union acpi_object
*mcc_value
;
9624 if (wrdd
->type
!= ACPI_TYPE_PACKAGE
||
9625 wrdd
->package
.count
< 2 ||
9626 wrdd
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
9627 wrdd
->package
.elements
[0].integer
.value
!= 0) {
9628 ath10k_warn(ar
, "ignoring malformed/unsupported wrdd structure\n");
9632 for (i
= 1; i
< wrdd
->package
.count
; ++i
) {
9633 mcc_pkg
= &wrdd
->package
.elements
[i
];
9635 if (mcc_pkg
->type
!= ACPI_TYPE_PACKAGE
)
9637 if (mcc_pkg
->package
.count
< 2)
9639 if (mcc_pkg
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
9640 mcc_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
)
9643 domain_type
= &mcc_pkg
->package
.elements
[0];
9644 if (domain_type
->integer
.value
!= WRDD_WIFI
)
9647 mcc_value
= &mcc_pkg
->package
.elements
[1];
9648 return mcc_value
->integer
.value
;
9653 static int ath10k_mac_get_wrdd_regulatory(struct ath10k
*ar
, u16
*rd
)
9655 acpi_handle root_handle
;
9657 struct acpi_buffer wrdd
= {ACPI_ALLOCATE_BUFFER
, NULL
};
9662 root_handle
= ACPI_HANDLE(ar
->dev
);
9666 status
= acpi_get_handle(root_handle
, (acpi_string
)WRD_METHOD
, &handle
);
9667 if (ACPI_FAILURE(status
)) {
9668 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9669 "failed to get wrd method %d\n", status
);
9673 status
= acpi_evaluate_object(handle
, NULL
, NULL
, &wrdd
);
9674 if (ACPI_FAILURE(status
)) {
9675 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9676 "failed to call wrdc %d\n", status
);
9680 alpha2_code
= ath10k_mac_wrdd_get_mcc(ar
, wrdd
.pointer
);
9681 kfree(wrdd
.pointer
);
9685 alpha2
[0] = (alpha2_code
>> 8) & 0xff;
9686 alpha2
[1] = (alpha2_code
>> 0) & 0xff;
9689 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9690 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2
);
9692 *rd
= ath_regd_find_country_by_name(alpha2
);
9696 *rd
|= COUNTRY_ERD_FLAG
;
9700 static int ath10k_mac_init_rd(struct ath10k
*ar
)
9705 ret
= ath10k_mac_get_wrdd_regulatory(ar
, &rd
);
9707 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
9708 "fallback to eeprom programmed regulatory settings\n");
9709 rd
= ar
->hw_eeprom_rd
;
9712 ar
->ath_common
.regulatory
.current_rd
= rd
;
9716 int ath10k_mac_register(struct ath10k
*ar
)
9718 static const u32 cipher_suites
[] = {
9719 WLAN_CIPHER_SUITE_WEP40
,
9720 WLAN_CIPHER_SUITE_WEP104
,
9721 WLAN_CIPHER_SUITE_TKIP
,
9722 WLAN_CIPHER_SUITE_CCMP
,
9724 /* Do not add hardware supported ciphers before this line.
9725 * Allow software encryption for all chips. Don't forget to
9726 * update n_cipher_suites below.
9728 WLAN_CIPHER_SUITE_AES_CMAC
,
9729 WLAN_CIPHER_SUITE_BIP_CMAC_256
,
9730 WLAN_CIPHER_SUITE_BIP_GMAC_128
,
9731 WLAN_CIPHER_SUITE_BIP_GMAC_256
,
9733 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
9734 * and CCMP-256 in hardware.
9736 WLAN_CIPHER_SUITE_GCMP
,
9737 WLAN_CIPHER_SUITE_GCMP_256
,
9738 WLAN_CIPHER_SUITE_CCMP_256
,
9740 struct ieee80211_supported_band
*band
;
9744 if (!is_valid_ether_addr(ar
->mac_addr
)) {
9745 ath10k_warn(ar
, "invalid MAC address; choosing random\n");
9746 eth_random_addr(ar
->mac_addr
);
9748 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
9750 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
9752 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
9753 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
9756 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
9757 channels
= kmemdup(ath10k_2ghz_channels
,
9758 sizeof(ath10k_2ghz_channels
),
9765 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
9766 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
9767 band
->channels
= channels
;
9769 if (ar
->hw_params
.cck_rate_map_rev2
) {
9770 band
->n_bitrates
= ath10k_g_rates_rev2_size
;
9771 band
->bitrates
= ath10k_g_rates_rev2
;
9773 band
->n_bitrates
= ath10k_g_rates_size
;
9774 band
->bitrates
= ath10k_g_rates
;
9777 ar
->hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = band
;
9780 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
9781 channels
= kmemdup(ath10k_5ghz_channels
,
9782 sizeof(ath10k_5ghz_channels
),
9789 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
9790 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
9791 band
->channels
= channels
;
9792 band
->n_bitrates
= ath10k_a_rates_size
;
9793 band
->bitrates
= ath10k_a_rates
;
9794 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = band
;
9797 wiphy_read_of_freq_limits(ar
->hw
->wiphy
);
9798 ath10k_mac_setup_ht_vht_cap(ar
);
9800 ar
->hw
->wiphy
->interface_modes
=
9801 BIT(NL80211_IFTYPE_STATION
) |
9802 BIT(NL80211_IFTYPE_AP
) |
9803 BIT(NL80211_IFTYPE_MESH_POINT
);
9805 ar
->hw
->wiphy
->available_antennas_rx
= ar
->cfg_rx_chainmask
;
9806 ar
->hw
->wiphy
->available_antennas_tx
= ar
->cfg_tx_chainmask
;
9808 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->normal_mode_fw
.fw_file
.fw_features
))
9809 ar
->hw
->wiphy
->interface_modes
|=
9810 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
9811 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
9812 BIT(NL80211_IFTYPE_P2P_GO
);
9814 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
9816 if (!test_bit(ATH10K_FW_FEATURE_NO_PS
,
9817 ar
->running_fw
->fw_file
.fw_features
)) {
9818 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
9819 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
9822 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
9823 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
9824 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
9825 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
9826 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
9827 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
9828 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
9829 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
9830 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
9831 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
9832 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
9833 ieee80211_hw_set(ar
->hw
, SUPPORTS_TX_FRAG
);
9834 ieee80211_hw_set(ar
->hw
, REPORTS_LOW_ACK
);
9836 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
9837 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
9839 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
9840 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
9842 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
9843 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
9845 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
9846 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
9847 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
9850 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
9851 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
9853 if (test_bit(WMI_SERVICE_NLO
, ar
->wmi
.svc_map
)) {
9854 ar
->hw
->wiphy
->max_sched_scan_ssids
= WMI_PNO_MAX_SUPP_NETWORKS
;
9855 ar
->hw
->wiphy
->max_match_sets
= WMI_PNO_MAX_SUPP_NETWORKS
;
9856 ar
->hw
->wiphy
->max_sched_scan_ie_len
= WMI_PNO_MAX_IE_LENGTH
;
9857 ar
->hw
->wiphy
->max_sched_scan_plans
= WMI_PNO_MAX_SCHED_SCAN_PLANS
;
9858 ar
->hw
->wiphy
->max_sched_scan_plan_interval
=
9859 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT
;
9860 ar
->hw
->wiphy
->max_sched_scan_plan_iterations
=
9861 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS
;
9862 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
9865 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
9866 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
9867 ar
->hw
->txq_data_size
= sizeof(struct ath10k_txq
);
9869 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
9871 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
9872 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
9874 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
9875 * that userspace (e.g. wpa_supplicant/hostapd) can generate
9876 * correct Probe Responses. This is more of a hack advert..
9878 ar
->hw
->wiphy
->probe_resp_offload
|=
9879 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
9880 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
9881 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
9884 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
) ||
9885 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY
, ar
->wmi
.svc_map
)) {
9886 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
9887 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH
, ar
->wmi
.svc_map
))
9888 ieee80211_hw_set(ar
->hw
, TDLS_WIDER_BW
);
9891 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA
, ar
->wmi
.svc_map
))
9892 ieee80211_hw_set(ar
->hw
, SUPPORTS_TDLS_BUFFER_STA
);
9894 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
9895 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
9896 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
9898 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
9899 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
9900 NL80211_FEATURE_AP_SCAN
;
9902 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
9904 ret
= ath10k_wow_init(ar
);
9906 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
9910 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
9911 wiphy_ext_feature_set(ar
->hw
->wiphy
,
9912 NL80211_EXT_FEATURE_SET_SCAN_DWELL
);
9913 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_AQL
);
9915 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI
, ar
->wmi
.svc_map
) ||
9916 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS
, ar
->wmi
.svc_map
))
9917 wiphy_ext_feature_set(ar
->hw
->wiphy
,
9918 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT
);
9920 if (ath10k_peer_stats_enabled(ar
) ||
9921 test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
9922 wiphy_ext_feature_set(ar
->hw
->wiphy
,
9923 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
);
9925 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
))
9926 wiphy_ext_feature_set(ar
->hw
->wiphy
,
9927 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
);
9929 if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER
, ar
->wmi
.svc_map
))
9930 wiphy_ext_feature_set(ar
->hw
->wiphy
,
9931 NL80211_EXT_FEATURE_STA_TX_PWR
);
9933 if (test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT
, ar
->wmi
.svc_map
)) {
9934 ar
->hw
->wiphy
->tid_config_support
.vif
|=
9935 BIT(NL80211_TID_CONFIG_ATTR_NOACK
) |
9936 BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT
) |
9937 BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG
) |
9938 BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL
) |
9939 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE
) |
9940 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE
);
9942 if (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT
,
9944 ar
->hw
->wiphy
->tid_config_support
.vif
|=
9945 BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL
);
9948 ar
->hw
->wiphy
->tid_config_support
.peer
=
9949 ar
->hw
->wiphy
->tid_config_support
.vif
;
9950 ar
->hw
->wiphy
->max_data_retry_count
= ATH10K_MAX_RETRY_COUNT
;
9952 ar
->ops
->set_tid_config
= NULL
;
9955 * on LL hardware queues are managed entirely by the FW
9956 * so we only advertise to mac we can do the queues thing
9958 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
9960 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
9961 * something that vdev_ids can't reach so that we don't stop the queue
9964 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
9966 switch (ar
->running_fw
->fw_file
.wmi_op_version
) {
9967 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
9968 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
9969 ar
->hw
->wiphy
->n_iface_combinations
=
9970 ARRAY_SIZE(ath10k_if_comb
);
9971 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
9973 case ATH10K_FW_WMI_OP_VERSION_TLV
:
9974 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
9975 ar
->hw
->wiphy
->iface_combinations
=
9976 ath10k_tlv_qcs_if_comb
;
9977 ar
->hw
->wiphy
->n_iface_combinations
=
9978 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
9980 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
9981 ar
->hw
->wiphy
->n_iface_combinations
=
9982 ARRAY_SIZE(ath10k_tlv_if_comb
);
9984 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
9986 case ATH10K_FW_WMI_OP_VERSION_10_1
:
9987 case ATH10K_FW_WMI_OP_VERSION_10_2
:
9988 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
9989 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
9990 ar
->hw
->wiphy
->n_iface_combinations
=
9991 ARRAY_SIZE(ath10k_10x_if_comb
);
9993 case ATH10K_FW_WMI_OP_VERSION_10_4
:
9994 ar
->hw
->wiphy
->iface_combinations
= ath10k_10_4_if_comb
;
9995 ar
->hw
->wiphy
->n_iface_combinations
=
9996 ARRAY_SIZE(ath10k_10_4_if_comb
);
9997 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT
,
9999 ar
->hw
->wiphy
->iface_combinations
=
10000 ath10k_10_4_bcn_int_if_comb
;
10001 ar
->hw
->wiphy
->n_iface_combinations
=
10002 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb
);
10005 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
10006 case ATH10K_FW_WMI_OP_VERSION_MAX
:
10012 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
10013 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
10015 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
10016 /* Init ath dfs pattern detector */
10017 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
10018 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
10019 NL80211_DFS_UNSET
);
10021 if (!ar
->dfs_detector
)
10022 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
10025 ret
= ath10k_mac_init_rd(ar
);
10027 ath10k_err(ar
, "failed to derive regdom: %d\n", ret
);
10028 goto err_dfs_detector_exit
;
10031 /* Disable set_coverage_class for chipsets that do not support it. */
10032 if (!ar
->hw_params
.hw_ops
->set_coverage_class
)
10033 ar
->ops
->set_coverage_class
= NULL
;
10035 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
10036 ath10k_reg_notifier
);
10038 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
10039 goto err_dfs_detector_exit
;
10042 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
10043 ar
->hw
->wiphy
->features
|=
10044 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
10047 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
10049 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
10050 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
10051 * from chip specific hw_param table.
10053 if (!ar
->hw_params
.n_cipher_suites
||
10054 ar
->hw_params
.n_cipher_suites
> ARRAY_SIZE(cipher_suites
)) {
10055 ath10k_err(ar
, "invalid hw_params.n_cipher_suites %d\n",
10056 ar
->hw_params
.n_cipher_suites
);
10057 ar
->hw_params
.n_cipher_suites
= 8;
10059 ar
->hw
->wiphy
->n_cipher_suites
= ar
->hw_params
.n_cipher_suites
;
10061 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_CQM_RSSI_LIST
);
10063 ar
->hw
->weight_multiplier
= ATH10K_AIRTIME_WEIGHT_MULTIPLIER
;
10065 ret
= ieee80211_register_hw(ar
->hw
);
10067 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
10068 goto err_dfs_detector_exit
;
10071 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT
, ar
->wmi
.svc_map
)) {
10072 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
10073 ar
->hw
->wiphy
->software_iftypes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
10076 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
10077 ret
= regulatory_hint(ar
->hw
->wiphy
,
10078 ar
->ath_common
.regulatory
.alpha2
);
10080 goto err_unregister
;
10086 ieee80211_unregister_hw(ar
->hw
);
10088 err_dfs_detector_exit
:
10089 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
10090 ar
->dfs_detector
->exit(ar
->dfs_detector
);
10093 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
10094 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
10096 SET_IEEE80211_DEV(ar
->hw
, NULL
);
10100 void ath10k_mac_unregister(struct ath10k
*ar
)
10102 ieee80211_unregister_hw(ar
->hw
);
10104 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
10105 ar
->dfs_detector
->exit(ar
->dfs_detector
);
10107 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
10108 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
10110 SET_IEEE80211_DEV(ar
->hw
, NULL
);