xref: /linux/drivers/net/wireless/ath/ath12k/core.h (revision 816b02e63a759c4458edee142b721ab09c918b3d)
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
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/panic_notifier.h>
18 #include "qmi.h"
19 #include "htc.h"
20 #include "wmi.h"
21 #include "hal.h"
22 #include "dp.h"
23 #include "ce.h"
24 #include "mac.h"
25 #include "hw.h"
26 #include "hal_rx.h"
27 #include "reg.h"
28 #include "dbring.h"
29 #include "fw.h"
30 #include "acpi.h"
31 #include "wow.h"
32 #include "debugfs_htt_stats.h"
33 #include "coredump.h"
34 
35 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
36 
37 #define ATH12K_TX_MGMT_NUM_PENDING_MAX	512
38 
39 #define ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI 64
40 
41 /* Pending management packets threshold for dropping probe responses */
42 #define ATH12K_PRB_RSP_DROP_THRESHOLD ((ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI * 3) / 4)
43 
44 /* SMBIOS type containing Board Data File Name Extension */
45 #define ATH12K_SMBIOS_BDF_EXT_TYPE 0xF8
46 
47 /* SMBIOS type structure length (excluding strings-set) */
48 #define ATH12K_SMBIOS_BDF_EXT_LENGTH 0x9
49 
50 /* The magic used by QCA spec */
51 #define ATH12K_SMBIOS_BDF_EXT_MAGIC "BDF_"
52 
53 #define ATH12K_INVALID_HW_MAC_ID	0xFF
54 #define ATH12K_CONNECTION_LOSS_HZ	(3 * HZ)
55 #define	ATH12K_RX_RATE_TABLE_NUM	320
56 #define	ATH12K_RX_RATE_TABLE_11AX_NUM	576
57 
58 #define ATH12K_MON_TIMER_INTERVAL  10
59 #define ATH12K_RESET_TIMEOUT_HZ			(20 * HZ)
60 #define ATH12K_RESET_MAX_FAIL_COUNT_FIRST	3
61 #define ATH12K_RESET_MAX_FAIL_COUNT_FINAL	5
62 #define ATH12K_RESET_FAIL_TIMEOUT_HZ		(20 * HZ)
63 #define ATH12K_RECONFIGURE_TIMEOUT_HZ		(10 * HZ)
64 #define ATH12K_RECOVER_START_TIMEOUT_HZ		(20 * HZ)
65 
66 #define ATH12K_MAX_SOCS 3
67 #define ATH12K_GROUP_MAX_RADIO (ATH12K_MAX_SOCS * MAX_RADIOS)
68 #define ATH12K_INVALID_GROUP_ID  0xFF
69 #define ATH12K_INVALID_DEVICE_ID 0xFF
70 
71 #define ATH12K_MAX_MLO_PEERS            256
72 #define ATH12K_MLO_PEER_ID_INVALID      0xFFFF
73 
74 enum ath12k_bdf_search {
75 	ATH12K_BDF_SEARCH_DEFAULT,
76 	ATH12K_BDF_SEARCH_BUS_AND_BOARD,
77 };
78 
79 enum wme_ac {
80 	WME_AC_BE,
81 	WME_AC_BK,
82 	WME_AC_VI,
83 	WME_AC_VO,
84 	WME_NUM_AC
85 };
86 
87 #define ATH12K_HT_MCS_MAX	7
88 #define ATH12K_VHT_MCS_MAX	9
89 #define ATH12K_HE_MCS_MAX	11
90 
91 enum ath12k_crypt_mode {
92 	/* Only use hardware crypto engine */
93 	ATH12K_CRYPT_MODE_HW,
94 	/* Only use software crypto */
95 	ATH12K_CRYPT_MODE_SW,
96 };
97 
98 static inline enum wme_ac ath12k_tid_to_ac(u32 tid)
99 {
100 	return (((tid == 0) || (tid == 3)) ? WME_AC_BE :
101 		((tid == 1) || (tid == 2)) ? WME_AC_BK :
102 		((tid == 4) || (tid == 5)) ? WME_AC_VI :
103 		WME_AC_VO);
104 }
105 
106 static inline u64 ath12k_le32hilo_to_u64(__le32 hi, __le32 lo)
107 {
108 	u64 hi64 = le32_to_cpu(hi);
109 	u64 lo64 = le32_to_cpu(lo);
110 
111 	return (hi64 << 32) | lo64;
112 }
113 
114 enum ath12k_skb_flags {
115 	ATH12K_SKB_HW_80211_ENCAP = BIT(0),
116 	ATH12K_SKB_CIPHER_SET = BIT(1),
117 };
118 
119 struct ath12k_skb_cb {
120 	dma_addr_t paddr;
121 	struct ath12k *ar;
122 	struct ieee80211_vif *vif;
123 	dma_addr_t paddr_ext_desc;
124 	u32 cipher;
125 	u8 flags;
126 	u8 link_id;
127 };
128 
129 struct ath12k_skb_rxcb {
130 	dma_addr_t paddr;
131 	bool is_first_msdu;
132 	bool is_last_msdu;
133 	bool is_continuation;
134 	bool is_mcbc;
135 	bool is_eapol;
136 	struct hal_rx_desc *rx_desc;
137 	u8 err_rel_src;
138 	u8 err_code;
139 	u8 mac_id;
140 	u8 unmapped;
141 	u8 is_frag;
142 	u8 tid;
143 	u16 peer_id;
144 };
145 
146 enum ath12k_hw_rev {
147 	ATH12K_HW_QCN9274_HW10,
148 	ATH12K_HW_QCN9274_HW20,
149 	ATH12K_HW_WCN7850_HW20
150 };
151 
152 enum ath12k_firmware_mode {
153 	/* the default mode, standard 802.11 functionality */
154 	ATH12K_FIRMWARE_MODE_NORMAL,
155 
156 	/* factory tests etc */
157 	ATH12K_FIRMWARE_MODE_FTM,
158 };
159 
160 #define ATH12K_IRQ_NUM_MAX 57
161 #define ATH12K_EXT_IRQ_NUM_MAX	16
162 
163 struct ath12k_ext_irq_grp {
164 	struct ath12k_base *ab;
165 	u32 irqs[ATH12K_EXT_IRQ_NUM_MAX];
166 	u32 num_irq;
167 	u32 grp_id;
168 	u64 timestamp;
169 	struct napi_struct napi;
170 	struct net_device *napi_ndev;
171 };
172 
173 struct ath12k_smbios_bdf {
174 	struct dmi_header hdr;
175 	u32 padding;
176 	u8 bdf_enabled;
177 	u8 bdf_ext[];
178 } __packed;
179 
180 #define HEHANDLE_CAP_PHYINFO_SIZE       3
181 #define HECAP_PHYINFO_SIZE              9
182 #define HECAP_MACINFO_SIZE              5
183 #define HECAP_TXRX_MCS_NSS_SIZE         2
184 #define HECAP_PPET16_PPET8_MAX_SIZE     25
185 
186 #define HE_PPET16_PPET8_SIZE            8
187 
188 /* 802.11ax PPE (PPDU packet Extension) threshold */
189 struct he_ppe_threshold {
190 	u32 numss_m1;
191 	u32 ru_mask;
192 	u32 ppet16_ppet8_ru3_ru0[HE_PPET16_PPET8_SIZE];
193 };
194 
195 struct ath12k_he {
196 	u8 hecap_macinfo[HECAP_MACINFO_SIZE];
197 	u32 hecap_rxmcsnssmap;
198 	u32 hecap_txmcsnssmap;
199 	u32 hecap_phyinfo[HEHANDLE_CAP_PHYINFO_SIZE];
200 	struct he_ppe_threshold   hecap_ppet;
201 	u32 heop_param;
202 };
203 
204 enum {
205 	WMI_HOST_TP_SCALE_MAX   = 0,
206 	WMI_HOST_TP_SCALE_50    = 1,
207 	WMI_HOST_TP_SCALE_25    = 2,
208 	WMI_HOST_TP_SCALE_12    = 3,
209 	WMI_HOST_TP_SCALE_MIN   = 4,
210 	WMI_HOST_TP_SCALE_SIZE   = 5,
211 };
212 
213 enum ath12k_scan_state {
214 	ATH12K_SCAN_IDLE,
215 	ATH12K_SCAN_STARTING,
216 	ATH12K_SCAN_RUNNING,
217 	ATH12K_SCAN_ABORTING,
218 };
219 
220 enum ath12k_hw_group_flags {
221 	ATH12K_GROUP_FLAG_REGISTERED,
222 };
223 
224 enum ath12k_dev_flags {
225 	ATH12K_CAC_RUNNING,
226 	ATH12K_FLAG_CRASH_FLUSH,
227 	ATH12K_FLAG_RAW_MODE,
228 	ATH12K_FLAG_HW_CRYPTO_DISABLED,
229 	ATH12K_FLAG_RECOVERY,
230 	ATH12K_FLAG_UNREGISTERING,
231 	ATH12K_FLAG_REGISTERED,
232 	ATH12K_FLAG_QMI_FAIL,
233 	ATH12K_FLAG_HTC_SUSPEND_COMPLETE,
234 	ATH12K_FLAG_CE_IRQ_ENABLED,
235 	ATH12K_FLAG_EXT_IRQ_ENABLED,
236 	ATH12K_FLAG_QMI_FW_READY_COMPLETE,
237 };
238 
239 struct ath12k_tx_conf {
240 	bool changed;
241 	u16 ac;
242 	struct ieee80211_tx_queue_params tx_queue_params;
243 };
244 
245 struct ath12k_key_conf {
246 	enum set_key_cmd cmd;
247 	struct list_head list;
248 	struct ieee80211_sta *sta;
249 	struct ieee80211_key_conf *key;
250 };
251 
252 struct ath12k_vif_cache {
253 	struct ath12k_tx_conf tx_conf;
254 	struct ath12k_key_conf key_conf;
255 	u32 bss_conf_changed;
256 };
257 
258 struct ath12k_rekey_data {
259 	u8 kck[NL80211_KCK_LEN];
260 	u8 kek[NL80211_KCK_LEN];
261 	u64 replay_ctr;
262 	bool enable_offload;
263 };
264 
265 struct ath12k_link_vif {
266 	u32 vdev_id;
267 	u32 beacon_interval;
268 	u32 dtim_period;
269 	u16 ast_hash;
270 	u16 ast_idx;
271 	u16 tcl_metadata;
272 	u8 hal_addr_search_flags;
273 	u8 search_type;
274 
275 	struct ath12k *ar;
276 
277 	int bank_id;
278 	u8 vdev_id_check_en;
279 
280 	struct wmi_wmm_params_all_arg wmm_params;
281 	struct list_head list;
282 
283 	bool is_created;
284 	bool is_started;
285 	bool is_up;
286 	u8 bssid[ETH_ALEN];
287 	struct cfg80211_bitrate_mask bitrate_mask;
288 	struct delayed_work connection_loss_work;
289 	int num_legacy_stations;
290 	int rtscts_prot_mode;
291 	int txpower;
292 	bool rsnie_present;
293 	bool wpaie_present;
294 	struct ieee80211_chanctx_conf chanctx;
295 	u8 vdev_stats_id;
296 	u32 punct_bitmap;
297 	u8 link_id;
298 	struct ath12k_vif *ahvif;
299 	struct ath12k_rekey_data rekey_data;
300 };
301 
302 struct ath12k_vif {
303 	enum wmi_vdev_type vdev_type;
304 	enum wmi_vdev_subtype vdev_subtype;
305 	struct ieee80211_vif *vif;
306 	struct ath12k_hw *ah;
307 
308 	union {
309 		struct {
310 			u32 uapsd;
311 		} sta;
312 		struct {
313 			/* 127 stations; wmi limit */
314 			u8 tim_bitmap[16];
315 			u8 tim_len;
316 			u32 ssid_len;
317 			u8 ssid[IEEE80211_MAX_SSID_LEN];
318 			bool hidden_ssid;
319 			/* P2P_IE with NoA attribute for P2P_GO case */
320 			u32 noa_len;
321 			u8 *noa_data;
322 		} ap;
323 	} u;
324 
325 	u32 aid;
326 	u32 key_cipher;
327 	u8 tx_encap_type;
328 	bool ps;
329 
330 	struct ath12k_link_vif deflink;
331 	struct ath12k_link_vif __rcu *link[ATH12K_NUM_MAX_LINKS];
332 	struct ath12k_vif_cache *cache[IEEE80211_MLD_MAX_NUM_LINKS];
333 	/* indicates bitmap of link vif created in FW */
334 	u16 links_map;
335 	u8 last_scan_link;
336 
337 	/* Must be last - ends in a flexible-array member.
338 	 *
339 	 * FIXME: Driver should not copy struct ieee80211_chanctx_conf,
340 	 * especially because it has a flexible array. Find a better way.
341 	 */
342 	struct ieee80211_chanctx_conf chanctx;
343 };
344 
345 struct ath12k_vif_iter {
346 	u32 vdev_id;
347 	struct ath12k *ar;
348 	struct ath12k_link_vif *arvif;
349 };
350 
351 #define HAL_AST_IDX_INVALID	0xFFFF
352 #define HAL_RX_MAX_MCS		12
353 #define HAL_RX_MAX_MCS_HT	31
354 #define HAL_RX_MAX_MCS_VHT	9
355 #define HAL_RX_MAX_MCS_HE	11
356 #define HAL_RX_MAX_NSS		8
357 #define HAL_RX_MAX_NUM_LEGACY_RATES 12
358 #define ATH12K_RX_RATE_TABLE_11AX_NUM	576
359 #define ATH12K_RX_RATE_TABLE_NUM 320
360 
361 struct ath12k_rx_peer_rate_stats {
362 	u64 ht_mcs_count[HAL_RX_MAX_MCS_HT + 1];
363 	u64 vht_mcs_count[HAL_RX_MAX_MCS_VHT + 1];
364 	u64 he_mcs_count[HAL_RX_MAX_MCS_HE + 1];
365 	u64 nss_count[HAL_RX_MAX_NSS];
366 	u64 bw_count[HAL_RX_BW_MAX];
367 	u64 gi_count[HAL_RX_GI_MAX];
368 	u64 legacy_count[HAL_RX_MAX_NUM_LEGACY_RATES];
369 	u64 rx_rate[ATH12K_RX_RATE_TABLE_11AX_NUM];
370 };
371 
372 struct ath12k_rx_peer_stats {
373 	u64 num_msdu;
374 	u64 num_mpdu_fcs_ok;
375 	u64 num_mpdu_fcs_err;
376 	u64 tcp_msdu_count;
377 	u64 udp_msdu_count;
378 	u64 other_msdu_count;
379 	u64 ampdu_msdu_count;
380 	u64 non_ampdu_msdu_count;
381 	u64 stbc_count;
382 	u64 beamformed_count;
383 	u64 mcs_count[HAL_RX_MAX_MCS + 1];
384 	u64 nss_count[HAL_RX_MAX_NSS];
385 	u64 bw_count[HAL_RX_BW_MAX];
386 	u64 gi_count[HAL_RX_GI_MAX];
387 	u64 coding_count[HAL_RX_SU_MU_CODING_MAX];
388 	u64 tid_count[IEEE80211_NUM_TIDS + 1];
389 	u64 pream_cnt[HAL_RX_PREAMBLE_MAX];
390 	u64 reception_type[HAL_RX_RECEPTION_TYPE_MAX];
391 	u64 rx_duration;
392 	u64 dcm_count;
393 	u64 ru_alloc_cnt[HAL_RX_RU_ALLOC_TYPE_MAX];
394 	struct ath12k_rx_peer_rate_stats pkt_stats;
395 	struct ath12k_rx_peer_rate_stats byte_stats;
396 };
397 
398 #define ATH12K_HE_MCS_NUM       12
399 #define ATH12K_VHT_MCS_NUM      10
400 #define ATH12K_BW_NUM           5
401 #define ATH12K_NSS_NUM          4
402 #define ATH12K_LEGACY_NUM       12
403 #define ATH12K_GI_NUM           4
404 #define ATH12K_HT_MCS_NUM       32
405 
406 enum ath12k_pkt_rx_err {
407 	ATH12K_PKT_RX_ERR_FCS,
408 	ATH12K_PKT_RX_ERR_TKIP,
409 	ATH12K_PKT_RX_ERR_CRYPT,
410 	ATH12K_PKT_RX_ERR_PEER_IDX_INVAL,
411 	ATH12K_PKT_RX_ERR_MAX,
412 };
413 
414 enum ath12k_ampdu_subfrm_num {
415 	ATH12K_AMPDU_SUBFRM_NUM_10,
416 	ATH12K_AMPDU_SUBFRM_NUM_20,
417 	ATH12K_AMPDU_SUBFRM_NUM_30,
418 	ATH12K_AMPDU_SUBFRM_NUM_40,
419 	ATH12K_AMPDU_SUBFRM_NUM_50,
420 	ATH12K_AMPDU_SUBFRM_NUM_60,
421 	ATH12K_AMPDU_SUBFRM_NUM_MORE,
422 	ATH12K_AMPDU_SUBFRM_NUM_MAX,
423 };
424 
425 enum ath12k_amsdu_subfrm_num {
426 	ATH12K_AMSDU_SUBFRM_NUM_1,
427 	ATH12K_AMSDU_SUBFRM_NUM_2,
428 	ATH12K_AMSDU_SUBFRM_NUM_3,
429 	ATH12K_AMSDU_SUBFRM_NUM_4,
430 	ATH12K_AMSDU_SUBFRM_NUM_MORE,
431 	ATH12K_AMSDU_SUBFRM_NUM_MAX,
432 };
433 
434 enum ath12k_counter_type {
435 	ATH12K_COUNTER_TYPE_BYTES,
436 	ATH12K_COUNTER_TYPE_PKTS,
437 	ATH12K_COUNTER_TYPE_MAX,
438 };
439 
440 enum ath12k_stats_type {
441 	ATH12K_STATS_TYPE_SUCC,
442 	ATH12K_STATS_TYPE_FAIL,
443 	ATH12K_STATS_TYPE_RETRY,
444 	ATH12K_STATS_TYPE_AMPDU,
445 	ATH12K_STATS_TYPE_MAX,
446 };
447 
448 struct ath12k_htt_data_stats {
449 	u64 legacy[ATH12K_COUNTER_TYPE_MAX][ATH12K_LEGACY_NUM];
450 	u64 ht[ATH12K_COUNTER_TYPE_MAX][ATH12K_HT_MCS_NUM];
451 	u64 vht[ATH12K_COUNTER_TYPE_MAX][ATH12K_VHT_MCS_NUM];
452 	u64 he[ATH12K_COUNTER_TYPE_MAX][ATH12K_HE_MCS_NUM];
453 	u64 bw[ATH12K_COUNTER_TYPE_MAX][ATH12K_BW_NUM];
454 	u64 nss[ATH12K_COUNTER_TYPE_MAX][ATH12K_NSS_NUM];
455 	u64 gi[ATH12K_COUNTER_TYPE_MAX][ATH12K_GI_NUM];
456 	u64 transmit_type[ATH12K_COUNTER_TYPE_MAX][HAL_RX_RECEPTION_TYPE_MAX];
457 	u64 ru_loc[ATH12K_COUNTER_TYPE_MAX][HAL_RX_RU_ALLOC_TYPE_MAX];
458 };
459 
460 struct ath12k_htt_tx_stats {
461 	struct ath12k_htt_data_stats stats[ATH12K_STATS_TYPE_MAX];
462 	u64 tx_duration;
463 	u64 ba_fails;
464 	u64 ack_fails;
465 	u16 ru_start;
466 	u16 ru_tones;
467 	u32 mu_group[MAX_MU_GROUP_ID];
468 };
469 
470 struct ath12k_per_ppdu_tx_stats {
471 	u16 succ_pkts;
472 	u16 failed_pkts;
473 	u16 retry_pkts;
474 	u32 succ_bytes;
475 	u32 failed_bytes;
476 	u32 retry_bytes;
477 };
478 
479 struct ath12k_wbm_tx_stats {
480 	u64 wbm_tx_comp_stats[HAL_WBM_REL_HTT_TX_COMP_STATUS_MAX];
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 	/* the following are protected by ar->data_lock */
491 	u32 changed; /* IEEE80211_RC_* */
492 	u32 bw;
493 	u32 nss;
494 	u32 smps;
495 
496 	struct wiphy_work update_wk;
497 	struct rate_info txrate;
498 	struct rate_info last_txrate;
499 	u64 rx_duration;
500 	u64 tx_duration;
501 	u8 rssi_comb;
502 	u8 link_id;
503 	struct ath12k_rx_peer_stats *rx_stats;
504 	struct ath12k_wbm_tx_stats *wbm_tx_stats;
505 	u32 bw_prev;
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 
514 struct ath12k_sta {
515 	struct ath12k_vif *ahvif;
516 	enum hal_pn_type pn_type;
517 	struct ath12k_link_sta deflink;
518 	struct ath12k_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
519 	/* indicates bitmap of link sta created in FW */
520 	u16 links_map;
521 	u8 assoc_link_id;
522 	u16 ml_peer_id;
523 	u8 num_peer;
524 
525 	enum ieee80211_sta_state state;
526 };
527 
528 #define ATH12K_MIN_5G_FREQ 4150
529 #define ATH12K_MIN_6G_FREQ 5925
530 #define ATH12K_MAX_6G_FREQ 7115
531 #define ATH12K_NUM_CHANS 101
532 #define ATH12K_MAX_5G_CHAN 173
533 
534 enum ath12k_hw_state {
535 	ATH12K_HW_STATE_OFF,
536 	ATH12K_HW_STATE_ON,
537 	ATH12K_HW_STATE_RESTARTING,
538 	ATH12K_HW_STATE_RESTARTED,
539 	ATH12K_HW_STATE_WEDGED,
540 	/* Add other states as required */
541 };
542 
543 /* Antenna noise floor */
544 #define ATH12K_DEFAULT_NOISE_FLOOR -95
545 
546 struct ath12k_fw_stats {
547 	u32 pdev_id;
548 	u32 stats_id;
549 	struct list_head pdevs;
550 	struct list_head vdevs;
551 	struct list_head bcn;
552 };
553 
554 struct ath12k_dbg_htt_stats {
555 	enum ath12k_dbg_htt_ext_stats_type type;
556 	u32 cfg_param[4];
557 	u8 reset;
558 	struct debug_htt_stats_req *stats_req;
559 };
560 
561 struct ath12k_debug {
562 	struct dentry *debugfs_pdev;
563 	struct dentry *debugfs_pdev_symlink;
564 	struct ath12k_dbg_htt_stats htt_stats;
565 };
566 
567 struct ath12k_per_peer_tx_stats {
568 	u32 succ_bytes;
569 	u32 retry_bytes;
570 	u32 failed_bytes;
571 	u32 duration;
572 	u16 succ_pkts;
573 	u16 retry_pkts;
574 	u16 failed_pkts;
575 	u16 ru_start;
576 	u16 ru_tones;
577 	u8 ba_fails;
578 	u8 ppdu_type;
579 	u32 mu_grpid;
580 	u32 mu_pos;
581 	bool is_ampdu;
582 };
583 
584 #define ATH12K_FLUSH_TIMEOUT (5 * HZ)
585 #define ATH12K_VDEV_DELETE_TIMEOUT_HZ (5 * HZ)
586 
587 struct ath12k {
588 	struct ath12k_base *ab;
589 	struct ath12k_pdev *pdev;
590 	struct ath12k_hw *ah;
591 	struct ath12k_wmi_pdev *wmi;
592 	struct ath12k_pdev_dp dp;
593 	u8 mac_addr[ETH_ALEN];
594 	u32 ht_cap_info;
595 	u32 vht_cap_info;
596 	struct ath12k_he ar_he;
597 	bool supports_6ghz;
598 	struct {
599 		struct completion started;
600 		struct completion completed;
601 		struct completion on_channel;
602 		struct delayed_work timeout;
603 		enum ath12k_scan_state state;
604 		bool is_roc;
605 		int vdev_id;
606 		int roc_freq;
607 		bool roc_notify;
608 	} scan;
609 
610 	struct {
611 		struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
612 		struct ieee80211_sband_iftype_data
613 			iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
614 	} mac;
615 
616 	unsigned long dev_flags;
617 	unsigned int filter_flags;
618 	u32 min_tx_power;
619 	u32 max_tx_power;
620 	u32 txpower_limit_2g;
621 	u32 txpower_limit_5g;
622 	u32 txpower_scale;
623 	u32 power_scale;
624 	u32 chan_tx_pwr;
625 	u32 num_stations;
626 	u32 max_num_stations;
627 
628 	/* protects the radio specific data like debug stats, ppdu_stats_info stats,
629 	 * vdev_stop_status info, scan data, ath12k_sta info, ath12k_link_vif info,
630 	 * channel context data, survey info, test mode data.
631 	 */
632 	spinlock_t data_lock;
633 
634 	struct list_head arvifs;
635 	/* should never be NULL; needed for regular htt rx */
636 	struct ieee80211_channel *rx_channel;
637 
638 	/* valid during scan; needed for mgmt rx during scan */
639 	struct ieee80211_channel *scan_channel;
640 
641 	u8 cfg_tx_chainmask;
642 	u8 cfg_rx_chainmask;
643 	u8 num_rx_chains;
644 	u8 num_tx_chains;
645 	/* pdev_idx starts from 0 whereas pdev->pdev_id starts with 1 */
646 	u8 pdev_idx;
647 	u8 lmac_id;
648 	u8 hw_link_id;
649 
650 	struct completion peer_assoc_done;
651 	struct completion peer_delete_done;
652 
653 	int install_key_status;
654 	struct completion install_key_done;
655 
656 	int last_wmi_vdev_start_status;
657 	struct completion vdev_setup_done;
658 	struct completion vdev_delete_done;
659 
660 	int num_peers;
661 	int max_num_peers;
662 	u32 num_started_vdevs;
663 	u32 num_created_vdevs;
664 	unsigned long long allocated_vdev_map;
665 
666 	struct idr txmgmt_idr;
667 	/* protects txmgmt_idr data */
668 	spinlock_t txmgmt_idr_lock;
669 	atomic_t num_pending_mgmt_tx;
670 	wait_queue_head_t txmgmt_empty_waitq;
671 
672 	/* cycle count is reported twice for each visited channel during scan.
673 	 * access protected by data_lock
674 	 */
675 	u32 survey_last_rx_clear_count;
676 	u32 survey_last_cycle_count;
677 
678 	/* Channel info events are expected to come in pairs without and with
679 	 * COMPLETE flag set respectively for each channel visit during scan.
680 	 *
681 	 * However there are deviations from this rule. This flag is used to
682 	 * avoid reporting garbage data.
683 	 */
684 	bool ch_info_can_report_survey;
685 	struct survey_info survey[ATH12K_NUM_CHANS];
686 	struct completion bss_survey_done;
687 
688 	struct work_struct regd_update_work;
689 
690 	struct wiphy_work wmi_mgmt_tx_work;
691 	struct sk_buff_head wmi_mgmt_tx_queue;
692 
693 	struct ath12k_wow wow;
694 	struct completion target_suspend;
695 	bool target_suspend_ack;
696 	struct ath12k_per_peer_tx_stats peer_tx_stats;
697 	struct list_head ppdu_stats_info;
698 	u32 ppdu_stat_list_depth;
699 
700 	struct ath12k_per_peer_tx_stats cached_stats;
701 	u32 last_ppdu_id;
702 	u32 cached_ppdu_id;
703 #ifdef CONFIG_ATH12K_DEBUGFS
704 	struct ath12k_debug debug;
705 #endif
706 
707 	bool dfs_block_radar_events;
708 	bool monitor_conf_enabled;
709 	bool monitor_vdev_created;
710 	bool monitor_started;
711 	int monitor_vdev_id;
712 
713 	u32 freq_low;
714 	u32 freq_high;
715 
716 	bool nlo_enabled;
717 };
718 
719 struct ath12k_hw {
720 	struct ieee80211_hw *hw;
721 	struct device *dev;
722 
723 	/* Protect the write operation of the hardware state ath12k_hw::state
724 	 * between hardware start<=>reconfigure<=>stop transitions.
725 	 */
726 	struct mutex hw_mutex;
727 	enum ath12k_hw_state state;
728 	bool regd_updated;
729 	bool use_6ghz_regd;
730 
731 	u8 num_radio;
732 
733 	DECLARE_BITMAP(free_ml_peer_id_map, ATH12K_MAX_MLO_PEERS);
734 
735 	/* protected by wiphy_lock() */
736 	struct list_head ml_peers;
737 
738 	/* Keep last */
739 	struct ath12k radio[] __aligned(sizeof(void *));
740 };
741 
742 struct ath12k_band_cap {
743 	u32 phy_id;
744 	u32 max_bw_supported;
745 	u32 ht_cap_info;
746 	u32 he_cap_info[2];
747 	u32 he_mcs;
748 	u32 he_cap_phy_info[PSOC_HOST_MAX_PHY_SIZE];
749 	struct ath12k_wmi_ppe_threshold_arg he_ppet;
750 	u16 he_6ghz_capa;
751 	u32 eht_cap_mac_info[WMI_MAX_EHTCAP_MAC_SIZE];
752 	u32 eht_cap_phy_info[WMI_MAX_EHTCAP_PHY_SIZE];
753 	u32 eht_mcs_20_only;
754 	u32 eht_mcs_80;
755 	u32 eht_mcs_160;
756 	u32 eht_mcs_320;
757 	struct ath12k_wmi_ppe_threshold_arg eht_ppet;
758 	u32 eht_cap_info_internal;
759 };
760 
761 struct ath12k_pdev_cap {
762 	u32 supported_bands;
763 	u32 ampdu_density;
764 	u32 vht_cap;
765 	u32 vht_mcs;
766 	u32 he_mcs;
767 	u32 tx_chain_mask;
768 	u32 rx_chain_mask;
769 	u32 tx_chain_mask_shift;
770 	u32 rx_chain_mask_shift;
771 	struct ath12k_band_cap band[NUM_NL80211_BANDS];
772 };
773 
774 struct mlo_timestamp {
775 	u32 info;
776 	u32 sync_timestamp_lo_us;
777 	u32 sync_timestamp_hi_us;
778 	u32 mlo_offset_lo;
779 	u32 mlo_offset_hi;
780 	u32 mlo_offset_clks;
781 	u32 mlo_comp_clks;
782 	u32 mlo_comp_timer;
783 };
784 
785 struct ath12k_pdev {
786 	struct ath12k *ar;
787 	u32 pdev_id;
788 	u32 hw_link_id;
789 	struct ath12k_pdev_cap cap;
790 	u8 mac_addr[ETH_ALEN];
791 	struct mlo_timestamp timestamp;
792 };
793 
794 struct ath12k_fw_pdev {
795 	u32 pdev_id;
796 	u32 phy_id;
797 	u32 supported_bands;
798 };
799 
800 struct ath12k_board_data {
801 	const struct firmware *fw;
802 	const void *data;
803 	size_t len;
804 };
805 
806 struct ath12k_soc_dp_tx_err_stats {
807 	/* TCL Ring Descriptor unavailable */
808 	u32 desc_na[DP_TCL_NUM_RING_MAX];
809 	/* Other failures during dp_tx due to mem allocation failure
810 	 * idr unavailable etc.
811 	 */
812 	atomic_t misc_fail;
813 };
814 
815 struct ath12k_soc_dp_stats {
816 	u32 err_ring_pkts;
817 	u32 invalid_rbm;
818 	u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX];
819 	u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX];
820 	u32 hal_reo_error[DP_REO_DST_RING_MAX];
821 	struct ath12k_soc_dp_tx_err_stats tx_err;
822 };
823 
824 /* Holds info on the group of devices that are registered as a single
825  * wiphy, protected with struct ath12k_hw_group::mutex.
826  */
827 struct ath12k_hw_group {
828 	struct list_head list;
829 	u8 id;
830 	u8 num_devices;
831 	u8 num_probed;
832 	u8 num_started;
833 	unsigned long flags;
834 	struct ath12k_base *ab[ATH12K_MAX_SOCS];
835 
836 	/* protects access to this struct */
837 	struct mutex mutex;
838 
839 	/* Holds information of wiphy (hw) registration.
840 	 *
841 	 * In Multi/Single Link Operation case, all pdevs are registered as
842 	 * a single wiphy. In other (legacy/Non-MLO) cases, each pdev is
843 	 * registered as separate wiphys.
844 	 */
845 	struct ath12k_hw *ah[ATH12K_GROUP_MAX_RADIO];
846 	u8 num_hw;
847 	bool mlo_capable;
848 };
849 
850 /* Master structure to hold the hw data which may be used in core module */
851 struct ath12k_base {
852 	enum ath12k_hw_rev hw_rev;
853 	struct platform_device *pdev;
854 	struct device *dev;
855 	struct ath12k_qmi qmi;
856 	struct ath12k_wmi_base wmi_ab;
857 	struct completion fw_ready;
858 	u8 device_id;
859 	int num_radios;
860 	/* HW channel counters frequency value in hertz common to all MACs */
861 	u32 cc_freq_hz;
862 
863 	struct ath12k_dump_file_data *dump_data;
864 	size_t ath12k_coredump_len;
865 	struct work_struct dump_work;
866 
867 	struct ath12k_htc htc;
868 
869 	struct ath12k_dp dp;
870 
871 	void __iomem *mem;
872 	unsigned long mem_len;
873 
874 	struct {
875 		enum ath12k_bus bus;
876 		const struct ath12k_hif_ops *ops;
877 	} hif;
878 
879 	struct {
880 		struct completion wakeup_completed;
881 		u32 wmi_conf_rx_decap_mode;
882 	} wow;
883 
884 	struct ath12k_ce ce;
885 	struct timer_list rx_replenish_retry;
886 	struct ath12k_hal hal;
887 	/* To synchronize core_start/core_stop */
888 	struct mutex core_lock;
889 	/* Protects data like peers */
890 	spinlock_t base_lock;
891 
892 	/* Single pdev device (struct ath12k_hw_params::single_pdev_only):
893 	 *
894 	 * Firmware maintains data for all bands but advertises a single
895 	 * phy to the host which is stored as a single element in this
896 	 * array.
897 	 *
898 	 * Other devices:
899 	 *
900 	 * This array will contain as many elements as the number of
901 	 * radios.
902 	 */
903 	struct ath12k_pdev pdevs[MAX_RADIOS];
904 
905 	/* struct ath12k_hw_params::single_pdev_only devices use this to
906 	 * store phy specific data
907 	 */
908 	struct ath12k_fw_pdev fw_pdev[MAX_RADIOS];
909 	u8 fw_pdev_count;
910 
911 	struct ath12k_pdev __rcu *pdevs_active[MAX_RADIOS];
912 
913 	struct ath12k_wmi_hal_reg_capabilities_ext_arg hal_reg_cap[MAX_RADIOS];
914 	unsigned long long free_vdev_map;
915 	unsigned long long free_vdev_stats_id_map;
916 	struct list_head peers;
917 	wait_queue_head_t peer_mapping_wq;
918 	u8 mac_addr[ETH_ALEN];
919 	bool wmi_ready;
920 	u32 wlan_init_status;
921 	int irq_num[ATH12K_IRQ_NUM_MAX];
922 	struct ath12k_ext_irq_grp ext_irq_grp[ATH12K_EXT_IRQ_GRP_NUM_MAX];
923 	struct napi_struct *napi;
924 	struct ath12k_wmi_target_cap_arg target_caps;
925 	u32 ext_service_bitmap[WMI_SERVICE_EXT_BM_SIZE];
926 	bool pdevs_macaddr_valid;
927 
928 	const struct ath12k_hw_params *hw_params;
929 
930 	const struct firmware *cal_file;
931 
932 	/* Below regd's are protected by ab->data_lock */
933 	/* This is the regd set for every radio
934 	 * by the firmware during initialization
935 	 */
936 	struct ieee80211_regdomain *default_regd[MAX_RADIOS];
937 	/* This regd is set during dynamic country setting
938 	 * This may or may not be used during the runtime
939 	 */
940 	struct ieee80211_regdomain *new_regd[MAX_RADIOS];
941 
942 	/* Current DFS Regulatory */
943 	enum ath12k_dfs_region dfs_region;
944 	struct ath12k_soc_dp_stats soc_stats;
945 #ifdef CONFIG_ATH12K_DEBUGFS
946 	struct dentry *debugfs_soc;
947 #endif
948 
949 	unsigned long dev_flags;
950 	struct completion driver_recovery;
951 	struct workqueue_struct *workqueue;
952 	struct work_struct restart_work;
953 	struct workqueue_struct *workqueue_aux;
954 	struct work_struct reset_work;
955 	atomic_t reset_count;
956 	atomic_t recovery_count;
957 	bool is_reset;
958 	struct completion reset_complete;
959 	/* continuous recovery fail count */
960 	atomic_t fail_cont_count;
961 	unsigned long reset_fail_timeout;
962 	struct {
963 		/* protected by data_lock */
964 		u32 fw_crash_counter;
965 	} stats;
966 	u32 pktlog_defs_checksum;
967 
968 	struct ath12k_dbring_cap *db_caps;
969 	u32 num_db_cap;
970 
971 	struct timer_list mon_reap_timer;
972 
973 	struct completion htc_suspend;
974 
975 	u64 fw_soc_drop_count;
976 	bool static_window_map;
977 
978 	struct work_struct rfkill_work;
979 	/* true means radio is on */
980 	bool rfkill_radio_on;
981 
982 	struct {
983 		enum ath12k_bdf_search bdf_search;
984 		u32 vendor;
985 		u32 device;
986 		u32 subsystem_vendor;
987 		u32 subsystem_device;
988 	} id;
989 
990 	struct {
991 		u32 api_version;
992 
993 		const struct firmware *fw;
994 		const u8 *amss_data;
995 		size_t amss_len;
996 		const u8 *amss_dualmac_data;
997 		size_t amss_dualmac_len;
998 		const u8 *m3_data;
999 		size_t m3_len;
1000 
1001 		DECLARE_BITMAP(fw_features, ATH12K_FW_FEATURE_COUNT);
1002 	} fw;
1003 
1004 	const struct hal_rx_ops *hal_rx_ops;
1005 
1006 	/* Denotes the whether MLO is possible within the chip */
1007 	bool single_chip_mlo_supp;
1008 
1009 	struct completion restart_completed;
1010 
1011 #ifdef CONFIG_ACPI
1012 
1013 	struct {
1014 		bool started;
1015 		u32 func_bit;
1016 		bool acpi_tas_enable;
1017 		bool acpi_bios_sar_enable;
1018 		u8 tas_cfg[ATH12K_ACPI_DSM_TAS_CFG_SIZE];
1019 		u8 tas_sar_power_table[ATH12K_ACPI_DSM_TAS_DATA_SIZE];
1020 		u8 bios_sar_data[ATH12K_ACPI_DSM_BIOS_SAR_DATA_SIZE];
1021 		u8 geo_offset_data[ATH12K_ACPI_DSM_GEO_OFFSET_DATA_SIZE];
1022 		u8 cca_data[ATH12K_ACPI_DSM_CCA_DATA_SIZE];
1023 		u8 band_edge_power[ATH12K_ACPI_DSM_BAND_EDGE_DATA_SIZE];
1024 	} acpi;
1025 
1026 #endif /* CONFIG_ACPI */
1027 
1028 	struct notifier_block panic_nb;
1029 
1030 	struct ath12k_hw_group *ag;
1031 
1032 	/* must be last */
1033 	u8 drv_priv[] __aligned(sizeof(void *));
1034 };
1035 
1036 struct ath12k_pdev_map {
1037 	struct ath12k_base *ab;
1038 	u8 pdev_idx;
1039 };
1040 
1041 int ath12k_core_qmi_firmware_ready(struct ath12k_base *ab);
1042 int ath12k_core_pre_init(struct ath12k_base *ab);
1043 int ath12k_core_init(struct ath12k_base *ath12k);
1044 void ath12k_core_deinit(struct ath12k_base *ath12k);
1045 struct ath12k_base *ath12k_core_alloc(struct device *dev, size_t priv_size,
1046 				      enum ath12k_bus bus);
1047 void ath12k_core_free(struct ath12k_base *ath12k);
1048 int ath12k_core_fetch_board_data_api_1(struct ath12k_base *ab,
1049 				       struct ath12k_board_data *bd,
1050 				       char *filename);
1051 int ath12k_core_fetch_bdf(struct ath12k_base *ath12k,
1052 			  struct ath12k_board_data *bd);
1053 void ath12k_core_free_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd);
1054 int ath12k_core_fetch_regdb(struct ath12k_base *ab, struct ath12k_board_data *bd);
1055 int ath12k_core_check_dt(struct ath12k_base *ath12k);
1056 int ath12k_core_check_smbios(struct ath12k_base *ab);
1057 void ath12k_core_halt(struct ath12k *ar);
1058 int ath12k_core_resume_early(struct ath12k_base *ab);
1059 int ath12k_core_resume(struct ath12k_base *ab);
1060 int ath12k_core_suspend(struct ath12k_base *ab);
1061 int ath12k_core_suspend_late(struct ath12k_base *ab);
1062 void ath12k_core_hw_group_unassign(struct ath12k_base *ab);
1063 
1064 const struct firmware *ath12k_core_firmware_request(struct ath12k_base *ab,
1065 						    const char *filename);
1066 u32 ath12k_core_get_max_station_per_radio(struct ath12k_base *ab);
1067 u32 ath12k_core_get_max_peers_per_radio(struct ath12k_base *ab);
1068 u32 ath12k_core_get_max_num_tids(struct ath12k_base *ab);
1069 
1070 void ath12k_core_hw_group_set_mlo_capable(struct ath12k_hw_group *ag);
1071 
1072 static inline const char *ath12k_scan_state_str(enum ath12k_scan_state state)
1073 {
1074 	switch (state) {
1075 	case ATH12K_SCAN_IDLE:
1076 		return "idle";
1077 	case ATH12K_SCAN_STARTING:
1078 		return "starting";
1079 	case ATH12K_SCAN_RUNNING:
1080 		return "running";
1081 	case ATH12K_SCAN_ABORTING:
1082 		return "aborting";
1083 	}
1084 
1085 	return "unknown";
1086 }
1087 
1088 static inline struct ath12k_skb_cb *ATH12K_SKB_CB(struct sk_buff *skb)
1089 {
1090 	BUILD_BUG_ON(sizeof(struct ath12k_skb_cb) >
1091 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
1092 	return (struct ath12k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
1093 }
1094 
1095 static inline struct ath12k_skb_rxcb *ATH12K_SKB_RXCB(struct sk_buff *skb)
1096 {
1097 	BUILD_BUG_ON(sizeof(struct ath12k_skb_rxcb) > sizeof(skb->cb));
1098 	return (struct ath12k_skb_rxcb *)skb->cb;
1099 }
1100 
1101 static inline struct ath12k_vif *ath12k_vif_to_ahvif(struct ieee80211_vif *vif)
1102 {
1103 	return (struct ath12k_vif *)vif->drv_priv;
1104 }
1105 
1106 static inline struct ath12k_sta *ath12k_sta_to_ahsta(struct ieee80211_sta *sta)
1107 {
1108 	return (struct ath12k_sta *)sta->drv_priv;
1109 }
1110 
1111 static inline struct ieee80211_sta *ath12k_ahsta_to_sta(struct ath12k_sta *ahsta)
1112 {
1113 	return container_of((void *)ahsta, struct ieee80211_sta, drv_priv);
1114 }
1115 
1116 static inline struct ieee80211_vif *ath12k_ahvif_to_vif(struct ath12k_vif *ahvif)
1117 {
1118 	return container_of((void *)ahvif, struct ieee80211_vif, drv_priv);
1119 }
1120 
1121 static inline struct ath12k *ath12k_ab_to_ar(struct ath12k_base *ab,
1122 					     int mac_id)
1123 {
1124 	return ab->pdevs[ath12k_hw_mac_id_to_pdev_id(ab->hw_params, mac_id)].ar;
1125 }
1126 
1127 static inline void ath12k_core_create_firmware_path(struct ath12k_base *ab,
1128 						    const char *filename,
1129 						    void *buf, size_t buf_len)
1130 {
1131 	snprintf(buf, buf_len, "%s/%s/%s", ATH12K_FW_DIR,
1132 		 ab->hw_params->fw.dir, filename);
1133 }
1134 
1135 static inline const char *ath12k_bus_str(enum ath12k_bus bus)
1136 {
1137 	switch (bus) {
1138 	case ATH12K_BUS_PCI:
1139 		return "pci";
1140 	}
1141 
1142 	return "unknown";
1143 }
1144 
1145 static inline struct ath12k_hw *ath12k_hw_to_ah(struct ieee80211_hw  *hw)
1146 {
1147 	return hw->priv;
1148 }
1149 
1150 static inline struct ath12k *ath12k_ah_to_ar(struct ath12k_hw *ah, u8 hw_link_id)
1151 {
1152 	if (WARN(hw_link_id >= ah->num_radio,
1153 		 "bad hw link id %d, so switch to default link\n", hw_link_id))
1154 		hw_link_id = 0;
1155 
1156 	return &ah->radio[hw_link_id];
1157 }
1158 
1159 static inline struct ath12k_hw *ath12k_ar_to_ah(struct ath12k *ar)
1160 {
1161 	return ar->ah;
1162 }
1163 
1164 static inline struct ieee80211_hw *ath12k_ar_to_hw(struct ath12k *ar)
1165 {
1166 	return ar->ah->hw;
1167 }
1168 
1169 #define for_each_ar(ah, ar, index) \
1170 	for ((index) = 0; ((index) < (ah)->num_radio && \
1171 	     ((ar) = &(ah)->radio[(index)])); (index)++)
1172 
1173 static inline struct ath12k_hw *ath12k_ab_to_ah(struct ath12k_base *ab, int idx)
1174 {
1175 	return ab->ag->ah[idx];
1176 }
1177 
1178 static inline void ath12k_ab_set_ah(struct ath12k_base *ab, int idx,
1179 				    struct ath12k_hw *ah)
1180 {
1181 	ab->ag->ah[idx] = ah;
1182 }
1183 
1184 static inline int ath12k_get_num_hw(struct ath12k_base *ab)
1185 {
1186 	return ab->ag->num_hw;
1187 }
1188 
1189 static inline struct ath12k_hw_group *ath12k_ab_to_ag(struct ath12k_base *ab)
1190 {
1191 	return ab->ag;
1192 }
1193 
1194 static inline void ath12k_core_started(struct ath12k_base *ab)
1195 {
1196 	lockdep_assert_held(&ab->ag->mutex);
1197 
1198 	ab->ag->num_started++;
1199 }
1200 
1201 static inline void ath12k_core_stopped(struct ath12k_base *ab)
1202 {
1203 	lockdep_assert_held(&ab->ag->mutex);
1204 
1205 	ab->ag->num_started--;
1206 }
1207 
1208 #endif /* _CORE_H_ */
1209