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
;
571 case NL80211_CHAN_WIDTH_5
:
572 case NL80211_CHAN_WIDTH_10
:
573 case NL80211_CHAN_WIDTH_80
:
574 case NL80211_CHAN_WIDTH_80P80
:
575 case NL80211_CHAN_WIDTH_160
:
576 phymode
= MODE_UNKNOWN
;
580 case NL80211_BAND_5GHZ
:
581 switch (chandef
->width
) {
582 case NL80211_CHAN_WIDTH_20_NOHT
:
585 case NL80211_CHAN_WIDTH_20
:
586 phymode
= MODE_11NA_HT20
;
588 case NL80211_CHAN_WIDTH_40
:
589 phymode
= MODE_11NA_HT40
;
591 case NL80211_CHAN_WIDTH_80
:
592 phymode
= MODE_11AC_VHT80
;
594 case NL80211_CHAN_WIDTH_160
:
595 phymode
= MODE_11AC_VHT160
;
597 case NL80211_CHAN_WIDTH_80P80
:
598 phymode
= MODE_11AC_VHT80_80
;
600 case NL80211_CHAN_WIDTH_5
:
601 case NL80211_CHAN_WIDTH_10
:
602 phymode
= MODE_UNKNOWN
;
610 WARN_ON(phymode
== MODE_UNKNOWN
);
614 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
617 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
618 * 0 for no restriction
627 switch (mpdudensity
) {
633 /* Our lower layer calculations limit our precision to
650 int ath10k_mac_vif_chan(struct ieee80211_vif
*vif
,
651 struct cfg80211_chan_def
*def
)
653 struct ieee80211_chanctx_conf
*conf
;
656 conf
= rcu_dereference(vif
->chanctx_conf
);
668 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw
*hw
,
669 struct ieee80211_chanctx_conf
*conf
,
677 static int ath10k_mac_num_chanctxs(struct ath10k
*ar
)
681 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
682 ath10k_mac_num_chanctxs_iter
,
689 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw
*hw
,
690 struct ieee80211_chanctx_conf
*conf
,
693 struct cfg80211_chan_def
**def
= data
;
698 static void ath10k_wait_for_peer_delete_done(struct ath10k
*ar
, u32 vdev_id
,
701 unsigned long time_left
;
704 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
705 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
707 ath10k_warn(ar
, "failed wait for peer deleted");
711 time_left
= wait_for_completion_timeout(&ar
->peer_delete_done
,
714 ath10k_warn(ar
, "Timeout in receiving peer delete response\n");
718 static int ath10k_peer_create(struct ath10k
*ar
,
719 struct ieee80211_vif
*vif
,
720 struct ieee80211_sta
*sta
,
723 enum wmi_peer_type peer_type
)
725 struct ath10k_vif
*arvif
;
726 struct ath10k_peer
*peer
;
730 lockdep_assert_held(&ar
->conf_mutex
);
732 num_peers
= ar
->num_peers
;
734 /* Each vdev consumes a peer entry as well */
735 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
738 if (num_peers
>= ar
->max_num_peers
)
741 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
, peer_type
);
743 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
748 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
750 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
755 spin_lock_bh(&ar
->data_lock
);
757 peer
= ath10k_peer_find(ar
, vdev_id
, addr
);
759 spin_unlock_bh(&ar
->data_lock
);
760 ath10k_warn(ar
, "failed to find peer %pM on vdev %i after creation\n",
762 ath10k_wait_for_peer_delete_done(ar
, vdev_id
, addr
);
769 spin_unlock_bh(&ar
->data_lock
);
776 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
778 struct ath10k
*ar
= arvif
->ar
;
782 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
783 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
784 ATH10K_KICKOUT_THRESHOLD
);
786 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
787 arvif
->vdev_id
, ret
);
791 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
792 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
793 ATH10K_KEEPALIVE_MIN_IDLE
);
795 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
796 arvif
->vdev_id
, ret
);
800 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
801 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
802 ATH10K_KEEPALIVE_MAX_IDLE
);
804 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
805 arvif
->vdev_id
, ret
);
809 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
810 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
811 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
813 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
814 arvif
->vdev_id
, ret
);
821 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
823 struct ath10k
*ar
= arvif
->ar
;
826 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
827 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
830 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
834 lockdep_assert_held(&ar
->conf_mutex
);
836 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
840 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
844 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
845 unsigned long time_left
;
847 time_left
= wait_for_completion_timeout
848 (&ar
->peer_delete_done
, 5 * HZ
);
851 ath10k_warn(ar
, "Timeout in receiving peer delete response\n");
861 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
863 struct ath10k_peer
*peer
, *tmp
;
867 lockdep_assert_held(&ar
->conf_mutex
);
869 spin_lock_bh(&ar
->data_lock
);
870 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
871 if (peer
->vdev_id
!= vdev_id
)
874 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
875 peer
->addr
, vdev_id
);
877 for_each_set_bit(peer_id
, peer
->peer_ids
,
878 ATH10K_MAX_NUM_PEER_IDS
) {
879 ar
->peer_map
[peer_id
] = NULL
;
882 /* Double check that peer is properly un-referenced from
885 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
886 if (ar
->peer_map
[i
] == peer
) {
887 ath10k_warn(ar
, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
888 peer
->addr
, peer
, i
);
889 ar
->peer_map
[i
] = NULL
;
893 list_del(&peer
->list
);
897 spin_unlock_bh(&ar
->data_lock
);
900 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
902 struct ath10k_peer
*peer
, *tmp
;
905 lockdep_assert_held(&ar
->conf_mutex
);
907 spin_lock_bh(&ar
->data_lock
);
908 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
909 list_del(&peer
->list
);
913 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++)
914 ar
->peer_map
[i
] = NULL
;
916 spin_unlock_bh(&ar
->data_lock
);
919 ar
->num_stations
= 0;
922 static int ath10k_mac_tdls_peer_update(struct ath10k
*ar
, u32 vdev_id
,
923 struct ieee80211_sta
*sta
,
924 enum wmi_tdls_peer_state state
)
927 struct wmi_tdls_peer_update_cmd_arg arg
= {};
928 struct wmi_tdls_peer_capab_arg cap
= {};
929 struct wmi_channel_arg chan_arg
= {};
931 lockdep_assert_held(&ar
->conf_mutex
);
933 arg
.vdev_id
= vdev_id
;
934 arg
.peer_state
= state
;
935 ether_addr_copy(arg
.addr
, sta
->addr
);
937 cap
.peer_max_sp
= sta
->max_sp
;
938 cap
.peer_uapsd_queues
= sta
->uapsd_queues
;
940 if (state
== WMI_TDLS_PEER_STATE_CONNECTED
&&
941 !sta
->tdls_initiator
)
942 cap
.is_peer_responder
= 1;
944 ret
= ath10k_wmi_tdls_peer_update(ar
, &arg
, &cap
, &chan_arg
);
946 ath10k_warn(ar
, "failed to update tdls peer %pM on vdev %i: %i\n",
947 arg
.addr
, vdev_id
, ret
);
954 /************************/
955 /* Interface management */
956 /************************/
958 void ath10k_mac_vif_beacon_free(struct ath10k_vif
*arvif
)
960 struct ath10k
*ar
= arvif
->ar
;
962 lockdep_assert_held(&ar
->data_lock
);
967 if (!arvif
->beacon_buf
)
968 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
969 arvif
->beacon
->len
, DMA_TO_DEVICE
);
971 if (WARN_ON(arvif
->beacon_state
!= ATH10K_BEACON_SCHEDULED
&&
972 arvif
->beacon_state
!= ATH10K_BEACON_SENT
))
975 dev_kfree_skb_any(arvif
->beacon
);
977 arvif
->beacon
= NULL
;
978 arvif
->beacon_state
= ATH10K_BEACON_SCHEDULED
;
981 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif
*arvif
)
983 struct ath10k
*ar
= arvif
->ar
;
985 lockdep_assert_held(&ar
->data_lock
);
987 ath10k_mac_vif_beacon_free(arvif
);
989 if (arvif
->beacon_buf
) {
990 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
991 arvif
->beacon_buf
, arvif
->beacon_paddr
);
992 arvif
->beacon_buf
= NULL
;
996 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
998 unsigned long time_left
;
1000 lockdep_assert_held(&ar
->conf_mutex
);
1002 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
1005 time_left
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
1006 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
1010 return ar
->last_wmi_vdev_start_status
;
1013 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
1015 struct cfg80211_chan_def
*chandef
= NULL
;
1016 struct ieee80211_channel
*channel
= NULL
;
1017 struct wmi_vdev_start_request_arg arg
= {};
1020 lockdep_assert_held(&ar
->conf_mutex
);
1022 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1023 ath10k_mac_get_any_chandef_iter
,
1025 if (WARN_ON_ONCE(!chandef
))
1028 channel
= chandef
->chan
;
1030 arg
.vdev_id
= vdev_id
;
1031 arg
.channel
.freq
= channel
->center_freq
;
1032 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1033 arg
.channel
.band_center_freq2
= chandef
->center_freq2
;
1035 /* TODO setup this dynamically, what in case we
1036 * don't have any vifs?
1038 arg
.channel
.mode
= chan_to_phymode(chandef
);
1039 arg
.channel
.chan_radar
=
1040 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
1042 arg
.channel
.min_power
= 0;
1043 arg
.channel
.max_power
= channel
->max_power
* 2;
1044 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
1045 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
1047 reinit_completion(&ar
->vdev_setup_done
);
1048 reinit_completion(&ar
->vdev_delete_done
);
1050 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1052 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
1057 ret
= ath10k_vdev_setup_sync(ar
);
1059 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i start: %d\n",
1064 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
1066 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
1071 ar
->monitor_vdev_id
= vdev_id
;
1073 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
1074 ar
->monitor_vdev_id
);
1078 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
1080 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
1081 ar
->monitor_vdev_id
, ret
);
1086 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
1090 lockdep_assert_held(&ar
->conf_mutex
);
1092 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
1094 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
1095 ar
->monitor_vdev_id
, ret
);
1097 reinit_completion(&ar
->vdev_setup_done
);
1098 reinit_completion(&ar
->vdev_delete_done
);
1100 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
1102 ath10k_warn(ar
, "failed to request monitor vdev %i stop: %d\n",
1103 ar
->monitor_vdev_id
, ret
);
1105 ret
= ath10k_vdev_setup_sync(ar
);
1107 ath10k_warn(ar
, "failed to synchronize monitor vdev %i stop: %d\n",
1108 ar
->monitor_vdev_id
, ret
);
1110 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
1111 ar
->monitor_vdev_id
);
1115 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
1119 lockdep_assert_held(&ar
->conf_mutex
);
1121 if (ar
->free_vdev_map
== 0) {
1122 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
1126 bit
= __ffs64(ar
->free_vdev_map
);
1128 ar
->monitor_vdev_id
= bit
;
1130 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
1131 WMI_VDEV_TYPE_MONITOR
,
1134 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
1135 ar
->monitor_vdev_id
, ret
);
1139 ar
->free_vdev_map
&= ~(1LL << ar
->monitor_vdev_id
);
1140 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
1141 ar
->monitor_vdev_id
);
1146 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
1150 lockdep_assert_held(&ar
->conf_mutex
);
1152 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
1154 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
1155 ar
->monitor_vdev_id
, ret
);
1159 ar
->free_vdev_map
|= 1LL << ar
->monitor_vdev_id
;
1161 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
1162 ar
->monitor_vdev_id
);
1166 static int ath10k_monitor_start(struct ath10k
*ar
)
1170 lockdep_assert_held(&ar
->conf_mutex
);
1172 ret
= ath10k_monitor_vdev_create(ar
);
1174 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
1178 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
1180 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
1181 ath10k_monitor_vdev_delete(ar
);
1185 ar
->monitor_started
= true;
1186 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
1191 static int ath10k_monitor_stop(struct ath10k
*ar
)
1195 lockdep_assert_held(&ar
->conf_mutex
);
1197 ret
= ath10k_monitor_vdev_stop(ar
);
1199 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
1203 ret
= ath10k_monitor_vdev_delete(ar
);
1205 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
1209 ar
->monitor_started
= false;
1210 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
1215 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k
*ar
)
1219 /* At least one chanctx is required to derive a channel to start
1222 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1226 /* If there's already an existing special monitor interface then don't
1227 * bother creating another monitor vdev.
1229 if (ar
->monitor_arvif
)
1232 return ar
->monitor
||
1233 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST
,
1234 ar
->running_fw
->fw_file
.fw_features
) &&
1235 (ar
->filter_flags
& FIF_OTHER_BSS
)) ||
1236 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1239 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k
*ar
)
1243 num_ctx
= ath10k_mac_num_chanctxs(ar
);
1245 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1246 * shouldn't allow this but make sure to prevent handling the following
1247 * case anyway since multi-channel DFS hasn't been tested at all.
1249 if (test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
) && num_ctx
> 1)
1255 static int ath10k_monitor_recalc(struct ath10k
*ar
)
1261 lockdep_assert_held(&ar
->conf_mutex
);
1263 needed
= ath10k_mac_monitor_vdev_is_needed(ar
);
1264 allowed
= ath10k_mac_monitor_vdev_is_allowed(ar
);
1266 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1267 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1268 ar
->monitor_started
, needed
, allowed
);
1270 if (WARN_ON(needed
&& !allowed
)) {
1271 if (ar
->monitor_started
) {
1272 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopping disallowed monitor\n");
1274 ret
= ath10k_monitor_stop(ar
);
1276 ath10k_warn(ar
, "failed to stop disallowed monitor: %d\n",
1284 if (needed
== ar
->monitor_started
)
1288 return ath10k_monitor_start(ar
);
1290 return ath10k_monitor_stop(ar
);
1293 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif
*arvif
)
1295 struct ath10k
*ar
= arvif
->ar
;
1297 lockdep_assert_held(&ar
->conf_mutex
);
1299 if (!arvif
->is_started
) {
1300 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "defer cts setup, vdev is not ready yet\n");
1307 static int ath10k_mac_set_cts_prot(struct ath10k_vif
*arvif
)
1309 struct ath10k
*ar
= arvif
->ar
;
1312 lockdep_assert_held(&ar
->conf_mutex
);
1314 vdev_param
= ar
->wmi
.vdev_param
->protection_mode
;
1316 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_protection %d\n",
1317 arvif
->vdev_id
, arvif
->use_cts_prot
);
1319 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1320 arvif
->use_cts_prot
? 1 : 0);
1323 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
1325 struct ath10k
*ar
= arvif
->ar
;
1326 u32 vdev_param
, rts_cts
= 0;
1328 lockdep_assert_held(&ar
->conf_mutex
);
1330 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
1332 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
1334 if (arvif
->num_legacy_stations
> 0)
1335 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
1336 WMI_RTSCTS_PROFILE
);
1338 rts_cts
|= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES
,
1339 WMI_RTSCTS_PROFILE
);
1341 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d recalc rts/cts prot %d\n",
1342 arvif
->vdev_id
, rts_cts
);
1344 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
1348 static int ath10k_start_cac(struct ath10k
*ar
)
1352 lockdep_assert_held(&ar
->conf_mutex
);
1354 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1356 ret
= ath10k_monitor_recalc(ar
);
1358 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
1359 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1363 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
1364 ar
->monitor_vdev_id
);
1369 static int ath10k_stop_cac(struct ath10k
*ar
)
1371 lockdep_assert_held(&ar
->conf_mutex
);
1373 /* CAC is not running - do nothing */
1374 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
1377 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
1378 ath10k_monitor_stop(ar
);
1380 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
1385 static void ath10k_mac_has_radar_iter(struct ieee80211_hw
*hw
,
1386 struct ieee80211_chanctx_conf
*conf
,
1391 if (!*ret
&& conf
->radar_enabled
)
1395 static bool ath10k_mac_has_radar_enabled(struct ath10k
*ar
)
1397 bool has_radar
= false;
1399 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
1400 ath10k_mac_has_radar_iter
,
1406 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
1410 lockdep_assert_held(&ar
->conf_mutex
);
1412 ath10k_stop_cac(ar
);
1414 if (!ath10k_mac_has_radar_enabled(ar
))
1417 if (ar
->num_started_vdevs
> 0)
1420 ret
= ath10k_start_cac(ar
);
1423 * Not possible to start CAC on current channel so starting
1424 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1425 * by indicating that radar was detected.
1427 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
1428 ieee80211_radar_detected(ar
->hw
);
1432 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
1434 struct ath10k
*ar
= arvif
->ar
;
1437 lockdep_assert_held(&ar
->conf_mutex
);
1439 reinit_completion(&ar
->vdev_setup_done
);
1440 reinit_completion(&ar
->vdev_delete_done
);
1442 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
1444 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
1445 arvif
->vdev_id
, ret
);
1449 ret
= ath10k_vdev_setup_sync(ar
);
1451 ath10k_warn(ar
, "failed to synchronize setup for vdev %i: %d\n",
1452 arvif
->vdev_id
, ret
);
1456 WARN_ON(ar
->num_started_vdevs
== 0);
1458 if (ar
->num_started_vdevs
!= 0) {
1459 ar
->num_started_vdevs
--;
1460 ath10k_recalc_radar_detection(ar
);
1466 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
,
1467 const struct cfg80211_chan_def
*chandef
,
1470 struct ath10k
*ar
= arvif
->ar
;
1471 struct wmi_vdev_start_request_arg arg
= {};
1474 lockdep_assert_held(&ar
->conf_mutex
);
1476 reinit_completion(&ar
->vdev_setup_done
);
1477 reinit_completion(&ar
->vdev_delete_done
);
1479 arg
.vdev_id
= arvif
->vdev_id
;
1480 arg
.dtim_period
= arvif
->dtim_period
;
1481 arg
.bcn_intval
= arvif
->beacon_interval
;
1483 arg
.channel
.freq
= chandef
->chan
->center_freq
;
1484 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
1485 arg
.channel
.band_center_freq2
= chandef
->center_freq2
;
1486 arg
.channel
.mode
= chan_to_phymode(chandef
);
1488 arg
.channel
.min_power
= 0;
1489 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
1490 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
1491 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
1493 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1494 arg
.ssid
= arvif
->u
.ap
.ssid
;
1495 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
1496 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
1498 /* For now allow DFS for AP mode */
1499 arg
.channel
.chan_radar
=
1500 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
1501 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
1502 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
1503 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
1506 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1507 "mac vdev %d start center_freq %d phymode %s\n",
1508 arg
.vdev_id
, arg
.channel
.freq
,
1509 ath10k_wmi_phymode_str(arg
.channel
.mode
));
1512 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
1514 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
1517 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
1522 ret
= ath10k_vdev_setup_sync(ar
);
1525 "failed to synchronize setup for vdev %i restart %d: %d\n",
1526 arg
.vdev_id
, restart
, ret
);
1530 ar
->num_started_vdevs
++;
1531 ath10k_recalc_radar_detection(ar
);
1536 static int ath10k_vdev_start(struct ath10k_vif
*arvif
,
1537 const struct cfg80211_chan_def
*def
)
1539 return ath10k_vdev_start_restart(arvif
, def
, false);
1542 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
,
1543 const struct cfg80211_chan_def
*def
)
1545 return ath10k_vdev_start_restart(arvif
, def
, true);
1548 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif
*arvif
,
1549 struct sk_buff
*bcn
)
1551 struct ath10k
*ar
= arvif
->ar
;
1552 struct ieee80211_mgmt
*mgmt
;
1556 if (arvif
->vif
->type
!= NL80211_IFTYPE_AP
|| !arvif
->vif
->p2p
)
1559 mgmt
= (void *)bcn
->data
;
1560 p2p_ie
= cfg80211_find_vendor_ie(WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1561 mgmt
->u
.beacon
.variable
,
1562 bcn
->len
- (mgmt
->u
.beacon
.variable
-
1567 ret
= ath10k_wmi_p2p_go_bcn_ie(ar
, arvif
->vdev_id
, p2p_ie
);
1569 ath10k_warn(ar
, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1570 arvif
->vdev_id
, ret
);
1577 static int ath10k_mac_remove_vendor_ie(struct sk_buff
*skb
, unsigned int oui
,
1578 u8 oui_type
, size_t ie_offset
)
1585 if (WARN_ON(skb
->len
< ie_offset
))
1588 ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
1589 skb
->data
+ ie_offset
,
1590 skb
->len
- ie_offset
);
1595 end
= skb
->data
+ skb
->len
;
1598 if (WARN_ON(next
> end
))
1601 memmove(ie
, next
, end
- next
);
1602 skb_trim(skb
, skb
->len
- len
);
1607 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif
*arvif
)
1609 struct ath10k
*ar
= arvif
->ar
;
1610 struct ieee80211_hw
*hw
= ar
->hw
;
1611 struct ieee80211_vif
*vif
= arvif
->vif
;
1612 struct ieee80211_mutable_offsets offs
= {};
1613 struct sk_buff
*bcn
;
1616 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1619 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
1620 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
1623 bcn
= ieee80211_beacon_get_template(hw
, vif
, &offs
);
1625 ath10k_warn(ar
, "failed to get beacon template from mac80211\n");
1629 ret
= ath10k_mac_setup_bcn_p2p_ie(arvif
, bcn
);
1631 ath10k_warn(ar
, "failed to setup p2p go bcn ie: %d\n", ret
);
1636 /* P2P IE is inserted by firmware automatically (as configured above)
1637 * so remove it from the base beacon template to avoid duplicate P2P
1638 * IEs in beacon frames.
1640 ath10k_mac_remove_vendor_ie(bcn
, WLAN_OUI_WFA
, WLAN_OUI_TYPE_WFA_P2P
,
1641 offsetof(struct ieee80211_mgmt
,
1642 u
.beacon
.variable
));
1644 ret
= ath10k_wmi_bcn_tmpl(ar
, arvif
->vdev_id
, offs
.tim_offset
, bcn
, 0,
1649 ath10k_warn(ar
, "failed to submit beacon template command: %d\n",
1657 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif
*arvif
)
1659 struct ath10k
*ar
= arvif
->ar
;
1660 struct ieee80211_hw
*hw
= ar
->hw
;
1661 struct ieee80211_vif
*vif
= arvif
->vif
;
1662 struct sk_buff
*prb
;
1665 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1668 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
1671 /* For mesh, probe response and beacon share the same template */
1672 if (ieee80211_vif_is_mesh(vif
))
1675 prb
= ieee80211_proberesp_get(hw
, vif
);
1677 ath10k_warn(ar
, "failed to get probe resp template from mac80211\n");
1681 ret
= ath10k_wmi_prb_tmpl(ar
, arvif
->vdev_id
, prb
);
1685 ath10k_warn(ar
, "failed to submit probe resp template command: %d\n",
1693 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif
*arvif
)
1695 struct ath10k
*ar
= arvif
->ar
;
1696 struct cfg80211_chan_def def
;
1699 /* When originally vdev is started during assign_vif_chanctx() some
1700 * information is missing, notably SSID. Firmware revisions with beacon
1701 * offloading require the SSID to be provided during vdev (re)start to
1702 * handle hidden SSID properly.
1704 * Vdev restart must be done after vdev has been both started and
1705 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1706 * deliver vdev restart response event causing timeouts during vdev
1707 * syncing in ath10k.
1709 * Note: The vdev down/up and template reinstallation could be skipped
1710 * since only wmi-tlv firmware are known to have beacon offload and
1711 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1712 * response delivery. It's probably more robust to keep it as is.
1714 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
))
1717 if (WARN_ON(!arvif
->is_started
))
1720 if (WARN_ON(!arvif
->is_up
))
1723 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
1726 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1728 ath10k_warn(ar
, "failed to bring down ap vdev %i: %d\n",
1729 arvif
->vdev_id
, ret
);
1733 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1734 * firmware will crash upon vdev up.
1737 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
1739 ath10k_warn(ar
, "failed to update beacon template: %d\n", ret
);
1743 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
1745 ath10k_warn(ar
, "failed to update presp template: %d\n", ret
);
1749 ret
= ath10k_vdev_restart(arvif
, &def
);
1751 ath10k_warn(ar
, "failed to restart ap vdev %i: %d\n",
1752 arvif
->vdev_id
, ret
);
1756 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1759 ath10k_warn(ar
, "failed to bring up ap vdev %i: %d\n",
1760 arvif
->vdev_id
, ret
);
1767 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
1768 struct ieee80211_bss_conf
*info
)
1770 struct ath10k
*ar
= arvif
->ar
;
1773 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1775 if (!info
->enable_beacon
) {
1776 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1778 ath10k_warn(ar
, "failed to down vdev_id %i: %d\n",
1779 arvif
->vdev_id
, ret
);
1781 arvif
->is_up
= false;
1783 spin_lock_bh(&arvif
->ar
->data_lock
);
1784 ath10k_mac_vif_beacon_free(arvif
);
1785 spin_unlock_bh(&arvif
->ar
->data_lock
);
1790 arvif
->tx_seq_no
= 0x1000;
1793 ether_addr_copy(arvif
->bssid
, info
->bssid
);
1795 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
1798 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
1799 arvif
->vdev_id
, ret
);
1803 arvif
->is_up
= true;
1805 ret
= ath10k_mac_vif_fix_hidden_ssid(arvif
);
1807 ath10k_warn(ar
, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1808 arvif
->vdev_id
, ret
);
1812 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
1815 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
1816 struct ieee80211_bss_conf
*info
,
1817 const u8 self_peer
[ETH_ALEN
])
1819 struct ath10k
*ar
= arvif
->ar
;
1823 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1825 if (!info
->ibss_joined
) {
1826 if (is_zero_ether_addr(arvif
->bssid
))
1829 eth_zero_addr(arvif
->bssid
);
1834 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
1835 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
1836 ATH10K_DEFAULT_ATIM
);
1838 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
1839 arvif
->vdev_id
, ret
);
1842 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif
*arvif
)
1844 struct ath10k
*ar
= arvif
->ar
;
1849 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1851 if (arvif
->u
.sta
.uapsd
)
1852 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER
;
1854 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1856 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1857 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
, value
);
1859 ath10k_warn(ar
, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1860 value
, arvif
->vdev_id
, ret
);
1867 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif
*arvif
)
1869 struct ath10k
*ar
= arvif
->ar
;
1874 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1876 if (arvif
->u
.sta
.uapsd
)
1877 value
= WMI_STA_PS_PSPOLL_COUNT_UAPSD
;
1879 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1881 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1882 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1885 ath10k_warn(ar
, "failed to submit ps poll count %u on vdev %i: %d\n",
1886 value
, arvif
->vdev_id
, ret
);
1893 static int ath10k_mac_num_vifs_started(struct ath10k
*ar
)
1895 struct ath10k_vif
*arvif
;
1898 lockdep_assert_held(&ar
->conf_mutex
);
1900 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
1901 if (arvif
->is_started
)
1907 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1909 struct ath10k
*ar
= arvif
->ar
;
1910 struct ieee80211_vif
*vif
= arvif
->vif
;
1911 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1912 enum wmi_sta_powersave_param param
;
1913 enum wmi_sta_ps_mode psmode
;
1918 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1920 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1923 enable_ps
= arvif
->ps
;
1925 if (enable_ps
&& ath10k_mac_num_vifs_started(ar
) > 1 &&
1926 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
,
1927 ar
->running_fw
->fw_file
.fw_features
)) {
1928 ath10k_warn(ar
, "refusing to enable ps on vdev %i: not supported by fw\n",
1933 if (!arvif
->is_started
) {
1934 /* mac80211 can update vif powersave state while disconnected.
1935 * Firmware doesn't behave nicely and consumes more power than
1936 * necessary if PS is disabled on a non-started vdev. Hence
1937 * force-enable PS for non-running vdevs.
1939 psmode
= WMI_STA_PS_MODE_ENABLED
;
1940 } else if (enable_ps
) {
1941 psmode
= WMI_STA_PS_MODE_ENABLED
;
1942 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1944 ps_timeout
= conf
->dynamic_ps_timeout
;
1945 if (ps_timeout
== 0) {
1946 /* Firmware doesn't like 0 */
1947 ps_timeout
= ieee80211_tu_to_usec(
1948 vif
->bss_conf
.beacon_int
) / 1000;
1951 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1954 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1955 arvif
->vdev_id
, ret
);
1959 psmode
= WMI_STA_PS_MODE_DISABLED
;
1962 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1963 arvif
->vdev_id
, psmode
? "enable" : "disable");
1965 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1967 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1968 psmode
, arvif
->vdev_id
, ret
);
1975 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif
*arvif
)
1977 struct ath10k
*ar
= arvif
->ar
;
1978 struct wmi_sta_keepalive_arg arg
= {};
1981 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1983 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
1986 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE
, ar
->wmi
.svc_map
))
1989 /* Some firmware revisions have a bug and ignore the `enabled` field.
1990 * Instead use the interval to disable the keepalive.
1992 arg
.vdev_id
= arvif
->vdev_id
;
1994 arg
.method
= WMI_STA_KEEPALIVE_METHOD_NULL_FRAME
;
1995 arg
.interval
= WMI_STA_KEEPALIVE_INTERVAL_DISABLE
;
1997 ret
= ath10k_wmi_sta_keepalive(ar
, &arg
);
1999 ath10k_warn(ar
, "failed to submit keepalive on vdev %i: %d\n",
2000 arvif
->vdev_id
, ret
);
2007 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif
*arvif
)
2009 struct ath10k
*ar
= arvif
->ar
;
2010 struct ieee80211_vif
*vif
= arvif
->vif
;
2013 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
2015 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)))
2018 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
2021 if (!vif
->csa_active
)
2027 if (!ieee80211_csa_is_complete(vif
)) {
2028 ieee80211_csa_update_counter(vif
);
2030 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
2032 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
2035 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
2037 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
2040 ieee80211_csa_finish(vif
);
2044 static void ath10k_mac_vif_ap_csa_work(struct work_struct
*work
)
2046 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
2048 struct ath10k
*ar
= arvif
->ar
;
2050 mutex_lock(&ar
->conf_mutex
);
2051 ath10k_mac_vif_ap_csa_count_down(arvif
);
2052 mutex_unlock(&ar
->conf_mutex
);
2055 static void ath10k_mac_handle_beacon_iter(void *data
, u8
*mac
,
2056 struct ieee80211_vif
*vif
)
2058 struct sk_buff
*skb
= data
;
2059 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
2060 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2062 if (vif
->type
!= NL80211_IFTYPE_STATION
)
2065 if (!ether_addr_equal(mgmt
->bssid
, vif
->bss_conf
.bssid
))
2068 cancel_delayed_work(&arvif
->connection_loss_work
);
2071 void ath10k_mac_handle_beacon(struct ath10k
*ar
, struct sk_buff
*skb
)
2073 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2074 IEEE80211_IFACE_ITER_NORMAL
,
2075 ath10k_mac_handle_beacon_iter
,
2079 static void ath10k_mac_handle_beacon_miss_iter(void *data
, u8
*mac
,
2080 struct ieee80211_vif
*vif
)
2082 u32
*vdev_id
= data
;
2083 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2084 struct ath10k
*ar
= arvif
->ar
;
2085 struct ieee80211_hw
*hw
= ar
->hw
;
2087 if (arvif
->vdev_id
!= *vdev_id
)
2093 ieee80211_beacon_loss(vif
);
2095 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2096 * (done by mac80211) succeeds but beacons do not resume then it
2097 * doesn't make sense to continue operation. Queue connection loss work
2098 * which can be cancelled when beacon is received.
2100 ieee80211_queue_delayed_work(hw
, &arvif
->connection_loss_work
,
2101 ATH10K_CONNECTION_LOSS_HZ
);
2104 void ath10k_mac_handle_beacon_miss(struct ath10k
*ar
, u32 vdev_id
)
2106 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2107 IEEE80211_IFACE_ITER_NORMAL
,
2108 ath10k_mac_handle_beacon_miss_iter
,
2112 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct
*work
)
2114 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
2115 connection_loss_work
.work
);
2116 struct ieee80211_vif
*vif
= arvif
->vif
;
2121 ieee80211_connection_loss(vif
);
2124 /**********************/
2125 /* Station management */
2126 /**********************/
2128 static u32
ath10k_peer_assoc_h_listen_intval(struct ath10k
*ar
,
2129 struct ieee80211_vif
*vif
)
2131 /* Some firmware revisions have unstable STA powersave when listen
2132 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2133 * generate NullFunc frames properly even if buffered frames have been
2134 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2135 * buffered frames. Often pinging the device from AP would simply fail.
2137 * As a workaround set it to 1.
2139 if (vif
->type
== NL80211_IFTYPE_STATION
)
2142 return ar
->hw
->conf
.listen_interval
;
2145 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
2146 struct ieee80211_vif
*vif
,
2147 struct ieee80211_sta
*sta
,
2148 struct wmi_peer_assoc_complete_arg
*arg
)
2150 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2153 lockdep_assert_held(&ar
->conf_mutex
);
2155 if (vif
->type
== NL80211_IFTYPE_STATION
)
2156 aid
= vif
->bss_conf
.aid
;
2160 ether_addr_copy(arg
->addr
, sta
->addr
);
2161 arg
->vdev_id
= arvif
->vdev_id
;
2162 arg
->peer_aid
= aid
;
2163 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->auth
;
2164 arg
->peer_listen_intval
= ath10k_peer_assoc_h_listen_intval(ar
, vif
);
2165 arg
->peer_num_spatial_streams
= 1;
2166 arg
->peer_caps
= vif
->bss_conf
.assoc_capability
;
2169 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
2170 struct ieee80211_vif
*vif
,
2171 struct ieee80211_sta
*sta
,
2172 struct wmi_peer_assoc_complete_arg
*arg
)
2174 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
2175 struct cfg80211_chan_def def
;
2176 struct cfg80211_bss
*bss
;
2177 const u8
*rsnie
= NULL
;
2178 const u8
*wpaie
= NULL
;
2180 lockdep_assert_held(&ar
->conf_mutex
);
2182 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2185 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, def
.chan
, info
->bssid
, NULL
, 0,
2186 IEEE80211_BSS_TYPE_ANY
, IEEE80211_PRIVACY_ANY
);
2188 const struct cfg80211_bss_ies
*ies
;
2191 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
2193 ies
= rcu_dereference(bss
->ies
);
2195 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
2196 WLAN_OUI_TYPE_MICROSOFT_WPA
,
2200 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
2203 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2204 if (rsnie
|| wpaie
) {
2205 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
2206 arg
->peer_flags
|= ar
->wmi
.peer_flags
->need_ptk_4_way
;
2210 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
2211 arg
->peer_flags
|= ar
->wmi
.peer_flags
->need_gtk_2_way
;
2215 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT
,
2216 ar
->running_fw
->fw_file
.fw_features
)) {
2217 arg
->peer_flags
|= ar
->wmi
.peer_flags
->pmf
;
2221 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
2222 struct ieee80211_vif
*vif
,
2223 struct ieee80211_sta
*sta
,
2224 struct wmi_peer_assoc_complete_arg
*arg
)
2226 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2227 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
2228 struct cfg80211_chan_def def
;
2229 const struct ieee80211_supported_band
*sband
;
2230 const struct ieee80211_rate
*rates
;
2231 enum nl80211_band band
;
2236 lockdep_assert_held(&ar
->conf_mutex
);
2238 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2241 band
= def
.chan
->band
;
2242 sband
= ar
->hw
->wiphy
->bands
[band
];
2243 ratemask
= sta
->supp_rates
[band
];
2244 ratemask
&= arvif
->bitrate_mask
.control
[band
].legacy
;
2245 rates
= sband
->bitrates
;
2247 rateset
->num_rates
= 0;
2249 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
2250 if (!(ratemask
& 1))
2253 rate
= ath10k_mac_bitrate_to_rate(rates
->bitrate
);
2254 rateset
->rates
[rateset
->num_rates
] = rate
;
2255 rateset
->num_rates
++;
2260 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask
[IEEE80211_HT_MCS_MASK_LEN
])
2264 for (nss
= 0; nss
< IEEE80211_HT_MCS_MASK_LEN
; nss
++)
2265 if (ht_mcs_mask
[nss
])
2272 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
2276 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++)
2277 if (vht_mcs_mask
[nss
])
2283 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
2284 struct ieee80211_vif
*vif
,
2285 struct ieee80211_sta
*sta
,
2286 struct wmi_peer_assoc_complete_arg
*arg
)
2288 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2289 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2290 struct cfg80211_chan_def def
;
2291 enum nl80211_band band
;
2292 const u8
*ht_mcs_mask
;
2293 const u16
*vht_mcs_mask
;
2298 lockdep_assert_held(&ar
->conf_mutex
);
2300 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2303 if (!ht_cap
->ht_supported
)
2306 band
= def
.chan
->band
;
2307 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2308 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2310 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
) &&
2311 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2314 arg
->peer_flags
|= ar
->wmi
.peer_flags
->ht
;
2315 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2316 ht_cap
->ampdu_factor
)) - 1;
2318 arg
->peer_mpdu_density
=
2319 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
2321 arg
->peer_ht_caps
= ht_cap
->cap
;
2322 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
2324 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
2325 arg
->peer_flags
|= ar
->wmi
.peer_flags
->ldbc
;
2327 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
2328 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw40
;
2329 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
2332 if (arvif
->bitrate_mask
.control
[band
].gi
!= NL80211_TXRATE_FORCE_LGI
) {
2333 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
2334 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2336 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
2337 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
2340 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
2341 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
2342 arg
->peer_flags
|= ar
->wmi
.peer_flags
->stbc
;
2345 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
2346 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
2347 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2348 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
2349 arg
->peer_rate_caps
|= stbc
;
2350 arg
->peer_flags
|= ar
->wmi
.peer_flags
->stbc
;
2353 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
2354 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
2355 else if (ht_cap
->mcs
.rx_mask
[1])
2356 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
2358 for (i
= 0, n
= 0, max_nss
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
* 8; i
++)
2359 if ((ht_cap
->mcs
.rx_mask
[i
/ 8] & BIT(i
% 8)) &&
2360 (ht_mcs_mask
[i
/ 8] & BIT(i
% 8))) {
2361 max_nss
= (i
/ 8) + 1;
2362 arg
->peer_ht_rates
.rates
[n
++] = i
;
2366 * This is a workaround for HT-enabled STAs which break the spec
2367 * and have no HT capabilities RX mask (no HT RX MCS map).
2369 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2370 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2372 * Firmware asserts if such situation occurs.
2375 arg
->peer_ht_rates
.num_rates
= 8;
2376 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
2377 arg
->peer_ht_rates
.rates
[i
] = i
;
2379 arg
->peer_ht_rates
.num_rates
= n
;
2380 arg
->peer_num_spatial_streams
= min(sta
->rx_nss
, max_nss
);
2383 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
2385 arg
->peer_ht_rates
.num_rates
,
2386 arg
->peer_num_spatial_streams
);
2389 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
2390 struct ath10k_vif
*arvif
,
2391 struct ieee80211_sta
*sta
)
2397 lockdep_assert_held(&ar
->conf_mutex
);
2399 if (sta
->wme
&& sta
->uapsd_queues
) {
2400 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
2401 sta
->uapsd_queues
, sta
->max_sp
);
2403 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2404 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
2405 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
2406 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2407 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
2408 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
2409 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2410 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
2411 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
2412 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2413 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
2414 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
2416 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
2417 max_sp
= sta
->max_sp
;
2419 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2421 WMI_AP_PS_PEER_PARAM_UAPSD
,
2424 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2425 arvif
->vdev_id
, ret
);
2429 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
2431 WMI_AP_PS_PEER_PARAM_MAX_SP
,
2434 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2435 arvif
->vdev_id
, ret
);
2439 /* TODO setup this based on STA listen interval and
2440 * beacon interval. Currently we don't know
2441 * sta->listen_interval - mac80211 patch required.
2442 * Currently use 10 seconds
2444 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
2445 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
2448 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2449 arvif
->vdev_id
, ret
);
2458 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set
,
2459 const u16 vht_mcs_limit
[NL80211_VHT_NSS_MAX
])
2466 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
2467 mcs_map
= ath10k_mac_get_max_vht_mcs_map(tx_mcs_set
, nss
) &
2471 idx_limit
= fls(mcs_map
) - 1;
2475 switch (idx_limit
) {
2476 case 0: /* fall through */
2477 case 1: /* fall through */
2478 case 2: /* fall through */
2479 case 3: /* fall through */
2480 case 4: /* fall through */
2481 case 5: /* fall through */
2482 case 6: /* fall through */
2484 /* see ath10k_mac_can_set_bitrate_mask() */
2488 mcs
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
2491 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_7
;
2494 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_8
;
2497 mcs
= IEEE80211_VHT_MCS_SUPPORT_0_9
;
2501 tx_mcs_set
&= ~(0x3 << (nss
* 2));
2502 tx_mcs_set
|= mcs
<< (nss
* 2);
2508 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
2509 struct ieee80211_vif
*vif
,
2510 struct ieee80211_sta
*sta
,
2511 struct wmi_peer_assoc_complete_arg
*arg
)
2513 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
2514 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2515 struct cfg80211_chan_def def
;
2516 enum nl80211_band band
;
2517 const u16
*vht_mcs_mask
;
2519 u8 max_nss
, vht_mcs
;
2522 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2525 if (!vht_cap
->vht_supported
)
2528 band
= def
.chan
->band
;
2529 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2531 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
))
2534 arg
->peer_flags
|= ar
->wmi
.peer_flags
->vht
;
2536 if (def
.chan
->band
== NL80211_BAND_2GHZ
)
2537 arg
->peer_flags
|= ar
->wmi
.peer_flags
->vht_2g
;
2539 arg
->peer_vht_caps
= vht_cap
->cap
;
2541 ampdu_factor
= (vht_cap
->cap
&
2542 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
2543 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
2545 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2546 * zero in VHT IE. Using it would result in degraded throughput.
2547 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2548 * it if VHT max_mpdu is smaller.
2550 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
2551 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
2552 ampdu_factor
)) - 1);
2554 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2555 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw80
;
2557 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_160
)
2558 arg
->peer_flags
|= ar
->wmi
.peer_flags
->bw160
;
2560 /* Calculate peer NSS capability from VHT capabilities if STA
2563 for (i
= 0, max_nss
= 0, vht_mcs
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
2564 vht_mcs
= __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
) >>
2567 if ((vht_mcs
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
) &&
2571 arg
->peer_num_spatial_streams
= min(sta
->rx_nss
, max_nss
);
2572 arg
->peer_vht_rates
.rx_max_rate
=
2573 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
2574 arg
->peer_vht_rates
.rx_mcs_set
=
2575 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
2576 arg
->peer_vht_rates
.tx_max_rate
=
2577 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
2578 arg
->peer_vht_rates
.tx_mcs_set
= ath10k_peer_assoc_h_vht_limit(
2579 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
), vht_mcs_mask
);
2581 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2582 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
2584 if (arg
->peer_vht_rates
.rx_max_rate
&&
2585 (sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
)) {
2586 switch (arg
->peer_vht_rates
.rx_max_rate
) {
2588 /* Must be 2x2 at 160Mhz is all it can do. */
2589 arg
->peer_bw_rxnss_override
= 2;
2592 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2593 arg
->peer_bw_rxnss_override
= 1;
2599 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
2600 struct ieee80211_vif
*vif
,
2601 struct ieee80211_sta
*sta
,
2602 struct wmi_peer_assoc_complete_arg
*arg
)
2604 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2606 switch (arvif
->vdev_type
) {
2607 case WMI_VDEV_TYPE_AP
:
2609 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2611 if (sta
->wme
&& sta
->uapsd_queues
) {
2612 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->apsd
;
2613 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
2616 case WMI_VDEV_TYPE_STA
:
2618 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2620 case WMI_VDEV_TYPE_IBSS
:
2622 arg
->peer_flags
|= arvif
->ar
->wmi
.peer_flags
->qos
;
2628 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM qos %d\n",
2629 sta
->addr
, !!(arg
->peer_flags
&
2630 arvif
->ar
->wmi
.peer_flags
->qos
));
2633 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta
*sta
)
2635 return sta
->supp_rates
[NL80211_BAND_2GHZ
] >>
2636 ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
2639 static enum wmi_phy_mode
ath10k_mac_get_phymode_vht(struct ath10k
*ar
,
2640 struct ieee80211_sta
*sta
)
2642 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_160
) {
2643 switch (sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) {
2644 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
:
2645 return MODE_11AC_VHT160
;
2646 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
:
2647 return MODE_11AC_VHT80_80
;
2649 /* not sure if this is a valid case? */
2650 return MODE_11AC_VHT160
;
2654 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
2655 return MODE_11AC_VHT80
;
2657 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2658 return MODE_11AC_VHT40
;
2660 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
2661 return MODE_11AC_VHT20
;
2663 return MODE_UNKNOWN
;
2666 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
2667 struct ieee80211_vif
*vif
,
2668 struct ieee80211_sta
*sta
,
2669 struct wmi_peer_assoc_complete_arg
*arg
)
2671 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2672 struct cfg80211_chan_def def
;
2673 enum nl80211_band band
;
2674 const u8
*ht_mcs_mask
;
2675 const u16
*vht_mcs_mask
;
2676 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
2678 if (WARN_ON(ath10k_mac_vif_chan(vif
, &def
)))
2681 band
= def
.chan
->band
;
2682 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
2683 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
2686 case NL80211_BAND_2GHZ
:
2687 if (sta
->vht_cap
.vht_supported
&&
2688 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2689 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2690 phymode
= MODE_11AC_VHT40
;
2692 phymode
= MODE_11AC_VHT20
;
2693 } else if (sta
->ht_cap
.ht_supported
&&
2694 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2695 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
2696 phymode
= MODE_11NG_HT40
;
2698 phymode
= MODE_11NG_HT20
;
2699 } else if (ath10k_mac_sta_has_ofdm_only(sta
)) {
2706 case NL80211_BAND_5GHZ
:
2710 if (sta
->vht_cap
.vht_supported
&&
2711 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask
)) {
2712 phymode
= ath10k_mac_get_phymode_vht(ar
, sta
);
2713 } else if (sta
->ht_cap
.ht_supported
&&
2714 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask
)) {
2715 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
)
2716 phymode
= MODE_11NA_HT40
;
2718 phymode
= MODE_11NA_HT20
;
2728 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
2729 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
2731 arg
->peer_phymode
= phymode
;
2732 WARN_ON(phymode
== MODE_UNKNOWN
);
2735 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
2736 struct ieee80211_vif
*vif
,
2737 struct ieee80211_sta
*sta
,
2738 struct wmi_peer_assoc_complete_arg
*arg
)
2740 lockdep_assert_held(&ar
->conf_mutex
);
2742 memset(arg
, 0, sizeof(*arg
));
2744 ath10k_peer_assoc_h_basic(ar
, vif
, sta
, arg
);
2745 ath10k_peer_assoc_h_crypto(ar
, vif
, sta
, arg
);
2746 ath10k_peer_assoc_h_rates(ar
, vif
, sta
, arg
);
2747 ath10k_peer_assoc_h_ht(ar
, vif
, sta
, arg
);
2748 ath10k_peer_assoc_h_vht(ar
, vif
, sta
, arg
);
2749 ath10k_peer_assoc_h_qos(ar
, vif
, sta
, arg
);
2750 ath10k_peer_assoc_h_phymode(ar
, vif
, sta
, arg
);
2755 static const u32 ath10k_smps_map
[] = {
2756 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
2757 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
2758 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
2759 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
2762 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
2764 const struct ieee80211_sta_ht_cap
*ht_cap
)
2768 if (!ht_cap
->ht_supported
)
2771 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
2772 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2774 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
2777 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
2778 ar
->wmi
.peer_param
->smps_state
,
2779 ath10k_smps_map
[smps
]);
2782 static int ath10k_mac_vif_recalc_txbf(struct ath10k
*ar
,
2783 struct ieee80211_vif
*vif
,
2784 struct ieee80211_sta_vht_cap vht_cap
)
2786 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2791 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_AFTER_ASSOC
)
2794 if (!(ar
->vht_cap_info
&
2795 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2796 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
|
2797 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2798 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
2801 param
= ar
->wmi
.vdev_param
->txbf
;
2804 if (WARN_ON(param
== WMI_VDEV_PARAM_UNSUPPORTED
))
2807 /* The following logic is correct. If a remote STA advertises support
2808 * for being a beamformer then we should enable us being a beamformee.
2811 if (ar
->vht_cap_info
&
2812 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
2813 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
2814 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
2815 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2817 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
2818 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
;
2821 if (ar
->vht_cap_info
&
2822 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
2823 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
2824 if (vht_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
2825 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2827 if (vht_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
2828 value
|= WMI_VDEV_PARAM_TXBF_MU_TX_BFER
;
2831 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
)
2832 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
2834 if (value
& WMI_VDEV_PARAM_TXBF_MU_TX_BFER
)
2835 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
2837 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
, value
);
2839 ath10k_warn(ar
, "failed to submit vdev param txbf 0x%x: %d\n",
2847 /* can be called only in mac80211 callbacks due to `key_count` usage */
2848 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
2849 struct ieee80211_vif
*vif
,
2850 struct ieee80211_bss_conf
*bss_conf
)
2852 struct ath10k
*ar
= hw
->priv
;
2853 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2854 struct ieee80211_sta_ht_cap ht_cap
;
2855 struct ieee80211_sta_vht_cap vht_cap
;
2856 struct wmi_peer_assoc_complete_arg peer_arg
;
2857 struct ieee80211_sta
*ap_sta
;
2860 lockdep_assert_held(&ar
->conf_mutex
);
2862 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i assoc bssid %pM aid %d\n",
2863 arvif
->vdev_id
, arvif
->bssid
, arvif
->aid
);
2867 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2869 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
2870 bss_conf
->bssid
, arvif
->vdev_id
);
2875 /* ap_sta must be accessed only within rcu section which must be left
2876 * before calling ath10k_setup_peer_smps() which might sleep.
2878 ht_cap
= ap_sta
->ht_cap
;
2879 vht_cap
= ap_sta
->vht_cap
;
2881 ret
= ath10k_peer_assoc_prepare(ar
, vif
, ap_sta
, &peer_arg
);
2883 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2884 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2891 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2893 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
2894 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
2898 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
2900 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
2901 arvif
->vdev_id
, ret
);
2905 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2907 ath10k_warn(ar
, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2908 arvif
->vdev_id
, bss_conf
->bssid
, ret
);
2912 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2913 "mac vdev %d up (associated) bssid %pM aid %d\n",
2914 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
2916 WARN_ON(arvif
->is_up
);
2918 arvif
->aid
= bss_conf
->aid
;
2919 ether_addr_copy(arvif
->bssid
, bss_conf
->bssid
);
2921 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
2923 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
2924 arvif
->vdev_id
, ret
);
2928 arvif
->is_up
= true;
2930 /* Workaround: Some firmware revisions (tested with qca6174
2931 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2932 * poked with peer param command.
2934 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, arvif
->bssid
,
2935 ar
->wmi
.peer_param
->dummy_var
, 1);
2937 ath10k_warn(ar
, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2938 arvif
->bssid
, arvif
->vdev_id
, ret
);
2943 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
2944 struct ieee80211_vif
*vif
)
2946 struct ath10k
*ar
= hw
->priv
;
2947 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2948 struct ieee80211_sta_vht_cap vht_cap
= {};
2951 lockdep_assert_held(&ar
->conf_mutex
);
2953 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i disassoc bssid %pM\n",
2954 arvif
->vdev_id
, arvif
->bssid
);
2956 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2958 ath10k_warn(ar
, "failed to down vdev %i: %d\n",
2959 arvif
->vdev_id
, ret
);
2961 arvif
->def_wep_key_idx
= -1;
2963 ret
= ath10k_mac_vif_recalc_txbf(ar
, vif
, vht_cap
);
2965 ath10k_warn(ar
, "failed to recalc txbf for vdev %i: %d\n",
2966 arvif
->vdev_id
, ret
);
2970 arvif
->is_up
= false;
2972 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
2975 static int ath10k_station_assoc(struct ath10k
*ar
,
2976 struct ieee80211_vif
*vif
,
2977 struct ieee80211_sta
*sta
,
2980 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
2981 struct wmi_peer_assoc_complete_arg peer_arg
;
2984 lockdep_assert_held(&ar
->conf_mutex
);
2986 ret
= ath10k_peer_assoc_prepare(ar
, vif
, sta
, &peer_arg
);
2988 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2989 sta
->addr
, arvif
->vdev_id
, ret
);
2993 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
2995 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2996 sta
->addr
, arvif
->vdev_id
, ret
);
3000 /* Re-assoc is run only to update supported rates for given station. It
3001 * doesn't make much sense to reconfigure the peer completely.
3004 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
,
3007 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
3008 arvif
->vdev_id
, ret
);
3012 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
3014 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
3015 sta
->addr
, arvif
->vdev_id
, ret
);
3020 arvif
->num_legacy_stations
++;
3021 ret
= ath10k_recalc_rtscts_prot(arvif
);
3023 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3024 arvif
->vdev_id
, ret
);
3029 /* Plumb cached keys only for static WEP */
3030 if ((arvif
->def_wep_key_idx
!= -1) && (!sta
->tdls
)) {
3031 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
3033 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
3034 arvif
->vdev_id
, ret
);
3043 static int ath10k_station_disassoc(struct ath10k
*ar
,
3044 struct ieee80211_vif
*vif
,
3045 struct ieee80211_sta
*sta
)
3047 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3050 lockdep_assert_held(&ar
->conf_mutex
);
3053 arvif
->num_legacy_stations
--;
3054 ret
= ath10k_recalc_rtscts_prot(arvif
);
3056 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3057 arvif
->vdev_id
, ret
);
3062 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
3064 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
3065 arvif
->vdev_id
, ret
);
3076 static int ath10k_update_channel_list(struct ath10k
*ar
)
3078 struct ieee80211_hw
*hw
= ar
->hw
;
3079 struct ieee80211_supported_band
**bands
;
3080 enum nl80211_band band
;
3081 struct ieee80211_channel
*channel
;
3082 struct wmi_scan_chan_list_arg arg
= {0};
3083 struct wmi_channel_arg
*ch
;
3089 lockdep_assert_held(&ar
->conf_mutex
);
3091 bands
= hw
->wiphy
->bands
;
3092 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
3096 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
3097 if (bands
[band
]->channels
[i
].flags
&
3098 IEEE80211_CHAN_DISABLED
)
3105 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
3106 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
3111 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
3115 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
3116 channel
= &bands
[band
]->channels
[i
];
3118 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
3121 ch
->allow_ht
= true;
3123 /* FIXME: when should we really allow VHT? */
3124 ch
->allow_vht
= true;
3127 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
3130 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
3133 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
3135 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
3136 ch
->passive
= passive
;
3138 /* the firmware is ignoring the "radar" flag of the
3139 * channel and is scanning actively using Probe Requests
3140 * on "Radar detection"/DFS channels which are not
3141 * marked as "available"
3143 ch
->passive
|= ch
->chan_radar
;
3145 ch
->freq
= channel
->center_freq
;
3146 ch
->band_center_freq1
= channel
->center_freq
;
3148 ch
->max_power
= channel
->max_power
* 2;
3149 ch
->max_reg_power
= channel
->max_reg_power
* 2;
3150 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
3151 ch
->reg_class_id
= 0; /* FIXME */
3153 /* FIXME: why use only legacy modes, why not any
3154 * HT/VHT modes? Would that even make any
3157 if (channel
->band
== NL80211_BAND_2GHZ
)
3158 ch
->mode
= MODE_11G
;
3160 ch
->mode
= MODE_11A
;
3162 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
3165 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
3166 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3167 ch
- arg
.channels
, arg
.n_channels
,
3168 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
3169 ch
->max_antenna_gain
, ch
->mode
);
3175 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
3176 kfree(arg
.channels
);
3181 static enum wmi_dfs_region
3182 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
3184 switch (dfs_region
) {
3185 case NL80211_DFS_UNSET
:
3186 return WMI_UNINIT_DFS_DOMAIN
;
3187 case NL80211_DFS_FCC
:
3188 return WMI_FCC_DFS_DOMAIN
;
3189 case NL80211_DFS_ETSI
:
3190 return WMI_ETSI_DFS_DOMAIN
;
3191 case NL80211_DFS_JP
:
3192 return WMI_MKK4_DFS_DOMAIN
;
3194 return WMI_UNINIT_DFS_DOMAIN
;
3197 static void ath10k_regd_update(struct ath10k
*ar
)
3199 struct reg_dmn_pair_mapping
*regpair
;
3201 enum wmi_dfs_region wmi_dfs_reg
;
3202 enum nl80211_dfs_regions nl_dfs_reg
;
3204 lockdep_assert_held(&ar
->conf_mutex
);
3206 ret
= ath10k_update_channel_list(ar
);
3208 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
3210 regpair
= ar
->ath_common
.regulatory
.regpair
;
3212 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3213 nl_dfs_reg
= ar
->dfs_detector
->region
;
3214 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
3216 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
3219 /* Target allows setting up per-band regdomain but ath_common provides
3220 * a combined one only
3222 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
3223 regpair
->reg_domain
,
3224 regpair
->reg_domain
, /* 2ghz */
3225 regpair
->reg_domain
, /* 5ghz */
3226 regpair
->reg_2ghz_ctl
,
3227 regpair
->reg_5ghz_ctl
,
3230 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
3233 static void ath10k_mac_update_channel_list(struct ath10k
*ar
,
3234 struct ieee80211_supported_band
*band
)
3238 if (ar
->low_5ghz_chan
&& ar
->high_5ghz_chan
) {
3239 for (i
= 0; i
< band
->n_channels
; i
++) {
3240 if (band
->channels
[i
].center_freq
< ar
->low_5ghz_chan
||
3241 band
->channels
[i
].center_freq
> ar
->high_5ghz_chan
)
3242 band
->channels
[i
].flags
|=
3243 IEEE80211_CHAN_DISABLED
;
3248 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
3249 struct regulatory_request
*request
)
3251 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
3252 struct ath10k
*ar
= hw
->priv
;
3255 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
3257 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
3258 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
3259 request
->dfs_region
);
3260 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
3261 request
->dfs_region
);
3263 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3264 request
->dfs_region
);
3267 mutex_lock(&ar
->conf_mutex
);
3268 if (ar
->state
== ATH10K_STATE_ON
)
3269 ath10k_regd_update(ar
);
3270 mutex_unlock(&ar
->conf_mutex
);
3272 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
3273 ath10k_mac_update_channel_list(ar
,
3274 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
]);
3277 static void ath10k_stop_radar_confirmation(struct ath10k
*ar
)
3279 spin_lock_bh(&ar
->data_lock
);
3280 ar
->radar_conf_state
= ATH10K_RADAR_CONFIRMATION_STOPPED
;
3281 spin_unlock_bh(&ar
->data_lock
);
3283 cancel_work_sync(&ar
->radar_confirmation_work
);
3290 enum ath10k_mac_tx_path
{
3292 ATH10K_MAC_TX_HTT_MGMT
,
3293 ATH10K_MAC_TX_WMI_MGMT
,
3294 ATH10K_MAC_TX_UNKNOWN
,
3297 void ath10k_mac_tx_lock(struct ath10k
*ar
, int reason
)
3299 lockdep_assert_held(&ar
->htt
.tx_lock
);
3301 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3302 ar
->tx_paused
|= BIT(reason
);
3303 ieee80211_stop_queues(ar
->hw
);
3306 static void ath10k_mac_tx_unlock_iter(void *data
, u8
*mac
,
3307 struct ieee80211_vif
*vif
)
3309 struct ath10k
*ar
= data
;
3310 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3312 if (arvif
->tx_paused
)
3315 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3318 void ath10k_mac_tx_unlock(struct ath10k
*ar
, int reason
)
3320 lockdep_assert_held(&ar
->htt
.tx_lock
);
3322 WARN_ON(reason
>= ATH10K_TX_PAUSE_MAX
);
3323 ar
->tx_paused
&= ~BIT(reason
);
3328 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3329 IEEE80211_IFACE_ITER_RESUME_ALL
,
3330 ath10k_mac_tx_unlock_iter
,
3333 ieee80211_wake_queue(ar
->hw
, ar
->hw
->offchannel_tx_hw_queue
);
3336 void ath10k_mac_vif_tx_lock(struct ath10k_vif
*arvif
, int reason
)
3338 struct ath10k
*ar
= arvif
->ar
;
3340 lockdep_assert_held(&ar
->htt
.tx_lock
);
3342 WARN_ON(reason
>= BITS_PER_LONG
);
3343 arvif
->tx_paused
|= BIT(reason
);
3344 ieee80211_stop_queue(ar
->hw
, arvif
->vdev_id
);
3347 void ath10k_mac_vif_tx_unlock(struct ath10k_vif
*arvif
, int reason
)
3349 struct ath10k
*ar
= arvif
->ar
;
3351 lockdep_assert_held(&ar
->htt
.tx_lock
);
3353 WARN_ON(reason
>= BITS_PER_LONG
);
3354 arvif
->tx_paused
&= ~BIT(reason
);
3359 if (arvif
->tx_paused
)
3362 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
3365 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif
*arvif
,
3366 enum wmi_tlv_tx_pause_id pause_id
,
3367 enum wmi_tlv_tx_pause_action action
)
3369 struct ath10k
*ar
= arvif
->ar
;
3371 lockdep_assert_held(&ar
->htt
.tx_lock
);
3374 case WMI_TLV_TX_PAUSE_ACTION_STOP
:
3375 ath10k_mac_vif_tx_lock(arvif
, pause_id
);
3377 case WMI_TLV_TX_PAUSE_ACTION_WAKE
:
3378 ath10k_mac_vif_tx_unlock(arvif
, pause_id
);
3381 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
3382 "received unknown tx pause action %d on vdev %i, ignoring\n",
3383 action
, arvif
->vdev_id
);
3388 struct ath10k_mac_tx_pause
{
3390 enum wmi_tlv_tx_pause_id pause_id
;
3391 enum wmi_tlv_tx_pause_action action
;
3394 static void ath10k_mac_handle_tx_pause_iter(void *data
, u8
*mac
,
3395 struct ieee80211_vif
*vif
)
3397 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3398 struct ath10k_mac_tx_pause
*arg
= data
;
3400 if (arvif
->vdev_id
!= arg
->vdev_id
)
3403 ath10k_mac_vif_handle_tx_pause(arvif
, arg
->pause_id
, arg
->action
);
3406 void ath10k_mac_handle_tx_pause_vdev(struct ath10k
*ar
, u32 vdev_id
,
3407 enum wmi_tlv_tx_pause_id pause_id
,
3408 enum wmi_tlv_tx_pause_action action
)
3410 struct ath10k_mac_tx_pause arg
= {
3412 .pause_id
= pause_id
,
3416 spin_lock_bh(&ar
->htt
.tx_lock
);
3417 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3418 IEEE80211_IFACE_ITER_RESUME_ALL
,
3419 ath10k_mac_handle_tx_pause_iter
,
3421 spin_unlock_bh(&ar
->htt
.tx_lock
);
3424 static enum ath10k_hw_txrx_mode
3425 ath10k_mac_tx_h_get_txmode(struct ath10k
*ar
,
3426 struct ieee80211_vif
*vif
,
3427 struct ieee80211_sta
*sta
,
3428 struct sk_buff
*skb
)
3430 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3431 const struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
3432 __le16 fc
= hdr
->frame_control
;
3434 if (!vif
|| vif
->type
== NL80211_IFTYPE_MONITOR
)
3435 return ATH10K_HW_TXRX_RAW
;
3437 if (ieee80211_is_mgmt(fc
))
3438 return ATH10K_HW_TXRX_MGMT
;
3442 * NullFunc frames are mostly used to ping if a client or AP are still
3443 * reachable and responsive. This implies tx status reports must be
3444 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3445 * come to a conclusion that the other end disappeared and tear down
3446 * BSS connection or it can never disconnect from BSS/client (which is
3449 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3450 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3451 * which seems to deliver correct tx reports for NullFunc frames. The
3452 * downside of using it is it ignores client powersave state so it can
3453 * end up disconnecting sleeping clients in AP mode. It should fix STA
3454 * mode though because AP don't sleep.
3456 if (ar
->htt
.target_version_major
< 3 &&
3457 (ieee80211_is_nullfunc(fc
) || ieee80211_is_qos_nullfunc(fc
)) &&
3458 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3459 ar
->running_fw
->fw_file
.fw_features
))
3460 return ATH10K_HW_TXRX_MGMT
;
3464 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3465 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3466 * to work with Ethernet txmode so use it.
3468 * FIXME: Check if raw mode works with TDLS.
3470 if (ieee80211_is_data_present(fc
) && sta
&& sta
->tdls
)
3471 return ATH10K_HW_TXRX_ETHERNET
;
3473 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
) ||
3474 skb_cb
->flags
& ATH10K_SKB_F_RAW_TX
)
3475 return ATH10K_HW_TXRX_RAW
;
3477 return ATH10K_HW_TXRX_NATIVE_WIFI
;
3480 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif
*vif
,
3481 struct sk_buff
*skb
)
3483 const struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3484 const struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3485 const u32 mask
= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
3486 IEEE80211_TX_CTL_INJECTED
;
3488 if (!ieee80211_has_protected(hdr
->frame_control
))
3491 if ((info
->flags
& mask
) == mask
)
3495 return !((struct ath10k_vif
*)vif
->drv_priv
)->nohwcrypt
;
3500 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3501 * Control in the header.
3503 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3505 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3506 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3509 if (!ieee80211_is_data_qos(hdr
->frame_control
))
3512 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
3513 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
3514 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
3515 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
3517 /* Some firmware revisions don't handle sending QoS NullFunc well.
3518 * These frames are mainly used for CQM purposes so it doesn't really
3519 * matter whether QoS NullFunc or NullFunc are sent.
3521 hdr
= (void *)skb
->data
;
3522 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
3523 cb
->flags
&= ~ATH10K_SKB_F_QOS
;
3525 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
3528 static void ath10k_tx_h_8023(struct sk_buff
*skb
)
3530 struct ieee80211_hdr
*hdr
;
3531 struct rfc1042_hdr
*rfc1042
;
3538 hdr
= (void *)skb
->data
;
3539 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
3540 rfc1042
= (void *)skb
->data
+ hdrlen
;
3542 ether_addr_copy(da
, ieee80211_get_DA(hdr
));
3543 ether_addr_copy(sa
, ieee80211_get_SA(hdr
));
3544 type
= rfc1042
->snap_type
;
3546 skb_pull(skb
, hdrlen
+ sizeof(*rfc1042
));
3547 skb_push(skb
, sizeof(*eth
));
3549 eth
= (void *)skb
->data
;
3550 ether_addr_copy(eth
->h_dest
, da
);
3551 ether_addr_copy(eth
->h_source
, sa
);
3552 eth
->h_proto
= type
;
3555 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
3556 struct ieee80211_vif
*vif
,
3557 struct sk_buff
*skb
)
3559 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
3560 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
3562 /* This is case only for P2P_GO */
3563 if (vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
)
3566 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
3567 spin_lock_bh(&ar
->data_lock
);
3568 if (arvif
->u
.ap
.noa_data
)
3569 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
3571 skb_put_data(skb
, arvif
->u
.ap
.noa_data
,
3572 arvif
->u
.ap
.noa_len
);
3573 spin_unlock_bh(&ar
->data_lock
);
3577 static void ath10k_mac_tx_h_fill_cb(struct ath10k
*ar
,
3578 struct ieee80211_vif
*vif
,
3579 struct ieee80211_txq
*txq
,
3580 struct ieee80211_sta
*sta
,
3581 struct sk_buff
*skb
, u16 airtime
)
3583 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3584 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
3585 const struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3586 bool is_data
= ieee80211_is_data(hdr
->frame_control
) ||
3587 ieee80211_is_data_qos(hdr
->frame_control
);
3588 struct ath10k_sta
*arsta
;
3591 if (!ath10k_tx_h_use_hwcrypto(vif
, skb
))
3592 cb
->flags
|= ATH10K_SKB_F_NO_HWCRYPT
;
3594 if (ieee80211_is_mgmt(hdr
->frame_control
))
3595 cb
->flags
|= ATH10K_SKB_F_MGMT
;
3597 if (ieee80211_is_data_qos(hdr
->frame_control
))
3598 cb
->flags
|= ATH10K_SKB_F_QOS
;
3600 /* Data frames encrypted in software will be posted to firmware
3601 * with tx encap mode set to RAW. Ex: Multicast traffic generated
3602 * for a specific VLAN group will always be encrypted in software.
3604 if (is_data
&& ieee80211_has_protected(hdr
->frame_control
) &&
3605 !info
->control
.hw_key
) {
3606 cb
->flags
|= ATH10K_SKB_F_NO_HWCRYPT
;
3607 cb
->flags
|= ATH10K_SKB_F_RAW_TX
;
3612 cb
->airtime_est
= airtime
;
3614 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3615 spin_lock_bh(&ar
->data_lock
);
3616 cb
->ucast_cipher
= arsta
->ucast_cipher
;
3617 spin_unlock_bh(&ar
->data_lock
);
3621 bool ath10k_mac_tx_frm_has_freq(struct ath10k
*ar
)
3623 /* FIXME: Not really sure since when the behaviour changed. At some
3624 * point new firmware stopped requiring creation of peer entries for
3625 * offchannel tx (and actually creating them causes issues with wmi-htc
3626 * tx credit replenishment and reliability). Assuming it's at least 3.4
3627 * because that's when the `freq` was introduced to TX_FRM HTT command.
3629 return (ar
->htt
.target_version_major
>= 3 &&
3630 ar
->htt
.target_version_minor
>= 4 &&
3631 ar
->running_fw
->fw_file
.htt_op_version
== ATH10K_FW_HTT_OP_VERSION_TLV
);
3634 static int ath10k_mac_tx_wmi_mgmt(struct ath10k
*ar
, struct sk_buff
*skb
)
3636 struct sk_buff_head
*q
= &ar
->wmi_mgmt_tx_queue
;
3639 spin_lock_bh(&ar
->data_lock
);
3641 if (skb_queue_len(q
) == ATH10K_MAX_NUM_MGMT_PENDING
) {
3642 ath10k_warn(ar
, "wmi mgmt tx queue is full\n");
3647 __skb_queue_tail(q
, skb
);
3648 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
3651 spin_unlock_bh(&ar
->data_lock
);
3656 static enum ath10k_mac_tx_path
3657 ath10k_mac_tx_h_get_txpath(struct ath10k
*ar
,
3658 struct sk_buff
*skb
,
3659 enum ath10k_hw_txrx_mode txmode
)
3662 case ATH10K_HW_TXRX_RAW
:
3663 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3664 case ATH10K_HW_TXRX_ETHERNET
:
3665 return ATH10K_MAC_TX_HTT
;
3666 case ATH10K_HW_TXRX_MGMT
:
3667 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
3668 ar
->running_fw
->fw_file
.fw_features
) ||
3669 test_bit(WMI_SERVICE_MGMT_TX_WMI
,
3671 return ATH10K_MAC_TX_WMI_MGMT
;
3672 else if (ar
->htt
.target_version_major
>= 3)
3673 return ATH10K_MAC_TX_HTT
;
3675 return ATH10K_MAC_TX_HTT_MGMT
;
3678 return ATH10K_MAC_TX_UNKNOWN
;
3681 static int ath10k_mac_tx_submit(struct ath10k
*ar
,
3682 enum ath10k_hw_txrx_mode txmode
,
3683 enum ath10k_mac_tx_path txpath
,
3684 struct sk_buff
*skb
)
3686 struct ath10k_htt
*htt
= &ar
->htt
;
3690 case ATH10K_MAC_TX_HTT
:
3691 ret
= ath10k_htt_tx(htt
, txmode
, skb
);
3693 case ATH10K_MAC_TX_HTT_MGMT
:
3694 ret
= ath10k_htt_mgmt_tx(htt
, skb
);
3696 case ATH10K_MAC_TX_WMI_MGMT
:
3697 ret
= ath10k_mac_tx_wmi_mgmt(ar
, skb
);
3699 case ATH10K_MAC_TX_UNKNOWN
:
3706 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
3708 ieee80211_free_txskb(ar
->hw
, skb
);
3714 /* This function consumes the sk_buff regardless of return value as far as
3715 * caller is concerned so no freeing is necessary afterwards.
3717 static int ath10k_mac_tx(struct ath10k
*ar
,
3718 struct ieee80211_vif
*vif
,
3719 enum ath10k_hw_txrx_mode txmode
,
3720 enum ath10k_mac_tx_path txpath
,
3721 struct sk_buff
*skb
, bool noque_offchan
)
3723 struct ieee80211_hw
*hw
= ar
->hw
;
3724 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3725 const struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(skb
);
3728 /* We should disable CCK RATE due to P2P */
3729 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
3730 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3733 case ATH10K_HW_TXRX_MGMT
:
3734 case ATH10K_HW_TXRX_NATIVE_WIFI
:
3735 ath10k_tx_h_nwifi(hw
, skb
);
3736 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
3737 ath10k_tx_h_seq_no(vif
, skb
);
3739 case ATH10K_HW_TXRX_ETHERNET
:
3740 ath10k_tx_h_8023(skb
);
3742 case ATH10K_HW_TXRX_RAW
:
3743 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
) &&
3744 !(skb_cb
->flags
& ATH10K_SKB_F_RAW_TX
)) {
3746 ieee80211_free_txskb(hw
, skb
);
3751 if (!noque_offchan
&& info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
3752 if (!ath10k_mac_tx_frm_has_freq(ar
)) {
3753 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac queued offchannel skb %pK len %d\n",
3756 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
3757 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
3762 ret
= ath10k_mac_tx_submit(ar
, txmode
, txpath
, skb
);
3764 ath10k_warn(ar
, "failed to submit frame: %d\n", ret
);
3771 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
3773 struct sk_buff
*skb
;
3776 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3780 ieee80211_free_txskb(ar
->hw
, skb
);
3784 void ath10k_offchan_tx_work(struct work_struct
*work
)
3786 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
3787 struct ath10k_peer
*peer
;
3788 struct ath10k_vif
*arvif
;
3789 enum ath10k_hw_txrx_mode txmode
;
3790 enum ath10k_mac_tx_path txpath
;
3791 struct ieee80211_hdr
*hdr
;
3792 struct ieee80211_vif
*vif
;
3793 struct ieee80211_sta
*sta
;
3794 struct sk_buff
*skb
;
3795 const u8
*peer_addr
;
3798 unsigned long time_left
;
3799 bool tmp_peer_created
= false;
3801 /* FW requirement: We must create a peer before FW will send out
3802 * an offchannel frame. Otherwise the frame will be stuck and
3803 * never transmitted. We delete the peer upon tx completion.
3804 * It is unlikely that a peer for offchannel tx will already be
3805 * present. However it may be in some rare cases so account for that.
3806 * Otherwise we might remove a legitimate peer and break stuff.
3810 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
3814 mutex_lock(&ar
->conf_mutex
);
3816 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %pK len %d\n",
3819 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3820 peer_addr
= ieee80211_get_DA(hdr
);
3822 spin_lock_bh(&ar
->data_lock
);
3823 vdev_id
= ar
->scan
.vdev_id
;
3824 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
3825 spin_unlock_bh(&ar
->data_lock
);
3828 /* FIXME: should this use ath10k_warn()? */
3829 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
3830 peer_addr
, vdev_id
);
3833 ret
= ath10k_peer_create(ar
, NULL
, NULL
, vdev_id
,
3835 WMI_PEER_TYPE_DEFAULT
);
3837 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
3838 peer_addr
, vdev_id
, ret
);
3839 tmp_peer_created
= (ret
== 0);
3842 spin_lock_bh(&ar
->data_lock
);
3843 reinit_completion(&ar
->offchan_tx_completed
);
3844 ar
->offchan_tx_skb
= skb
;
3845 spin_unlock_bh(&ar
->data_lock
);
3847 /* It's safe to access vif and sta - conf_mutex guarantees that
3848 * sta_state() and remove_interface() are locked exclusively
3849 * out wrt to this offchannel worker.
3851 arvif
= ath10k_get_arvif(ar
, vdev_id
);
3854 sta
= ieee80211_find_sta(vif
, peer_addr
);
3860 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
3861 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
3863 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, true);
3865 ath10k_warn(ar
, "failed to transmit offchannel frame: %d\n",
3871 wait_for_completion_timeout(&ar
->offchan_tx_completed
, 3 * HZ
);
3873 ath10k_warn(ar
, "timed out waiting for offchannel skb %pK, len: %d\n",
3876 if (!peer
&& tmp_peer_created
) {
3877 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
3879 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
3880 peer_addr
, vdev_id
, ret
);
3883 mutex_unlock(&ar
->conf_mutex
);
3887 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
3889 struct sk_buff
*skb
;
3892 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3896 ieee80211_free_txskb(ar
->hw
, skb
);
3900 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
3902 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
3903 struct sk_buff
*skb
;
3908 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
3912 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF
,
3913 ar
->running_fw
->fw_file
.fw_features
)) {
3914 paddr
= dma_map_single(ar
->dev
, skb
->data
,
3915 skb
->len
, DMA_TO_DEVICE
);
3916 if (dma_mapping_error(ar
->dev
, paddr
)) {
3917 ieee80211_free_txskb(ar
->hw
, skb
);
3920 ret
= ath10k_wmi_mgmt_tx_send(ar
, skb
, paddr
);
3922 ath10k_warn(ar
, "failed to transmit management frame by ref via WMI: %d\n",
3924 dma_unmap_single(ar
->dev
, paddr
, skb
->len
,
3926 ieee80211_free_txskb(ar
->hw
, skb
);
3929 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
3931 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
3933 ieee80211_free_txskb(ar
->hw
, skb
);
3939 static void ath10k_mac_txq_init(struct ieee80211_txq
*txq
)
3941 struct ath10k_txq
*artxq
;
3946 artxq
= (void *)txq
->drv_priv
;
3947 INIT_LIST_HEAD(&artxq
->list
);
3950 static void ath10k_mac_txq_unref(struct ath10k
*ar
, struct ieee80211_txq
*txq
)
3952 struct ath10k_skb_cb
*cb
;
3953 struct sk_buff
*msdu
;
3959 spin_lock_bh(&ar
->htt
.tx_lock
);
3960 idr_for_each_entry(&ar
->htt
.pending_tx
, msdu
, msdu_id
) {
3961 cb
= ATH10K_SKB_CB(msdu
);
3965 spin_unlock_bh(&ar
->htt
.tx_lock
);
3968 struct ieee80211_txq
*ath10k_mac_txq_lookup(struct ath10k
*ar
,
3972 struct ath10k_peer
*peer
;
3974 lockdep_assert_held(&ar
->data_lock
);
3976 peer
= ar
->peer_map
[peer_id
];
3984 return peer
->sta
->txq
[tid
];
3986 return peer
->vif
->txq
;
3991 static bool ath10k_mac_tx_can_push(struct ieee80211_hw
*hw
,
3992 struct ieee80211_txq
*txq
)
3994 struct ath10k
*ar
= hw
->priv
;
3995 struct ath10k_txq
*artxq
= (void *)txq
->drv_priv
;
3997 /* No need to get locks */
3998 if (ar
->htt
.tx_q_state
.mode
== HTT_TX_MODE_SWITCH_PUSH
)
4001 if (ar
->htt
.num_pending_tx
< ar
->htt
.tx_q_state
.num_push_allowed
)
4004 if (artxq
->num_fw_queued
< artxq
->num_push_allowed
)
4010 /* Return estimated airtime in microsecond, which is calculated using last
4011 * reported TX rate. This is just a rough estimation because host driver has no
4012 * knowledge of the actual transmit rate, retries or aggregation. If actual
4013 * airtime can be reported by firmware, then delta between estimated and actual
4014 * airtime can be adjusted from deficit.
4016 #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
4017 #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
4018 static u16
ath10k_mac_update_airtime(struct ath10k
*ar
,
4019 struct ieee80211_txq
*txq
,
4020 struct sk_buff
*skb
)
4022 struct ath10k_sta
*arsta
;
4026 if (!txq
|| !txq
->sta
)
4029 if (test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
4032 spin_lock_bh(&ar
->data_lock
);
4033 arsta
= (struct ath10k_sta
*)txq
->sta
->drv_priv
;
4035 pktlen
= skb
->len
+ 38; /* Assume MAC header 30, SNAP 8 for most case */
4036 if (arsta
->last_tx_bitrate
) {
4037 /* airtime in us, last_tx_bitrate in 100kbps */
4038 airtime
= (pktlen
* 8 * (1000 / 100))
4039 / arsta
->last_tx_bitrate
;
4040 /* overhead for media access time and IFS */
4041 airtime
+= IEEE80211_ATF_OVERHEAD_IFS
;
4043 /* This is mostly for throttle excessive BC/MC frames, and the
4044 * airtime/rate doesn't need be exact. Airtime of BC/MC frames
4045 * in 2G get some discount, which helps prevent very low rate
4046 * frames from being blocked for too long.
4048 airtime
= (pktlen
* 8 * (1000 / 100)) / 60; /* 6M */
4049 airtime
+= IEEE80211_ATF_OVERHEAD
;
4051 spin_unlock_bh(&ar
->data_lock
);
4056 int ath10k_mac_tx_push_txq(struct ieee80211_hw
*hw
,
4057 struct ieee80211_txq
*txq
)
4059 struct ath10k
*ar
= hw
->priv
;
4060 struct ath10k_htt
*htt
= &ar
->htt
;
4061 struct ath10k_txq
*artxq
= (void *)txq
->drv_priv
;
4062 struct ieee80211_vif
*vif
= txq
->vif
;
4063 struct ieee80211_sta
*sta
= txq
->sta
;
4064 enum ath10k_hw_txrx_mode txmode
;
4065 enum ath10k_mac_tx_path txpath
;
4066 struct sk_buff
*skb
;
4067 struct ieee80211_hdr
*hdr
;
4069 bool is_mgmt
, is_presp
;
4073 spin_lock_bh(&ar
->htt
.tx_lock
);
4074 ret
= ath10k_htt_tx_inc_pending(htt
);
4075 spin_unlock_bh(&ar
->htt
.tx_lock
);
4080 skb
= ieee80211_tx_dequeue_ni(hw
, txq
);
4082 spin_lock_bh(&ar
->htt
.tx_lock
);
4083 ath10k_htt_tx_dec_pending(htt
);
4084 spin_unlock_bh(&ar
->htt
.tx_lock
);
4089 airtime
= ath10k_mac_update_airtime(ar
, txq
, skb
);
4090 ath10k_mac_tx_h_fill_cb(ar
, vif
, txq
, sta
, skb
, airtime
);
4093 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4094 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4095 is_mgmt
= (txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4098 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4099 is_presp
= ieee80211_is_probe_resp(hdr
->frame_control
);
4101 spin_lock_bh(&ar
->htt
.tx_lock
);
4102 ret
= ath10k_htt_tx_mgmt_inc_pending(htt
, is_mgmt
, is_presp
);
4105 ath10k_htt_tx_dec_pending(htt
);
4106 spin_unlock_bh(&ar
->htt
.tx_lock
);
4109 spin_unlock_bh(&ar
->htt
.tx_lock
);
4112 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, false);
4113 if (unlikely(ret
)) {
4114 ath10k_warn(ar
, "failed to push frame: %d\n", ret
);
4116 spin_lock_bh(&ar
->htt
.tx_lock
);
4117 ath10k_htt_tx_dec_pending(htt
);
4119 ath10k_htt_tx_mgmt_dec_pending(htt
);
4120 spin_unlock_bh(&ar
->htt
.tx_lock
);
4125 spin_lock_bh(&ar
->htt
.tx_lock
);
4126 artxq
->num_fw_queued
++;
4127 spin_unlock_bh(&ar
->htt
.tx_lock
);
4132 static int ath10k_mac_schedule_txq(struct ieee80211_hw
*hw
, u32 ac
)
4134 struct ieee80211_txq
*txq
;
4137 ieee80211_txq_schedule_start(hw
, ac
);
4138 while ((txq
= ieee80211_next_txq(hw
, ac
))) {
4139 while (ath10k_mac_tx_can_push(hw
, txq
)) {
4140 ret
= ath10k_mac_tx_push_txq(hw
, txq
);
4144 ieee80211_return_txq(hw
, txq
, false);
4145 ath10k_htt_tx_txq_update(hw
, txq
);
4149 ieee80211_txq_schedule_end(hw
, ac
);
4154 void ath10k_mac_tx_push_pending(struct ath10k
*ar
)
4156 struct ieee80211_hw
*hw
= ar
->hw
;
4159 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH
)
4162 if (ar
->htt
.num_pending_tx
>= (ar
->htt
.max_num_pending_tx
/ 2))
4166 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
4167 if (ath10k_mac_schedule_txq(hw
, ac
) == -EBUSY
)
4172 EXPORT_SYMBOL(ath10k_mac_tx_push_pending
);
4178 void __ath10k_scan_finish(struct ath10k
*ar
)
4180 lockdep_assert_held(&ar
->data_lock
);
4182 switch (ar
->scan
.state
) {
4183 case ATH10K_SCAN_IDLE
:
4185 case ATH10K_SCAN_RUNNING
:
4186 case ATH10K_SCAN_ABORTING
:
4187 if (!ar
->scan
.is_roc
) {
4188 struct cfg80211_scan_info info
= {
4189 .aborted
= (ar
->scan
.state
==
4190 ATH10K_SCAN_ABORTING
),
4193 ieee80211_scan_completed(ar
->hw
, &info
);
4194 } else if (ar
->scan
.roc_notify
) {
4195 ieee80211_remain_on_channel_expired(ar
->hw
);
4198 case ATH10K_SCAN_STARTING
:
4199 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
4200 ar
->scan_channel
= NULL
;
4201 ar
->scan
.roc_freq
= 0;
4202 ath10k_offchan_tx_purge(ar
);
4203 cancel_delayed_work(&ar
->scan
.timeout
);
4204 complete(&ar
->scan
.completed
);
4209 void ath10k_scan_finish(struct ath10k
*ar
)
4211 spin_lock_bh(&ar
->data_lock
);
4212 __ath10k_scan_finish(ar
);
4213 spin_unlock_bh(&ar
->data_lock
);
4216 static int ath10k_scan_stop(struct ath10k
*ar
)
4218 struct wmi_stop_scan_arg arg
= {
4219 .req_id
= 1, /* FIXME */
4220 .req_type
= WMI_SCAN_STOP_ONE
,
4221 .u
.scan_id
= ATH10K_SCAN_ID
,
4225 lockdep_assert_held(&ar
->conf_mutex
);
4227 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
4229 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
4233 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3 * HZ
);
4235 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
4237 } else if (ret
> 0) {
4242 /* Scan state should be updated upon scan completion but in case
4243 * firmware fails to deliver the event (for whatever reason) it is
4244 * desired to clean up scan state anyway. Firmware may have just
4245 * dropped the scan completion event delivery due to transport pipe
4246 * being overflown with data and/or it can recover on its own before
4247 * next scan request is submitted.
4249 spin_lock_bh(&ar
->data_lock
);
4250 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
4251 __ath10k_scan_finish(ar
);
4252 spin_unlock_bh(&ar
->data_lock
);
4257 static void ath10k_scan_abort(struct ath10k
*ar
)
4261 lockdep_assert_held(&ar
->conf_mutex
);
4263 spin_lock_bh(&ar
->data_lock
);
4265 switch (ar
->scan
.state
) {
4266 case ATH10K_SCAN_IDLE
:
4267 /* This can happen if timeout worker kicked in and called
4268 * abortion while scan completion was being processed.
4271 case ATH10K_SCAN_STARTING
:
4272 case ATH10K_SCAN_ABORTING
:
4273 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4274 ath10k_scan_state_str(ar
->scan
.state
),
4277 case ATH10K_SCAN_RUNNING
:
4278 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
4279 spin_unlock_bh(&ar
->data_lock
);
4281 ret
= ath10k_scan_stop(ar
);
4283 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
4285 spin_lock_bh(&ar
->data_lock
);
4289 spin_unlock_bh(&ar
->data_lock
);
4292 void ath10k_scan_timeout_work(struct work_struct
*work
)
4294 struct ath10k
*ar
= container_of(work
, struct ath10k
,
4297 mutex_lock(&ar
->conf_mutex
);
4298 ath10k_scan_abort(ar
);
4299 mutex_unlock(&ar
->conf_mutex
);
4302 static int ath10k_start_scan(struct ath10k
*ar
,
4303 const struct wmi_start_scan_arg
*arg
)
4307 lockdep_assert_held(&ar
->conf_mutex
);
4309 ret
= ath10k_wmi_start_scan(ar
, arg
);
4313 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1 * HZ
);
4315 ret
= ath10k_scan_stop(ar
);
4317 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
4322 /* If we failed to start the scan, return error code at
4323 * this point. This is probably due to some issue in the
4324 * firmware, but no need to wedge the driver due to that...
4326 spin_lock_bh(&ar
->data_lock
);
4327 if (ar
->scan
.state
== ATH10K_SCAN_IDLE
) {
4328 spin_unlock_bh(&ar
->data_lock
);
4331 spin_unlock_bh(&ar
->data_lock
);
4336 /**********************/
4337 /* mac80211 callbacks */
4338 /**********************/
4340 static void ath10k_mac_op_tx(struct ieee80211_hw
*hw
,
4341 struct ieee80211_tx_control
*control
,
4342 struct sk_buff
*skb
)
4344 struct ath10k
*ar
= hw
->priv
;
4345 struct ath10k_htt
*htt
= &ar
->htt
;
4346 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
4347 struct ieee80211_vif
*vif
= info
->control
.vif
;
4348 struct ieee80211_sta
*sta
= control
->sta
;
4349 struct ieee80211_txq
*txq
= NULL
;
4350 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
4351 enum ath10k_hw_txrx_mode txmode
;
4352 enum ath10k_mac_tx_path txpath
;
4359 airtime
= ath10k_mac_update_airtime(ar
, txq
, skb
);
4360 ath10k_mac_tx_h_fill_cb(ar
, vif
, txq
, sta
, skb
, airtime
);
4362 txmode
= ath10k_mac_tx_h_get_txmode(ar
, vif
, sta
, skb
);
4363 txpath
= ath10k_mac_tx_h_get_txpath(ar
, skb
, txmode
);
4364 is_htt
= (txpath
== ATH10K_MAC_TX_HTT
||
4365 txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4366 is_mgmt
= (txpath
== ATH10K_MAC_TX_HTT_MGMT
);
4369 spin_lock_bh(&ar
->htt
.tx_lock
);
4370 is_presp
= ieee80211_is_probe_resp(hdr
->frame_control
);
4372 ret
= ath10k_htt_tx_inc_pending(htt
);
4374 ath10k_warn(ar
, "failed to increase tx pending count: %d, dropping\n",
4376 spin_unlock_bh(&ar
->htt
.tx_lock
);
4377 ieee80211_free_txskb(ar
->hw
, skb
);
4381 ret
= ath10k_htt_tx_mgmt_inc_pending(htt
, is_mgmt
, is_presp
);
4383 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "failed to increase tx mgmt pending count: %d, dropping\n",
4385 ath10k_htt_tx_dec_pending(htt
);
4386 spin_unlock_bh(&ar
->htt
.tx_lock
);
4387 ieee80211_free_txskb(ar
->hw
, skb
);
4390 spin_unlock_bh(&ar
->htt
.tx_lock
);
4393 ret
= ath10k_mac_tx(ar
, vif
, txmode
, txpath
, skb
, false);
4395 ath10k_warn(ar
, "failed to transmit frame: %d\n", ret
);
4397 spin_lock_bh(&ar
->htt
.tx_lock
);
4398 ath10k_htt_tx_dec_pending(htt
);
4400 ath10k_htt_tx_mgmt_dec_pending(htt
);
4401 spin_unlock_bh(&ar
->htt
.tx_lock
);
4407 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw
*hw
,
4408 struct ieee80211_txq
*txq
)
4410 struct ath10k
*ar
= hw
->priv
;
4414 ath10k_htt_tx_txq_update(hw
, txq
);
4415 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH
)
4419 ieee80211_txq_schedule_start(hw
, ac
);
4420 txq
= ieee80211_next_txq(hw
, ac
);
4424 while (ath10k_mac_tx_can_push(hw
, txq
)) {
4425 ret
= ath10k_mac_tx_push_txq(hw
, txq
);
4429 ieee80211_return_txq(hw
, txq
, false);
4430 ath10k_htt_tx_txq_update(hw
, txq
);
4432 ieee80211_txq_schedule_end(hw
, ac
);
4435 /* Must not be called with conf_mutex held as workers can use that also. */
4436 void ath10k_drain_tx(struct ath10k
*ar
)
4438 /* make sure rcu-protected mac80211 tx path itself is drained */
4441 ath10k_offchan_tx_purge(ar
);
4442 ath10k_mgmt_over_wmi_tx_purge(ar
);
4444 cancel_work_sync(&ar
->offchan_tx_work
);
4445 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
4448 void ath10k_halt(struct ath10k
*ar
)
4450 struct ath10k_vif
*arvif
;
4452 lockdep_assert_held(&ar
->conf_mutex
);
4454 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
4455 ar
->filter_flags
= 0;
4456 ar
->monitor
= false;
4457 ar
->monitor_arvif
= NULL
;
4459 if (ar
->monitor_started
)
4460 ath10k_monitor_stop(ar
);
4462 ar
->monitor_started
= false;
4465 ath10k_scan_finish(ar
);
4466 ath10k_peer_cleanup_all(ar
);
4467 ath10k_stop_radar_confirmation(ar
);
4468 ath10k_core_stop(ar
);
4469 ath10k_hif_power_down(ar
);
4471 spin_lock_bh(&ar
->data_lock
);
4472 list_for_each_entry(arvif
, &ar
->arvifs
, list
)
4473 ath10k_mac_vif_beacon_cleanup(arvif
);
4474 spin_unlock_bh(&ar
->data_lock
);
4477 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
4479 struct ath10k
*ar
= hw
->priv
;
4481 mutex_lock(&ar
->conf_mutex
);
4483 *tx_ant
= ar
->cfg_tx_chainmask
;
4484 *rx_ant
= ar
->cfg_rx_chainmask
;
4486 mutex_unlock(&ar
->conf_mutex
);
4491 static void ath10k_check_chain_mask(struct ath10k
*ar
, u32 cm
, const char *dbg
)
4493 /* It is not clear that allowing gaps in chainmask
4494 * is helpful. Probably it will not do what user
4495 * is hoping for, so warn in that case.
4497 if (cm
== 15 || cm
== 7 || cm
== 3 || cm
== 1 || cm
== 0)
4500 ath10k_warn(ar
, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4504 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k
*ar
)
4506 int nsts
= ar
->vht_cap_info
;
4508 nsts
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
4509 nsts
>>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
4511 /* If firmware does not deliver to host number of space-time
4512 * streams supported, assume it support up to 4 BF STS and return
4513 * the value for VHT CAP: nsts-1)
4521 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k
*ar
)
4523 int sound_dim
= ar
->vht_cap_info
;
4525 sound_dim
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
4526 sound_dim
>>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
4528 /* If the sounding dimension is not advertised by the firmware,
4529 * let's use a default value of 1
4537 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
4539 struct ieee80211_sta_vht_cap vht_cap
= {0};
4540 struct ath10k_hw_params
*hw
= &ar
->hw_params
;
4545 vht_cap
.vht_supported
= 1;
4546 vht_cap
.cap
= ar
->vht_cap_info
;
4548 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
4549 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)) {
4550 val
= ath10k_mac_get_vht_cap_bf_sts(ar
);
4551 val
<<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT
;
4552 val
&= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
4557 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
4558 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)) {
4559 val
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
4560 val
<<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT
;
4561 val
&= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
;
4566 /* Currently the firmware seems to be buggy, don't enable 80+80
4567 * mode until that's resolved.
4569 if ((ar
->vht_cap_info
& IEEE80211_VHT_CAP_SHORT_GI_160
) &&
4570 (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) == 0)
4571 vht_cap
.cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
4574 for (i
= 0; i
< 8; i
++) {
4575 if ((i
< ar
->num_rf_chains
) && (ar
->cfg_tx_chainmask
& BIT(i
)))
4576 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
* 2);
4578 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
* 2);
4581 if (ar
->cfg_tx_chainmask
<= 1)
4582 vht_cap
.cap
&= ~IEEE80211_VHT_CAP_TXSTBC
;
4584 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
4585 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
4587 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4588 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4589 * user-space a clue if that is the case.
4591 if ((vht_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) &&
4592 (hw
->vht160_mcs_rx_highest
!= 0 ||
4593 hw
->vht160_mcs_tx_highest
!= 0)) {
4594 vht_cap
.vht_mcs
.rx_highest
= cpu_to_le16(hw
->vht160_mcs_rx_highest
);
4595 vht_cap
.vht_mcs
.tx_highest
= cpu_to_le16(hw
->vht160_mcs_tx_highest
);
4601 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
4604 struct ieee80211_sta_ht_cap ht_cap
= {0};
4606 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
4609 ht_cap
.ht_supported
= 1;
4610 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
4611 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
4612 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
4613 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
4615 WLAN_HT_CAP_SM_PS_DISABLED
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
4617 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
4618 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
4620 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
4621 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
4623 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
4626 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
4627 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
4632 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
&& (ar
->cfg_tx_chainmask
> 1))
4633 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
4635 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
4638 stbc
= ar
->ht_cap_info
;
4639 stbc
&= WMI_HT_CAP_RX_STBC
;
4640 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
4641 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
4642 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
4647 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
|| (ar
->ht_cap_info
&
4648 WMI_HT_CAP_RX_LDPC
&& (ar
->ht_cap_info
& WMI_HT_CAP_TX_LDPC
)))
4649 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
4651 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
4652 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
4654 /* max AMSDU is implicitly taken from vht_cap_info */
4655 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
4656 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
4658 for (i
= 0; i
< ar
->num_rf_chains
; i
++) {
4659 if (ar
->cfg_rx_chainmask
& BIT(i
))
4660 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
4663 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
4668 static void ath10k_mac_setup_ht_vht_cap(struct ath10k
*ar
)
4670 struct ieee80211_supported_band
*band
;
4671 struct ieee80211_sta_vht_cap vht_cap
;
4672 struct ieee80211_sta_ht_cap ht_cap
;
4674 ht_cap
= ath10k_get_ht_cap(ar
);
4675 vht_cap
= ath10k_create_vht_cap(ar
);
4677 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
4678 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
4679 band
->ht_cap
= ht_cap
;
4681 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
4682 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
4683 band
->ht_cap
= ht_cap
;
4684 band
->vht_cap
= vht_cap
;
4688 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
4692 lockdep_assert_held(&ar
->conf_mutex
);
4694 ath10k_check_chain_mask(ar
, tx_ant
, "tx");
4695 ath10k_check_chain_mask(ar
, rx_ant
, "rx");
4697 ar
->cfg_tx_chainmask
= tx_ant
;
4698 ar
->cfg_rx_chainmask
= rx_ant
;
4700 if ((ar
->state
!= ATH10K_STATE_ON
) &&
4701 (ar
->state
!= ATH10K_STATE_RESTARTED
))
4704 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
4707 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
4712 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
4715 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
4720 /* Reload HT/VHT capability */
4721 ath10k_mac_setup_ht_vht_cap(ar
);
4726 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
4728 struct ath10k
*ar
= hw
->priv
;
4731 mutex_lock(&ar
->conf_mutex
);
4732 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
4733 mutex_unlock(&ar
->conf_mutex
);
4737 static int __ath10k_fetch_bb_timing_dt(struct ath10k
*ar
,
4738 struct wmi_bb_timing_cfg_arg
*bb_timing
)
4740 struct device_node
*node
;
4741 const char *fem_name
;
4744 node
= ar
->dev
->of_node
;
4748 ret
= of_property_read_string_index(node
, "ext-fem-name", 0, &fem_name
);
4753 * If external Front End module used in hardware, then default base band timing
4754 * parameter cannot be used since they were fine tuned for reference hardware,
4755 * so choosing different value suitable for that external FEM.
4757 if (!strcmp("microsemi-lx5586", fem_name
)) {
4758 bb_timing
->bb_tx_timing
= 0x00;
4759 bb_timing
->bb_xpa_timing
= 0x0101;
4764 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
4765 bb_timing
->bb_tx_timing
, bb_timing
->bb_xpa_timing
);
4769 static int ath10k_mac_rfkill_config(struct ath10k
*ar
)
4774 if (ar
->hw_values
->rfkill_pin
== 0) {
4775 ath10k_warn(ar
, "ath10k does not support hardware rfkill with this device\n");
4779 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4780 "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
4781 ar
->hw_values
->rfkill_pin
, ar
->hw_values
->rfkill_cfg
,
4782 ar
->hw_values
->rfkill_on_level
);
4784 param
= FIELD_PREP(WMI_TLV_RFKILL_CFG_RADIO_LEVEL
,
4785 ar
->hw_values
->rfkill_on_level
) |
4786 FIELD_PREP(WMI_TLV_RFKILL_CFG_GPIO_PIN_NUM
,
4787 ar
->hw_values
->rfkill_pin
) |
4788 FIELD_PREP(WMI_TLV_RFKILL_CFG_PIN_AS_GPIO
,
4789 ar
->hw_values
->rfkill_cfg
);
4791 ret
= ath10k_wmi_pdev_set_param(ar
,
4792 ar
->wmi
.pdev_param
->rfkill_config
,
4796 "failed to set rfkill config 0x%x: %d\n",
4803 int ath10k_mac_rfkill_enable_radio(struct ath10k
*ar
, bool enable
)
4805 enum wmi_tlv_rfkill_enable_radio param
;
4809 param
= WMI_TLV_RFKILL_ENABLE_RADIO_ON
;
4811 param
= WMI_TLV_RFKILL_ENABLE_RADIO_OFF
;
4813 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac rfkill enable %d", param
);
4815 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rfkill_enable
,
4818 ath10k_warn(ar
, "failed to set rfkill enable param %d: %d\n",
4826 static int ath10k_start(struct ieee80211_hw
*hw
)
4828 struct ath10k
*ar
= hw
->priv
;
4831 struct wmi_bb_timing_cfg_arg bb_timing
= {0};
4834 * This makes sense only when restarting hw. It is harmless to call
4835 * unconditionally. This is necessary to make sure no HTT/WMI tx
4836 * commands will be submitted while restarting.
4838 ath10k_drain_tx(ar
);
4840 mutex_lock(&ar
->conf_mutex
);
4842 switch (ar
->state
) {
4843 case ATH10K_STATE_OFF
:
4844 ar
->state
= ATH10K_STATE_ON
;
4846 case ATH10K_STATE_RESTARTING
:
4847 ar
->state
= ATH10K_STATE_RESTARTED
;
4849 case ATH10K_STATE_ON
:
4850 case ATH10K_STATE_RESTARTED
:
4851 case ATH10K_STATE_WEDGED
:
4855 case ATH10K_STATE_UTF
:
4860 spin_lock_bh(&ar
->data_lock
);
4862 if (ar
->hw_rfkill_on
) {
4863 ar
->hw_rfkill_on
= false;
4864 spin_unlock_bh(&ar
->data_lock
);
4868 spin_unlock_bh(&ar
->data_lock
);
4870 ret
= ath10k_hif_power_up(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
4872 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
4876 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
,
4877 &ar
->normal_mode_fw
);
4879 ath10k_err(ar
, "Could not init core: %d\n", ret
);
4880 goto err_power_down
;
4883 if (ar
->sys_cap_info
& WMI_TLV_SYS_CAP_INFO_RFKILL
) {
4884 ret
= ath10k_mac_rfkill_config(ar
);
4885 if (ret
&& ret
!= -EOPNOTSUPP
) {
4886 ath10k_warn(ar
, "failed to configure rfkill: %d", ret
);
4891 param
= ar
->wmi
.pdev_param
->pmf_qos
;
4892 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
4894 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
4898 param
= ar
->wmi
.pdev_param
->dynamic_bw
;
4899 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
4901 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
4905 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
4906 ret
= ath10k_wmi_scan_prob_req_oui(ar
, ar
->mac_addr
);
4908 ath10k_err(ar
, "failed to set prob req oui: %i\n", ret
);
4913 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
4914 ret
= ath10k_wmi_adaptive_qcs(ar
, true);
4916 ath10k_warn(ar
, "failed to enable adaptive qcs: %d\n",
4922 if (test_bit(WMI_SERVICE_BURST
, ar
->wmi
.svc_map
)) {
4923 param
= ar
->wmi
.pdev_param
->burst_enable
;
4924 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
4926 ath10k_warn(ar
, "failed to disable burst: %d\n", ret
);
4931 param
= ar
->wmi
.pdev_param
->idle_ps_config
;
4932 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
4933 if (ret
&& ret
!= -EOPNOTSUPP
) {
4934 ath10k_warn(ar
, "failed to enable idle_ps_config: %d\n", ret
);
4938 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
, ar
->cfg_rx_chainmask
);
4941 * By default FW set ARP frames ac to voice (6). In that case ARP
4942 * exchange is not working properly for UAPSD enabled AP. ARP requests
4943 * which arrives with access category 0 are processed by network stack
4944 * and send back with access category 0, but FW changes access category
4945 * to 6. Set ARP frames access category to best effort (0) solves
4949 param
= ar
->wmi
.pdev_param
->arp_ac_override
;
4950 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
4952 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
4957 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA
,
4958 ar
->running_fw
->fw_file
.fw_features
)) {
4959 ret
= ath10k_wmi_pdev_enable_adaptive_cca(ar
, 1,
4960 WMI_CCA_DETECT_LEVEL_AUTO
,
4961 WMI_CCA_DETECT_MARGIN_AUTO
);
4963 ath10k_warn(ar
, "failed to enable adaptive cca: %d\n",
4969 param
= ar
->wmi
.pdev_param
->ani_enable
;
4970 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 1);
4972 ath10k_warn(ar
, "failed to enable ani by default: %d\n",
4977 ar
->ani_enabled
= true;
4979 if (ath10k_peer_stats_enabled(ar
)) {
4980 param
= ar
->wmi
.pdev_param
->peer_stats_update_period
;
4981 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
4982 PEER_DEFAULT_STATS_UPDATE_PERIOD
);
4985 "failed to set peer stats period : %d\n",
4991 param
= ar
->wmi
.pdev_param
->enable_btcoex
;
4992 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
) &&
4993 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM
,
4994 ar
->running_fw
->fw_file
.fw_features
) &&
4996 ret
= ath10k_wmi_pdev_set_param(ar
, param
, 0);
4999 "failed to set btcoex param: %d\n", ret
);
5002 clear_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
5005 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT
, ar
->wmi
.svc_map
)) {
5006 ret
= __ath10k_fetch_bb_timing_dt(ar
, &bb_timing
);
5008 ret
= ath10k_wmi_pdev_bb_timing(ar
, &bb_timing
);
5011 "failed to set bb timings: %d\n",
5018 ar
->num_started_vdevs
= 0;
5019 ath10k_regd_update(ar
);
5021 ath10k_spectral_start(ar
);
5022 ath10k_thermal_set_throttling(ar
);
5024 ar
->radar_conf_state
= ATH10K_RADAR_CONFIRMATION_IDLE
;
5026 mutex_unlock(&ar
->conf_mutex
);
5030 ath10k_core_stop(ar
);
5033 ath10k_hif_power_down(ar
);
5036 ar
->state
= ATH10K_STATE_OFF
;
5039 mutex_unlock(&ar
->conf_mutex
);
5043 static void ath10k_stop(struct ieee80211_hw
*hw
)
5045 struct ath10k
*ar
= hw
->priv
;
5047 ath10k_drain_tx(ar
);
5049 mutex_lock(&ar
->conf_mutex
);
5050 if (ar
->state
!= ATH10K_STATE_OFF
) {
5051 if (!ar
->hw_rfkill_on
)
5053 ar
->state
= ATH10K_STATE_OFF
;
5055 mutex_unlock(&ar
->conf_mutex
);
5057 cancel_work_sync(&ar
->set_coverage_class_work
);
5058 cancel_delayed_work_sync(&ar
->scan
.timeout
);
5059 cancel_work_sync(&ar
->restart_work
);
5062 static int ath10k_config_ps(struct ath10k
*ar
)
5064 struct ath10k_vif
*arvif
;
5067 lockdep_assert_held(&ar
->conf_mutex
);
5069 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5070 ret
= ath10k_mac_vif_setup_ps(arvif
);
5072 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
5080 static int ath10k_mac_txpower_setup(struct ath10k
*ar
, int txpower
)
5085 lockdep_assert_held(&ar
->conf_mutex
);
5087 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac txpower %d\n", txpower
);
5089 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
5090 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
5092 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
5097 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
5098 ret
= ath10k_wmi_pdev_set_param(ar
, param
, txpower
* 2);
5100 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
5108 static int ath10k_mac_txpower_recalc(struct ath10k
*ar
)
5110 struct ath10k_vif
*arvif
;
5111 int ret
, txpower
= -1;
5113 lockdep_assert_held(&ar
->conf_mutex
);
5115 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
5116 /* txpower not initialized yet? */
5117 if (arvif
->txpower
== INT_MIN
)
5121 txpower
= arvif
->txpower
;
5123 txpower
= min(txpower
, arvif
->txpower
);
5129 ret
= ath10k_mac_txpower_setup(ar
, txpower
);
5131 ath10k_warn(ar
, "failed to setup tx power %d: %d\n",
5139 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
5141 struct ath10k
*ar
= hw
->priv
;
5142 struct ieee80211_conf
*conf
= &hw
->conf
;
5145 mutex_lock(&ar
->conf_mutex
);
5147 if (changed
& IEEE80211_CONF_CHANGE_PS
)
5148 ath10k_config_ps(ar
);
5150 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
5151 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
5152 ret
= ath10k_monitor_recalc(ar
);
5154 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5157 mutex_unlock(&ar
->conf_mutex
);
5161 static u32
get_nss_from_chainmask(u16 chain_mask
)
5163 if ((chain_mask
& 0xf) == 0xf)
5165 else if ((chain_mask
& 0x7) == 0x7)
5167 else if ((chain_mask
& 0x3) == 0x3)
5172 static int ath10k_mac_set_txbf_conf(struct ath10k_vif
*arvif
)
5175 struct ath10k
*ar
= arvif
->ar
;
5179 if (ath10k_wmi_get_txbf_conf_scheme(ar
) != WMI_TXBF_CONF_BEFORE_ASSOC
)
5182 nsts
= ath10k_mac_get_vht_cap_bf_sts(ar
);
5183 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
5184 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
))
5185 value
|= SM(nsts
, WMI_TXBF_STS_CAP_OFFSET
);
5187 sound_dim
= ath10k_mac_get_vht_cap_bf_sound_dim(ar
);
5188 if (ar
->vht_cap_info
& (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
5189 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
))
5190 value
|= SM(sound_dim
, WMI_BF_SOUND_DIM_OFFSET
);
5195 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
5196 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFER
;
5198 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
5199 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER
|
5200 WMI_VDEV_PARAM_TXBF_SU_TX_BFER
);
5202 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
5203 value
|= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
;
5205 if (ar
->vht_cap_info
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
5206 value
|= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE
|
5207 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE
);
5209 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5210 ar
->wmi
.vdev_param
->txbf
, value
);
5215 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5216 * because we will send mgmt frames without CCK. This requirement
5217 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5220 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
5221 struct ieee80211_vif
*vif
)
5223 struct ath10k
*ar
= hw
->priv
;
5224 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5225 struct ath10k_peer
*peer
;
5226 enum wmi_sta_powersave_param param
;
5233 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
5235 mutex_lock(&ar
->conf_mutex
);
5237 memset(arvif
, 0, sizeof(*arvif
));
5238 ath10k_mac_txq_init(vif
->txq
);
5243 INIT_LIST_HEAD(&arvif
->list
);
5244 INIT_WORK(&arvif
->ap_csa_work
, ath10k_mac_vif_ap_csa_work
);
5245 INIT_DELAYED_WORK(&arvif
->connection_loss_work
,
5246 ath10k_mac_vif_sta_connection_loss_work
);
5248 for (i
= 0; i
< ARRAY_SIZE(arvif
->bitrate_mask
.control
); i
++) {
5249 arvif
->bitrate_mask
.control
[i
].legacy
= 0xffffffff;
5250 memset(arvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
5251 sizeof(arvif
->bitrate_mask
.control
[i
].ht_mcs
));
5252 memset(arvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
5253 sizeof(arvif
->bitrate_mask
.control
[i
].vht_mcs
));
5256 if (ar
->num_peers
>= ar
->max_num_peers
) {
5257 ath10k_warn(ar
, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5262 if (ar
->free_vdev_map
== 0) {
5263 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
5267 bit
= __ffs64(ar
->free_vdev_map
);
5269 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac create vdev %i map %llx\n",
5270 bit
, ar
->free_vdev_map
);
5272 arvif
->vdev_id
= bit
;
5273 arvif
->vdev_subtype
=
5274 ath10k_wmi_get_vdev_subtype(ar
, WMI_VDEV_SUBTYPE_NONE
);
5276 switch (vif
->type
) {
5277 case NL80211_IFTYPE_P2P_DEVICE
:
5278 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
5279 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5280 (ar
, WMI_VDEV_SUBTYPE_P2P_DEVICE
);
5282 case NL80211_IFTYPE_UNSPECIFIED
:
5283 case NL80211_IFTYPE_STATION
:
5284 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
5286 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5287 (ar
, WMI_VDEV_SUBTYPE_P2P_CLIENT
);
5289 case NL80211_IFTYPE_ADHOC
:
5290 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
5292 case NL80211_IFTYPE_MESH_POINT
:
5293 if (test_bit(WMI_SERVICE_MESH_11S
, ar
->wmi
.svc_map
)) {
5294 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5295 (ar
, WMI_VDEV_SUBTYPE_MESH_11S
);
5296 } else if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
5298 ath10k_warn(ar
, "must load driver with rawmode=1 to add mesh interfaces\n");
5301 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
5303 case NL80211_IFTYPE_AP
:
5304 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
5307 arvif
->vdev_subtype
= ath10k_wmi_get_vdev_subtype
5308 (ar
, WMI_VDEV_SUBTYPE_P2P_GO
);
5310 case NL80211_IFTYPE_MONITOR
:
5311 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
5318 /* Using vdev_id as queue number will make it very easy to do per-vif
5319 * tx queue locking. This shouldn't wrap due to interface combinations
5320 * but do a modulo for correctness sake and prevent using offchannel tx
5321 * queues for regular vif tx.
5323 vif
->cab_queue
= arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
5324 for (i
= 0; i
< ARRAY_SIZE(vif
->hw_queue
); i
++)
5325 vif
->hw_queue
[i
] = arvif
->vdev_id
% (IEEE80211_MAX_QUEUES
- 1);
5327 /* Some firmware revisions don't wait for beacon tx completion before
5328 * sending another SWBA event. This could lead to hardware using old
5329 * (freed) beacon data in some cases, e.g. tx credit starvation
5330 * combined with missed TBTT. This is very very rare.
5332 * On non-IOMMU-enabled hosts this could be a possible security issue
5333 * because hw could beacon some random data on the air. On
5334 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5335 * device would crash.
5337 * Since there are no beacon tx completions (implicit nor explicit)
5338 * propagated to host the only workaround for this is to allocate a
5339 * DMA-coherent buffer for a lifetime of a vif and use it for all
5340 * beacon tx commands. Worst case for this approach is some beacons may
5341 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5343 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
5344 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
5345 vif
->type
== NL80211_IFTYPE_AP
) {
5346 arvif
->beacon_buf
= dma_alloc_coherent(ar
->dev
,
5347 IEEE80211_MAX_FRAME_LEN
,
5348 &arvif
->beacon_paddr
,
5350 if (!arvif
->beacon_buf
) {
5352 ath10k_warn(ar
, "failed to allocate beacon buffer: %d\n",
5357 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
))
5358 arvif
->nohwcrypt
= true;
5360 if (arvif
->nohwcrypt
&&
5361 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
5362 ath10k_warn(ar
, "cryptmode module param needed for sw crypto\n");
5366 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5367 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
,
5368 arvif
->beacon_buf
? "single-buf" : "per-skb");
5370 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
5371 arvif
->vdev_subtype
, vif
->addr
);
5373 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
5374 arvif
->vdev_id
, ret
);
5378 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT
,
5380 vdev_param
= ar
->wmi
.vdev_param
->disable_4addr_src_lrn
;
5381 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5382 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN
);
5383 if (ret
&& ret
!= -EOPNOTSUPP
) {
5384 ath10k_warn(ar
, "failed to disable 4addr src lrn vdev %i: %d\n",
5385 arvif
->vdev_id
, ret
);
5389 ar
->free_vdev_map
&= ~(1LL << arvif
->vdev_id
);
5390 spin_lock_bh(&ar
->data_lock
);
5391 list_add(&arvif
->list
, &ar
->arvifs
);
5392 spin_unlock_bh(&ar
->data_lock
);
5394 /* It makes no sense to have firmware do keepalives. mac80211 already
5395 * takes care of this with idle connection polling.
5397 ret
= ath10k_mac_vif_disable_keepalive(arvif
);
5399 ath10k_warn(ar
, "failed to disable keepalive on vdev %i: %d\n",
5400 arvif
->vdev_id
, ret
);
5401 goto err_vdev_delete
;
5404 arvif
->def_wep_key_idx
= -1;
5406 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
5407 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5408 ATH10K_HW_TXRX_NATIVE_WIFI
);
5409 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5410 if (ret
&& ret
!= -EOPNOTSUPP
) {
5411 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
5412 arvif
->vdev_id
, ret
);
5413 goto err_vdev_delete
;
5416 /* Configuring number of spatial stream for monitor interface is causing
5417 * target assert in qca9888 and qca6174.
5419 if (ar
->cfg_tx_chainmask
&& (vif
->type
!= NL80211_IFTYPE_MONITOR
)) {
5420 u16 nss
= get_nss_from_chainmask(ar
->cfg_tx_chainmask
);
5422 vdev_param
= ar
->wmi
.vdev_param
->nss
;
5423 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5426 ath10k_warn(ar
, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5427 arvif
->vdev_id
, ar
->cfg_tx_chainmask
, nss
,
5429 goto err_vdev_delete
;
5433 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5434 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5435 ret
= ath10k_peer_create(ar
, vif
, NULL
, arvif
->vdev_id
,
5436 vif
->addr
, WMI_PEER_TYPE_DEFAULT
);
5438 ath10k_warn(ar
, "failed to create vdev %i peer for AP/IBSS: %d\n",
5439 arvif
->vdev_id
, ret
);
5440 goto err_vdev_delete
;
5443 spin_lock_bh(&ar
->data_lock
);
5445 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, vif
->addr
);
5447 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
5448 vif
->addr
, arvif
->vdev_id
);
5449 spin_unlock_bh(&ar
->data_lock
);
5451 goto err_peer_delete
;
5454 arvif
->peer_id
= find_first_bit(peer
->peer_ids
,
5455 ATH10K_MAX_NUM_PEER_IDS
);
5457 spin_unlock_bh(&ar
->data_lock
);
5459 arvif
->peer_id
= HTT_INVALID_PEERID
;
5462 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
5463 ret
= ath10k_mac_set_kickout(arvif
);
5465 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
5466 arvif
->vdev_id
, ret
);
5467 goto err_peer_delete
;
5471 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
5472 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
5473 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
5474 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
5477 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
5478 arvif
->vdev_id
, ret
);
5479 goto err_peer_delete
;
5482 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
5484 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
5485 arvif
->vdev_id
, ret
);
5486 goto err_peer_delete
;
5489 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
5491 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
5492 arvif
->vdev_id
, ret
);
5493 goto err_peer_delete
;
5497 ret
= ath10k_mac_set_txbf_conf(arvif
);
5499 ath10k_warn(ar
, "failed to set txbf for vdev %d: %d\n",
5500 arvif
->vdev_id
, ret
);
5501 goto err_peer_delete
;
5504 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
5506 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
5507 arvif
->vdev_id
, ret
);
5508 goto err_peer_delete
;
5511 arvif
->txpower
= vif
->bss_conf
.txpower
;
5512 ret
= ath10k_mac_txpower_recalc(ar
);
5514 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
5515 goto err_peer_delete
;
5518 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
)) {
5519 vdev_param
= ar
->wmi
.vdev_param
->rtt_responder_role
;
5520 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5521 arvif
->ftm_responder
);
5523 /* It is harmless to not set FTM role. Do not warn */
5524 if (ret
&& ret
!= -EOPNOTSUPP
)
5525 ath10k_warn(ar
, "failed to set vdev %i FTM Responder: %d\n",
5526 arvif
->vdev_id
, ret
);
5529 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
5530 ar
->monitor_arvif
= arvif
;
5531 ret
= ath10k_monitor_recalc(ar
);
5533 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5534 goto err_peer_delete
;
5538 spin_lock_bh(&ar
->htt
.tx_lock
);
5540 ieee80211_wake_queue(ar
->hw
, arvif
->vdev_id
);
5541 spin_unlock_bh(&ar
->htt
.tx_lock
);
5543 mutex_unlock(&ar
->conf_mutex
);
5547 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5548 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5549 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
5550 ath10k_wait_for_peer_delete_done(ar
, arvif
->vdev_id
,
5555 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
5556 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
5557 spin_lock_bh(&ar
->data_lock
);
5558 list_del(&arvif
->list
);
5559 spin_unlock_bh(&ar
->data_lock
);
5562 if (arvif
->beacon_buf
) {
5563 dma_free_coherent(ar
->dev
, IEEE80211_MAX_FRAME_LEN
,
5564 arvif
->beacon_buf
, arvif
->beacon_paddr
);
5565 arvif
->beacon_buf
= NULL
;
5568 mutex_unlock(&ar
->conf_mutex
);
5573 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif
*arvif
)
5577 for (i
= 0; i
< BITS_PER_LONG
; i
++)
5578 ath10k_mac_vif_tx_unlock(arvif
, i
);
5581 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
5582 struct ieee80211_vif
*vif
)
5584 struct ath10k
*ar
= hw
->priv
;
5585 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5586 struct ath10k_peer
*peer
;
5587 unsigned long time_left
;
5591 cancel_work_sync(&arvif
->ap_csa_work
);
5592 cancel_delayed_work_sync(&arvif
->connection_loss_work
);
5594 mutex_lock(&ar
->conf_mutex
);
5596 ret
= ath10k_spectral_vif_stop(arvif
);
5598 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
5599 arvif
->vdev_id
, ret
);
5601 ar
->free_vdev_map
|= 1LL << arvif
->vdev_id
;
5602 spin_lock_bh(&ar
->data_lock
);
5603 list_del(&arvif
->list
);
5604 spin_unlock_bh(&ar
->data_lock
);
5606 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5607 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5608 ret
= ath10k_wmi_peer_delete(arvif
->ar
, arvif
->vdev_id
,
5611 ath10k_warn(ar
, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5612 arvif
->vdev_id
, ret
);
5614 ath10k_wait_for_peer_delete_done(ar
, arvif
->vdev_id
,
5616 kfree(arvif
->u
.ap
.noa_data
);
5619 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
5622 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
5624 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
5625 arvif
->vdev_id
, ret
);
5627 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS
, ar
->wmi
.svc_map
)) {
5628 time_left
= wait_for_completion_timeout(&ar
->vdev_delete_done
,
5629 ATH10K_VDEV_DELETE_TIMEOUT_HZ
);
5630 if (time_left
== 0) {
5631 ath10k_warn(ar
, "Timeout in receiving vdev delete response\n");
5636 /* Some firmware revisions don't notify host about self-peer removal
5637 * until after associated vdev is deleted.
5639 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
||
5640 arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
5641 ret
= ath10k_wait_for_peer_deleted(ar
, arvif
->vdev_id
,
5644 ath10k_warn(ar
, "failed to remove AP self-peer on vdev %i: %d\n",
5645 arvif
->vdev_id
, ret
);
5647 spin_lock_bh(&ar
->data_lock
);
5649 spin_unlock_bh(&ar
->data_lock
);
5652 spin_lock_bh(&ar
->data_lock
);
5653 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
5654 peer
= ar
->peer_map
[i
];
5658 if (peer
->vif
== vif
) {
5659 ath10k_warn(ar
, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5660 vif
->addr
, arvif
->vdev_id
);
5665 /* Clean this up late, less opportunity for firmware to access
5666 * DMA memory we have deleted.
5668 ath10k_mac_vif_beacon_cleanup(arvif
);
5669 spin_unlock_bh(&ar
->data_lock
);
5671 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
5672 ath10k_mac_txq_unref(ar
, vif
->txq
);
5674 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
5675 ar
->monitor_arvif
= NULL
;
5676 ret
= ath10k_monitor_recalc(ar
);
5678 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5681 ret
= ath10k_mac_txpower_recalc(ar
);
5683 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
5685 spin_lock_bh(&ar
->htt
.tx_lock
);
5686 ath10k_mac_vif_tx_unlock_all(arvif
);
5687 spin_unlock_bh(&ar
->htt
.tx_lock
);
5689 ath10k_mac_txq_unref(ar
, vif
->txq
);
5692 mutex_unlock(&ar
->conf_mutex
);
5696 * FIXME: Has to be verified.
5698 #define SUPPORTED_FILTERS \
5703 FIF_BCN_PRBRESP_PROMISC | \
5707 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
5708 unsigned int changed_flags
,
5709 unsigned int *total_flags
,
5712 struct ath10k
*ar
= hw
->priv
;
5715 mutex_lock(&ar
->conf_mutex
);
5717 changed_flags
&= SUPPORTED_FILTERS
;
5718 *total_flags
&= SUPPORTED_FILTERS
;
5719 ar
->filter_flags
= *total_flags
;
5721 ret
= ath10k_monitor_recalc(ar
);
5723 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
5725 mutex_unlock(&ar
->conf_mutex
);
5728 static void ath10k_recalculate_mgmt_rate(struct ath10k
*ar
,
5729 struct ieee80211_vif
*vif
,
5730 struct cfg80211_chan_def
*def
)
5732 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5733 const struct ieee80211_supported_band
*sband
;
5740 lockdep_assert_held(&ar
->conf_mutex
);
5742 sband
= ar
->hw
->wiphy
->bands
[def
->chan
->band
];
5743 basic_rate_idx
= ffs(vif
->bss_conf
.basic_rates
) - 1;
5744 bitrate
= sband
->bitrates
[basic_rate_idx
].bitrate
;
5746 hw_rate_code
= ath10k_mac_get_rate_hw_value(bitrate
);
5747 if (hw_rate_code
< 0) {
5748 ath10k_warn(ar
, "bitrate not supported %d\n", bitrate
);
5752 vdev_param
= ar
->wmi
.vdev_param
->mgmt_rate
;
5753 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5756 ath10k_warn(ar
, "failed to set mgmt tx rate %d\n", ret
);
5759 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
5760 struct ieee80211_vif
*vif
,
5761 struct ieee80211_bss_conf
*info
,
5764 struct ath10k
*ar
= hw
->priv
;
5765 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
5766 struct cfg80211_chan_def def
;
5767 u32 vdev_param
, pdev_param
, slottime
, preamble
;
5768 u16 bitrate
, hw_value
;
5770 int ret
= 0, mcast_rate
;
5771 enum nl80211_band band
;
5773 mutex_lock(&ar
->conf_mutex
);
5775 if (changed
& BSS_CHANGED_IBSS
)
5776 ath10k_control_ibss(arvif
, info
, vif
->addr
);
5778 if (changed
& BSS_CHANGED_BEACON_INT
) {
5779 arvif
->beacon_interval
= info
->beacon_int
;
5780 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
5781 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5782 arvif
->beacon_interval
);
5783 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5784 "mac vdev %d beacon_interval %d\n",
5785 arvif
->vdev_id
, arvif
->beacon_interval
);
5788 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
5789 arvif
->vdev_id
, ret
);
5792 if (changed
& BSS_CHANGED_BEACON
) {
5793 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5794 "vdev %d set beacon tx mode to staggered\n",
5797 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
5798 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
5799 WMI_BEACON_STAGGERED_MODE
);
5801 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
5802 arvif
->vdev_id
, ret
);
5804 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
5806 ath10k_warn(ar
, "failed to update beacon template: %d\n",
5809 if (ieee80211_vif_is_mesh(vif
)) {
5810 /* mesh doesn't use SSID but firmware needs it */
5811 strncpy(arvif
->u
.ap
.ssid
, "mesh",
5812 sizeof(arvif
->u
.ap
.ssid
));
5813 arvif
->u
.ap
.ssid_len
= 4;
5817 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
5818 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
5820 ath10k_warn(ar
, "failed to setup probe resp template on vdev %i: %d\n",
5821 arvif
->vdev_id
, ret
);
5824 if (changed
& (BSS_CHANGED_BEACON_INFO
| BSS_CHANGED_BEACON
)) {
5825 arvif
->dtim_period
= info
->dtim_period
;
5827 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5828 "mac vdev %d dtim_period %d\n",
5829 arvif
->vdev_id
, arvif
->dtim_period
);
5831 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
5832 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5833 arvif
->dtim_period
);
5835 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
5836 arvif
->vdev_id
, ret
);
5839 if (changed
& BSS_CHANGED_SSID
&&
5840 vif
->type
== NL80211_IFTYPE_AP
) {
5841 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
5843 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
5844 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
5847 if (changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
))
5848 ether_addr_copy(arvif
->bssid
, info
->bssid
);
5850 if (changed
& BSS_CHANGED_FTM_RESPONDER
&&
5851 arvif
->ftm_responder
!= info
->ftm_responder
&&
5852 test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
)) {
5853 arvif
->ftm_responder
= info
->ftm_responder
;
5855 vdev_param
= ar
->wmi
.vdev_param
->rtt_responder_role
;
5856 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5857 arvif
->ftm_responder
);
5859 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5860 "mac vdev %d ftm_responder %d:ret %d\n",
5861 arvif
->vdev_id
, arvif
->ftm_responder
, ret
);
5864 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
5865 ath10k_control_beaconing(arvif
, info
);
5867 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
5868 arvif
->use_cts_prot
= info
->use_cts_prot
;
5870 ret
= ath10k_recalc_rtscts_prot(arvif
);
5872 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5873 arvif
->vdev_id
, ret
);
5875 if (ath10k_mac_can_set_cts_prot(arvif
)) {
5876 ret
= ath10k_mac_set_cts_prot(arvif
);
5878 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
5879 arvif
->vdev_id
, ret
);
5883 if (changed
& BSS_CHANGED_ERP_SLOT
) {
5884 if (info
->use_short_slot
)
5885 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
5888 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
5890 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
5891 arvif
->vdev_id
, slottime
);
5893 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
5894 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5897 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
5898 arvif
->vdev_id
, ret
);
5901 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
5902 if (info
->use_short_preamble
)
5903 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
5905 preamble
= WMI_VDEV_PREAMBLE_LONG
;
5907 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5908 "mac vdev %d preamble %dn",
5909 arvif
->vdev_id
, preamble
);
5911 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
5912 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
5915 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
5916 arvif
->vdev_id
, ret
);
5919 if (changed
& BSS_CHANGED_ASSOC
) {
5921 /* Workaround: Make sure monitor vdev is not running
5922 * when associating to prevent some firmware revisions
5923 * (e.g. 10.1 and 10.2) from crashing.
5925 if (ar
->monitor_started
)
5926 ath10k_monitor_stop(ar
);
5927 ath10k_bss_assoc(hw
, vif
, info
);
5928 ath10k_monitor_recalc(ar
);
5930 ath10k_bss_disassoc(hw
, vif
);
5934 if (changed
& BSS_CHANGED_TXPOWER
) {
5935 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev_id %i txpower %d\n",
5936 arvif
->vdev_id
, info
->txpower
);
5938 arvif
->txpower
= info
->txpower
;
5939 ret
= ath10k_mac_txpower_recalc(ar
);
5941 ath10k_warn(ar
, "failed to recalc tx power: %d\n", ret
);
5944 if (changed
& BSS_CHANGED_PS
) {
5945 arvif
->ps
= vif
->bss_conf
.ps
;
5947 ret
= ath10k_config_ps(ar
);
5949 ath10k_warn(ar
, "failed to setup ps on vdev %i: %d\n",
5950 arvif
->vdev_id
, ret
);
5953 if (changed
& BSS_CHANGED_MCAST_RATE
&&
5954 !ath10k_mac_vif_chan(arvif
->vif
, &def
)) {
5955 band
= def
.chan
->band
;
5956 mcast_rate
= vif
->bss_conf
.mcast_rate
[band
];
5958 rateidx
= mcast_rate
- 1;
5960 rateidx
= ffs(vif
->bss_conf
.basic_rates
) - 1;
5962 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
5963 rateidx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
5965 bitrate
= ath10k_wmi_legacy_rates
[rateidx
].bitrate
;
5966 hw_value
= ath10k_wmi_legacy_rates
[rateidx
].hw_value
;
5967 if (ath10k_mac_bitrate_is_cck(bitrate
))
5968 preamble
= WMI_RATE_PREAMBLE_CCK
;
5970 preamble
= WMI_RATE_PREAMBLE_OFDM
;
5972 rate
= ATH10K_HW_RATECODE(hw_value
, 0, preamble
);
5974 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
5975 "mac vdev %d mcast_rate %x\n",
5976 arvif
->vdev_id
, rate
);
5978 vdev_param
= ar
->wmi
.vdev_param
->mcast_data_rate
;
5979 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5983 "failed to set mcast rate on vdev %i: %d\n",
5984 arvif
->vdev_id
, ret
);
5986 vdev_param
= ar
->wmi
.vdev_param
->bcast_data_rate
;
5987 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
5991 "failed to set bcast rate on vdev %i: %d\n",
5992 arvif
->vdev_id
, ret
);
5995 if (changed
& BSS_CHANGED_BASIC_RATES
&&
5996 !ath10k_mac_vif_chan(arvif
->vif
, &def
))
5997 ath10k_recalculate_mgmt_rate(ar
, vif
, &def
);
5999 mutex_unlock(&ar
->conf_mutex
);
6002 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw
*hw
, s16 value
)
6004 struct ath10k
*ar
= hw
->priv
;
6006 /* This function should never be called if setting the coverage class
6007 * is not supported on this hardware.
6009 if (!ar
->hw_params
.hw_ops
->set_coverage_class
) {
6013 ar
->hw_params
.hw_ops
->set_coverage_class(ar
, value
);
6016 struct ath10k_mac_tdls_iter_data
{
6017 u32 num_tdls_stations
;
6018 struct ieee80211_vif
*curr_vif
;
6021 static void ath10k_mac_tdls_vif_stations_count_iter(void *data
,
6022 struct ieee80211_sta
*sta
)
6024 struct ath10k_mac_tdls_iter_data
*iter_data
= data
;
6025 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6026 struct ieee80211_vif
*sta_vif
= arsta
->arvif
->vif
;
6028 if (sta
->tdls
&& sta_vif
== iter_data
->curr_vif
)
6029 iter_data
->num_tdls_stations
++;
6032 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw
*hw
,
6033 struct ieee80211_vif
*vif
)
6035 struct ath10k_mac_tdls_iter_data data
= {};
6037 data
.curr_vif
= vif
;
6039 ieee80211_iterate_stations_atomic(hw
,
6040 ath10k_mac_tdls_vif_stations_count_iter
,
6042 return data
.num_tdls_stations
;
6045 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
6046 struct ieee80211_vif
*vif
,
6047 struct ieee80211_scan_request
*hw_req
)
6049 struct ath10k
*ar
= hw
->priv
;
6050 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6051 struct cfg80211_scan_request
*req
= &hw_req
->req
;
6052 struct wmi_start_scan_arg arg
;
6057 mutex_lock(&ar
->conf_mutex
);
6059 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
6064 spin_lock_bh(&ar
->data_lock
);
6065 switch (ar
->scan
.state
) {
6066 case ATH10K_SCAN_IDLE
:
6067 reinit_completion(&ar
->scan
.started
);
6068 reinit_completion(&ar
->scan
.completed
);
6069 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
6070 ar
->scan
.is_roc
= false;
6071 ar
->scan
.vdev_id
= arvif
->vdev_id
;
6074 case ATH10K_SCAN_STARTING
:
6075 case ATH10K_SCAN_RUNNING
:
6076 case ATH10K_SCAN_ABORTING
:
6080 spin_unlock_bh(&ar
->data_lock
);
6085 memset(&arg
, 0, sizeof(arg
));
6086 ath10k_wmi_start_scan_init(ar
, &arg
);
6087 arg
.vdev_id
= arvif
->vdev_id
;
6088 arg
.scan_id
= ATH10K_SCAN_ID
;
6091 arg
.ie_len
= req
->ie_len
;
6092 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
6096 arg
.n_ssids
= req
->n_ssids
;
6097 for (i
= 0; i
< arg
.n_ssids
; i
++) {
6098 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
6099 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
6102 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
6105 if (req
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6106 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ
;
6107 ether_addr_copy(arg
.mac_addr
.addr
, req
->mac_addr
);
6108 ether_addr_copy(arg
.mac_mask
.addr
, req
->mac_addr_mask
);
6111 if (req
->n_channels
) {
6112 arg
.n_channels
= req
->n_channels
;
6113 for (i
= 0; i
< arg
.n_channels
; i
++)
6114 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
6117 /* if duration is set, default dwell times will be overwritten */
6118 if (req
->duration
) {
6119 arg
.dwell_time_active
= req
->duration
;
6120 arg
.dwell_time_passive
= req
->duration
;
6121 arg
.burst_duration_ms
= req
->duration
;
6123 scan_timeout
= min_t(u32
, arg
.max_rest_time
*
6124 (arg
.n_channels
- 1) + (req
->duration
+
6125 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD
) *
6126 arg
.n_channels
, arg
.max_scan_time
+ 200);
6129 /* Add a 200ms margin to account for event/command processing */
6130 scan_timeout
= arg
.max_scan_time
+ 200;
6133 ret
= ath10k_start_scan(ar
, &arg
);
6135 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
6136 spin_lock_bh(&ar
->data_lock
);
6137 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
6138 spin_unlock_bh(&ar
->data_lock
);
6141 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
6142 msecs_to_jiffies(scan_timeout
));
6145 mutex_unlock(&ar
->conf_mutex
);
6149 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
6150 struct ieee80211_vif
*vif
)
6152 struct ath10k
*ar
= hw
->priv
;
6154 mutex_lock(&ar
->conf_mutex
);
6155 ath10k_scan_abort(ar
);
6156 mutex_unlock(&ar
->conf_mutex
);
6158 cancel_delayed_work_sync(&ar
->scan
.timeout
);
6161 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
6162 struct ath10k_vif
*arvif
,
6163 enum set_key_cmd cmd
,
6164 struct ieee80211_key_conf
*key
)
6166 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
6169 /* 10.1 firmware branch requires default key index to be set to group
6170 * key index after installing it. Otherwise FW/HW Txes corrupted
6171 * frames with multi-vif APs. This is not required for main firmware
6172 * branch (e.g. 636).
6174 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6176 * FIXME: It remains unknown if this is required for multi-vif STA
6177 * interfaces on 10.1.
6180 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
&&
6181 arvif
->vdev_type
!= WMI_VDEV_TYPE_IBSS
)
6184 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
6187 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
6190 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6196 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
6199 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
6200 arvif
->vdev_id
, ret
);
6203 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6204 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
6205 struct ieee80211_key_conf
*key
)
6207 struct ath10k
*ar
= hw
->priv
;
6208 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6209 struct ath10k_sta
*arsta
;
6210 struct ath10k_peer
*peer
;
6211 const u8
*peer_addr
;
6212 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
6213 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
6219 /* this one needs to be done in software */
6220 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
6221 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
6222 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
||
6223 key
->cipher
== WLAN_CIPHER_SUITE_BIP_CMAC_256
)
6226 if (arvif
->nohwcrypt
)
6229 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
6232 mutex_lock(&ar
->conf_mutex
);
6235 arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6236 peer_addr
= sta
->addr
;
6237 spin_lock_bh(&ar
->data_lock
);
6238 arsta
->ucast_cipher
= key
->cipher
;
6239 spin_unlock_bh(&ar
->data_lock
);
6240 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
6241 peer_addr
= vif
->bss_conf
.bssid
;
6243 peer_addr
= vif
->addr
;
6246 key
->hw_key_idx
= key
->keyidx
;
6250 arvif
->wep_keys
[key
->keyidx
] = key
;
6252 arvif
->wep_keys
[key
->keyidx
] = NULL
;
6255 /* the peer should not disappear in mid-way (unless FW goes awry) since
6256 * we already hold conf_mutex. we just make sure its there now.
6258 spin_lock_bh(&ar
->data_lock
);
6259 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6260 spin_unlock_bh(&ar
->data_lock
);
6263 if (cmd
== SET_KEY
) {
6264 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
6269 /* if the peer doesn't exist there is no key to disable anymore */
6274 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
6275 flags
|= WMI_KEY_PAIRWISE
;
6277 flags
|= WMI_KEY_GROUP
;
6280 if (cmd
== DISABLE_KEY
)
6281 ath10k_clear_vdev_key(arvif
, key
);
6283 /* When WEP keys are uploaded it's possible that there are
6284 * stations associated already (e.g. when merging) without any
6285 * keys. Static WEP needs an explicit per-peer key upload.
6287 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
6289 ath10k_mac_vif_update_wep_key(arvif
, key
);
6291 /* 802.1x never sets the def_wep_key_idx so each set_key()
6292 * call changes default tx key.
6294 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6295 * after first set_key().
6297 if (cmd
== SET_KEY
&& arvif
->def_wep_key_idx
== -1)
6298 flags
|= WMI_KEY_TX_USAGE
;
6301 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags
);
6304 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
6305 arvif
->vdev_id
, peer_addr
, ret
);
6309 /* mac80211 sets static WEP keys as groupwise while firmware requires
6310 * them to be installed twice as both pairwise and groupwise.
6312 if (is_wep
&& !sta
&& vif
->type
== NL80211_IFTYPE_STATION
) {
6314 flags2
&= ~WMI_KEY_GROUP
;
6315 flags2
|= WMI_KEY_PAIRWISE
;
6317 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
, flags2
);
6320 ath10k_warn(ar
, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6321 arvif
->vdev_id
, peer_addr
, ret
);
6322 ret2
= ath10k_install_key(arvif
, key
, DISABLE_KEY
,
6326 ath10k_warn(ar
, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6327 arvif
->vdev_id
, peer_addr
, ret2
);
6333 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
6335 spin_lock_bh(&ar
->data_lock
);
6336 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
6337 if (peer
&& cmd
== SET_KEY
)
6338 peer
->keys
[key
->keyidx
] = key
;
6339 else if (peer
&& cmd
== DISABLE_KEY
)
6340 peer
->keys
[key
->keyidx
] = NULL
;
6341 else if (peer
== NULL
)
6342 /* impossible unless FW goes crazy */
6343 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
6344 spin_unlock_bh(&ar
->data_lock
);
6346 if (sta
&& sta
->tdls
)
6347 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6348 ar
->wmi
.peer_param
->authorize
, 1);
6349 else if (sta
&& cmd
== SET_KEY
&& (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
6350 ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, peer_addr
,
6351 ar
->wmi
.peer_param
->authorize
, 1);
6354 mutex_unlock(&ar
->conf_mutex
);
6358 static void ath10k_set_default_unicast_key(struct ieee80211_hw
*hw
,
6359 struct ieee80211_vif
*vif
,
6362 struct ath10k
*ar
= hw
->priv
;
6363 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6366 mutex_lock(&arvif
->ar
->conf_mutex
);
6368 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
6371 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
6372 arvif
->vdev_id
, keyidx
);
6374 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
6376 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
6380 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
6386 arvif
->def_wep_key_idx
= keyidx
;
6389 mutex_unlock(&arvif
->ar
->conf_mutex
);
6392 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
6395 struct ath10k_vif
*arvif
;
6396 struct ath10k_sta
*arsta
;
6397 struct ieee80211_sta
*sta
;
6398 struct cfg80211_chan_def def
;
6399 enum nl80211_band band
;
6400 const u8
*ht_mcs_mask
;
6401 const u16
*vht_mcs_mask
;
6402 u32 changed
, bw
, nss
, smps
;
6405 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
6406 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
6407 arvif
= arsta
->arvif
;
6410 if (WARN_ON(ath10k_mac_vif_chan(arvif
->vif
, &def
)))
6413 band
= def
.chan
->band
;
6414 ht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].ht_mcs
;
6415 vht_mcs_mask
= arvif
->bitrate_mask
.control
[band
].vht_mcs
;
6417 spin_lock_bh(&ar
->data_lock
);
6419 changed
= arsta
->changed
;
6426 spin_unlock_bh(&ar
->data_lock
);
6428 mutex_lock(&ar
->conf_mutex
);
6430 nss
= max_t(u32
, 1, nss
);
6431 nss
= min(nss
, max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
6432 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
6434 if (changed
& IEEE80211_RC_BW_CHANGED
) {
6435 enum wmi_phy_mode mode
;
6437 mode
= chan_to_phymode(&def
);
6438 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d phymode %d\n",
6439 sta
->addr
, bw
, mode
);
6441 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6442 ar
->wmi
.peer_param
->phymode
, mode
);
6444 ath10k_warn(ar
, "failed to update STA %pM peer phymode %d: %d\n",
6445 sta
->addr
, mode
, err
);
6449 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6450 ar
->wmi
.peer_param
->chan_width
, bw
);
6452 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
6453 sta
->addr
, bw
, err
);
6456 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
6457 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
6460 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6461 ar
->wmi
.peer_param
->nss
, nss
);
6463 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
6464 sta
->addr
, nss
, err
);
6467 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
6468 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
6471 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6472 ar
->wmi
.peer_param
->smps_state
, smps
);
6474 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
6475 sta
->addr
, smps
, err
);
6478 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
6479 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates\n",
6482 err
= ath10k_station_assoc(ar
, arvif
->vif
, sta
, true);
6484 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
6489 mutex_unlock(&ar
->conf_mutex
);
6492 static int ath10k_mac_inc_num_stations(struct ath10k_vif
*arvif
,
6493 struct ieee80211_sta
*sta
)
6495 struct ath10k
*ar
= arvif
->ar
;
6497 lockdep_assert_held(&ar
->conf_mutex
);
6499 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6502 if (ar
->num_stations
>= ar
->max_num_stations
)
6510 static void ath10k_mac_dec_num_stations(struct ath10k_vif
*arvif
,
6511 struct ieee80211_sta
*sta
)
6513 struct ath10k
*ar
= arvif
->ar
;
6515 lockdep_assert_held(&ar
->conf_mutex
);
6517 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& !sta
->tdls
)
6523 static int ath10k_sta_set_txpwr(struct ieee80211_hw
*hw
,
6524 struct ieee80211_vif
*vif
,
6525 struct ieee80211_sta
*sta
)
6527 struct ath10k
*ar
= hw
->priv
;
6528 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6532 if (sta
->txpwr
.type
== NL80211_TX_POWER_AUTOMATIC
) {
6535 txpwr
= sta
->txpwr
.power
;
6540 if (txpwr
> ATH10K_TX_POWER_MAX_VAL
|| txpwr
< ATH10K_TX_POWER_MIN_VAL
)
6543 mutex_lock(&ar
->conf_mutex
);
6545 ret
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
6546 ar
->wmi
.peer_param
->use_fixed_power
, txpwr
);
6548 ath10k_warn(ar
, "failed to set tx power for station ret: %d\n",
6554 mutex_unlock(&ar
->conf_mutex
);
6558 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
6559 struct ieee80211_vif
*vif
,
6560 struct ieee80211_sta
*sta
,
6561 enum ieee80211_sta_state old_state
,
6562 enum ieee80211_sta_state new_state
)
6564 struct ath10k
*ar
= hw
->priv
;
6565 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6566 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
6567 struct ath10k_peer
*peer
;
6571 if (old_state
== IEEE80211_STA_NOTEXIST
&&
6572 new_state
== IEEE80211_STA_NONE
) {
6573 memset(arsta
, 0, sizeof(*arsta
));
6574 arsta
->arvif
= arvif
;
6575 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
6576 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
6578 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
6579 ath10k_mac_txq_init(sta
->txq
[i
]);
6582 /* cancel must be done outside the mutex to avoid deadlock */
6583 if ((old_state
== IEEE80211_STA_NONE
&&
6584 new_state
== IEEE80211_STA_NOTEXIST
))
6585 cancel_work_sync(&arsta
->update_wk
);
6587 mutex_lock(&ar
->conf_mutex
);
6589 if (old_state
== IEEE80211_STA_NOTEXIST
&&
6590 new_state
== IEEE80211_STA_NONE
) {
6592 * New station addition.
6594 enum wmi_peer_type peer_type
= WMI_PEER_TYPE_DEFAULT
;
6595 u32 num_tdls_stations
;
6597 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6598 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6599 arvif
->vdev_id
, sta
->addr
,
6600 ar
->num_stations
+ 1, ar
->max_num_stations
,
6601 ar
->num_peers
+ 1, ar
->max_num_peers
);
6603 num_tdls_stations
= ath10k_mac_tdls_vif_stations_count(hw
, vif
);
6606 if (num_tdls_stations
>= ar
->max_num_tdls_vdevs
) {
6607 ath10k_warn(ar
, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6609 ar
->max_num_tdls_vdevs
);
6613 peer_type
= WMI_PEER_TYPE_TDLS
;
6616 ret
= ath10k_mac_inc_num_stations(arvif
, sta
);
6618 ath10k_warn(ar
, "refusing to associate station: too many connected already (%d)\n",
6619 ar
->max_num_stations
);
6623 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
6624 arsta
->tx_stats
= kzalloc(sizeof(*arsta
->tx_stats
),
6626 if (!arsta
->tx_stats
) {
6627 ath10k_mac_dec_num_stations(arvif
, sta
);
6633 ret
= ath10k_peer_create(ar
, vif
, sta
, arvif
->vdev_id
,
6634 sta
->addr
, peer_type
);
6636 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6637 sta
->addr
, arvif
->vdev_id
, ret
);
6638 ath10k_mac_dec_num_stations(arvif
, sta
);
6639 kfree(arsta
->tx_stats
);
6643 spin_lock_bh(&ar
->data_lock
);
6645 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
6647 ath10k_warn(ar
, "failed to lookup peer %pM on vdev %i\n",
6648 vif
->addr
, arvif
->vdev_id
);
6649 spin_unlock_bh(&ar
->data_lock
);
6650 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
6651 ath10k_mac_dec_num_stations(arvif
, sta
);
6652 kfree(arsta
->tx_stats
);
6657 arsta
->peer_id
= find_first_bit(peer
->peer_ids
,
6658 ATH10K_MAX_NUM_PEER_IDS
);
6660 spin_unlock_bh(&ar
->data_lock
);
6665 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
6666 WMI_TDLS_ENABLE_ACTIVE
);
6668 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
6669 arvif
->vdev_id
, ret
);
6670 ath10k_peer_delete(ar
, arvif
->vdev_id
,
6672 ath10k_mac_dec_num_stations(arvif
, sta
);
6673 kfree(arsta
->tx_stats
);
6677 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
6678 WMI_TDLS_PEER_STATE_PEERING
);
6681 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6682 sta
->addr
, arvif
->vdev_id
, ret
);
6683 ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
6684 ath10k_mac_dec_num_stations(arvif
, sta
);
6685 kfree(arsta
->tx_stats
);
6687 if (num_tdls_stations
!= 0)
6689 ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
6692 } else if ((old_state
== IEEE80211_STA_NONE
&&
6693 new_state
== IEEE80211_STA_NOTEXIST
)) {
6695 * Existing station deletion.
6697 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
6698 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6699 arvif
->vdev_id
, sta
->addr
, sta
);
6702 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
,
6704 WMI_TDLS_PEER_STATE_TEARDOWN
);
6706 ath10k_warn(ar
, "failed to update tdls peer state for %pM state %d: %i\n",
6708 WMI_TDLS_PEER_STATE_TEARDOWN
, ret
);
6711 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
6713 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
6714 sta
->addr
, arvif
->vdev_id
, ret
);
6716 ath10k_mac_dec_num_stations(arvif
, sta
);
6718 spin_lock_bh(&ar
->data_lock
);
6719 for (i
= 0; i
< ARRAY_SIZE(ar
->peer_map
); i
++) {
6720 peer
= ar
->peer_map
[i
];
6724 if (peer
->sta
== sta
) {
6725 ath10k_warn(ar
, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6726 sta
->addr
, peer
, i
, arvif
->vdev_id
);
6729 /* Clean up the peer object as well since we
6730 * must have failed to do this above.
6732 list_del(&peer
->list
);
6733 ar
->peer_map
[i
] = NULL
;
6738 spin_unlock_bh(&ar
->data_lock
);
6740 if (ath10k_debug_is_extd_tx_stats_enabled(ar
)) {
6741 kfree(arsta
->tx_stats
);
6742 arsta
->tx_stats
= NULL
;
6745 for (i
= 0; i
< ARRAY_SIZE(sta
->txq
); i
++)
6746 ath10k_mac_txq_unref(ar
, sta
->txq
[i
]);
6751 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
))
6754 /* This was the last tdls peer in current vif */
6755 ret
= ath10k_wmi_update_fw_tdls_state(ar
, arvif
->vdev_id
,
6758 ath10k_warn(ar
, "failed to update fw tdls state on vdev %i: %i\n",
6759 arvif
->vdev_id
, ret
);
6761 } else if (old_state
== IEEE80211_STA_AUTH
&&
6762 new_state
== IEEE80211_STA_ASSOC
&&
6763 (vif
->type
== NL80211_IFTYPE_AP
||
6764 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
6765 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
6769 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
6772 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
6774 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
6775 sta
->addr
, arvif
->vdev_id
, ret
);
6776 } else if (old_state
== IEEE80211_STA_ASSOC
&&
6777 new_state
== IEEE80211_STA_AUTHORIZED
&&
6780 * Tdls station authorized.
6782 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac tdls sta %pM authorized\n",
6785 ret
= ath10k_station_assoc(ar
, vif
, sta
, false);
6787 ath10k_warn(ar
, "failed to associate tdls station %pM for vdev %i: %i\n",
6788 sta
->addr
, arvif
->vdev_id
, ret
);
6792 ret
= ath10k_mac_tdls_peer_update(ar
, arvif
->vdev_id
, sta
,
6793 WMI_TDLS_PEER_STATE_CONNECTED
);
6795 ath10k_warn(ar
, "failed to update tdls peer %pM for vdev %i: %i\n",
6796 sta
->addr
, arvif
->vdev_id
, ret
);
6797 } else if (old_state
== IEEE80211_STA_ASSOC
&&
6798 new_state
== IEEE80211_STA_AUTH
&&
6799 (vif
->type
== NL80211_IFTYPE_AP
||
6800 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
6801 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
6805 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
6808 ret
= ath10k_station_disassoc(ar
, vif
, sta
);
6810 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
6811 sta
->addr
, arvif
->vdev_id
, ret
);
6814 mutex_unlock(&ar
->conf_mutex
);
6818 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
6819 u16 ac
, bool enable
)
6821 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6822 struct wmi_sta_uapsd_auto_trig_arg arg
= {};
6823 u32 prio
= 0, acc
= 0;
6827 lockdep_assert_held(&ar
->conf_mutex
);
6829 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
6833 case IEEE80211_AC_VO
:
6834 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
6835 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
6839 case IEEE80211_AC_VI
:
6840 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
6841 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
6845 case IEEE80211_AC_BE
:
6846 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
6847 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
6851 case IEEE80211_AC_BK
:
6852 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
6853 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
6860 arvif
->u
.sta
.uapsd
|= value
;
6862 arvif
->u
.sta
.uapsd
&= ~value
;
6864 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
6865 WMI_STA_PS_PARAM_UAPSD
,
6866 arvif
->u
.sta
.uapsd
);
6868 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
6872 if (arvif
->u
.sta
.uapsd
)
6873 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
6875 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
6877 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
6878 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
6881 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
6883 ret
= ath10k_mac_vif_recalc_ps_wake_threshold(arvif
);
6885 ath10k_warn(ar
, "failed to recalc ps wake threshold on vdev %i: %d\n",
6886 arvif
->vdev_id
, ret
);
6890 ret
= ath10k_mac_vif_recalc_ps_poll_count(arvif
);
6892 ath10k_warn(ar
, "failed to recalc ps poll count on vdev %i: %d\n",
6893 arvif
->vdev_id
, ret
);
6897 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG
, ar
->wmi
.svc_map
) ||
6898 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG
, ar
->wmi
.svc_map
)) {
6899 /* Only userspace can make an educated decision when to send
6900 * trigger frame. The following effectively disables u-UAPSD
6901 * autotrigger in firmware (which is enabled by default
6902 * provided the autotrigger service is available).
6906 arg
.user_priority
= prio
;
6907 arg
.service_interval
= 0;
6908 arg
.suspend_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
6909 arg
.delay_interval
= WMI_STA_UAPSD_MAX_INTERVAL_MSEC
;
6911 ret
= ath10k_wmi_vdev_sta_uapsd(ar
, arvif
->vdev_id
,
6912 arvif
->bssid
, &arg
, 1);
6914 ath10k_warn(ar
, "failed to set uapsd auto trigger %d\n",
6924 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
6925 struct ieee80211_vif
*vif
, u16 ac
,
6926 const struct ieee80211_tx_queue_params
*params
)
6928 struct ath10k
*ar
= hw
->priv
;
6929 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
6930 struct wmi_wmm_params_arg
*p
= NULL
;
6933 mutex_lock(&ar
->conf_mutex
);
6936 case IEEE80211_AC_VO
:
6937 p
= &arvif
->wmm_params
.ac_vo
;
6939 case IEEE80211_AC_VI
:
6940 p
= &arvif
->wmm_params
.ac_vi
;
6942 case IEEE80211_AC_BE
:
6943 p
= &arvif
->wmm_params
.ac_be
;
6945 case IEEE80211_AC_BK
:
6946 p
= &arvif
->wmm_params
.ac_bk
;
6955 p
->cwmin
= params
->cw_min
;
6956 p
->cwmax
= params
->cw_max
;
6957 p
->aifs
= params
->aifs
;
6960 * The channel time duration programmed in the HW is in absolute
6961 * microseconds, while mac80211 gives the txop in units of
6964 p
->txop
= params
->txop
* 32;
6966 if (ar
->wmi
.ops
->gen_vdev_wmm_conf
) {
6967 ret
= ath10k_wmi_vdev_wmm_conf(ar
, arvif
->vdev_id
,
6968 &arvif
->wmm_params
);
6970 ath10k_warn(ar
, "failed to set vdev wmm params on vdev %i: %d\n",
6971 arvif
->vdev_id
, ret
);
6975 /* This won't work well with multi-interface cases but it's
6976 * better than nothing.
6978 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &arvif
->wmm_params
);
6980 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
6985 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
6987 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
6990 mutex_unlock(&ar
->conf_mutex
);
6994 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6996 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
6997 struct ieee80211_vif
*vif
,
6998 struct ieee80211_channel
*chan
,
7000 enum ieee80211_roc_type type
)
7002 struct ath10k
*ar
= hw
->priv
;
7003 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7004 struct wmi_start_scan_arg arg
;
7008 mutex_lock(&ar
->conf_mutex
);
7010 if (ath10k_mac_tdls_vif_stations_count(hw
, vif
) > 0) {
7015 spin_lock_bh(&ar
->data_lock
);
7016 switch (ar
->scan
.state
) {
7017 case ATH10K_SCAN_IDLE
:
7018 reinit_completion(&ar
->scan
.started
);
7019 reinit_completion(&ar
->scan
.completed
);
7020 reinit_completion(&ar
->scan
.on_channel
);
7021 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
7022 ar
->scan
.is_roc
= true;
7023 ar
->scan
.vdev_id
= arvif
->vdev_id
;
7024 ar
->scan
.roc_freq
= chan
->center_freq
;
7025 ar
->scan
.roc_notify
= true;
7028 case ATH10K_SCAN_STARTING
:
7029 case ATH10K_SCAN_RUNNING
:
7030 case ATH10K_SCAN_ABORTING
:
7034 spin_unlock_bh(&ar
->data_lock
);
7039 scan_time_msec
= ar
->hw
->wiphy
->max_remain_on_channel_duration
* 2;
7041 memset(&arg
, 0, sizeof(arg
));
7042 ath10k_wmi_start_scan_init(ar
, &arg
);
7043 arg
.vdev_id
= arvif
->vdev_id
;
7044 arg
.scan_id
= ATH10K_SCAN_ID
;
7046 arg
.channels
[0] = chan
->center_freq
;
7047 arg
.dwell_time_active
= scan_time_msec
;
7048 arg
.dwell_time_passive
= scan_time_msec
;
7049 arg
.max_scan_time
= scan_time_msec
;
7050 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
7051 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
7052 arg
.burst_duration_ms
= duration
;
7054 ret
= ath10k_start_scan(ar
, &arg
);
7056 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
7057 spin_lock_bh(&ar
->data_lock
);
7058 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
7059 spin_unlock_bh(&ar
->data_lock
);
7063 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3 * HZ
);
7065 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
7067 ret
= ath10k_scan_stop(ar
);
7069 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
7075 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
7076 msecs_to_jiffies(duration
));
7080 mutex_unlock(&ar
->conf_mutex
);
7084 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
,
7085 struct ieee80211_vif
*vif
)
7087 struct ath10k
*ar
= hw
->priv
;
7089 mutex_lock(&ar
->conf_mutex
);
7091 spin_lock_bh(&ar
->data_lock
);
7092 ar
->scan
.roc_notify
= false;
7093 spin_unlock_bh(&ar
->data_lock
);
7095 ath10k_scan_abort(ar
);
7097 mutex_unlock(&ar
->conf_mutex
);
7099 cancel_delayed_work_sync(&ar
->scan
.timeout
);
7105 * Both RTS and Fragmentation threshold are interface-specific
7106 * in ath10k, but device-specific in mac80211.
7109 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
7111 struct ath10k
*ar
= hw
->priv
;
7112 struct ath10k_vif
*arvif
;
7115 mutex_lock(&ar
->conf_mutex
);
7116 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
7117 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
7118 arvif
->vdev_id
, value
);
7120 ret
= ath10k_mac_set_rts(arvif
, value
);
7122 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
7123 arvif
->vdev_id
, ret
);
7127 mutex_unlock(&ar
->conf_mutex
);
7132 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
7134 /* Even though there's a WMI enum for fragmentation threshold no known
7135 * firmware actually implements it. Moreover it is not possible to rely
7136 * frame fragmentation to mac80211 because firmware clears the "more
7137 * fragments" bit in frame control making it impossible for remote
7138 * devices to reassemble frames.
7140 * Hence implement a dummy callback just to say fragmentation isn't
7141 * supported. This effectively prevents mac80211 from doing frame
7142 * fragmentation in software.
7147 void ath10k_mac_wait_tx_complete(struct ath10k
*ar
)
7152 /* mac80211 doesn't care if we really xmit queued frames or not
7153 * we'll collect those frames either way if we stop/delete vdevs
7156 if (ar
->state
== ATH10K_STATE_WEDGED
)
7159 time_left
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
7162 spin_lock_bh(&ar
->htt
.tx_lock
);
7163 empty
= (ar
->htt
.num_pending_tx
== 0);
7164 spin_unlock_bh(&ar
->htt
.tx_lock
);
7166 skip
= (ar
->state
== ATH10K_STATE_WEDGED
) ||
7167 test_bit(ATH10K_FLAG_CRASH_FLUSH
,
7171 }), ATH10K_FLUSH_TIMEOUT_HZ
);
7173 if (time_left
== 0 || skip
)
7174 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
7175 skip
, ar
->state
, time_left
);
7178 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
7179 u32 queues
, bool drop
)
7181 struct ath10k
*ar
= hw
->priv
;
7182 struct ath10k_vif
*arvif
;
7186 if (vif
&& vif
->type
== NL80211_IFTYPE_STATION
) {
7187 bitmap
= ~(1 << WMI_MGMT_TID
);
7188 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
7189 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
7190 ath10k_wmi_peer_flush(ar
, arvif
->vdev_id
,
7191 arvif
->bssid
, bitmap
);
7197 mutex_lock(&ar
->conf_mutex
);
7198 ath10k_mac_wait_tx_complete(ar
);
7199 mutex_unlock(&ar
->conf_mutex
);
7202 /* TODO: Implement this function properly
7203 * For now it is needed to reply to Probe Requests in IBSS mode.
7204 * Propably we need this information from FW.
7206 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
7211 static void ath10k_reconfig_complete(struct ieee80211_hw
*hw
,
7212 enum ieee80211_reconfig_type reconfig_type
)
7214 struct ath10k
*ar
= hw
->priv
;
7216 if (reconfig_type
!= IEEE80211_RECONFIG_TYPE_RESTART
)
7219 mutex_lock(&ar
->conf_mutex
);
7221 /* If device failed to restart it will be in a different state, e.g.
7222 * ATH10K_STATE_WEDGED
7224 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
7225 ath10k_info(ar
, "device successfully recovered\n");
7226 ar
->state
= ATH10K_STATE_ON
;
7227 ieee80211_wake_queues(ar
->hw
);
7230 mutex_unlock(&ar
->conf_mutex
);
7234 ath10k_mac_update_bss_chan_survey(struct ath10k
*ar
,
7235 struct ieee80211_channel
*channel
)
7238 enum wmi_bss_survey_req_type type
= WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR
;
7240 lockdep_assert_held(&ar
->conf_mutex
);
7242 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64
, ar
->wmi
.svc_map
) ||
7243 (ar
->rx_channel
!= channel
))
7246 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
) {
7247 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "ignoring bss chan info request while scanning..\n");
7251 reinit_completion(&ar
->bss_survey_done
);
7253 ret
= ath10k_wmi_pdev_bss_chan_info_request(ar
, type
);
7255 ath10k_warn(ar
, "failed to send pdev bss chan info request\n");
7259 ret
= wait_for_completion_timeout(&ar
->bss_survey_done
, 3 * HZ
);
7261 ath10k_warn(ar
, "bss channel survey timed out\n");
7266 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
7267 struct survey_info
*survey
)
7269 struct ath10k
*ar
= hw
->priv
;
7270 struct ieee80211_supported_band
*sband
;
7271 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
7274 mutex_lock(&ar
->conf_mutex
);
7276 sband
= hw
->wiphy
->bands
[NL80211_BAND_2GHZ
];
7277 if (sband
&& idx
>= sband
->n_channels
) {
7278 idx
-= sband
->n_channels
;
7283 sband
= hw
->wiphy
->bands
[NL80211_BAND_5GHZ
];
7285 if (!sband
|| idx
>= sband
->n_channels
) {
7290 ath10k_mac_update_bss_chan_survey(ar
, &sband
->channels
[idx
]);
7292 spin_lock_bh(&ar
->data_lock
);
7293 memcpy(survey
, ar_survey
, sizeof(*survey
));
7294 spin_unlock_bh(&ar
->data_lock
);
7296 survey
->channel
= &sband
->channels
[idx
];
7298 if (ar
->rx_channel
== survey
->channel
)
7299 survey
->filled
|= SURVEY_INFO_IN_USE
;
7302 mutex_unlock(&ar
->conf_mutex
);
7307 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k
*ar
,
7308 enum nl80211_band band
,
7309 const struct cfg80211_bitrate_mask
*mask
,
7315 num_rates
+= hweight32(mask
->control
[band
].legacy
);
7317 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++)
7318 num_rates
+= hweight8(mask
->control
[band
].ht_mcs
[i
]);
7321 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
7322 tmp
= hweight16(mask
->control
[band
].vht_mcs
[i
]);
7324 *vht_num_rates
+= tmp
;
7327 return num_rates
== 1;
7331 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k
*ar
,
7332 enum nl80211_band band
,
7333 const struct cfg80211_bitrate_mask
*mask
,
7336 struct ieee80211_supported_band
*sband
= &ar
->mac
.sbands
[band
];
7337 u16 vht_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
7339 u8 vht_nss_mask
= 0;
7342 if (mask
->control
[band
].legacy
)
7345 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
7346 if (mask
->control
[band
].ht_mcs
[i
] == 0)
7348 else if (mask
->control
[band
].ht_mcs
[i
] ==
7349 sband
->ht_cap
.mcs
.rx_mask
[i
])
7350 ht_nss_mask
|= BIT(i
);
7355 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
7356 if (mask
->control
[band
].vht_mcs
[i
] == 0)
7358 else if (mask
->control
[band
].vht_mcs
[i
] ==
7359 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map
, i
))
7360 vht_nss_mask
|= BIT(i
);
7365 if (ht_nss_mask
!= vht_nss_mask
)
7368 if (ht_nss_mask
== 0)
7371 if (BIT(fls(ht_nss_mask
)) - 1 != ht_nss_mask
)
7374 *nss
= fls(ht_nss_mask
);
7380 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k
*ar
,
7381 enum nl80211_band band
,
7382 const struct cfg80211_bitrate_mask
*mask
,
7383 u8
*rate
, u8
*nss
, bool vht_only
)
7394 if (hweight32(mask
->control
[band
].legacy
) == 1) {
7395 rate_idx
= ffs(mask
->control
[band
].legacy
) - 1;
7397 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
)
7398 rate_idx
+= ATH10K_MAC_FIRST_OFDM_RATE_IDX
;
7400 hw_rate
= ath10k_wmi_legacy_rates
[rate_idx
].hw_value
;
7401 bitrate
= ath10k_wmi_legacy_rates
[rate_idx
].bitrate
;
7403 if (ath10k_mac_bitrate_is_cck(bitrate
))
7404 preamble
= WMI_RATE_PREAMBLE_CCK
;
7406 preamble
= WMI_RATE_PREAMBLE_OFDM
;
7409 *rate
= preamble
<< 6 |
7416 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].ht_mcs
); i
++) {
7417 if (hweight8(mask
->control
[band
].ht_mcs
[i
]) == 1) {
7419 *rate
= WMI_RATE_PREAMBLE_HT
<< 6 |
7421 (ffs(mask
->control
[band
].ht_mcs
[i
]) - 1);
7428 for (i
= 0; i
< ARRAY_SIZE(mask
->control
[band
].vht_mcs
); i
++) {
7429 if (hweight16(mask
->control
[band
].vht_mcs
[i
]) == 1) {
7431 *rate
= WMI_RATE_PREAMBLE_VHT
<< 6 |
7433 (ffs(mask
->control
[band
].vht_mcs
[i
]) - 1);
7442 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif
*arvif
,
7443 u8 rate
, u8 nss
, u8 sgi
, u8 ldpc
)
7445 struct ath10k
*ar
= arvif
->ar
;
7449 lockdep_assert_held(&ar
->conf_mutex
);
7451 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7452 arvif
->vdev_id
, rate
, nss
, sgi
);
7454 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
7455 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, rate
);
7457 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
7462 vdev_param
= ar
->wmi
.vdev_param
->nss
;
7463 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, nss
);
7465 ath10k_warn(ar
, "failed to set nss param %d: %d\n", nss
, ret
);
7469 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
7470 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, sgi
);
7472 ath10k_warn(ar
, "failed to set sgi param %d: %d\n", sgi
, ret
);
7476 vdev_param
= ar
->wmi
.vdev_param
->ldpc
;
7477 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, ldpc
);
7479 ath10k_warn(ar
, "failed to set ldpc param %d: %d\n", ldpc
, ret
);
7487 ath10k_mac_can_set_bitrate_mask(struct ath10k
*ar
,
7488 enum nl80211_band band
,
7489 const struct cfg80211_bitrate_mask
*mask
,
7495 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7496 * to express all VHT MCS rate masks. Effectively only the following
7497 * ranges can be used: none, 0-7, 0-8 and 0-9.
7499 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
7500 vht_mcs
= mask
->control
[band
].vht_mcs
[i
];
7510 ath10k_warn(ar
, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7518 static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k
*ar
,
7519 struct ath10k_vif
*arvif
,
7520 struct ieee80211_sta
*sta
)
7523 u8 rate
= arvif
->vht_pfr
;
7525 /* skip non vht and multiple rate peers */
7526 if (!sta
->vht_cap
.vht_supported
|| arvif
->vht_num_rates
!= 1)
7529 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
7530 WMI_PEER_PARAM_FIXED_RATE
, rate
);
7532 ath10k_warn(ar
, "failed to enable STA %pM peer fixed rate: %d\n",
7538 static void ath10k_mac_set_bitrate_mask_iter(void *data
,
7539 struct ieee80211_sta
*sta
)
7541 struct ath10k_vif
*arvif
= data
;
7542 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7543 struct ath10k
*ar
= arvif
->ar
;
7545 if (arsta
->arvif
!= arvif
)
7548 if (ath10k_mac_set_vht_bitrate_mask_fixup(ar
, arvif
, sta
))
7551 spin_lock_bh(&ar
->data_lock
);
7552 arsta
->changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
7553 spin_unlock_bh(&ar
->data_lock
);
7555 ieee80211_queue_work(ar
->hw
, &arsta
->update_wk
);
7558 static void ath10k_mac_clr_bitrate_mask_iter(void *data
,
7559 struct ieee80211_sta
*sta
)
7561 struct ath10k_vif
*arvif
= data
;
7562 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7563 struct ath10k
*ar
= arvif
->ar
;
7566 /* clear vht peers only */
7567 if (arsta
->arvif
!= arvif
|| !sta
->vht_cap
.vht_supported
)
7570 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
7571 WMI_PEER_PARAM_FIXED_RATE
,
7572 WMI_FIXED_RATE_NONE
);
7574 ath10k_warn(ar
, "failed to clear STA %pM peer fixed rate: %d\n",
7578 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw
*hw
,
7579 struct ieee80211_vif
*vif
,
7580 const struct cfg80211_bitrate_mask
*mask
)
7582 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7583 struct cfg80211_chan_def def
;
7584 struct ath10k
*ar
= arvif
->ar
;
7585 enum nl80211_band band
;
7586 const u8
*ht_mcs_mask
;
7587 const u16
*vht_mcs_mask
;
7594 int vht_num_rates
, allow_pfr
;
7596 bool update_bitrate_mask
= true;
7598 if (ath10k_mac_vif_chan(vif
, &def
))
7601 band
= def
.chan
->band
;
7602 ht_mcs_mask
= mask
->control
[band
].ht_mcs
;
7603 vht_mcs_mask
= mask
->control
[band
].vht_mcs
;
7604 ldpc
= !!(ar
->ht_cap_info
& WMI_HT_CAP_LDPC
);
7606 sgi
= mask
->control
[band
].gi
;
7607 if (sgi
== NL80211_TXRATE_FORCE_LGI
)
7610 allow_pfr
= test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE
,
7611 ar
->normal_mode_fw
.fw_file
.fw_features
);
7613 mutex_lock(&ar
->conf_mutex
);
7614 ieee80211_iterate_stations_atomic(ar
->hw
,
7615 ath10k_mac_clr_bitrate_mask_iter
,
7617 mutex_unlock(&ar
->conf_mutex
);
7620 if (ath10k_mac_bitrate_mask_has_single_rate(ar
, band
, mask
,
7622 ret
= ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
7626 ath10k_warn(ar
, "failed to get single rate for vdev %i: %d\n",
7627 arvif
->vdev_id
, ret
);
7630 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar
, band
, mask
,
7632 rate
= WMI_FIXED_RATE_NONE
;
7635 rate
= WMI_FIXED_RATE_NONE
;
7636 nss
= min(ar
->num_rf_chains
,
7637 max(ath10k_mac_max_ht_nss(ht_mcs_mask
),
7638 ath10k_mac_max_vht_nss(vht_mcs_mask
)));
7640 if (!ath10k_mac_can_set_bitrate_mask(ar
, band
, mask
,
7644 if (!allow_pfr
|| vht_num_rates
!= 1)
7647 /* Reach here, firmware supports peer fixed rate and has
7648 * single vht rate, and don't update vif birate_mask, as
7649 * the rate only for specific peer.
7651 ath10k_mac_bitrate_mask_get_single_rate(ar
, band
, mask
,
7655 update_bitrate_mask
= false;
7660 mutex_lock(&ar
->conf_mutex
);
7662 if (update_bitrate_mask
)
7663 arvif
->bitrate_mask
= *mask
;
7664 arvif
->vht_num_rates
= vht_num_rates
;
7665 arvif
->vht_pfr
= vht_pfr
;
7666 ieee80211_iterate_stations_atomic(ar
->hw
,
7667 ath10k_mac_set_bitrate_mask_iter
,
7670 mutex_unlock(&ar
->conf_mutex
);
7673 mutex_lock(&ar
->conf_mutex
);
7675 ret
= ath10k_mac_set_fixed_rate_params(arvif
, rate
, nss
, sgi
, ldpc
);
7677 ath10k_warn(ar
, "failed to set fixed rate params on vdev %i: %d\n",
7678 arvif
->vdev_id
, ret
);
7683 mutex_unlock(&ar
->conf_mutex
);
7688 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
7689 struct ieee80211_vif
*vif
,
7690 struct ieee80211_sta
*sta
,
7693 struct ath10k
*ar
= hw
->priv
;
7694 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
7695 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7696 struct ath10k_peer
*peer
;
7699 spin_lock_bh(&ar
->data_lock
);
7701 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, sta
->addr
);
7703 spin_unlock_bh(&ar
->data_lock
);
7704 ath10k_warn(ar
, "mac sta rc update failed to find peer %pM on vdev %i\n",
7705 sta
->addr
, arvif
->vdev_id
);
7709 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
7710 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7711 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
7714 if (changed
& IEEE80211_RC_BW_CHANGED
) {
7715 bw
= WMI_PEER_CHWIDTH_20MHZ
;
7717 switch (sta
->bandwidth
) {
7718 case IEEE80211_STA_RX_BW_20
:
7719 bw
= WMI_PEER_CHWIDTH_20MHZ
;
7721 case IEEE80211_STA_RX_BW_40
:
7722 bw
= WMI_PEER_CHWIDTH_40MHZ
;
7724 case IEEE80211_STA_RX_BW_80
:
7725 bw
= WMI_PEER_CHWIDTH_80MHZ
;
7727 case IEEE80211_STA_RX_BW_160
:
7728 bw
= WMI_PEER_CHWIDTH_160MHZ
;
7731 ath10k_warn(ar
, "Invalid bandwidth %d in rc update for %pM\n",
7732 sta
->bandwidth
, sta
->addr
);
7733 bw
= WMI_PEER_CHWIDTH_20MHZ
;
7740 if (changed
& IEEE80211_RC_NSS_CHANGED
)
7741 arsta
->nss
= sta
->rx_nss
;
7743 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
7744 smps
= WMI_PEER_SMPS_PS_NONE
;
7746 switch (sta
->smps_mode
) {
7747 case IEEE80211_SMPS_AUTOMATIC
:
7748 case IEEE80211_SMPS_OFF
:
7749 smps
= WMI_PEER_SMPS_PS_NONE
;
7751 case IEEE80211_SMPS_STATIC
:
7752 smps
= WMI_PEER_SMPS_STATIC
;
7754 case IEEE80211_SMPS_DYNAMIC
:
7755 smps
= WMI_PEER_SMPS_DYNAMIC
;
7757 case IEEE80211_SMPS_NUM_MODES
:
7758 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
7759 sta
->smps_mode
, sta
->addr
);
7760 smps
= WMI_PEER_SMPS_PS_NONE
;
7767 arsta
->changed
|= changed
;
7769 spin_unlock_bh(&ar
->data_lock
);
7771 ieee80211_queue_work(hw
, &arsta
->update_wk
);
7774 static void ath10k_offset_tsf(struct ieee80211_hw
*hw
,
7775 struct ieee80211_vif
*vif
, s64 tsf_offset
)
7777 struct ath10k
*ar
= hw
->priv
;
7778 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7779 u32 offset
, vdev_param
;
7782 if (tsf_offset
< 0) {
7783 vdev_param
= ar
->wmi
.vdev_param
->dec_tsf
;
7784 offset
= -tsf_offset
;
7786 vdev_param
= ar
->wmi
.vdev_param
->inc_tsf
;
7787 offset
= tsf_offset
;
7790 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
7791 vdev_param
, offset
);
7793 if (ret
&& ret
!= -EOPNOTSUPP
)
7794 ath10k_warn(ar
, "failed to set tsf offset %d cmd %d: %d\n",
7795 offset
, vdev_param
, ret
);
7798 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
7799 struct ieee80211_vif
*vif
,
7800 struct ieee80211_ampdu_params
*params
)
7802 struct ath10k
*ar
= hw
->priv
;
7803 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
7804 struct ieee80211_sta
*sta
= params
->sta
;
7805 enum ieee80211_ampdu_mlme_action action
= params
->action
;
7806 u16 tid
= params
->tid
;
7808 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7809 arvif
->vdev_id
, sta
->addr
, tid
, action
);
7812 case IEEE80211_AMPDU_RX_START
:
7813 case IEEE80211_AMPDU_RX_STOP
:
7814 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7815 * creation/removal. Do we need to verify this?
7818 case IEEE80211_AMPDU_TX_START
:
7819 case IEEE80211_AMPDU_TX_STOP_CONT
:
7820 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
7821 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
7822 case IEEE80211_AMPDU_TX_OPERATIONAL
:
7823 /* Firmware offloads Tx aggregation entirely so deny mac80211
7824 * Tx aggregation requests.
7833 ath10k_mac_update_rx_channel(struct ath10k
*ar
,
7834 struct ieee80211_chanctx_conf
*ctx
,
7835 struct ieee80211_vif_chanctx_switch
*vifs
,
7838 struct cfg80211_chan_def
*def
= NULL
;
7840 /* Both locks are required because ar->rx_channel is modified. This
7841 * allows readers to hold either lock.
7843 lockdep_assert_held(&ar
->conf_mutex
);
7844 lockdep_assert_held(&ar
->data_lock
);
7846 WARN_ON(ctx
&& vifs
);
7847 WARN_ON(vifs
&& !n_vifs
);
7849 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7850 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7851 * ppdu on Rx may reduce performance on low-end systems. It should be
7852 * possible to make tables/hashmaps to speed the lookup up (be vary of
7853 * cpu data cache lines though regarding sizes) but to keep the initial
7854 * implementation simple and less intrusive fallback to the slow lookup
7855 * only for multi-channel cases. Single-channel cases will remain to
7856 * use the old channel derival and thus performance should not be
7860 if (!ctx
&& ath10k_mac_num_chanctxs(ar
) == 1) {
7861 ieee80211_iter_chan_contexts_atomic(ar
->hw
,
7862 ath10k_mac_get_any_chandef_iter
,
7866 def
= &vifs
[0].new_ctx
->def
;
7868 ar
->rx_channel
= def
->chan
;
7869 } else if ((ctx
&& ath10k_mac_num_chanctxs(ar
) == 0) ||
7870 (ctx
&& (ar
->state
== ATH10K_STATE_RESTARTED
))) {
7871 /* During driver restart due to firmware assert, since mac80211
7872 * already has valid channel context for given radio, channel
7873 * context iteration return num_chanctx > 0. So fix rx_channel
7874 * when restart is in progress.
7876 ar
->rx_channel
= ctx
->def
.chan
;
7878 ar
->rx_channel
= NULL
;
7884 ath10k_mac_update_vif_chan(struct ath10k
*ar
,
7885 struct ieee80211_vif_chanctx_switch
*vifs
,
7888 struct ath10k_vif
*arvif
;
7892 lockdep_assert_held(&ar
->conf_mutex
);
7894 /* First stop monitor interface. Some FW versions crash if there's a
7895 * lone monitor interface.
7897 if (ar
->monitor_started
)
7898 ath10k_monitor_stop(ar
);
7900 for (i
= 0; i
< n_vifs
; i
++) {
7901 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
7903 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
7904 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7906 vifs
[i
].old_ctx
->def
.chan
->center_freq
,
7907 vifs
[i
].new_ctx
->def
.chan
->center_freq
,
7908 vifs
[i
].old_ctx
->def
.width
,
7909 vifs
[i
].new_ctx
->def
.width
);
7911 if (WARN_ON(!arvif
->is_started
))
7914 if (WARN_ON(!arvif
->is_up
))
7917 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
7919 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
7920 arvif
->vdev_id
, ret
);
7925 /* All relevant vdevs are downed and associated channel resources
7926 * should be available for the channel switch now.
7929 spin_lock_bh(&ar
->data_lock
);
7930 ath10k_mac_update_rx_channel(ar
, NULL
, vifs
, n_vifs
);
7931 spin_unlock_bh(&ar
->data_lock
);
7933 for (i
= 0; i
< n_vifs
; i
++) {
7934 arvif
= (void *)vifs
[i
].vif
->drv_priv
;
7936 if (WARN_ON(!arvif
->is_started
))
7939 if (WARN_ON(!arvif
->is_up
))
7942 ret
= ath10k_mac_setup_bcn_tmpl(arvif
);
7944 ath10k_warn(ar
, "failed to update bcn tmpl during csa: %d\n",
7947 ret
= ath10k_mac_setup_prb_tmpl(arvif
);
7949 ath10k_warn(ar
, "failed to update prb tmpl during csa: %d\n",
7952 ret
= ath10k_vdev_restart(arvif
, &vifs
[i
].new_ctx
->def
);
7954 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
7955 arvif
->vdev_id
, ret
);
7959 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
7962 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
7963 arvif
->vdev_id
, ret
);
7968 ath10k_monitor_recalc(ar
);
7972 ath10k_mac_op_add_chanctx(struct ieee80211_hw
*hw
,
7973 struct ieee80211_chanctx_conf
*ctx
)
7975 struct ath10k
*ar
= hw
->priv
;
7977 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
7978 "mac chanctx add freq %hu width %d ptr %pK\n",
7979 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
7981 mutex_lock(&ar
->conf_mutex
);
7983 spin_lock_bh(&ar
->data_lock
);
7984 ath10k_mac_update_rx_channel(ar
, ctx
, NULL
, 0);
7985 spin_unlock_bh(&ar
->data_lock
);
7987 ath10k_recalc_radar_detection(ar
);
7988 ath10k_monitor_recalc(ar
);
7990 mutex_unlock(&ar
->conf_mutex
);
7996 ath10k_mac_op_remove_chanctx(struct ieee80211_hw
*hw
,
7997 struct ieee80211_chanctx_conf
*ctx
)
7999 struct ath10k
*ar
= hw
->priv
;
8001 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8002 "mac chanctx remove freq %hu width %d ptr %pK\n",
8003 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
);
8005 mutex_lock(&ar
->conf_mutex
);
8007 spin_lock_bh(&ar
->data_lock
);
8008 ath10k_mac_update_rx_channel(ar
, NULL
, NULL
, 0);
8009 spin_unlock_bh(&ar
->data_lock
);
8011 ath10k_recalc_radar_detection(ar
);
8012 ath10k_monitor_recalc(ar
);
8014 mutex_unlock(&ar
->conf_mutex
);
8017 struct ath10k_mac_change_chanctx_arg
{
8018 struct ieee80211_chanctx_conf
*ctx
;
8019 struct ieee80211_vif_chanctx_switch
*vifs
;
8025 ath10k_mac_change_chanctx_cnt_iter(void *data
, u8
*mac
,
8026 struct ieee80211_vif
*vif
)
8028 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8030 if (rcu_access_pointer(vif
->chanctx_conf
) != arg
->ctx
)
8037 ath10k_mac_change_chanctx_fill_iter(void *data
, u8
*mac
,
8038 struct ieee80211_vif
*vif
)
8040 struct ath10k_mac_change_chanctx_arg
*arg
= data
;
8041 struct ieee80211_chanctx_conf
*ctx
;
8043 ctx
= rcu_access_pointer(vif
->chanctx_conf
);
8044 if (ctx
!= arg
->ctx
)
8047 if (WARN_ON(arg
->next_vif
== arg
->n_vifs
))
8050 arg
->vifs
[arg
->next_vif
].vif
= vif
;
8051 arg
->vifs
[arg
->next_vif
].old_ctx
= ctx
;
8052 arg
->vifs
[arg
->next_vif
].new_ctx
= ctx
;
8057 ath10k_mac_op_change_chanctx(struct ieee80211_hw
*hw
,
8058 struct ieee80211_chanctx_conf
*ctx
,
8061 struct ath10k
*ar
= hw
->priv
;
8062 struct ath10k_mac_change_chanctx_arg arg
= { .ctx
= ctx
};
8064 mutex_lock(&ar
->conf_mutex
);
8066 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8067 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
8068 ctx
->def
.chan
->center_freq
, ctx
->def
.width
, ctx
, changed
);
8070 /* This shouldn't really happen because channel switching should use
8071 * switch_vif_chanctx().
8073 if (WARN_ON(changed
& IEEE80211_CHANCTX_CHANGE_CHANNEL
))
8076 if (changed
& IEEE80211_CHANCTX_CHANGE_WIDTH
) {
8077 ieee80211_iterate_active_interfaces_atomic(
8079 IEEE80211_IFACE_ITER_NORMAL
,
8080 ath10k_mac_change_chanctx_cnt_iter
,
8082 if (arg
.n_vifs
== 0)
8085 arg
.vifs
= kcalloc(arg
.n_vifs
, sizeof(arg
.vifs
[0]),
8090 ieee80211_iterate_active_interfaces_atomic(
8092 IEEE80211_IFACE_ITER_NORMAL
,
8093 ath10k_mac_change_chanctx_fill_iter
,
8095 ath10k_mac_update_vif_chan(ar
, arg
.vifs
, arg
.n_vifs
);
8100 ath10k_recalc_radar_detection(ar
);
8102 /* FIXME: How to configure Rx chains properly? */
8104 /* No other actions are actually necessary. Firmware maintains channel
8105 * definitions per vdev internally and there's no host-side channel
8106 * context abstraction to configure, e.g. channel width.
8110 mutex_unlock(&ar
->conf_mutex
);
8114 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
8115 struct ieee80211_vif
*vif
,
8116 struct ieee80211_chanctx_conf
*ctx
)
8118 struct ath10k
*ar
= hw
->priv
;
8119 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8122 mutex_lock(&ar
->conf_mutex
);
8124 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8125 "mac chanctx assign ptr %pK vdev_id %i\n",
8126 ctx
, arvif
->vdev_id
);
8128 if (WARN_ON(arvif
->is_started
)) {
8129 mutex_unlock(&ar
->conf_mutex
);
8133 ret
= ath10k_vdev_start(arvif
, &ctx
->def
);
8135 ath10k_warn(ar
, "failed to start vdev %i addr %pM on freq %d: %d\n",
8136 arvif
->vdev_id
, vif
->addr
,
8137 ctx
->def
.chan
->center_freq
, ret
);
8141 arvif
->is_started
= true;
8143 ret
= ath10k_mac_vif_setup_ps(arvif
);
8145 ath10k_warn(ar
, "failed to update vdev %i ps: %d\n",
8146 arvif
->vdev_id
, ret
);
8150 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
8151 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, 0, vif
->addr
);
8153 ath10k_warn(ar
, "failed to up monitor vdev %i: %d\n",
8154 arvif
->vdev_id
, ret
);
8158 arvif
->is_up
= true;
8161 if (ath10k_mac_can_set_cts_prot(arvif
)) {
8162 ret
= ath10k_mac_set_cts_prot(arvif
);
8164 ath10k_warn(ar
, "failed to set cts protection for vdev %d: %d\n",
8165 arvif
->vdev_id
, ret
);
8168 if (ath10k_peer_stats_enabled(ar
) &&
8169 ar
->hw_params
.tx_stats_over_pktlog
) {
8170 ar
->pktlog_filter
|= ATH10K_PKTLOG_PEER_STATS
;
8171 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
8174 ath10k_warn(ar
, "failed to enable pktlog %d\n", ret
);
8179 mutex_unlock(&ar
->conf_mutex
);
8183 ath10k_vdev_stop(arvif
);
8184 arvif
->is_started
= false;
8185 ath10k_mac_vif_setup_ps(arvif
);
8188 mutex_unlock(&ar
->conf_mutex
);
8193 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
8194 struct ieee80211_vif
*vif
,
8195 struct ieee80211_chanctx_conf
*ctx
)
8197 struct ath10k
*ar
= hw
->priv
;
8198 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8201 mutex_lock(&ar
->conf_mutex
);
8203 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8204 "mac chanctx unassign ptr %pK vdev_id %i\n",
8205 ctx
, arvif
->vdev_id
);
8207 WARN_ON(!arvif
->is_started
);
8209 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
8210 WARN_ON(!arvif
->is_up
);
8212 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
8214 ath10k_warn(ar
, "failed to down monitor vdev %i: %d\n",
8215 arvif
->vdev_id
, ret
);
8217 arvif
->is_up
= false;
8220 ret
= ath10k_vdev_stop(arvif
);
8222 ath10k_warn(ar
, "failed to stop vdev %i: %d\n",
8223 arvif
->vdev_id
, ret
);
8225 arvif
->is_started
= false;
8227 mutex_unlock(&ar
->conf_mutex
);
8231 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw
*hw
,
8232 struct ieee80211_vif_chanctx_switch
*vifs
,
8234 enum ieee80211_chanctx_switch_mode mode
)
8236 struct ath10k
*ar
= hw
->priv
;
8238 mutex_lock(&ar
->conf_mutex
);
8240 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
8241 "mac chanctx switch n_vifs %d mode %d\n",
8243 ath10k_mac_update_vif_chan(ar
, vifs
, n_vifs
);
8245 mutex_unlock(&ar
->conf_mutex
);
8249 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
8250 struct ieee80211_vif
*vif
,
8251 struct ieee80211_sta
*sta
)
8254 struct ath10k_peer
*peer
;
8258 list_for_each_entry(peer
, &ar
->peers
, list
)
8259 if (peer
->sta
== sta
)
8260 peer
->removed
= true;
8263 static void ath10k_sta_statistics(struct ieee80211_hw
*hw
,
8264 struct ieee80211_vif
*vif
,
8265 struct ieee80211_sta
*sta
,
8266 struct station_info
*sinfo
)
8268 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
8269 struct ath10k
*ar
= arsta
->arvif
->ar
;
8271 if (!ath10k_peer_stats_enabled(ar
))
8274 sinfo
->rx_duration
= arsta
->rx_duration
;
8275 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_DURATION
);
8277 if (!arsta
->txrate
.legacy
&& !arsta
->txrate
.nss
)
8280 if (arsta
->txrate
.legacy
) {
8281 sinfo
->txrate
.legacy
= arsta
->txrate
.legacy
;
8283 sinfo
->txrate
.mcs
= arsta
->txrate
.mcs
;
8284 sinfo
->txrate
.nss
= arsta
->txrate
.nss
;
8285 sinfo
->txrate
.bw
= arsta
->txrate
.bw
;
8287 sinfo
->txrate
.flags
= arsta
->txrate
.flags
;
8288 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
8291 static const struct ieee80211_ops ath10k_ops
= {
8292 .tx
= ath10k_mac_op_tx
,
8293 .wake_tx_queue
= ath10k_mac_op_wake_tx_queue
,
8294 .start
= ath10k_start
,
8295 .stop
= ath10k_stop
,
8296 .config
= ath10k_config
,
8297 .add_interface
= ath10k_add_interface
,
8298 .remove_interface
= ath10k_remove_interface
,
8299 .configure_filter
= ath10k_configure_filter
,
8300 .bss_info_changed
= ath10k_bss_info_changed
,
8301 .set_coverage_class
= ath10k_mac_op_set_coverage_class
,
8302 .hw_scan
= ath10k_hw_scan
,
8303 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
8304 .set_key
= ath10k_set_key
,
8305 .set_default_unicast_key
= ath10k_set_default_unicast_key
,
8306 .sta_state
= ath10k_sta_state
,
8307 .sta_set_txpwr
= ath10k_sta_set_txpwr
,
8308 .conf_tx
= ath10k_conf_tx
,
8309 .remain_on_channel
= ath10k_remain_on_channel
,
8310 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
8311 .set_rts_threshold
= ath10k_set_rts_threshold
,
8312 .set_frag_threshold
= ath10k_mac_op_set_frag_threshold
,
8313 .flush
= ath10k_flush
,
8314 .tx_last_beacon
= ath10k_tx_last_beacon
,
8315 .set_antenna
= ath10k_set_antenna
,
8316 .get_antenna
= ath10k_get_antenna
,
8317 .reconfig_complete
= ath10k_reconfig_complete
,
8318 .get_survey
= ath10k_get_survey
,
8319 .set_bitrate_mask
= ath10k_mac_op_set_bitrate_mask
,
8320 .sta_rc_update
= ath10k_sta_rc_update
,
8321 .offset_tsf
= ath10k_offset_tsf
,
8322 .ampdu_action
= ath10k_ampdu_action
,
8323 .get_et_sset_count
= ath10k_debug_get_et_sset_count
,
8324 .get_et_stats
= ath10k_debug_get_et_stats
,
8325 .get_et_strings
= ath10k_debug_get_et_strings
,
8326 .add_chanctx
= ath10k_mac_op_add_chanctx
,
8327 .remove_chanctx
= ath10k_mac_op_remove_chanctx
,
8328 .change_chanctx
= ath10k_mac_op_change_chanctx
,
8329 .assign_vif_chanctx
= ath10k_mac_op_assign_vif_chanctx
,
8330 .unassign_vif_chanctx
= ath10k_mac_op_unassign_vif_chanctx
,
8331 .switch_vif_chanctx
= ath10k_mac_op_switch_vif_chanctx
,
8332 .sta_pre_rcu_remove
= ath10k_mac_op_sta_pre_rcu_remove
,
8333 .sta_statistics
= ath10k_sta_statistics
,
8335 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
8338 .suspend
= ath10k_wow_op_suspend
,
8339 .resume
= ath10k_wow_op_resume
,
8340 .set_wakeup
= ath10k_wow_op_set_wakeup
,
8342 #ifdef CONFIG_MAC80211_DEBUGFS
8343 .sta_add_debugfs
= ath10k_sta_add_debugfs
,
8347 #define CHAN2G(_channel, _freq, _flags) { \
8348 .band = NL80211_BAND_2GHZ, \
8349 .hw_value = (_channel), \
8350 .center_freq = (_freq), \
8351 .flags = (_flags), \
8352 .max_antenna_gain = 0, \
8356 #define CHAN5G(_channel, _freq, _flags) { \
8357 .band = NL80211_BAND_5GHZ, \
8358 .hw_value = (_channel), \
8359 .center_freq = (_freq), \
8360 .flags = (_flags), \
8361 .max_antenna_gain = 0, \
8365 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
8375 CHAN2G(10, 2457, 0),
8376 CHAN2G(11, 2462, 0),
8377 CHAN2G(12, 2467, 0),
8378 CHAN2G(13, 2472, 0),
8379 CHAN2G(14, 2484, 0),
8382 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
8383 CHAN5G(36, 5180, 0),
8384 CHAN5G(40, 5200, 0),
8385 CHAN5G(44, 5220, 0),
8386 CHAN5G(48, 5240, 0),
8387 CHAN5G(52, 5260, 0),
8388 CHAN5G(56, 5280, 0),
8389 CHAN5G(60, 5300, 0),
8390 CHAN5G(64, 5320, 0),
8391 CHAN5G(100, 5500, 0),
8392 CHAN5G(104, 5520, 0),
8393 CHAN5G(108, 5540, 0),
8394 CHAN5G(112, 5560, 0),
8395 CHAN5G(116, 5580, 0),
8396 CHAN5G(120, 5600, 0),
8397 CHAN5G(124, 5620, 0),
8398 CHAN5G(128, 5640, 0),
8399 CHAN5G(132, 5660, 0),
8400 CHAN5G(136, 5680, 0),
8401 CHAN5G(140, 5700, 0),
8402 CHAN5G(144, 5720, 0),
8403 CHAN5G(149, 5745, 0),
8404 CHAN5G(153, 5765, 0),
8405 CHAN5G(157, 5785, 0),
8406 CHAN5G(161, 5805, 0),
8407 CHAN5G(165, 5825, 0),
8408 CHAN5G(169, 5845, 0),
8409 CHAN5G(173, 5865, 0),
8410 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
8411 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
8414 struct ath10k
*ath10k_mac_create(size_t priv_size
)
8416 struct ieee80211_hw
*hw
;
8417 struct ieee80211_ops
*ops
;
8420 ops
= kmemdup(&ath10k_ops
, sizeof(ath10k_ops
), GFP_KERNEL
);
8424 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, ops
);
8437 void ath10k_mac_destroy(struct ath10k
*ar
)
8439 struct ieee80211_ops
*ops
= ar
->ops
;
8441 ieee80211_free_hw(ar
->hw
);
8445 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
8448 .types
= BIT(NL80211_IFTYPE_STATION
)
8449 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
8453 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
8457 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
8461 .types
= BIT(NL80211_IFTYPE_AP
)
8462 #ifdef CONFIG_MAC80211_MESH
8463 | BIT(NL80211_IFTYPE_MESH_POINT
)
8468 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
8471 .types
= BIT(NL80211_IFTYPE_AP
)
8472 #ifdef CONFIG_MAC80211_MESH
8473 | BIT(NL80211_IFTYPE_MESH_POINT
)
8478 .types
= BIT(NL80211_IFTYPE_STATION
)
8482 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
8484 .limits
= ath10k_if_limits
,
8485 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
8486 .max_interfaces
= 8,
8487 .num_different_channels
= 1,
8488 .beacon_int_infra_match
= true,
8492 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
8494 .limits
= ath10k_10x_if_limits
,
8495 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
8496 .max_interfaces
= 8,
8497 .num_different_channels
= 1,
8498 .beacon_int_infra_match
= true,
8499 .beacon_int_min_gcd
= 1,
8500 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8501 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
8502 BIT(NL80211_CHAN_WIDTH_20
) |
8503 BIT(NL80211_CHAN_WIDTH_40
) |
8504 BIT(NL80211_CHAN_WIDTH_80
),
8509 static const struct ieee80211_iface_limit ath10k_tlv_if_limit
[] = {
8512 .types
= BIT(NL80211_IFTYPE_STATION
),
8516 .types
= BIT(NL80211_IFTYPE_AP
) |
8517 #ifdef CONFIG_MAC80211_MESH
8518 BIT(NL80211_IFTYPE_MESH_POINT
) |
8520 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
8521 BIT(NL80211_IFTYPE_P2P_GO
),
8525 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
8529 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit
[] = {
8532 .types
= BIT(NL80211_IFTYPE_STATION
),
8536 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
),
8540 .types
= BIT(NL80211_IFTYPE_AP
) |
8541 #ifdef CONFIG_MAC80211_MESH
8542 BIT(NL80211_IFTYPE_MESH_POINT
) |
8544 BIT(NL80211_IFTYPE_P2P_GO
),
8548 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
8552 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss
[] = {
8555 .types
= BIT(NL80211_IFTYPE_STATION
),
8559 .types
= BIT(NL80211_IFTYPE_ADHOC
),
8563 /* FIXME: This is not thouroughly tested. These combinations may over- or
8564 * underestimate hw/fw capabilities.
8566 static struct ieee80211_iface_combination ath10k_tlv_if_comb
[] = {
8568 .limits
= ath10k_tlv_if_limit
,
8569 .num_different_channels
= 1,
8570 .max_interfaces
= 4,
8571 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
8574 .limits
= ath10k_tlv_if_limit_ibss
,
8575 .num_different_channels
= 1,
8576 .max_interfaces
= 2,
8577 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
8581 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb
[] = {
8583 .limits
= ath10k_tlv_if_limit
,
8584 .num_different_channels
= 1,
8585 .max_interfaces
= 4,
8586 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit
),
8589 .limits
= ath10k_tlv_qcs_if_limit
,
8590 .num_different_channels
= 2,
8591 .max_interfaces
= 4,
8592 .n_limits
= ARRAY_SIZE(ath10k_tlv_qcs_if_limit
),
8595 .limits
= ath10k_tlv_if_limit_ibss
,
8596 .num_different_channels
= 1,
8597 .max_interfaces
= 2,
8598 .n_limits
= ARRAY_SIZE(ath10k_tlv_if_limit_ibss
),
8602 static const struct ieee80211_iface_limit ath10k_10_4_if_limits
[] = {
8605 .types
= BIT(NL80211_IFTYPE_STATION
),
8609 .types
= BIT(NL80211_IFTYPE_AP
)
8610 #ifdef CONFIG_MAC80211_MESH
8611 | BIT(NL80211_IFTYPE_MESH_POINT
)
8616 static const struct ieee80211_iface_combination ath10k_10_4_if_comb
[] = {
8618 .limits
= ath10k_10_4_if_limits
,
8619 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
8620 .max_interfaces
= 16,
8621 .num_different_channels
= 1,
8622 .beacon_int_infra_match
= true,
8623 .beacon_int_min_gcd
= 1,
8624 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8625 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
8626 BIT(NL80211_CHAN_WIDTH_20
) |
8627 BIT(NL80211_CHAN_WIDTH_40
) |
8628 BIT(NL80211_CHAN_WIDTH_80
),
8634 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb
[] = {
8636 .limits
= ath10k_10_4_if_limits
,
8637 .n_limits
= ARRAY_SIZE(ath10k_10_4_if_limits
),
8638 .max_interfaces
= 16,
8639 .num_different_channels
= 1,
8640 .beacon_int_infra_match
= true,
8641 .beacon_int_min_gcd
= 100,
8642 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8643 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
8644 BIT(NL80211_CHAN_WIDTH_20
) |
8645 BIT(NL80211_CHAN_WIDTH_40
) |
8646 BIT(NL80211_CHAN_WIDTH_80
),
8651 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
8652 struct ieee80211_vif
*vif
)
8654 struct ath10k_vif_iter
*arvif_iter
= data
;
8655 struct ath10k_vif
*arvif
= (void *)vif
->drv_priv
;
8657 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
8658 arvif_iter
->arvif
= arvif
;
8661 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
8663 struct ath10k_vif_iter arvif_iter
;
8666 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
8667 arvif_iter
.vdev_id
= vdev_id
;
8669 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
8670 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
8672 ath10k_get_arvif_iter
,
8674 if (!arvif_iter
.arvif
) {
8675 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
8679 return arvif_iter
.arvif
;
8682 #define WRD_METHOD "WRDD"
8683 #define WRDD_WIFI (0x07)
8685 static u32
ath10k_mac_wrdd_get_mcc(struct ath10k
*ar
, union acpi_object
*wrdd
)
8687 union acpi_object
*mcc_pkg
;
8688 union acpi_object
*domain_type
;
8689 union acpi_object
*mcc_value
;
8692 if (wrdd
->type
!= ACPI_TYPE_PACKAGE
||
8693 wrdd
->package
.count
< 2 ||
8694 wrdd
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
8695 wrdd
->package
.elements
[0].integer
.value
!= 0) {
8696 ath10k_warn(ar
, "ignoring malformed/unsupported wrdd structure\n");
8700 for (i
= 1; i
< wrdd
->package
.count
; ++i
) {
8701 mcc_pkg
= &wrdd
->package
.elements
[i
];
8703 if (mcc_pkg
->type
!= ACPI_TYPE_PACKAGE
)
8705 if (mcc_pkg
->package
.count
< 2)
8707 if (mcc_pkg
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
8708 mcc_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
)
8711 domain_type
= &mcc_pkg
->package
.elements
[0];
8712 if (domain_type
->integer
.value
!= WRDD_WIFI
)
8715 mcc_value
= &mcc_pkg
->package
.elements
[1];
8716 return mcc_value
->integer
.value
;
8721 static int ath10k_mac_get_wrdd_regulatory(struct ath10k
*ar
, u16
*rd
)
8723 acpi_handle root_handle
;
8725 struct acpi_buffer wrdd
= {ACPI_ALLOCATE_BUFFER
, NULL
};
8730 root_handle
= ACPI_HANDLE(ar
->dev
);
8734 status
= acpi_get_handle(root_handle
, (acpi_string
)WRD_METHOD
, &handle
);
8735 if (ACPI_FAILURE(status
)) {
8736 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
8737 "failed to get wrd method %d\n", status
);
8741 status
= acpi_evaluate_object(handle
, NULL
, NULL
, &wrdd
);
8742 if (ACPI_FAILURE(status
)) {
8743 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
8744 "failed to call wrdc %d\n", status
);
8748 alpha2_code
= ath10k_mac_wrdd_get_mcc(ar
, wrdd
.pointer
);
8749 kfree(wrdd
.pointer
);
8753 alpha2
[0] = (alpha2_code
>> 8) & 0xff;
8754 alpha2
[1] = (alpha2_code
>> 0) & 0xff;
8757 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
8758 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2
);
8760 *rd
= ath_regd_find_country_by_name(alpha2
);
8764 *rd
|= COUNTRY_ERD_FLAG
;
8768 static int ath10k_mac_init_rd(struct ath10k
*ar
)
8773 ret
= ath10k_mac_get_wrdd_regulatory(ar
, &rd
);
8775 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
8776 "fallback to eeprom programmed regulatory settings\n");
8777 rd
= ar
->hw_eeprom_rd
;
8780 ar
->ath_common
.regulatory
.current_rd
= rd
;
8784 int ath10k_mac_register(struct ath10k
*ar
)
8786 static const u32 cipher_suites
[] = {
8787 WLAN_CIPHER_SUITE_WEP40
,
8788 WLAN_CIPHER_SUITE_WEP104
,
8789 WLAN_CIPHER_SUITE_TKIP
,
8790 WLAN_CIPHER_SUITE_CCMP
,
8792 /* Do not add hardware supported ciphers before this line.
8793 * Allow software encryption for all chips. Don't forget to
8794 * update n_cipher_suites below.
8796 WLAN_CIPHER_SUITE_AES_CMAC
,
8797 WLAN_CIPHER_SUITE_BIP_CMAC_256
,
8798 WLAN_CIPHER_SUITE_BIP_GMAC_128
,
8799 WLAN_CIPHER_SUITE_BIP_GMAC_256
,
8801 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8802 * and CCMP-256 in hardware.
8804 WLAN_CIPHER_SUITE_GCMP
,
8805 WLAN_CIPHER_SUITE_GCMP_256
,
8806 WLAN_CIPHER_SUITE_CCMP_256
,
8808 struct ieee80211_supported_band
*band
;
8812 if (!is_valid_ether_addr(ar
->mac_addr
)) {
8813 ath10k_warn(ar
, "invalid MAC address; choosing random\n");
8814 eth_random_addr(ar
->mac_addr
);
8816 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
8818 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
8820 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels
) +
8821 ARRAY_SIZE(ath10k_5ghz_channels
)) !=
8824 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
8825 channels
= kmemdup(ath10k_2ghz_channels
,
8826 sizeof(ath10k_2ghz_channels
),
8833 band
= &ar
->mac
.sbands
[NL80211_BAND_2GHZ
];
8834 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
8835 band
->channels
= channels
;
8837 if (ar
->hw_params
.cck_rate_map_rev2
) {
8838 band
->n_bitrates
= ath10k_g_rates_rev2_size
;
8839 band
->bitrates
= ath10k_g_rates_rev2
;
8841 band
->n_bitrates
= ath10k_g_rates_size
;
8842 band
->bitrates
= ath10k_g_rates
;
8845 ar
->hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = band
;
8848 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
8849 channels
= kmemdup(ath10k_5ghz_channels
,
8850 sizeof(ath10k_5ghz_channels
),
8857 band
= &ar
->mac
.sbands
[NL80211_BAND_5GHZ
];
8858 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
8859 band
->channels
= channels
;
8860 band
->n_bitrates
= ath10k_a_rates_size
;
8861 band
->bitrates
= ath10k_a_rates
;
8862 ar
->hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = band
;
8865 wiphy_read_of_freq_limits(ar
->hw
->wiphy
);
8866 ath10k_mac_setup_ht_vht_cap(ar
);
8868 ar
->hw
->wiphy
->interface_modes
=
8869 BIT(NL80211_IFTYPE_STATION
) |
8870 BIT(NL80211_IFTYPE_AP
) |
8871 BIT(NL80211_IFTYPE_MESH_POINT
);
8873 ar
->hw
->wiphy
->available_antennas_rx
= ar
->cfg_rx_chainmask
;
8874 ar
->hw
->wiphy
->available_antennas_tx
= ar
->cfg_tx_chainmask
;
8876 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->normal_mode_fw
.fw_file
.fw_features
))
8877 ar
->hw
->wiphy
->interface_modes
|=
8878 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
8879 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
8880 BIT(NL80211_IFTYPE_P2P_GO
);
8882 ieee80211_hw_set(ar
->hw
, SIGNAL_DBM
);
8884 if (!test_bit(ATH10K_FW_FEATURE_NO_PS
,
8885 ar
->running_fw
->fw_file
.fw_features
)) {
8886 ieee80211_hw_set(ar
->hw
, SUPPORTS_PS
);
8887 ieee80211_hw_set(ar
->hw
, SUPPORTS_DYNAMIC_PS
);
8890 ieee80211_hw_set(ar
->hw
, MFP_CAPABLE
);
8891 ieee80211_hw_set(ar
->hw
, REPORTS_TX_ACK_STATUS
);
8892 ieee80211_hw_set(ar
->hw
, HAS_RATE_CONTROL
);
8893 ieee80211_hw_set(ar
->hw
, AP_LINK_PS
);
8894 ieee80211_hw_set(ar
->hw
, SPECTRUM_MGMT
);
8895 ieee80211_hw_set(ar
->hw
, SUPPORT_FAST_XMIT
);
8896 ieee80211_hw_set(ar
->hw
, CONNECTION_MONITOR
);
8897 ieee80211_hw_set(ar
->hw
, SUPPORTS_PER_STA_GTK
);
8898 ieee80211_hw_set(ar
->hw
, WANT_MONITOR_VIF
);
8899 ieee80211_hw_set(ar
->hw
, CHANCTX_STA_CSA
);
8900 ieee80211_hw_set(ar
->hw
, QUEUE_CONTROL
);
8901 ieee80211_hw_set(ar
->hw
, SUPPORTS_TX_FRAG
);
8902 ieee80211_hw_set(ar
->hw
, REPORTS_LOW_ACK
);
8904 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
8905 ieee80211_hw_set(ar
->hw
, SW_CRYPTO_CONTROL
);
8907 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_STATIC_SMPS
;
8908 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
8910 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
8911 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_DYNAMIC_SMPS
;
8913 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
8914 ieee80211_hw_set(ar
->hw
, AMPDU_AGGREGATION
);
8915 ieee80211_hw_set(ar
->hw
, TX_AMPDU_SETUP_IN_HW
);
8918 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
8919 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
8921 if (test_bit(WMI_SERVICE_NLO
, ar
->wmi
.svc_map
)) {
8922 ar
->hw
->wiphy
->max_sched_scan_reqs
= 1;
8923 ar
->hw
->wiphy
->max_sched_scan_ssids
= WMI_PNO_MAX_SUPP_NETWORKS
;
8924 ar
->hw
->wiphy
->max_match_sets
= WMI_PNO_MAX_SUPP_NETWORKS
;
8925 ar
->hw
->wiphy
->max_sched_scan_ie_len
= WMI_PNO_MAX_IE_LENGTH
;
8926 ar
->hw
->wiphy
->max_sched_scan_plans
= WMI_PNO_MAX_SCHED_SCAN_PLANS
;
8927 ar
->hw
->wiphy
->max_sched_scan_plan_interval
=
8928 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT
;
8929 ar
->hw
->wiphy
->max_sched_scan_plan_iterations
=
8930 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS
;
8931 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
8934 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
8935 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
8936 ar
->hw
->txq_data_size
= sizeof(struct ath10k_txq
);
8938 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
8940 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD
, ar
->wmi
.svc_map
)) {
8941 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
8943 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8944 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8945 * correct Probe Responses. This is more of a hack advert..
8947 ar
->hw
->wiphy
->probe_resp_offload
|=
8948 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
8949 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
8950 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
8953 if (test_bit(WMI_SERVICE_TDLS
, ar
->wmi
.svc_map
) ||
8954 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY
, ar
->wmi
.svc_map
)) {
8955 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
8956 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH
, ar
->wmi
.svc_map
))
8957 ieee80211_hw_set(ar
->hw
, TDLS_WIDER_BW
);
8960 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA
, ar
->wmi
.svc_map
))
8961 ieee80211_hw_set(ar
->hw
, SUPPORTS_TDLS_BUFFER_STA
);
8963 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
8964 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
8965 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
8967 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
8968 ar
->hw
->wiphy
->features
|= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
8969 NL80211_FEATURE_AP_SCAN
;
8971 ar
->hw
->wiphy
->max_ap_assoc_sta
= ar
->max_num_stations
;
8973 ret
= ath10k_wow_init(ar
);
8975 ath10k_warn(ar
, "failed to init wow: %d\n", ret
);
8979 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
8980 wiphy_ext_feature_set(ar
->hw
->wiphy
,
8981 NL80211_EXT_FEATURE_SET_SCAN_DWELL
);
8982 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_AQL
);
8984 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI
, ar
->wmi
.svc_map
) ||
8985 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS
, ar
->wmi
.svc_map
))
8986 wiphy_ext_feature_set(ar
->hw
->wiphy
,
8987 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT
);
8989 if (ath10k_peer_stats_enabled(ar
) ||
8990 test_bit(WMI_SERVICE_REPORT_AIRTIME
, ar
->wmi
.svc_map
))
8991 wiphy_ext_feature_set(ar
->hw
->wiphy
,
8992 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
);
8994 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE
, ar
->wmi
.svc_map
))
8995 wiphy_ext_feature_set(ar
->hw
->wiphy
,
8996 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
);
8998 if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER
, ar
->wmi
.svc_map
))
8999 wiphy_ext_feature_set(ar
->hw
->wiphy
,
9000 NL80211_EXT_FEATURE_STA_TX_PWR
);
9002 * on LL hardware queues are managed entirely by the FW
9003 * so we only advertise to mac we can do the queues thing
9005 ar
->hw
->queues
= IEEE80211_MAX_QUEUES
;
9007 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
9008 * something that vdev_ids can't reach so that we don't stop the queue
9011 ar
->hw
->offchannel_tx_hw_queue
= IEEE80211_MAX_QUEUES
- 1;
9013 switch (ar
->running_fw
->fw_file
.wmi_op_version
) {
9014 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
9015 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
9016 ar
->hw
->wiphy
->n_iface_combinations
=
9017 ARRAY_SIZE(ath10k_if_comb
);
9018 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
9020 case ATH10K_FW_WMI_OP_VERSION_TLV
:
9021 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS
, ar
->wmi
.svc_map
)) {
9022 ar
->hw
->wiphy
->iface_combinations
=
9023 ath10k_tlv_qcs_if_comb
;
9024 ar
->hw
->wiphy
->n_iface_combinations
=
9025 ARRAY_SIZE(ath10k_tlv_qcs_if_comb
);
9027 ar
->hw
->wiphy
->iface_combinations
= ath10k_tlv_if_comb
;
9028 ar
->hw
->wiphy
->n_iface_combinations
=
9029 ARRAY_SIZE(ath10k_tlv_if_comb
);
9031 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
9033 case ATH10K_FW_WMI_OP_VERSION_10_1
:
9034 case ATH10K_FW_WMI_OP_VERSION_10_2
:
9035 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
9036 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
9037 ar
->hw
->wiphy
->n_iface_combinations
=
9038 ARRAY_SIZE(ath10k_10x_if_comb
);
9040 case ATH10K_FW_WMI_OP_VERSION_10_4
:
9041 ar
->hw
->wiphy
->iface_combinations
= ath10k_10_4_if_comb
;
9042 ar
->hw
->wiphy
->n_iface_combinations
=
9043 ARRAY_SIZE(ath10k_10_4_if_comb
);
9044 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT
,
9046 ar
->hw
->wiphy
->iface_combinations
=
9047 ath10k_10_4_bcn_int_if_comb
;
9048 ar
->hw
->wiphy
->n_iface_combinations
=
9049 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb
);
9052 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
9053 case ATH10K_FW_WMI_OP_VERSION_MAX
:
9059 if (!test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
))
9060 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
9062 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
9063 /* Init ath dfs pattern detector */
9064 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
9065 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
9068 if (!ar
->dfs_detector
)
9069 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
9072 ret
= ath10k_mac_init_rd(ar
);
9074 ath10k_err(ar
, "failed to derive regdom: %d\n", ret
);
9075 goto err_dfs_detector_exit
;
9078 /* Disable set_coverage_class for chipsets that do not support it. */
9079 if (!ar
->hw_params
.hw_ops
->set_coverage_class
)
9080 ar
->ops
->set_coverage_class
= NULL
;
9082 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
9083 ath10k_reg_notifier
);
9085 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
9086 goto err_dfs_detector_exit
;
9089 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT
, ar
->wmi
.svc_map
)) {
9090 ar
->hw
->wiphy
->features
|=
9091 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
9094 ar
->hw
->wiphy
->cipher_suites
= cipher_suites
;
9096 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
9097 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
9098 * from chip specific hw_param table.
9100 if (!ar
->hw_params
.n_cipher_suites
||
9101 ar
->hw_params
.n_cipher_suites
> ARRAY_SIZE(cipher_suites
)) {
9102 ath10k_err(ar
, "invalid hw_params.n_cipher_suites %d\n",
9103 ar
->hw_params
.n_cipher_suites
);
9104 ar
->hw_params
.n_cipher_suites
= 8;
9106 ar
->hw
->wiphy
->n_cipher_suites
= ar
->hw_params
.n_cipher_suites
;
9108 wiphy_ext_feature_set(ar
->hw
->wiphy
, NL80211_EXT_FEATURE_CQM_RSSI_LIST
);
9110 ar
->hw
->weight_multiplier
= ATH10K_AIRTIME_WEIGHT_MULTIPLIER
;
9112 ret
= ieee80211_register_hw(ar
->hw
);
9114 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
9115 goto err_dfs_detector_exit
;
9118 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT
, ar
->wmi
.svc_map
)) {
9119 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
9120 ar
->hw
->wiphy
->software_iftypes
|= BIT(NL80211_IFTYPE_AP_VLAN
);
9123 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
9124 ret
= regulatory_hint(ar
->hw
->wiphy
,
9125 ar
->ath_common
.regulatory
.alpha2
);
9127 goto err_unregister
;
9133 ieee80211_unregister_hw(ar
->hw
);
9135 err_dfs_detector_exit
:
9136 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
9137 ar
->dfs_detector
->exit(ar
->dfs_detector
);
9140 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
9141 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
9143 SET_IEEE80211_DEV(ar
->hw
, NULL
);
9147 void ath10k_mac_unregister(struct ath10k
*ar
)
9149 ieee80211_unregister_hw(ar
->hw
);
9151 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
9152 ar
->dfs_detector
->exit(ar
->dfs_detector
);
9154 kfree(ar
->mac
.sbands
[NL80211_BAND_2GHZ
].channels
);
9155 kfree(ar
->mac
.sbands
[NL80211_BAND_5GHZ
].channels
);
9157 SET_IEEE80211_DEV(ar
->hw
, NULL
);