xref: /linux/drivers/net/wireless/ath/ath12k/core.h (revision d8674294aefef02266c4d47ad10131f1bffbe534)
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4  * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
5  */
6 
7 #ifndef ATH12K_CORE_H
8 #define ATH12K_CORE_H
9 
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/irq.h>
13 #include <linux/bitfield.h>
14 #include <linux/dmi.h>
15 #include <linux/ctype.h>
16 #include <linux/firmware.h>
17 #include <linux/of_reserved_mem.h>
18 #include <linux/average.h>
19 #include <linux/of.h>
20 #include <linux/rhashtable.h>
21 #include "qmi.h"
22 #include "htc.h"
23 #include "wmi.h"
24 #include "hal.h"
25 #include "dp.h"
26 #include "ce.h"
27 #include "mac.h"
28 #include "hw.h"
29 #include "reg.h"
30 #include "dbring.h"
31 #include "fw.h"
32 #include "acpi.h"
33 #include "wow.h"
34 #include "debugfs_htt_stats.h"
35 #include "coredump.h"
36 #include "cmn_defs.h"
37 #include "dp_cmn.h"
38 #include "thermal.h"
39 
40 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
41 
42 #define ATH12K_TX_MGMT_NUM_PENDING_MAX	512
43 
44 #define ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI 64
45 
46 /* Pending management packets threshold for dropping probe responses */
47 #define ATH12K_PRB_RSP_DROP_THRESHOLD ((ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI * 3) / 4)
48 
49 /* SMBIOS type containing Board Data File Name Extension */
50 #define ATH12K_SMBIOS_BDF_EXT_TYPE 0xF8
51 
52 /* SMBIOS type structure length (excluding strings-set) */
53 #define ATH12K_SMBIOS_BDF_EXT_LENGTH 0x9
54 
55 /* The magic used by QCA spec */
56 #define ATH12K_SMBIOS_BDF_EXT_MAGIC "BDF_"
57 
58 #define ATH12K_INVALID_HW_MAC_ID	0xFF
59 #define ATH12K_CONNECTION_LOSS_HZ	(3 * HZ)
60 
61 #define ATH12K_MON_TIMER_INTERVAL  10
62 #define ATH12K_RESET_TIMEOUT_HZ			(20 * HZ)
63 #define ATH12K_RESET_MAX_FAIL_COUNT_FIRST	3
64 #define ATH12K_RESET_MAX_FAIL_COUNT_FINAL	5
65 #define ATH12K_RESET_FAIL_TIMEOUT_HZ		(20 * HZ)
66 #define ATH12K_RECONFIGURE_TIMEOUT_HZ		(10 * HZ)
67 #define ATH12K_RECOVER_START_TIMEOUT_HZ		(20 * HZ)
68 
69 #define ATH12K_INVALID_GROUP_ID  0xFF
70 #define ATH12K_INVALID_DEVICE_ID 0xFF
71 
72 #define ATH12K_MAX_MLO_PEERS            256
73 #define ATH12K_MLO_PEER_ID_INVALID      0xFFFF
74 #define ATH12K_MLO_PEER_ID_PENDING      0xFFFE
75 
76 #define ATH12K_INVALID_RSSI_FULL -1
77 #define ATH12K_INVALID_RSSI_EMPTY -128
78 
79 enum ath12k_bdf_search {
80 	ATH12K_BDF_SEARCH_DEFAULT,
81 	ATH12K_BDF_SEARCH_BUS_AND_BOARD,
82 };
83 
84 enum wme_ac {
85 	WME_AC_BE,
86 	WME_AC_BK,
87 	WME_AC_VI,
88 	WME_AC_VO,
89 	WME_NUM_AC
90 };
91 
92 #define ATH12K_HT_MCS_MAX	7
93 #define ATH12K_VHT_MCS_MAX	9
94 #define ATH12K_HE_MCS_MAX	11
95 #define ATH12K_EHT_MCS_MAX	15
96 
97 enum ath12k_crypt_mode {
98 	/* Only use hardware crypto engine */
99 	ATH12K_CRYPT_MODE_HW,
100 	/* Only use software crypto */
101 	ATH12K_CRYPT_MODE_SW,
102 };
103 
104 static inline enum wme_ac ath12k_tid_to_ac(u32 tid)
105 {
106 	return (((tid == 0) || (tid == 3)) ? WME_AC_BE :
107 		((tid == 1) || (tid == 2)) ? WME_AC_BK :
108 		((tid == 4) || (tid == 5)) ? WME_AC_VI :
109 		WME_AC_VO);
110 }
111 
112 static inline u64 ath12k_le32hilo_to_u64(__le32 hi, __le32 lo)
113 {
114 	u64 hi64 = le32_to_cpu(hi);
115 	u64 lo64 = le32_to_cpu(lo);
116 
117 	return (hi64 << 32) | lo64;
118 }
119 
120 enum ath12k_skb_flags {
121 	ATH12K_SKB_HW_80211_ENCAP = BIT(0),
122 	ATH12K_SKB_CIPHER_SET = BIT(1),
123 	ATH12K_SKB_MLO_STA = BIT(2),
124 };
125 
126 struct ath12k_skb_cb {
127 	dma_addr_t paddr;
128 	struct ath12k *ar;
129 	struct ieee80211_vif *vif;
130 	dma_addr_t paddr_ext_desc;
131 	u32 cipher;
132 	u8 flags;
133 	u8 link_id;
134 };
135 
136 struct ath12k_skb_rxcb {
137 	dma_addr_t paddr;
138 	bool is_first_msdu;
139 	bool is_last_msdu;
140 	bool is_continuation;
141 	bool is_mcbc;
142 	bool is_eapol;
143 	struct hal_rx_desc *rx_desc;
144 	u8 err_rel_src;
145 	u8 err_code;
146 	u8 hw_link_id;
147 	u8 unmapped;
148 	u8 is_frag;
149 	u8 tid;
150 	u16 peer_id;
151 	bool is_end_of_ppdu;
152 };
153 
154 enum ath12k_hw_rev {
155 	ATH12K_HW_QCN9274_HW10,
156 	ATH12K_HW_QCN9274_HW20,
157 	ATH12K_HW_WCN7850_HW20,
158 	ATH12K_HW_IPQ5332_HW10,
159 	ATH12K_HW_QCC2072_HW10,
160 	ATH12K_HW_IPQ5424_HW10,
161 };
162 
163 #define ATH12K_IRQ_NUM_MAX 57
164 #define ATH12K_EXT_IRQ_NUM_MAX	16
165 #define ATH12K_MAX_TCL_RING_NUM	3
166 
167 struct ath12k_ext_irq_grp {
168 	struct ath12k_base *ab;
169 	u32 irqs[ATH12K_EXT_IRQ_NUM_MAX];
170 	u32 num_irq;
171 	u32 grp_id;
172 	u64 timestamp;
173 	bool napi_enabled;
174 	struct napi_struct napi;
175 	struct net_device *napi_ndev;
176 };
177 
178 enum ath12k_smbios_cc_type {
179 	/* disable country code setting from SMBIOS */
180 	ATH12K_SMBIOS_CC_DISABLE = 0,
181 
182 	/* set country code by ANSI country name, based on ISO3166-1 alpha2 */
183 	ATH12K_SMBIOS_CC_ISO = 1,
184 
185 	/* worldwide regdomain */
186 	ATH12K_SMBIOS_CC_WW = 2,
187 };
188 
189 struct ath12k_smbios_bdf {
190 	struct dmi_header hdr;
191 	u8 features_disabled;
192 
193 	/* enum ath12k_smbios_cc_type */
194 	u8 country_code_flag;
195 
196 	/* To set specific country, you need to set country code
197 	 * flag=ATH12K_SMBIOS_CC_ISO first, then if country is United
198 	 * States, then country code value = 0x5553 ("US",'U' = 0x55, 'S'=
199 	 * 0x53). To set country to INDONESIA, then country code value =
200 	 * 0x4944 ("IN", 'I'=0x49, 'D'=0x44). If country code flag =
201 	 * ATH12K_SMBIOS_CC_WW, then you can use worldwide regulatory
202 	 * setting.
203 	 */
204 	u16 cc_code;
205 
206 	u8 bdf_enabled;
207 	u8 bdf_ext[];
208 } __packed;
209 
210 #define HEHANDLE_CAP_PHYINFO_SIZE       3
211 #define HECAP_PHYINFO_SIZE              9
212 #define HECAP_MACINFO_SIZE              5
213 #define HECAP_TXRX_MCS_NSS_SIZE         2
214 #define HECAP_PPET16_PPET8_MAX_SIZE     25
215 
216 #define HE_PPET16_PPET8_SIZE            8
217 
218 /* 802.11ax PPE (PPDU packet Extension) threshold */
219 struct he_ppe_threshold {
220 	u32 numss_m1;
221 	u32 ru_mask;
222 	u32 ppet16_ppet8_ru3_ru0[HE_PPET16_PPET8_SIZE];
223 };
224 
225 struct ath12k_he {
226 	u8 hecap_macinfo[HECAP_MACINFO_SIZE];
227 	u32 hecap_rxmcsnssmap;
228 	u32 hecap_txmcsnssmap;
229 	u32 hecap_phyinfo[HEHANDLE_CAP_PHYINFO_SIZE];
230 	struct he_ppe_threshold   hecap_ppet;
231 	u32 heop_param;
232 };
233 
234 enum {
235 	WMI_HOST_TP_SCALE_MAX   = 0,
236 	WMI_HOST_TP_SCALE_50    = 1,
237 	WMI_HOST_TP_SCALE_25    = 2,
238 	WMI_HOST_TP_SCALE_12    = 3,
239 	WMI_HOST_TP_SCALE_MIN   = 4,
240 	WMI_HOST_TP_SCALE_SIZE   = 5,
241 };
242 
243 enum ath12k_scan_state {
244 	ATH12K_SCAN_IDLE,
245 	ATH12K_SCAN_STARTING,
246 	ATH12K_SCAN_RUNNING,
247 	ATH12K_SCAN_ABORTING,
248 };
249 
250 enum ath12k_11d_state {
251 	ATH12K_11D_IDLE,
252 	ATH12K_11D_PREPARING,
253 	ATH12K_11D_RUNNING,
254 };
255 
256 enum ath12k_hw_group_flags {
257 	ATH12K_GROUP_FLAG_REGISTERED,
258 	ATH12K_GROUP_FLAG_UNREGISTER,
259 };
260 
261 enum ath12k_dev_flags {
262 	ATH12K_FLAG_CAC_RUNNING,
263 	ATH12K_FLAG_CRASH_FLUSH,
264 	ATH12K_FLAG_RAW_MODE,
265 	ATH12K_FLAG_HW_CRYPTO_DISABLED,
266 	ATH12K_FLAG_RECOVERY,
267 	ATH12K_FLAG_UNREGISTERING,
268 	ATH12K_FLAG_REGISTERED,
269 	ATH12K_FLAG_QMI_FAIL,
270 	ATH12K_FLAG_HTC_SUSPEND_COMPLETE,
271 	ATH12K_FLAG_CE_IRQ_ENABLED,
272 	ATH12K_FLAG_EXT_IRQ_ENABLED,
273 	ATH12K_FLAG_QMI_FW_READY_COMPLETE,
274 	ATH12K_FLAG_FTM_SEGMENTED,
275 	ATH12K_FLAG_FIXED_MEM_REGION,
276 };
277 
278 struct ath12k_tx_conf {
279 	bool changed;
280 	u16 ac;
281 	struct ieee80211_tx_queue_params tx_queue_params;
282 };
283 
284 struct ath12k_key_conf {
285 	enum set_key_cmd cmd;
286 	struct list_head list;
287 	struct ieee80211_sta *sta;
288 	struct ieee80211_key_conf *key;
289 };
290 
291 struct ath12k_vif_cache {
292 	struct ath12k_tx_conf tx_conf;
293 	struct ath12k_key_conf key_conf;
294 	u32 bss_conf_changed;
295 };
296 
297 struct ath12k_rekey_data {
298 	u8 kck[NL80211_KCK_LEN];
299 	u8 kek[NL80211_KCK_LEN];
300 	u64 replay_ctr;
301 	bool enable_offload;
302 };
303 
304 struct ath12k_link_vif {
305 	u32 vdev_id;
306 	u32 beacon_interval;
307 	u32 dtim_period;
308 
309 	struct ath12k *ar;
310 
311 	bool beacon_prot;
312 
313 	struct wmi_wmm_params_all_arg wmm_params;
314 	struct list_head list;
315 
316 	bool is_created;
317 	bool is_started;
318 	bool is_up;
319 	u8 bssid[ETH_ALEN];
320 	struct cfg80211_bitrate_mask bitrate_mask;
321 	struct delayed_work connection_loss_work;
322 	int num_legacy_stations;
323 	int rtscts_prot_mode;
324 	int txpower;
325 	bool rsnie_present;
326 	bool wpaie_present;
327 	u8 vdev_stats_id;
328 	u32 punct_bitmap;
329 	u8 link_id;
330 	struct ath12k_vif *ahvif;
331 	struct ath12k_rekey_data rekey_data;
332 	struct ath12k_link_stats link_stats;
333 	spinlock_t link_stats_lock; /* Protects updates to link_stats */
334 
335 	u8 current_cntdown_counter;
336 
337 	/* only used in station mode */
338 	bool is_sta_assoc_link;
339 
340 	struct ath12k_reg_tpc_power_info reg_tpc_info;
341 
342 	bool group_key_valid;
343 	struct wmi_vdev_install_key_arg group_key;
344 	bool pairwise_key_done;
345 	u16 num_stations;
346 	bool is_csa_in_progress;
347 	struct wiphy_work bcn_tx_work;
348 
349 	bool set_wds_vdev_param;
350 	bool nawds_enabled;
351 };
352 
353 struct ath12k_vif {
354 	struct ath12k_dp_vif dp_vif;
355 
356 	enum wmi_vdev_type vdev_type;
357 	enum wmi_vdev_subtype vdev_subtype;
358 	struct ieee80211_vif *vif;
359 	struct ath12k_hw *ah;
360 
361 	union {
362 		struct {
363 			u32 uapsd;
364 		} sta;
365 		struct {
366 			/* 127 stations; wmi limit */
367 			u8 tim_bitmap[16];
368 			u8 tim_len;
369 			u32 ssid_len;
370 			u8 ssid[IEEE80211_MAX_SSID_LEN];
371 			bool hidden_ssid;
372 			/* P2P_IE with NoA attribute for P2P_GO case */
373 			u32 noa_len;
374 			u8 *noa_data;
375 		} ap;
376 	} u;
377 
378 	u32 aid;
379 	bool ps;
380 
381 	struct ath12k_link_vif deflink;
382 	struct ath12k_link_vif __rcu *link[ATH12K_NUM_MAX_LINKS];
383 	struct ath12k_vif_cache *cache[IEEE80211_MLD_MAX_NUM_LINKS];
384 	/* indicates bitmap of link vif created in FW */
385 	u32 links_map;
386 	/* Must be last - ends in a flexible-array member.
387 	 *
388 	 * FIXME: Driver should not copy struct ieee80211_chanctx_conf,
389 	 * especially because it has a flexible array. Find a better way.
390 	 */
391 	struct ieee80211_chanctx_conf chanctx;
392 };
393 
394 struct ath12k_vif_iter {
395 	u32 vdev_id;
396 	struct ath12k *ar;
397 	struct ath12k_link_vif *arvif;
398 };
399 
400 #define ATH12K_SCAN_TIMEOUT_HZ (20 * HZ)
401 
402 #define ATH12K_HE_MCS_NUM       12
403 #define ATH12K_VHT_MCS_NUM      10
404 #define ATH12K_BW_NUM           5
405 #define ATH12K_NSS_NUM          4
406 #define ATH12K_LEGACY_NUM       12
407 #define ATH12K_GI_NUM           4
408 #define ATH12K_HT_MCS_NUM       32
409 
410 enum ath12k_pkt_rx_err {
411 	ATH12K_PKT_RX_ERR_FCS,
412 	ATH12K_PKT_RX_ERR_TKIP,
413 	ATH12K_PKT_RX_ERR_CRYPT,
414 	ATH12K_PKT_RX_ERR_PEER_IDX_INVAL,
415 	ATH12K_PKT_RX_ERR_MAX,
416 };
417 
418 enum ath12k_ampdu_subfrm_num {
419 	ATH12K_AMPDU_SUBFRM_NUM_10,
420 	ATH12K_AMPDU_SUBFRM_NUM_20,
421 	ATH12K_AMPDU_SUBFRM_NUM_30,
422 	ATH12K_AMPDU_SUBFRM_NUM_40,
423 	ATH12K_AMPDU_SUBFRM_NUM_50,
424 	ATH12K_AMPDU_SUBFRM_NUM_60,
425 	ATH12K_AMPDU_SUBFRM_NUM_MORE,
426 	ATH12K_AMPDU_SUBFRM_NUM_MAX,
427 };
428 
429 enum ath12k_amsdu_subfrm_num {
430 	ATH12K_AMSDU_SUBFRM_NUM_1,
431 	ATH12K_AMSDU_SUBFRM_NUM_2,
432 	ATH12K_AMSDU_SUBFRM_NUM_3,
433 	ATH12K_AMSDU_SUBFRM_NUM_4,
434 	ATH12K_AMSDU_SUBFRM_NUM_MORE,
435 	ATH12K_AMSDU_SUBFRM_NUM_MAX,
436 };
437 
438 enum ath12k_counter_type {
439 	ATH12K_COUNTER_TYPE_BYTES,
440 	ATH12K_COUNTER_TYPE_PKTS,
441 	ATH12K_COUNTER_TYPE_MAX,
442 };
443 
444 enum ath12k_stats_type {
445 	ATH12K_STATS_TYPE_SUCC,
446 	ATH12K_STATS_TYPE_FAIL,
447 	ATH12K_STATS_TYPE_RETRY,
448 	ATH12K_STATS_TYPE_AMPDU,
449 	ATH12K_STATS_TYPE_MAX,
450 };
451 
452 struct ath12k_htt_data_stats {
453 	u64 legacy[ATH12K_COUNTER_TYPE_MAX][ATH12K_LEGACY_NUM];
454 	u64 ht[ATH12K_COUNTER_TYPE_MAX][ATH12K_HT_MCS_NUM];
455 	u64 vht[ATH12K_COUNTER_TYPE_MAX][ATH12K_VHT_MCS_NUM];
456 	u64 he[ATH12K_COUNTER_TYPE_MAX][ATH12K_HE_MCS_NUM];
457 	u64 bw[ATH12K_COUNTER_TYPE_MAX][ATH12K_BW_NUM];
458 	u64 nss[ATH12K_COUNTER_TYPE_MAX][ATH12K_NSS_NUM];
459 	u64 gi[ATH12K_COUNTER_TYPE_MAX][ATH12K_GI_NUM];
460 	u64 transmit_type[ATH12K_COUNTER_TYPE_MAX][HAL_RX_RECEPTION_TYPE_MAX];
461 	u64 ru_loc[ATH12K_COUNTER_TYPE_MAX][HAL_RX_RU_ALLOC_TYPE_MAX];
462 };
463 
464 struct ath12k_htt_tx_stats {
465 	struct ath12k_htt_data_stats stats[ATH12K_STATS_TYPE_MAX];
466 	u64 tx_duration;
467 	u64 ba_fails;
468 	u64 ack_fails;
469 	u16 ru_start;
470 	u16 ru_tones;
471 	u32 mu_group[MAX_MU_GROUP_ID];
472 };
473 
474 struct ath12k_per_ppdu_tx_stats {
475 	u16 succ_pkts;
476 	u16 failed_pkts;
477 	u16 retry_pkts;
478 	u32 succ_bytes;
479 	u32 failed_bytes;
480 	u32 retry_bytes;
481 };
482 
483 struct ath12k_link_sta {
484 	struct ath12k_link_vif *arvif;
485 	struct ath12k_sta *ahsta;
486 
487 	/* link address similar to ieee80211_link_sta */
488 	u8 addr[ETH_ALEN];
489 
490 	u16 tcl_metadata;
491 	u16 ast_hash;
492 	u16 ast_idx;
493 
494 	/* the following are protected by ar->data_lock */
495 	u32 changed; /* IEEE80211_RC_* */
496 	u32 bw;
497 	u32 nss;
498 	u32 smps;
499 
500 	struct wiphy_work update_wk;
501 	u8 link_id;
502 	u32 bw_prev;
503 	u32 peer_nss;
504 	s8 rssi_beacon;
505 	s8 chain_signal[IEEE80211_MAX_CHAINS];
506 
507 	/* For now the assoc link will be considered primary */
508 	bool is_assoc_link;
509 
510 	 /* for firmware use only */
511 	u8 link_idx;
512 
513 	/* peer addr based rhashtable list pointer */
514 	struct rhash_head rhash_addr;
515 };
516 
517 struct ath12k_sta {
518 	struct ath12k_vif *ahvif;
519 	enum hal_pn_type pn_type;
520 	struct ath12k_link_sta deflink;
521 	struct ath12k_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
522 	/* indicates bitmap of link sta created in FW */
523 	u16 links_map;
524 	u8 assoc_link_id;
525 	u16 ml_peer_id;
526 	u16 free_logical_link_idx_map;
527 
528 	enum ieee80211_sta_state state;
529 
530 	bool enable_4addr;
531 };
532 
533 #define ATH12K_HALF_20MHZ_BW	10
534 #define ATH12K_2GHZ_MIN_CENTER	2412
535 #define ATH12K_2GHZ_MAX_CENTER	2484
536 #define ATH12K_5GHZ_MIN_CENTER	4900
537 #define ATH12K_5GHZ_MAX_CENTER	5920
538 #define ATH12K_6GHZ_MIN_CENTER	5935
539 #define ATH12K_6GHZ_MAX_CENTER	7115
540 #define ATH12K_MIN_2GHZ_FREQ	(ATH12K_2GHZ_MIN_CENTER - ATH12K_HALF_20MHZ_BW - 1)
541 #define ATH12K_MAX_2GHZ_FREQ	(ATH12K_2GHZ_MAX_CENTER + ATH12K_HALF_20MHZ_BW + 1)
542 #define ATH12K_MIN_5GHZ_FREQ	(ATH12K_5GHZ_MIN_CENTER - ATH12K_HALF_20MHZ_BW)
543 #define ATH12K_MAX_5GHZ_FREQ	(ATH12K_5GHZ_MAX_CENTER + ATH12K_HALF_20MHZ_BW)
544 #define ATH12K_MIN_6GHZ_FREQ	(ATH12K_6GHZ_MIN_CENTER - ATH12K_HALF_20MHZ_BW)
545 #define ATH12K_MAX_6GHZ_FREQ	(ATH12K_6GHZ_MAX_CENTER + ATH12K_HALF_20MHZ_BW)
546 #define ATH12K_NUM_CHANS 102
547 #define ATH12K_MAX_5GHZ_CHAN 177
548 
549 static inline bool ath12k_is_2ghz_channel_freq(u32 freq)
550 {
551 	return freq >= ATH12K_MIN_2GHZ_FREQ &&
552 	       freq <= ATH12K_MAX_2GHZ_FREQ;
553 }
554 
555 enum ath12k_hw_state {
556 	ATH12K_HW_STATE_OFF,
557 	ATH12K_HW_STATE_ON,
558 	ATH12K_HW_STATE_RESTARTING,
559 	ATH12K_HW_STATE_RESTARTED,
560 	ATH12K_HW_STATE_WEDGED,
561 	ATH12K_HW_STATE_TM,
562 	/* Add other states as required */
563 };
564 
565 /* Antenna noise floor */
566 #define ATH12K_DEFAULT_NOISE_FLOOR -95
567 
568 struct ath12k_ftm_event_obj {
569 	u32 data_pos;
570 	u32 expected_seq;
571 	u8 *eventdata;
572 };
573 
574 struct ath12k_fw_stats {
575 	u32 pdev_id;
576 	u32 stats_id;
577 	struct list_head pdevs;
578 	struct list_head vdevs;
579 	struct list_head bcn;
580 	u32 num_vdev_recvd;
581 };
582 
583 struct ath12k_dbg_htt_stats {
584 	enum ath12k_dbg_htt_ext_stats_type type;
585 	u32 cfg_param[4];
586 	u8 reset;
587 	struct debug_htt_stats_req *stats_req;
588 };
589 
590 struct ath12k_debug {
591 	struct dentry *debugfs_pdev;
592 	struct dentry *debugfs_pdev_symlink;
593 	struct dentry *debugfs_pdev_symlink_default;
594 	struct ath12k_dbg_htt_stats htt_stats;
595 	enum wmi_halphy_ctrl_path_stats_id tpc_stats_type;
596 	bool tpc_request;
597 	struct completion tpc_complete;
598 	struct wmi_tpc_stats_arg *tpc_stats;
599 	u32 rx_filter;
600 	bool extd_rx_stats;
601 };
602 
603 struct ath12k_pdev_rssi_offsets {
604 	s32 temp_offset;
605 	s8 min_nf_dbm;
606 	/* Cache the sum here to avoid calculating it every time in hot path
607 	 * noise_floor = min_nf_dbm + temp_offset
608 	 */
609 	s32 noise_floor;
610 };
611 
612 #define ATH12K_FLUSH_TIMEOUT (5 * HZ)
613 #define ATH12K_VDEV_DELETE_TIMEOUT_HZ (5 * HZ)
614 
615 struct ath12k {
616 	struct ath12k_base *ab;
617 	struct ath12k_pdev *pdev;
618 	struct ath12k_hw *ah;
619 	struct ath12k_wmi_pdev *wmi;
620 	struct ath12k_pdev_dp dp;
621 	u8 mac_addr[ETH_ALEN];
622 	u32 ht_cap_info;
623 	u32 vht_cap_info;
624 	struct ath12k_he ar_he;
625 	bool supports_6ghz;
626 	struct {
627 		struct completion started;
628 		struct completion completed;
629 		struct completion on_channel;
630 		struct delayed_work timeout;
631 		enum ath12k_scan_state state;
632 		bool is_roc;
633 		int roc_freq;
634 		bool roc_notify;
635 		struct wiphy_work vdev_clean_wk;
636 		struct ath12k_link_vif *arvif;
637 	} scan;
638 
639 	struct {
640 		struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
641 		struct ieee80211_sband_iftype_data
642 			iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
643 	} mac;
644 
645 	unsigned long dev_flags;
646 	unsigned int filter_flags;
647 	u32 min_tx_power;
648 	u32 max_tx_power;
649 	u32 txpower_limit_2g;
650 	u32 txpower_limit_5g;
651 	u32 txpower_scale;
652 	u32 power_scale;
653 	u32 chan_tx_pwr;
654 	u32 rts_threshold;
655 	u32 num_stations;
656 	u32 max_num_stations;
657 
658 	/* protects the radio specific data like debug stats, ppdu_stats_info stats,
659 	 * vdev_stop_status info, scan data, ath12k_sta info, ath12k_link_vif info,
660 	 * channel context data, test mode data, regd_channel_update_queue,
661 	 * peer_delete_waits.
662 	 */
663 	spinlock_t data_lock;
664 
665 	struct list_head arvifs;
666 	/* should never be NULL; needed for regular htt rx */
667 	struct ieee80211_channel *rx_channel;
668 
669 	/* valid during scan; needed for mgmt rx during scan */
670 	struct ieee80211_channel *scan_channel;
671 
672 	u8 cfg_tx_chainmask;
673 	u8 cfg_rx_chainmask;
674 	u8 num_rx_chains;
675 	u8 num_tx_chains;
676 	/* pdev_idx starts from 0 whereas pdev->pdev_id starts with 1 */
677 	u8 pdev_idx;
678 	u8 lmac_id;
679 	u8 hw_link_id;
680 	u8 radio_idx;
681 
682 	struct completion peer_assoc_done;
683 	struct list_head peer_delete_waits;
684 
685 	int install_key_status;
686 	struct completion install_key_done;
687 
688 	int last_wmi_vdev_start_status;
689 	struct completion vdev_setup_done;
690 	struct completion vdev_delete_done;
691 
692 	int num_peers;
693 	int max_num_peers;
694 	u32 num_started_vdevs;
695 	u32 num_created_vdevs;
696 	unsigned long long allocated_vdev_map;
697 
698 	struct idr txmgmt_idr;
699 	/* protects txmgmt_idr data */
700 	spinlock_t txmgmt_idr_lock;
701 	atomic_t num_pending_mgmt_tx;
702 	wait_queue_head_t txmgmt_empty_waitq;
703 
704 	/* cycle count is reported twice for each visited channel during scan.
705 	 * access protected by data_lock
706 	 */
707 	u32 survey_last_rx_clear_count;
708 	u32 survey_last_cycle_count;
709 
710 	/* Channel info events are expected to come in pairs without and with
711 	 * COMPLETE flag set respectively for each channel visit during scan.
712 	 *
713 	 * However there are deviations from this rule. This flag is used to
714 	 * avoid reporting garbage data.
715 	 */
716 	bool ch_info_can_report_survey;
717 	struct completion bss_survey_done;
718 
719 	struct work_struct regd_update_work;
720 	struct work_struct regd_channel_update_work;
721 	struct list_head regd_channel_update_queue;
722 
723 	struct wiphy_work wmi_mgmt_tx_work;
724 	struct sk_buff_head wmi_mgmt_tx_queue;
725 
726 	struct ath12k_wow wow;
727 	struct completion target_suspend;
728 	bool target_suspend_ack;
729 
730 	struct ath12k_per_peer_tx_stats cached_stats;
731 	u32 last_ppdu_id;
732 	u32 cached_ppdu_id;
733 #ifdef CONFIG_ATH12K_DEBUGFS
734 	struct ath12k_debug debug;
735 #endif
736 
737 	bool dfs_block_radar_events;
738 	bool monitor_vdev_created;
739 	bool monitor_started;
740 	int monitor_vdev_id;
741 
742 	struct wiphy_radio_freq_range freq_range;
743 
744 	bool nlo_enabled;
745 
746 	/* Protected by wiphy::mtx lock. */
747 	u32 vdev_id_11d_scan;
748 	struct completion completed_11d_scan;
749 	enum ath12k_11d_state state_11d;
750 	u8 alpha2[REG_ALPHA2_LEN];
751 	bool regdom_set_by_user;
752 	struct completion regd_update_completed;
753 
754 	struct completion fw_stats_complete;
755 	struct completion fw_stats_done;
756 
757 	struct completion mlo_setup_done;
758 	u32 mlo_setup_status;
759 	u8 ftm_msgref;
760 	struct ath12k_fw_stats fw_stats;
761 	unsigned long last_tx_power_update;
762 
763 	s8 max_allowed_tx_power;
764 	struct ath12k_pdev_rssi_offsets rssi_info;
765 
766 	struct ath12k_thermal thermal;
767 
768 	/* Protected by ar->data_lock */
769 	struct ath12k_incumbent_signal_interference {
770 		u32 center_freq;
771 		enum nl80211_chan_width width;
772 		u32 chan_bw_interference_bitmap;
773 		bool handling_in_progress;
774 	} incumbent_signal_interference;
775 };
776 
777 struct ath12k_hw {
778 	struct ieee80211_hw *hw;
779 	struct device *dev;
780 
781 	/* Protect the write operation of the hardware state ath12k_hw::state
782 	 * between hardware start<=>reconfigure<=>stop transitions.
783 	 */
784 	struct mutex hw_mutex;
785 	enum ath12k_hw_state state;
786 
787 	/* protects survey[] shared across radios of this hw. */
788 	spinlock_t survey_lock;
789 	struct survey_info survey[ATH12K_NUM_CHANS];
790 
791 	bool regd_updated;
792 	bool use_6ghz_regd;
793 	bool host_alloc_ml_id;
794 	struct completion peer_ml_id_done;
795 
796 	u8 num_radio;
797 
798 	DECLARE_BITMAP(free_ml_peer_id_map, ATH12K_MAX_MLO_PEERS);
799 
800 	struct ath12k_dp_hw dp_hw;
801 
802 	/* Keep last */
803 	struct ath12k radio[] __aligned(sizeof(void *));
804 };
805 
806 struct ath12k_band_cap {
807 	u32 phy_id;
808 	u32 max_bw_supported;
809 	u32 ht_cap_info;
810 	u32 he_cap_info[2];
811 	u32 he_mcs;
812 	u32 he_cap_phy_info[PSOC_HOST_MAX_PHY_SIZE];
813 	struct ath12k_wmi_ppe_threshold_arg he_ppet;
814 	u16 he_6ghz_capa;
815 	u32 eht_cap_mac_info[WMI_MAX_EHTCAP_MAC_SIZE];
816 	u32 eht_cap_phy_info[WMI_MAX_EHTCAP_PHY_SIZE];
817 	u32 eht_mcs_20_only;
818 	u32 eht_mcs_80;
819 	u32 eht_mcs_160;
820 	u32 eht_mcs_320;
821 	struct ath12k_wmi_ppe_threshold_arg eht_ppet;
822 	u32 eht_cap_info_internal;
823 };
824 
825 struct ath12k_pdev_cap {
826 	u32 supported_bands;
827 	u32 ampdu_density;
828 	u32 vht_cap;
829 	u32 vht_mcs;
830 	u32 he_mcs;
831 	u32 tx_chain_mask;
832 	u32 rx_chain_mask;
833 	u32 tx_chain_mask_shift;
834 	u32 rx_chain_mask_shift;
835 	struct ath12k_band_cap band[NUM_NL80211_BANDS];
836 	u32 eml_cap;
837 	u32 mld_cap;
838 	bool nss_ratio_enabled;
839 	u8 nss_ratio_info;
840 };
841 
842 struct mlo_timestamp {
843 	u32 info;
844 	u32 sync_timestamp_lo_us;
845 	u32 sync_timestamp_hi_us;
846 	u32 mlo_offset_lo;
847 	u32 mlo_offset_hi;
848 	u32 mlo_offset_clks;
849 	u32 mlo_comp_clks;
850 	u32 mlo_comp_timer;
851 };
852 
853 struct ath12k_pdev {
854 	struct ath12k *ar;
855 	u32 pdev_id;
856 	u32 hw_link_id;
857 	struct ath12k_pdev_cap cap;
858 	u8 mac_addr[ETH_ALEN];
859 	struct mlo_timestamp timestamp;
860 };
861 
862 struct ath12k_fw_pdev {
863 	u32 pdev_id;
864 	u32 phy_id;
865 	u32 supported_bands;
866 };
867 
868 struct ath12k_board_data {
869 	const struct firmware *fw;
870 	const void *data;
871 	size_t len;
872 };
873 
874 struct ath12k_reg_freq {
875 	u32 start_freq;
876 	u32 end_freq;
877 };
878 
879 struct ath12k_mlo_memory {
880 	struct target_mem_chunk chunk[ATH12K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01];
881 	int mlo_mem_size;
882 	bool init_done;
883 };
884 
885 struct ath12k_hw_link {
886 	u8 device_id;
887 	u8 pdev_idx;
888 };
889 
890 /* Holds info on the group of devices that are registered as a single
891  * wiphy, protected with struct ath12k_hw_group::mutex.
892  */
893 struct ath12k_hw_group {
894 	/* Keep dp_hw_grp as the first member to allow efficient
895 	 * usage of cache lines for DP fields
896 	 */
897 	struct ath12k_dp_hw_group dp_hw_grp;
898 	struct ath12k_hw_link hw_links[ATH12K_GROUP_MAX_RADIO];
899 	struct list_head list;
900 	u8 id;
901 	u8 num_devices;
902 	u8 num_probed;
903 	u8 num_started;
904 	unsigned long flags;
905 	struct ath12k_base *ab[ATH12K_MAX_DEVICES];
906 
907 	/* protects access to this struct */
908 	struct mutex mutex;
909 
910 	/* Holds information of wiphy (hw) registration.
911 	 *
912 	 * In Multi/Single Link Operation case, all pdevs are registered as
913 	 * a single wiphy. In other (legacy/Non-MLO) cases, each pdev is
914 	 * registered as separate wiphys.
915 	 */
916 	struct ath12k_hw *ah[ATH12K_GROUP_MAX_RADIO];
917 	u8 num_hw;
918 	bool mlo_capable;
919 	struct device_node *wsi_node[ATH12K_MAX_DEVICES];
920 	struct ath12k_mlo_memory mlo_mem;
921 	bool hw_link_id_init_done;
922 };
923 
924 /* Holds WSI info specific to each device, excluding WSI group info */
925 struct ath12k_wsi_info {
926 	u32 index;
927 	u32 hw_link_id_base;
928 };
929 
930 struct ath12k_mem_profile_based_param {
931 	u32 num_vdevs;
932 	u32 max_client_single;
933 	u32 max_client_dbs;
934 	u32 max_client_dbs_sbs;
935 	struct ath12k_dp_profile_params dp_params;
936 };
937 
938 enum ath12k_device_family {
939 	ATH12K_DEVICE_FAMILY_START,
940 	ATH12K_DEVICE_FAMILY_WIFI7 = ATH12K_DEVICE_FAMILY_START,
941 	ATH12K_DEVICE_FAMILY_MAX,
942 };
943 
944 /* Master structure to hold the hw data which may be used in core module */
945 struct ath12k_base {
946 	enum ath12k_hw_rev hw_rev;
947 	struct platform_device *pdev;
948 	struct device *dev;
949 	struct ath12k_qmi qmi;
950 	struct ath12k_wmi_base wmi_ab;
951 	struct completion fw_ready;
952 	u8 device_id;
953 	int num_radios;
954 	/* HW channel counters frequency value in hertz common to all MACs */
955 	u32 cc_freq_hz;
956 
957 	struct ath12k_dump_file_data *dump_data;
958 	size_t ath12k_coredump_len;
959 	struct work_struct dump_work;
960 
961 	struct ath12k_htc htc;
962 
963 	struct ath12k_dp *dp;
964 
965 	void __iomem *mem;
966 	unsigned long mem_len;
967 
968 	void __iomem *mem_ce;
969 	u32 ce_remap_base_addr;
970 	u32 cmem_offset;
971 	bool ce_remap;
972 
973 	struct {
974 		enum ath12k_bus bus;
975 		const struct ath12k_hif_ops *ops;
976 	} hif;
977 
978 	struct {
979 		struct completion wakeup_completed;
980 		u32 wmi_conf_rx_decap_mode;
981 	} wow;
982 
983 	struct ath12k_ce ce;
984 	struct timer_list rx_replenish_retry;
985 	struct ath12k_hal hal;
986 	/* To synchronize core_start/core_stop */
987 	struct mutex core_lock;
988 	/* Protects data like peers */
989 	spinlock_t base_lock;
990 
991 	/* Single pdev device (struct ath12k_hw_params::single_pdev_only):
992 	 *
993 	 * Firmware maintains data for all bands but advertises a single
994 	 * phy to the host which is stored as a single element in this
995 	 * array.
996 	 *
997 	 * Other devices:
998 	 *
999 	 * This array will contain as many elements as the number of
1000 	 * radios.
1001 	 */
1002 	struct ath12k_pdev pdevs[MAX_RADIOS];
1003 
1004 	/* struct ath12k_hw_params::single_pdev_only devices use this to
1005 	 * store phy specific data
1006 	 */
1007 	struct ath12k_fw_pdev fw_pdev[MAX_RADIOS];
1008 	u8 fw_pdev_count;
1009 
1010 	struct ath12k_pdev __rcu *pdevs_active[MAX_RADIOS];
1011 
1012 	struct ath12k_wmi_hal_reg_capabilities_ext_arg hal_reg_cap[MAX_RADIOS];
1013 	unsigned long long free_vdev_map;
1014 	unsigned long long free_vdev_stats_id_map;
1015 	wait_queue_head_t peer_mapping_wq;
1016 	u8 mac_addr[ETH_ALEN];
1017 	bool wmi_ready;
1018 	u32 wlan_init_status;
1019 	int irq_num[ATH12K_IRQ_NUM_MAX];
1020 	struct ath12k_ext_irq_grp ext_irq_grp[ATH12K_EXT_IRQ_GRP_NUM_MAX];
1021 	struct napi_struct *napi;
1022 	struct ath12k_wmi_target_cap_arg target_caps;
1023 	u32 ext_service_bitmap[WMI_SERVICE_EXT_BM_SIZE];
1024 	bool pdevs_macaddr_valid;
1025 
1026 	const struct ath12k_hw_params *hw_params;
1027 
1028 	const struct firmware *cal_file;
1029 
1030 	/* Below regd's are protected by ab->data_lock */
1031 	/* This is the regd set for every radio
1032 	 * by the firmware during initialization
1033 	 */
1034 	struct ieee80211_regdomain *default_regd[MAX_RADIOS];
1035 	/* This regd is set during dynamic country setting
1036 	 * This may or may not be used during the runtime
1037 	 */
1038 	struct ieee80211_regdomain *new_regd[MAX_RADIOS];
1039 
1040 	struct ath12k_reg_info *reg_info[MAX_RADIOS];
1041 
1042 	/* Current DFS Regulatory */
1043 	enum ath12k_dfs_region dfs_region;
1044 #ifdef CONFIG_ATH12K_DEBUGFS
1045 	struct dentry *debugfs_soc;
1046 #endif
1047 
1048 	unsigned long dev_flags;
1049 	struct completion driver_recovery;
1050 	struct workqueue_struct *workqueue;
1051 	struct work_struct restart_work;
1052 	struct workqueue_struct *workqueue_aux;
1053 	struct work_struct reset_work;
1054 	atomic_t reset_count;
1055 	atomic_t recovery_count;
1056 	bool is_reset;
1057 	struct completion reset_complete;
1058 	/* continuous recovery fail count */
1059 	atomic_t fail_cont_count;
1060 	unsigned long reset_fail_timeout;
1061 	struct work_struct update_11d_work;
1062 	u8 new_alpha2[2];
1063 	struct {
1064 		/* protected by data_lock */
1065 		u32 fw_crash_counter;
1066 	} stats;
1067 	u32 pktlog_defs_checksum;
1068 
1069 	struct ath12k_dbring_cap *db_caps;
1070 	u32 num_db_cap;
1071 
1072 	struct completion htc_suspend;
1073 
1074 	u64 fw_soc_drop_count;
1075 	bool static_window_map;
1076 
1077 	struct work_struct rfkill_work;
1078 	/* true means radio is on */
1079 	bool rfkill_radio_on;
1080 
1081 	struct {
1082 		enum ath12k_bdf_search bdf_search;
1083 		u32 vendor;
1084 		u32 device;
1085 		u32 subsystem_vendor;
1086 		u32 subsystem_device;
1087 	} id;
1088 
1089 	struct {
1090 		u32 api_version;
1091 
1092 		const struct firmware *fw;
1093 		const u8 *amss_data;
1094 		size_t amss_len;
1095 		const u8 *amss_dualmac_data;
1096 		size_t amss_dualmac_len;
1097 		const u8 *m3_data;
1098 		size_t m3_len;
1099 		const u8 *aux_uc_data;
1100 		size_t aux_uc_len;
1101 
1102 		DECLARE_BITMAP(fw_features, ATH12K_FW_FEATURE_COUNT);
1103 		bool fw_features_valid;
1104 	} fw;
1105 
1106 	struct completion restart_completed;
1107 
1108 #ifdef CONFIG_ACPI
1109 
1110 	struct {
1111 		bool started;
1112 		u32 func_bit;
1113 		bool acpi_tas_enable;
1114 		bool acpi_bios_sar_enable;
1115 		bool acpi_disable_11be;
1116 		bool acpi_disable_rfkill;
1117 		bool acpi_cca_enable;
1118 		bool acpi_band_edge_enable;
1119 		bool acpi_enable_bdf;
1120 		u32 bit_flag;
1121 		char bdf_string[ATH12K_ACPI_BDF_MAX_LEN];
1122 		u8 tas_cfg[ATH12K_ACPI_DSM_TAS_CFG_SIZE];
1123 		u8 tas_sar_power_table[ATH12K_ACPI_DSM_TAS_DATA_SIZE];
1124 		u8 bios_sar_data[ATH12K_ACPI_DSM_BIOS_SAR_DATA_SIZE];
1125 		u8 geo_offset_data[ATH12K_ACPI_DSM_GEO_OFFSET_DATA_SIZE];
1126 		u8 cca_data[ATH12K_ACPI_DSM_CCA_DATA_SIZE];
1127 		u8 band_edge_power[ATH12K_ACPI_DSM_BAND_EDGE_DATA_SIZE];
1128 	} acpi;
1129 
1130 #endif /* CONFIG_ACPI */
1131 
1132 	struct ath12k_hw_group *ag;
1133 	struct ath12k_wsi_info wsi_info;
1134 	enum ath12k_qmi_firmware_mode fw_mode;
1135 	struct ath12k_ftm_event_obj ftm_event_obj;
1136 	bool hw_group_ref;
1137 
1138 	/* Denote whether MLO is possible within the device */
1139 	bool single_chip_mlo_support;
1140 
1141 	struct ath12k_reg_freq reg_freq_2ghz;
1142 	struct ath12k_reg_freq reg_freq_5ghz;
1143 	struct ath12k_reg_freq reg_freq_6ghz;
1144 	const struct ath12k_mem_profile_based_param *profile_param;
1145 	enum ath12k_qmi_mem_mode target_mem_mode;
1146 
1147 	/* FIXME: Define this field in a ag equivalent object available
1148 	 * during the initial phase of probe later.
1149 	 */
1150 	const struct ieee80211_ops *ath12k_ops;
1151 
1152 	struct rhashtable *rhead_sta_addr;
1153 	struct rhashtable_params rhash_sta_addr_param;
1154 
1155 	/* must be last */
1156 	u8 drv_priv[] __aligned(sizeof(void *));
1157 };
1158 
1159 struct ath12k_pdev_map {
1160 	struct ath12k_base *ab;
1161 	u8 pdev_idx;
1162 };
1163 
1164 struct ath12k_fw_stats_vdev {
1165 	struct list_head list;
1166 
1167 	u32 vdev_id;
1168 	u32 beacon_snr;
1169 	u32 data_snr;
1170 	u32 num_tx_frames[WLAN_MAX_AC];
1171 	u32 num_rx_frames;
1172 	u32 num_tx_frames_retries[WLAN_MAX_AC];
1173 	u32 num_tx_frames_failures[WLAN_MAX_AC];
1174 	u32 num_rts_fail;
1175 	u32 num_rts_success;
1176 	u32 num_rx_err;
1177 	u32 num_rx_discard;
1178 	u32 num_tx_not_acked;
1179 	u32 tx_rate_history[MAX_TX_RATE_VALUES];
1180 	u32 beacon_rssi_history[MAX_TX_RATE_VALUES];
1181 };
1182 
1183 struct ath12k_fw_stats_bcn {
1184 	struct list_head list;
1185 
1186 	u32 vdev_id;
1187 	u32 tx_bcn_succ_cnt;
1188 	u32 tx_bcn_outage_cnt;
1189 };
1190 
1191 struct ath12k_fw_stats_pdev {
1192 	struct list_head list;
1193 
1194 	/* PDEV stats */
1195 	s32 ch_noise_floor;
1196 	u32 tx_frame_count;
1197 	u32 rx_frame_count;
1198 	u32 rx_clear_count;
1199 	u32 cycle_count;
1200 	u32 phy_err_count;
1201 	u32 chan_tx_power;
1202 	u32 ack_rx_bad;
1203 	u32 rts_bad;
1204 	u32 rts_good;
1205 	u32 fcs_bad;
1206 	u32 no_beacons;
1207 	u32 mib_int_count;
1208 
1209 	/* PDEV TX stats */
1210 	s32 comp_queued;
1211 	s32 comp_delivered;
1212 	s32 msdu_enqued;
1213 	s32 mpdu_enqued;
1214 	s32 wmm_drop;
1215 	s32 local_enqued;
1216 	s32 local_freed;
1217 	s32 hw_queued;
1218 	s32 hw_reaped;
1219 	s32 underrun;
1220 	s32 tx_abort;
1221 	s32 mpdus_requed;
1222 	u32 tx_ko;
1223 	u32 data_rc;
1224 	u32 self_triggers;
1225 	u32 sw_retry_failure;
1226 	u32 illgl_rate_phy_err;
1227 	u32 pdev_cont_xretry;
1228 	u32 pdev_tx_timeout;
1229 	u32 pdev_resets;
1230 	u32 stateless_tid_alloc_failure;
1231 	u32 phy_underrun;
1232 	u32 txop_ovf;
1233 
1234 	/* PDEV RX stats */
1235 	s32 mid_ppdu_route_change;
1236 	s32 status_rcvd;
1237 	s32 r0_frags;
1238 	s32 r1_frags;
1239 	s32 r2_frags;
1240 	s32 r3_frags;
1241 	s32 htt_msdus;
1242 	s32 htt_mpdus;
1243 	s32 loc_msdus;
1244 	s32 loc_mpdus;
1245 	s32 oversize_amsdu;
1246 	s32 phy_errs;
1247 	s32 phy_err_drop;
1248 	s32 mpdu_errs;
1249 };
1250 
1251 int ath12k_core_qmi_firmware_ready(struct ath12k_base *ab);
1252 void ath12k_core_hw_group_cleanup(struct ath12k_hw_group *ag);
1253 int ath12k_core_pre_init(struct ath12k_base *ab);
1254 int ath12k_core_init(struct ath12k_base *ath12k);
1255 void ath12k_core_deinit(struct ath12k_base *ath12k);
1256 struct ath12k_base *ath12k_core_alloc(struct device *dev, size_t priv_size,
1257 				      enum ath12k_bus bus);
1258 void ath12k_core_free(struct ath12k_base *ath12k);
1259 int ath12k_core_fetch_board_data_api_1(struct ath12k_base *ab,
1260 				       struct ath12k_board_data *bd,
1261 				       char *filename);
1262 int ath12k_core_fetch_bdf(struct ath12k_base *ath12k,
1263 			  struct ath12k_board_data *bd);
1264 void ath12k_core_free_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd);
1265 int ath12k_core_fetch_regdb(struct ath12k_base *ab, struct ath12k_board_data *bd);
1266 int ath12k_core_check_dt(struct ath12k_base *ath12k);
1267 int ath12k_core_check_smbios(struct ath12k_base *ab);
1268 void ath12k_core_halt(struct ath12k *ar);
1269 int ath12k_core_resume_early(struct ath12k_base *ab);
1270 int ath12k_core_resume(struct ath12k_base *ab);
1271 int ath12k_core_suspend(struct ath12k_base *ab);
1272 int ath12k_core_suspend_late(struct ath12k_base *ab);
1273 void ath12k_core_hw_group_unassign(struct ath12k_base *ab);
1274 u8 ath12k_get_num_partner_link(struct ath12k *ar);
1275 
1276 const struct firmware *ath12k_core_firmware_request(struct ath12k_base *ab,
1277 						    const char *filename);
1278 u32 ath12k_core_get_max_station_per_radio(struct ath12k_base *ab);
1279 u32 ath12k_core_get_max_peers_per_radio(struct ath12k_base *ab);
1280 
1281 void ath12k_core_hw_group_set_mlo_capable(struct ath12k_hw_group *ag);
1282 void ath12k_fw_stats_init(struct ath12k *ar);
1283 void ath12k_fw_stats_bcn_free(struct list_head *head);
1284 void ath12k_fw_stats_free(struct ath12k_fw_stats *stats);
1285 void ath12k_fw_stats_reset(struct ath12k *ar);
1286 enum ath12k_qmi_mem_mode ath12k_core_get_memory_mode(struct ath12k_base *ab);
1287 
1288 static inline const char *ath12k_scan_state_str(enum ath12k_scan_state state)
1289 {
1290 	switch (state) {
1291 	case ATH12K_SCAN_IDLE:
1292 		return "idle";
1293 	case ATH12K_SCAN_STARTING:
1294 		return "starting";
1295 	case ATH12K_SCAN_RUNNING:
1296 		return "running";
1297 	case ATH12K_SCAN_ABORTING:
1298 		return "aborting";
1299 	}
1300 
1301 	return "unknown";
1302 }
1303 
1304 static inline struct ath12k_skb_cb *ATH12K_SKB_CB(struct sk_buff *skb)
1305 {
1306 	BUILD_BUG_ON(sizeof(struct ath12k_skb_cb) >
1307 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
1308 	return (struct ath12k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
1309 }
1310 
1311 static inline struct ath12k_skb_rxcb *ATH12K_SKB_RXCB(struct sk_buff *skb)
1312 {
1313 	BUILD_BUG_ON(sizeof(struct ath12k_skb_rxcb) > sizeof(skb->cb));
1314 	return (struct ath12k_skb_rxcb *)skb->cb;
1315 }
1316 
1317 static inline struct ath12k_vif *ath12k_vif_to_ahvif(struct ieee80211_vif *vif)
1318 {
1319 	return (struct ath12k_vif *)vif->drv_priv;
1320 }
1321 
1322 static inline struct ath12k_sta *ath12k_sta_to_ahsta(struct ieee80211_sta *sta)
1323 {
1324 	return (struct ath12k_sta *)sta->drv_priv;
1325 }
1326 
1327 static inline struct ieee80211_sta *ath12k_ahsta_to_sta(struct ath12k_sta *ahsta)
1328 {
1329 	return container_of((void *)ahsta, struct ieee80211_sta, drv_priv);
1330 }
1331 
1332 static inline struct ieee80211_vif *ath12k_ahvif_to_vif(struct ath12k_vif *ahvif)
1333 {
1334 	return container_of((void *)ahvif, struct ieee80211_vif, drv_priv);
1335 }
1336 
1337 static inline struct ath12k *ath12k_ab_to_ar(struct ath12k_base *ab,
1338 					     int mac_id)
1339 {
1340 	return ab->pdevs[ath12k_hw_mac_id_to_pdev_id(ab->hw_params, mac_id)].ar;
1341 }
1342 
1343 static inline void ath12k_core_create_firmware_path(struct ath12k_base *ab,
1344 						    const char *filename,
1345 						    void *buf, size_t buf_len)
1346 {
1347 	const char *fw_name = NULL;
1348 
1349 	of_property_read_string(ab->dev->of_node, "firmware-name", &fw_name);
1350 
1351 	if (fw_name && strncmp(filename, "board", 5))
1352 		snprintf(buf, buf_len, "%s/%s/%s/%s", ATH12K_FW_DIR,
1353 			 ab->hw_params->fw.dir, fw_name, filename);
1354 	else
1355 		snprintf(buf, buf_len, "%s/%s/%s", ATH12K_FW_DIR,
1356 			 ab->hw_params->fw.dir, filename);
1357 }
1358 
1359 static inline const char *ath12k_bus_str(enum ath12k_bus bus)
1360 {
1361 	switch (bus) {
1362 	case ATH12K_BUS_PCI:
1363 		return "pci";
1364 	case ATH12K_BUS_AHB:
1365 		return "ahb";
1366 	}
1367 
1368 	return "unknown";
1369 }
1370 
1371 static inline struct ath12k_hw *ath12k_hw_to_ah(struct ieee80211_hw  *hw)
1372 {
1373 	return hw->priv;
1374 }
1375 
1376 static inline struct ath12k *ath12k_ah_to_ar(struct ath12k_hw *ah, u8 radio_idx)
1377 {
1378 	if (WARN(radio_idx >= ah->num_radio,
1379 		 "bad radio index %d, use default radio\n", radio_idx))
1380 		radio_idx = 0;
1381 
1382 	return &ah->radio[radio_idx];
1383 }
1384 
1385 static inline struct ath12k_hw *ath12k_ar_to_ah(struct ath12k *ar)
1386 {
1387 	return ar->ah;
1388 }
1389 
1390 static inline struct ieee80211_hw *ath12k_ar_to_hw(struct ath12k *ar)
1391 {
1392 	return ar->ah->hw;
1393 }
1394 
1395 #define for_each_ar(ah, ar, index) \
1396 	for ((index) = 0; ((index) < (ah)->num_radio && \
1397 	     ((ar) = &(ah)->radio[(index)])); (index)++)
1398 
1399 static inline struct ath12k_hw *ath12k_ag_to_ah(struct ath12k_hw_group *ag, int idx)
1400 {
1401 	return ag->ah[idx];
1402 }
1403 
1404 static inline void ath12k_ag_set_ah(struct ath12k_hw_group *ag, int idx,
1405 				    struct ath12k_hw *ah)
1406 {
1407 	ag->ah[idx] = ah;
1408 }
1409 
1410 static inline struct ath12k_hw_group *ath12k_ab_to_ag(struct ath12k_base *ab)
1411 {
1412 	return ab->ag;
1413 }
1414 
1415 static inline struct ath12k_base *ath12k_ag_to_ab(struct ath12k_hw_group *ag,
1416 						  u8 device_id)
1417 {
1418 	return ag->ab[device_id];
1419 }
1420 
1421 static inline s32 ath12k_pdev_get_noise_floor(struct ath12k *ar)
1422 {
1423 	lockdep_assert_held(&ar->data_lock);
1424 
1425 	return ar->rssi_info.noise_floor;
1426 }
1427 
1428 /* The @ab->dp NULL check or assertion is intentionally omitted because
1429  * @ab->dp is guaranteed to be non-NULL after a successful probe and
1430  * remains valid until teardown. Invoking this before allocation or
1431  * after teardown is considered invalid usage.
1432  */
1433 static inline struct ath12k_dp *ath12k_ab_to_dp(struct ath12k_base *ab)
1434 {
1435 	return ab->dp;
1436 }
1437 
1438 static inline struct ath12k *ath12k_pdev_dp_to_ar(struct ath12k_pdev_dp *dp)
1439 {
1440 	return container_of(dp, struct ath12k, dp);
1441 }
1442 #endif /* _CORE_H_ */
1443