1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4  * Copyright (c) 2021-2022 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 "qmi.h"
15 #include "htc.h"
16 #include "wmi.h"
17 #include "hal.h"
18 #include "dp.h"
19 #include "ce.h"
20 #include "mac.h"
21 #include "hw.h"
22 #include "hal_rx.h"
23 #include "reg.h"
24 #include "dbring.h"
25 
26 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
27 
28 #define ATH12K_TX_MGMT_NUM_PENDING_MAX	512
29 
30 #define ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI 64
31 
32 /* Pending management packets threshold for dropping probe responses */
33 #define ATH12K_PRB_RSP_DROP_THRESHOLD ((ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI * 3) / 4)
34 
35 #define ATH12K_INVALID_HW_MAC_ID	0xFF
36 #define	ATH12K_RX_RATE_TABLE_NUM	320
37 #define	ATH12K_RX_RATE_TABLE_11AX_NUM	576
38 
39 #define ATH12K_MON_TIMER_INTERVAL  10
40 #define ATH12K_RESET_TIMEOUT_HZ			(20 * HZ)
41 #define ATH12K_RESET_MAX_FAIL_COUNT_FIRST	3
42 #define ATH12K_RESET_MAX_FAIL_COUNT_FINAL	5
43 #define ATH12K_RESET_FAIL_TIMEOUT_HZ		(20 * HZ)
44 #define ATH12K_RECONFIGURE_TIMEOUT_HZ		(10 * HZ)
45 #define ATH12K_RECOVER_START_TIMEOUT_HZ		(20 * HZ)
46 
47 enum wme_ac {
48 	WME_AC_BE,
49 	WME_AC_BK,
50 	WME_AC_VI,
51 	WME_AC_VO,
52 	WME_NUM_AC
53 };
54 
55 #define ATH12K_HT_MCS_MAX	7
56 #define ATH12K_VHT_MCS_MAX	9
57 #define ATH12K_HE_MCS_MAX	11
58 
59 enum ath12k_crypt_mode {
60 	/* Only use hardware crypto engine */
61 	ATH12K_CRYPT_MODE_HW,
62 	/* Only use software crypto */
63 	ATH12K_CRYPT_MODE_SW,
64 };
65 
66 static inline enum wme_ac ath12k_tid_to_ac(u32 tid)
67 {
68 	return (((tid == 0) || (tid == 3)) ? WME_AC_BE :
69 		((tid == 1) || (tid == 2)) ? WME_AC_BK :
70 		((tid == 4) || (tid == 5)) ? WME_AC_VI :
71 		WME_AC_VO);
72 }
73 
74 enum ath12k_skb_flags {
75 	ATH12K_SKB_HW_80211_ENCAP = BIT(0),
76 	ATH12K_SKB_CIPHER_SET = BIT(1),
77 };
78 
79 struct ath12k_skb_cb {
80 	dma_addr_t paddr;
81 	struct ath12k *ar;
82 	struct ieee80211_vif *vif;
83 	dma_addr_t paddr_ext_desc;
84 	u32 cipher;
85 	u8 flags;
86 };
87 
88 struct ath12k_skb_rxcb {
89 	dma_addr_t paddr;
90 	bool is_first_msdu;
91 	bool is_last_msdu;
92 	bool is_continuation;
93 	bool is_mcbc;
94 	bool is_eapol;
95 	struct hal_rx_desc *rx_desc;
96 	u8 err_rel_src;
97 	u8 err_code;
98 	u8 mac_id;
99 	u8 unmapped;
100 	u8 is_frag;
101 	u8 tid;
102 	u16 peer_id;
103 };
104 
105 enum ath12k_hw_rev {
106 	ATH12K_HW_QCN9274_HW10,
107 	ATH12K_HW_QCN9274_HW20,
108 	ATH12K_HW_WCN7850_HW20
109 };
110 
111 enum ath12k_firmware_mode {
112 	/* the default mode, standard 802.11 functionality */
113 	ATH12K_FIRMWARE_MODE_NORMAL,
114 
115 	/* factory tests etc */
116 	ATH12K_FIRMWARE_MODE_FTM,
117 };
118 
119 #define ATH12K_IRQ_NUM_MAX 57
120 #define ATH12K_EXT_IRQ_NUM_MAX	16
121 
122 struct ath12k_ext_irq_grp {
123 	struct ath12k_base *ab;
124 	u32 irqs[ATH12K_EXT_IRQ_NUM_MAX];
125 	u32 num_irq;
126 	u32 grp_id;
127 	u64 timestamp;
128 	struct napi_struct napi;
129 	struct net_device napi_ndev;
130 };
131 
132 #define HEHANDLE_CAP_PHYINFO_SIZE       3
133 #define HECAP_PHYINFO_SIZE              9
134 #define HECAP_MACINFO_SIZE              5
135 #define HECAP_TXRX_MCS_NSS_SIZE         2
136 #define HECAP_PPET16_PPET8_MAX_SIZE     25
137 
138 #define HE_PPET16_PPET8_SIZE            8
139 
140 /* 802.11ax PPE (PPDU packet Extension) threshold */
141 struct he_ppe_threshold {
142 	u32 numss_m1;
143 	u32 ru_mask;
144 	u32 ppet16_ppet8_ru3_ru0[HE_PPET16_PPET8_SIZE];
145 };
146 
147 struct ath12k_he {
148 	u8 hecap_macinfo[HECAP_MACINFO_SIZE];
149 	u32 hecap_rxmcsnssmap;
150 	u32 hecap_txmcsnssmap;
151 	u32 hecap_phyinfo[HEHANDLE_CAP_PHYINFO_SIZE];
152 	struct he_ppe_threshold   hecap_ppet;
153 	u32 heop_param;
154 };
155 
156 #define MAX_RADIOS 3
157 
158 enum {
159 	WMI_HOST_TP_SCALE_MAX   = 0,
160 	WMI_HOST_TP_SCALE_50    = 1,
161 	WMI_HOST_TP_SCALE_25    = 2,
162 	WMI_HOST_TP_SCALE_12    = 3,
163 	WMI_HOST_TP_SCALE_MIN   = 4,
164 	WMI_HOST_TP_SCALE_SIZE   = 5,
165 };
166 
167 enum ath12k_scan_state {
168 	ATH12K_SCAN_IDLE,
169 	ATH12K_SCAN_STARTING,
170 	ATH12K_SCAN_RUNNING,
171 	ATH12K_SCAN_ABORTING,
172 };
173 
174 enum ath12k_dev_flags {
175 	ATH12K_CAC_RUNNING,
176 	ATH12K_FLAG_CRASH_FLUSH,
177 	ATH12K_FLAG_RAW_MODE,
178 	ATH12K_FLAG_HW_CRYPTO_DISABLED,
179 	ATH12K_FLAG_RECOVERY,
180 	ATH12K_FLAG_UNREGISTERING,
181 	ATH12K_FLAG_REGISTERED,
182 	ATH12K_FLAG_QMI_FAIL,
183 	ATH12K_FLAG_HTC_SUSPEND_COMPLETE,
184 };
185 
186 enum ath12k_monitor_flags {
187 	ATH12K_FLAG_MONITOR_ENABLED,
188 };
189 
190 struct ath12k_vif {
191 	u32 vdev_id;
192 	enum wmi_vdev_type vdev_type;
193 	enum wmi_vdev_subtype vdev_subtype;
194 	u32 beacon_interval;
195 	u32 dtim_period;
196 	u16 ast_hash;
197 	u16 ast_idx;
198 	u16 tcl_metadata;
199 	u8 hal_addr_search_flags;
200 	u8 search_type;
201 
202 	struct ath12k *ar;
203 	struct ieee80211_vif *vif;
204 
205 	int bank_id;
206 	u8 vdev_id_check_en;
207 
208 	struct wmi_wmm_params_all_arg wmm_params;
209 	struct list_head list;
210 	union {
211 		struct {
212 			u32 uapsd;
213 		} sta;
214 		struct {
215 			/* 127 stations; wmi limit */
216 			u8 tim_bitmap[16];
217 			u8 tim_len;
218 			u32 ssid_len;
219 			u8 ssid[IEEE80211_MAX_SSID_LEN];
220 			bool hidden_ssid;
221 			/* P2P_IE with NoA attribute for P2P_GO case */
222 			u32 noa_len;
223 			u8 *noa_data;
224 		} ap;
225 	} u;
226 
227 	bool is_started;
228 	bool is_up;
229 	u32 aid;
230 	u8 bssid[ETH_ALEN];
231 	struct cfg80211_bitrate_mask bitrate_mask;
232 	int num_legacy_stations;
233 	int rtscts_prot_mode;
234 	int txpower;
235 	bool rsnie_present;
236 	bool wpaie_present;
237 	struct ieee80211_chanctx_conf chanctx;
238 	u32 key_cipher;
239 	u8 tx_encap_type;
240 	u8 vdev_stats_id;
241 };
242 
243 struct ath12k_vif_iter {
244 	u32 vdev_id;
245 	struct ath12k_vif *arvif;
246 };
247 
248 #define HAL_AST_IDX_INVALID	0xFFFF
249 #define HAL_RX_MAX_MCS		12
250 #define HAL_RX_MAX_MCS_HT	31
251 #define HAL_RX_MAX_MCS_VHT	9
252 #define HAL_RX_MAX_MCS_HE	11
253 #define HAL_RX_MAX_NSS		8
254 #define HAL_RX_MAX_NUM_LEGACY_RATES 12
255 #define ATH12K_RX_RATE_TABLE_11AX_NUM	576
256 #define ATH12K_RX_RATE_TABLE_NUM 320
257 
258 struct ath12k_rx_peer_rate_stats {
259 	u64 ht_mcs_count[HAL_RX_MAX_MCS_HT + 1];
260 	u64 vht_mcs_count[HAL_RX_MAX_MCS_VHT + 1];
261 	u64 he_mcs_count[HAL_RX_MAX_MCS_HE + 1];
262 	u64 nss_count[HAL_RX_MAX_NSS];
263 	u64 bw_count[HAL_RX_BW_MAX];
264 	u64 gi_count[HAL_RX_GI_MAX];
265 	u64 legacy_count[HAL_RX_MAX_NUM_LEGACY_RATES];
266 	u64 rx_rate[ATH12K_RX_RATE_TABLE_11AX_NUM];
267 };
268 
269 struct ath12k_rx_peer_stats {
270 	u64 num_msdu;
271 	u64 num_mpdu_fcs_ok;
272 	u64 num_mpdu_fcs_err;
273 	u64 tcp_msdu_count;
274 	u64 udp_msdu_count;
275 	u64 other_msdu_count;
276 	u64 ampdu_msdu_count;
277 	u64 non_ampdu_msdu_count;
278 	u64 stbc_count;
279 	u64 beamformed_count;
280 	u64 mcs_count[HAL_RX_MAX_MCS + 1];
281 	u64 nss_count[HAL_RX_MAX_NSS];
282 	u64 bw_count[HAL_RX_BW_MAX];
283 	u64 gi_count[HAL_RX_GI_MAX];
284 	u64 coding_count[HAL_RX_SU_MU_CODING_MAX];
285 	u64 tid_count[IEEE80211_NUM_TIDS + 1];
286 	u64 pream_cnt[HAL_RX_PREAMBLE_MAX];
287 	u64 reception_type[HAL_RX_RECEPTION_TYPE_MAX];
288 	u64 rx_duration;
289 	u64 dcm_count;
290 	u64 ru_alloc_cnt[HAL_RX_RU_ALLOC_TYPE_MAX];
291 	struct ath12k_rx_peer_rate_stats pkt_stats;
292 	struct ath12k_rx_peer_rate_stats byte_stats;
293 };
294 
295 #define ATH12K_HE_MCS_NUM       12
296 #define ATH12K_VHT_MCS_NUM      10
297 #define ATH12K_BW_NUM           5
298 #define ATH12K_NSS_NUM          4
299 #define ATH12K_LEGACY_NUM       12
300 #define ATH12K_GI_NUM           4
301 #define ATH12K_HT_MCS_NUM       32
302 
303 enum ath12k_pkt_rx_err {
304 	ATH12K_PKT_RX_ERR_FCS,
305 	ATH12K_PKT_RX_ERR_TKIP,
306 	ATH12K_PKT_RX_ERR_CRYPT,
307 	ATH12K_PKT_RX_ERR_PEER_IDX_INVAL,
308 	ATH12K_PKT_RX_ERR_MAX,
309 };
310 
311 enum ath12k_ampdu_subfrm_num {
312 	ATH12K_AMPDU_SUBFRM_NUM_10,
313 	ATH12K_AMPDU_SUBFRM_NUM_20,
314 	ATH12K_AMPDU_SUBFRM_NUM_30,
315 	ATH12K_AMPDU_SUBFRM_NUM_40,
316 	ATH12K_AMPDU_SUBFRM_NUM_50,
317 	ATH12K_AMPDU_SUBFRM_NUM_60,
318 	ATH12K_AMPDU_SUBFRM_NUM_MORE,
319 	ATH12K_AMPDU_SUBFRM_NUM_MAX,
320 };
321 
322 enum ath12k_amsdu_subfrm_num {
323 	ATH12K_AMSDU_SUBFRM_NUM_1,
324 	ATH12K_AMSDU_SUBFRM_NUM_2,
325 	ATH12K_AMSDU_SUBFRM_NUM_3,
326 	ATH12K_AMSDU_SUBFRM_NUM_4,
327 	ATH12K_AMSDU_SUBFRM_NUM_MORE,
328 	ATH12K_AMSDU_SUBFRM_NUM_MAX,
329 };
330 
331 enum ath12k_counter_type {
332 	ATH12K_COUNTER_TYPE_BYTES,
333 	ATH12K_COUNTER_TYPE_PKTS,
334 	ATH12K_COUNTER_TYPE_MAX,
335 };
336 
337 enum ath12k_stats_type {
338 	ATH12K_STATS_TYPE_SUCC,
339 	ATH12K_STATS_TYPE_FAIL,
340 	ATH12K_STATS_TYPE_RETRY,
341 	ATH12K_STATS_TYPE_AMPDU,
342 	ATH12K_STATS_TYPE_MAX,
343 };
344 
345 struct ath12k_htt_data_stats {
346 	u64 legacy[ATH12K_COUNTER_TYPE_MAX][ATH12K_LEGACY_NUM];
347 	u64 ht[ATH12K_COUNTER_TYPE_MAX][ATH12K_HT_MCS_NUM];
348 	u64 vht[ATH12K_COUNTER_TYPE_MAX][ATH12K_VHT_MCS_NUM];
349 	u64 he[ATH12K_COUNTER_TYPE_MAX][ATH12K_HE_MCS_NUM];
350 	u64 bw[ATH12K_COUNTER_TYPE_MAX][ATH12K_BW_NUM];
351 	u64 nss[ATH12K_COUNTER_TYPE_MAX][ATH12K_NSS_NUM];
352 	u64 gi[ATH12K_COUNTER_TYPE_MAX][ATH12K_GI_NUM];
353 	u64 transmit_type[ATH12K_COUNTER_TYPE_MAX][HAL_RX_RECEPTION_TYPE_MAX];
354 	u64 ru_loc[ATH12K_COUNTER_TYPE_MAX][HAL_RX_RU_ALLOC_TYPE_MAX];
355 };
356 
357 struct ath12k_htt_tx_stats {
358 	struct ath12k_htt_data_stats stats[ATH12K_STATS_TYPE_MAX];
359 	u64 tx_duration;
360 	u64 ba_fails;
361 	u64 ack_fails;
362 	u16 ru_start;
363 	u16 ru_tones;
364 	u32 mu_group[MAX_MU_GROUP_ID];
365 };
366 
367 struct ath12k_per_ppdu_tx_stats {
368 	u16 succ_pkts;
369 	u16 failed_pkts;
370 	u16 retry_pkts;
371 	u32 succ_bytes;
372 	u32 failed_bytes;
373 	u32 retry_bytes;
374 };
375 
376 struct ath12k_wbm_tx_stats {
377 	u64 wbm_tx_comp_stats[HAL_WBM_REL_HTT_TX_COMP_STATUS_MAX];
378 };
379 
380 struct ath12k_sta {
381 	struct ath12k_vif *arvif;
382 
383 	/* the following are protected by ar->data_lock */
384 	u32 changed; /* IEEE80211_RC_* */
385 	u32 bw;
386 	u32 nss;
387 	u32 smps;
388 	enum hal_pn_type pn_type;
389 
390 	struct work_struct update_wk;
391 	struct rate_info txrate;
392 	struct rate_info last_txrate;
393 	u64 rx_duration;
394 	u64 tx_duration;
395 	u8 rssi_comb;
396 	struct ath12k_rx_peer_stats *rx_stats;
397 	struct ath12k_wbm_tx_stats *wbm_tx_stats;
398 	u32 bw_prev;
399 };
400 
401 #define ATH12K_MIN_5G_FREQ 4150
402 #define ATH12K_MIN_6G_FREQ 5945
403 #define ATH12K_MAX_6G_FREQ 7115
404 #define ATH12K_NUM_CHANS 100
405 #define ATH12K_MAX_5G_CHAN 173
406 
407 enum ath12k_state {
408 	ATH12K_STATE_OFF,
409 	ATH12K_STATE_ON,
410 	ATH12K_STATE_RESTARTING,
411 	ATH12K_STATE_RESTARTED,
412 	ATH12K_STATE_WEDGED,
413 	/* Add other states as required */
414 };
415 
416 /* Antenna noise floor */
417 #define ATH12K_DEFAULT_NOISE_FLOOR -95
418 
419 struct ath12k_fw_stats {
420 	u32 pdev_id;
421 	u32 stats_id;
422 	struct list_head pdevs;
423 	struct list_head vdevs;
424 	struct list_head bcn;
425 };
426 
427 struct ath12k_per_peer_tx_stats {
428 	u32 succ_bytes;
429 	u32 retry_bytes;
430 	u32 failed_bytes;
431 	u32 duration;
432 	u16 succ_pkts;
433 	u16 retry_pkts;
434 	u16 failed_pkts;
435 	u16 ru_start;
436 	u16 ru_tones;
437 	u8 ba_fails;
438 	u8 ppdu_type;
439 	u32 mu_grpid;
440 	u32 mu_pos;
441 	bool is_ampdu;
442 };
443 
444 #define ATH12K_FLUSH_TIMEOUT (5 * HZ)
445 #define ATH12K_VDEV_DELETE_TIMEOUT_HZ (5 * HZ)
446 
447 struct ath12k {
448 	struct ath12k_base *ab;
449 	struct ath12k_pdev *pdev;
450 	struct ieee80211_hw *hw;
451 	struct ieee80211_ops *ops;
452 	struct ath12k_wmi_pdev *wmi;
453 	struct ath12k_pdev_dp dp;
454 	u8 mac_addr[ETH_ALEN];
455 	u32 ht_cap_info;
456 	u32 vht_cap_info;
457 	struct ath12k_he ar_he;
458 	enum ath12k_state state;
459 	bool supports_6ghz;
460 	struct {
461 		struct completion started;
462 		struct completion completed;
463 		struct completion on_channel;
464 		struct delayed_work timeout;
465 		enum ath12k_scan_state state;
466 		bool is_roc;
467 		int vdev_id;
468 		int roc_freq;
469 		bool roc_notify;
470 	} scan;
471 
472 	struct {
473 		struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
474 		struct ieee80211_sband_iftype_data
475 			iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
476 	} mac;
477 
478 	unsigned long dev_flags;
479 	unsigned int filter_flags;
480 	unsigned long monitor_flags;
481 	u32 min_tx_power;
482 	u32 max_tx_power;
483 	u32 txpower_limit_2g;
484 	u32 txpower_limit_5g;
485 	u32 txpower_scale;
486 	u32 power_scale;
487 	u32 chan_tx_pwr;
488 	u32 num_stations;
489 	u32 max_num_stations;
490 	bool monitor_present;
491 	/* To synchronize concurrent synchronous mac80211 callback operations,
492 	 * concurrent debugfs configuration and concurrent FW statistics events.
493 	 */
494 	struct mutex conf_mutex;
495 	/* protects the radio specific data like debug stats, ppdu_stats_info stats,
496 	 * vdev_stop_status info, scan data, ath12k_sta info, ath12k_vif info,
497 	 * channel context data, survey info, test mode data.
498 	 */
499 	spinlock_t data_lock;
500 
501 	struct list_head arvifs;
502 	/* should never be NULL; needed for regular htt rx */
503 	struct ieee80211_channel *rx_channel;
504 
505 	/* valid during scan; needed for mgmt rx during scan */
506 	struct ieee80211_channel *scan_channel;
507 
508 	u8 cfg_tx_chainmask;
509 	u8 cfg_rx_chainmask;
510 	u8 num_rx_chains;
511 	u8 num_tx_chains;
512 	/* pdev_idx starts from 0 whereas pdev->pdev_id starts with 1 */
513 	u8 pdev_idx;
514 	u8 lmac_id;
515 
516 	struct completion peer_assoc_done;
517 	struct completion peer_delete_done;
518 
519 	int install_key_status;
520 	struct completion install_key_done;
521 
522 	int last_wmi_vdev_start_status;
523 	struct completion vdev_setup_done;
524 	struct completion vdev_delete_done;
525 
526 	int num_peers;
527 	int max_num_peers;
528 	u32 num_started_vdevs;
529 	u32 num_created_vdevs;
530 	unsigned long long allocated_vdev_map;
531 
532 	struct idr txmgmt_idr;
533 	/* protects txmgmt_idr data */
534 	spinlock_t txmgmt_idr_lock;
535 	atomic_t num_pending_mgmt_tx;
536 
537 	/* cycle count is reported twice for each visited channel during scan.
538 	 * access protected by data_lock
539 	 */
540 	u32 survey_last_rx_clear_count;
541 	u32 survey_last_cycle_count;
542 
543 	/* Channel info events are expected to come in pairs without and with
544 	 * COMPLETE flag set respectively for each channel visit during scan.
545 	 *
546 	 * However there are deviations from this rule. This flag is used to
547 	 * avoid reporting garbage data.
548 	 */
549 	bool ch_info_can_report_survey;
550 	struct survey_info survey[ATH12K_NUM_CHANS];
551 	struct completion bss_survey_done;
552 
553 	struct work_struct regd_update_work;
554 
555 	struct work_struct wmi_mgmt_tx_work;
556 	struct sk_buff_head wmi_mgmt_tx_queue;
557 
558 	struct ath12k_per_peer_tx_stats peer_tx_stats;
559 	struct list_head ppdu_stats_info;
560 	u32 ppdu_stat_list_depth;
561 
562 	struct ath12k_per_peer_tx_stats cached_stats;
563 	u32 last_ppdu_id;
564 	u32 cached_ppdu_id;
565 
566 	bool dfs_block_radar_events;
567 	bool monitor_conf_enabled;
568 	bool monitor_vdev_created;
569 	bool monitor_started;
570 	int monitor_vdev_id;
571 };
572 
573 struct ath12k_band_cap {
574 	u32 phy_id;
575 	u32 max_bw_supported;
576 	u32 ht_cap_info;
577 	u32 he_cap_info[2];
578 	u32 he_mcs;
579 	u32 he_cap_phy_info[PSOC_HOST_MAX_PHY_SIZE];
580 	struct ath12k_wmi_ppe_threshold_arg he_ppet;
581 	u16 he_6ghz_capa;
582 };
583 
584 struct ath12k_pdev_cap {
585 	u32 supported_bands;
586 	u32 ampdu_density;
587 	u32 vht_cap;
588 	u32 vht_mcs;
589 	u32 he_mcs;
590 	u32 tx_chain_mask;
591 	u32 rx_chain_mask;
592 	u32 tx_chain_mask_shift;
593 	u32 rx_chain_mask_shift;
594 	struct ath12k_band_cap band[NUM_NL80211_BANDS];
595 };
596 
597 struct mlo_timestamp {
598 	u32 info;
599 	u32 sync_timestamp_lo_us;
600 	u32 sync_timestamp_hi_us;
601 	u32 mlo_offset_lo;
602 	u32 mlo_offset_hi;
603 	u32 mlo_offset_clks;
604 	u32 mlo_comp_clks;
605 	u32 mlo_comp_timer;
606 };
607 
608 struct ath12k_pdev {
609 	struct ath12k *ar;
610 	u32 pdev_id;
611 	struct ath12k_pdev_cap cap;
612 	u8 mac_addr[ETH_ALEN];
613 	struct mlo_timestamp timestamp;
614 };
615 
616 struct ath12k_board_data {
617 	const struct firmware *fw;
618 	const void *data;
619 	size_t len;
620 };
621 
622 struct ath12k_soc_dp_tx_err_stats {
623 	/* TCL Ring Descriptor unavailable */
624 	u32 desc_na[DP_TCL_NUM_RING_MAX];
625 	/* Other failures during dp_tx due to mem allocation failure
626 	 * idr unavailable etc.
627 	 */
628 	atomic_t misc_fail;
629 };
630 
631 struct ath12k_soc_dp_stats {
632 	u32 err_ring_pkts;
633 	u32 invalid_rbm;
634 	u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX];
635 	u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX];
636 	u32 hal_reo_error[DP_REO_DST_RING_MAX];
637 	struct ath12k_soc_dp_tx_err_stats tx_err;
638 };
639 
640 /* Master structure to hold the hw data which may be used in core module */
641 struct ath12k_base {
642 	enum ath12k_hw_rev hw_rev;
643 	struct platform_device *pdev;
644 	struct device *dev;
645 	struct ath12k_qmi qmi;
646 	struct ath12k_wmi_base wmi_ab;
647 	struct completion fw_ready;
648 	int num_radios;
649 	/* HW channel counters frequency value in hertz common to all MACs */
650 	u32 cc_freq_hz;
651 
652 	struct ath12k_htc htc;
653 
654 	struct ath12k_dp dp;
655 
656 	void __iomem *mem;
657 	unsigned long mem_len;
658 
659 	struct {
660 		enum ath12k_bus bus;
661 		const struct ath12k_hif_ops *ops;
662 	} hif;
663 
664 	struct ath12k_ce ce;
665 	struct timer_list rx_replenish_retry;
666 	struct ath12k_hal hal;
667 	/* To synchronize core_start/core_stop */
668 	struct mutex core_lock;
669 	/* Protects data like peers */
670 	spinlock_t base_lock;
671 	struct ath12k_pdev pdevs[MAX_RADIOS];
672 	struct ath12k_pdev __rcu *pdevs_active[MAX_RADIOS];
673 	struct ath12k_wmi_hal_reg_capabilities_ext_arg hal_reg_cap[MAX_RADIOS];
674 	unsigned long long free_vdev_map;
675 	unsigned long long free_vdev_stats_id_map;
676 	struct list_head peers;
677 	wait_queue_head_t peer_mapping_wq;
678 	u8 mac_addr[ETH_ALEN];
679 	bool wmi_ready;
680 	u32 wlan_init_status;
681 	int irq_num[ATH12K_IRQ_NUM_MAX];
682 	struct ath12k_ext_irq_grp ext_irq_grp[ATH12K_EXT_IRQ_GRP_NUM_MAX];
683 	struct napi_struct *napi;
684 	struct ath12k_wmi_target_cap_arg target_caps;
685 	u32 ext_service_bitmap[WMI_SERVICE_EXT_BM_SIZE];
686 	bool pdevs_macaddr_valid;
687 	int bd_api;
688 
689 	const struct ath12k_hw_params *hw_params;
690 
691 	const struct firmware *cal_file;
692 
693 	/* Below regd's are protected by ab->data_lock */
694 	/* This is the regd set for every radio
695 	 * by the firmware during initialization
696 	 */
697 	struct ieee80211_regdomain *default_regd[MAX_RADIOS];
698 	/* This regd is set during dynamic country setting
699 	 * This may or may not be used during the runtime
700 	 */
701 	struct ieee80211_regdomain *new_regd[MAX_RADIOS];
702 
703 	/* Current DFS Regulatory */
704 	enum ath12k_dfs_region dfs_region;
705 	struct ath12k_soc_dp_stats soc_stats;
706 
707 	unsigned long dev_flags;
708 	struct completion driver_recovery;
709 	struct workqueue_struct *workqueue;
710 	struct work_struct restart_work;
711 	struct workqueue_struct *workqueue_aux;
712 	struct work_struct reset_work;
713 	atomic_t reset_count;
714 	atomic_t recovery_count;
715 	atomic_t recovery_start_count;
716 	bool is_reset;
717 	struct completion reset_complete;
718 	struct completion reconfigure_complete;
719 	struct completion recovery_start;
720 	/* continuous recovery fail count */
721 	atomic_t fail_cont_count;
722 	unsigned long reset_fail_timeout;
723 	struct {
724 		/* protected by data_lock */
725 		u32 fw_crash_counter;
726 	} stats;
727 	u32 pktlog_defs_checksum;
728 
729 	struct ath12k_dbring_cap *db_caps;
730 	u32 num_db_cap;
731 
732 	struct timer_list mon_reap_timer;
733 
734 	struct completion htc_suspend;
735 
736 	u64 fw_soc_drop_count;
737 	bool static_window_map;
738 
739 	/* must be last */
740 	u8 drv_priv[] __aligned(sizeof(void *));
741 };
742 
743 int ath12k_core_qmi_firmware_ready(struct ath12k_base *ab);
744 int ath12k_core_pre_init(struct ath12k_base *ab);
745 int ath12k_core_init(struct ath12k_base *ath12k);
746 void ath12k_core_deinit(struct ath12k_base *ath12k);
747 struct ath12k_base *ath12k_core_alloc(struct device *dev, size_t priv_size,
748 				      enum ath12k_bus bus);
749 void ath12k_core_free(struct ath12k_base *ath12k);
750 int ath12k_core_fetch_board_data_api_1(struct ath12k_base *ab,
751 				       struct ath12k_board_data *bd,
752 				       char *filename);
753 int ath12k_core_fetch_bdf(struct ath12k_base *ath12k,
754 			  struct ath12k_board_data *bd);
755 void ath12k_core_free_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd);
756 int ath12k_core_check_dt(struct ath12k_base *ath12k);
757 
758 void ath12k_core_halt(struct ath12k *ar);
759 int ath12k_core_resume(struct ath12k_base *ab);
760 int ath12k_core_suspend(struct ath12k_base *ab);
761 
762 const struct firmware *ath12k_core_firmware_request(struct ath12k_base *ab,
763 						    const char *filename);
764 
765 static inline const char *ath12k_scan_state_str(enum ath12k_scan_state state)
766 {
767 	switch (state) {
768 	case ATH12K_SCAN_IDLE:
769 		return "idle";
770 	case ATH12K_SCAN_STARTING:
771 		return "starting";
772 	case ATH12K_SCAN_RUNNING:
773 		return "running";
774 	case ATH12K_SCAN_ABORTING:
775 		return "aborting";
776 	}
777 
778 	return "unknown";
779 }
780 
781 static inline struct ath12k_skb_cb *ATH12K_SKB_CB(struct sk_buff *skb)
782 {
783 	BUILD_BUG_ON(sizeof(struct ath12k_skb_cb) >
784 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
785 	return (struct ath12k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
786 }
787 
788 static inline struct ath12k_skb_rxcb *ATH12K_SKB_RXCB(struct sk_buff *skb)
789 {
790 	BUILD_BUG_ON(sizeof(struct ath12k_skb_rxcb) > sizeof(skb->cb));
791 	return (struct ath12k_skb_rxcb *)skb->cb;
792 }
793 
794 static inline struct ath12k_vif *ath12k_vif_to_arvif(struct ieee80211_vif *vif)
795 {
796 	return (struct ath12k_vif *)vif->drv_priv;
797 }
798 
799 static inline struct ath12k *ath12k_ab_to_ar(struct ath12k_base *ab,
800 					     int mac_id)
801 {
802 	return ab->pdevs[ath12k_hw_mac_id_to_pdev_id(ab->hw_params, mac_id)].ar;
803 }
804 
805 static inline void ath12k_core_create_firmware_path(struct ath12k_base *ab,
806 						    const char *filename,
807 						    void *buf, size_t buf_len)
808 {
809 	snprintf(buf, buf_len, "%s/%s/%s", ATH12K_FW_DIR,
810 		 ab->hw_params->fw.dir, filename);
811 }
812 
813 static inline const char *ath12k_bus_str(enum ath12k_bus bus)
814 {
815 	switch (bus) {
816 	case ATH12K_BUS_PCI:
817 		return "pci";
818 	}
819 
820 	return "unknown";
821 }
822 
823 #endif /* _CORE_H_ */
824