1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef ATH11K_CORE_H
7 #define ATH11K_CORE_H
8 
9 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/bitfield.h>
13 #include "qmi.h"
14 #include "htc.h"
15 #include "wmi.h"
16 #include "hal.h"
17 #include "dp.h"
18 #include "ce.h"
19 #include "mac.h"
20 #include "hw.h"
21 #include "hal_rx.h"
22 #include "reg.h"
23 #include "thermal.h"
24 #include "dbring.h"
25 #include "spectral.h"
26 
27 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
28 
29 #define ATH11K_TX_MGMT_NUM_PENDING_MAX	512
30 
31 #define ATH11K_TX_MGMT_TARGET_MAX_SUPPORT_WMI 64
32 
33 /* Pending management packets threshold for dropping probe responses */
34 #define ATH11K_PRB_RSP_DROP_THRESHOLD ((ATH11K_TX_MGMT_TARGET_MAX_SUPPORT_WMI * 3) / 4)
35 
36 #define ATH11K_INVALID_HW_MAC_ID	0xFF
37 #define ATH11K_CONNECTION_LOSS_HZ	(3 * HZ)
38 
39 extern unsigned int ath11k_frame_mode;
40 
41 #define ATH11K_MON_TIMER_INTERVAL  10
42 
43 enum ath11k_supported_bw {
44 	ATH11K_BW_20	= 0,
45 	ATH11K_BW_40	= 1,
46 	ATH11K_BW_80	= 2,
47 	ATH11K_BW_160	= 3,
48 };
49 
50 enum ath11k_bdf_search {
51 	ATH11K_BDF_SEARCH_DEFAULT,
52 	ATH11K_BDF_SEARCH_BUS_AND_BOARD,
53 };
54 
55 enum wme_ac {
56 	WME_AC_BE,
57 	WME_AC_BK,
58 	WME_AC_VI,
59 	WME_AC_VO,
60 	WME_NUM_AC
61 };
62 
63 #define ATH11K_HT_MCS_MAX	7
64 #define ATH11K_VHT_MCS_MAX	9
65 #define ATH11K_HE_MCS_MAX	11
66 
67 enum ath11k_crypt_mode {
68 	/* Only use hardware crypto engine */
69 	ATH11K_CRYPT_MODE_HW,
70 	/* Only use software crypto */
71 	ATH11K_CRYPT_MODE_SW,
72 };
73 
74 static inline enum wme_ac ath11k_tid_to_ac(u32 tid)
75 {
76 	return (((tid == 0) || (tid == 3)) ? WME_AC_BE :
77 		((tid == 1) || (tid == 2)) ? WME_AC_BK :
78 		((tid == 4) || (tid == 5)) ? WME_AC_VI :
79 		WME_AC_VO);
80 }
81 
82 enum ath11k_skb_flags {
83 	ATH11K_SKB_HW_80211_ENCAP = BIT(0),
84 	ATH11K_SKB_CIPHER_SET = BIT(1),
85 };
86 
87 struct ath11k_skb_cb {
88 	dma_addr_t paddr;
89 	u8 eid;
90 	u8 flags;
91 	u32 cipher;
92 	struct ath11k *ar;
93 	struct ieee80211_vif *vif;
94 } __packed;
95 
96 struct ath11k_skb_rxcb {
97 	dma_addr_t paddr;
98 	bool is_first_msdu;
99 	bool is_last_msdu;
100 	bool is_continuation;
101 	bool is_mcbc;
102 	bool is_eapol;
103 	struct hal_rx_desc *rx_desc;
104 	u8 err_rel_src;
105 	u8 err_code;
106 	u8 mac_id;
107 	u8 unmapped;
108 	u8 is_frag;
109 	u8 tid;
110 	u16 peer_id;
111 	u16 seq_no;
112 };
113 
114 enum ath11k_hw_rev {
115 	ATH11K_HW_IPQ8074,
116 	ATH11K_HW_QCA6390_HW20,
117 	ATH11K_HW_IPQ6018_HW10,
118 	ATH11K_HW_QCN9074_HW10,
119 	ATH11K_HW_WCN6855_HW20,
120 	ATH11K_HW_WCN6855_HW21,
121 };
122 
123 enum ath11k_firmware_mode {
124 	/* the default mode, standard 802.11 functionality */
125 	ATH11K_FIRMWARE_MODE_NORMAL,
126 
127 	/* factory tests etc */
128 	ATH11K_FIRMWARE_MODE_FTM,
129 
130 	/* Cold boot calibration */
131 	ATH11K_FIRMWARE_MODE_COLD_BOOT = 7,
132 };
133 
134 extern bool ath11k_cold_boot_cal;
135 
136 #define ATH11K_IRQ_NUM_MAX 52
137 #define ATH11K_EXT_IRQ_NUM_MAX	16
138 
139 struct ath11k_ext_irq_grp {
140 	struct ath11k_base *ab;
141 	u32 irqs[ATH11K_EXT_IRQ_NUM_MAX];
142 	u32 num_irq;
143 	u32 grp_id;
144 	u64 timestamp;
145 	bool napi_enabled;
146 	struct napi_struct napi;
147 	struct net_device napi_ndev;
148 };
149 
150 #define HEHANDLE_CAP_PHYINFO_SIZE       3
151 #define HECAP_PHYINFO_SIZE              9
152 #define HECAP_MACINFO_SIZE              5
153 #define HECAP_TXRX_MCS_NSS_SIZE         2
154 #define HECAP_PPET16_PPET8_MAX_SIZE     25
155 
156 #define HE_PPET16_PPET8_SIZE            8
157 
158 /* 802.11ax PPE (PPDU packet Extension) threshold */
159 struct he_ppe_threshold {
160 	u32 numss_m1;
161 	u32 ru_mask;
162 	u32 ppet16_ppet8_ru3_ru0[HE_PPET16_PPET8_SIZE];
163 };
164 
165 struct ath11k_he {
166 	u8 hecap_macinfo[HECAP_MACINFO_SIZE];
167 	u32 hecap_rxmcsnssmap;
168 	u32 hecap_txmcsnssmap;
169 	u32 hecap_phyinfo[HEHANDLE_CAP_PHYINFO_SIZE];
170 	struct he_ppe_threshold   hecap_ppet;
171 	u32 heop_param;
172 };
173 
174 #define MAX_RADIOS 3
175 
176 enum {
177 	WMI_HOST_TP_SCALE_MAX   = 0,
178 	WMI_HOST_TP_SCALE_50    = 1,
179 	WMI_HOST_TP_SCALE_25    = 2,
180 	WMI_HOST_TP_SCALE_12    = 3,
181 	WMI_HOST_TP_SCALE_MIN   = 4,
182 	WMI_HOST_TP_SCALE_SIZE   = 5,
183 };
184 
185 enum ath11k_scan_state {
186 	ATH11K_SCAN_IDLE,
187 	ATH11K_SCAN_STARTING,
188 	ATH11K_SCAN_RUNNING,
189 	ATH11K_SCAN_ABORTING,
190 };
191 
192 enum ath11k_dev_flags {
193 	ATH11K_CAC_RUNNING,
194 	ATH11K_FLAG_CORE_REGISTERED,
195 	ATH11K_FLAG_CRASH_FLUSH,
196 	ATH11K_FLAG_RAW_MODE,
197 	ATH11K_FLAG_HW_CRYPTO_DISABLED,
198 	ATH11K_FLAG_BTCOEX,
199 	ATH11K_FLAG_RECOVERY,
200 	ATH11K_FLAG_UNREGISTERING,
201 	ATH11K_FLAG_REGISTERED,
202 	ATH11K_FLAG_QMI_FAIL,
203 	ATH11K_FLAG_HTC_SUSPEND_COMPLETE,
204 	ATH11K_FLAG_CE_IRQ_ENABLED,
205 	ATH11K_FLAG_EXT_IRQ_ENABLED,
206 	ATH11K_FLAG_FIXED_MEM_RGN,
207 };
208 
209 enum ath11k_monitor_flags {
210 	ATH11K_FLAG_MONITOR_CONF_ENABLED,
211 	ATH11K_FLAG_MONITOR_STARTED,
212 	ATH11K_FLAG_MONITOR_VDEV_CREATED,
213 };
214 
215 struct ath11k_vif {
216 	u32 vdev_id;
217 	enum wmi_vdev_type vdev_type;
218 	enum wmi_vdev_subtype vdev_subtype;
219 	u32 beacon_interval;
220 	u32 dtim_period;
221 	u16 ast_hash;
222 	u16 ast_idx;
223 	u16 tcl_metadata;
224 	u8 hal_addr_search_flags;
225 	u8 search_type;
226 
227 	struct ath11k *ar;
228 	struct ieee80211_vif *vif;
229 
230 	u16 tx_seq_no;
231 	struct wmi_wmm_params_all_arg wmm_params;
232 	struct list_head list;
233 	union {
234 		struct {
235 			u32 uapsd;
236 		} sta;
237 		struct {
238 			/* 127 stations; wmi limit */
239 			u8 tim_bitmap[16];
240 			u8 tim_len;
241 			u32 ssid_len;
242 			u8 ssid[IEEE80211_MAX_SSID_LEN];
243 			bool hidden_ssid;
244 			/* P2P_IE with NoA attribute for P2P_GO case */
245 			u32 noa_len;
246 			u8 *noa_data;
247 		} ap;
248 	} u;
249 
250 	bool is_started;
251 	bool is_up;
252 	bool spectral_enabled;
253 	bool ps;
254 	u32 aid;
255 	u8 bssid[ETH_ALEN];
256 	struct cfg80211_bitrate_mask bitrate_mask;
257 	struct delayed_work connection_loss_work;
258 	int num_legacy_stations;
259 	int rtscts_prot_mode;
260 	int txpower;
261 	bool rsnie_present;
262 	bool wpaie_present;
263 	bool bcca_zero_sent;
264 	bool do_not_send_tmpl;
265 	struct ieee80211_chanctx_conf chanctx;
266 };
267 
268 struct ath11k_vif_iter {
269 	u32 vdev_id;
270 	struct ath11k_vif *arvif;
271 };
272 
273 struct ath11k_rx_peer_stats {
274 	u64 num_msdu;
275 	u64 num_mpdu_fcs_ok;
276 	u64 num_mpdu_fcs_err;
277 	u64 tcp_msdu_count;
278 	u64 udp_msdu_count;
279 	u64 other_msdu_count;
280 	u64 ampdu_msdu_count;
281 	u64 non_ampdu_msdu_count;
282 	u64 stbc_count;
283 	u64 beamformed_count;
284 	u64 mcs_count[HAL_RX_MAX_MCS + 1];
285 	u64 nss_count[HAL_RX_MAX_NSS];
286 	u64 bw_count[HAL_RX_BW_MAX];
287 	u64 gi_count[HAL_RX_GI_MAX];
288 	u64 coding_count[HAL_RX_SU_MU_CODING_MAX];
289 	u64 tid_count[IEEE80211_NUM_TIDS + 1];
290 	u64 pream_cnt[HAL_RX_PREAMBLE_MAX];
291 	u64 reception_type[HAL_RX_RECEPTION_TYPE_MAX];
292 	u64 rx_duration;
293 	u64 dcm_count;
294 	u64 ru_alloc_cnt[HAL_RX_RU_ALLOC_TYPE_MAX];
295 };
296 
297 #define ATH11K_HE_MCS_NUM       12
298 #define ATH11K_VHT_MCS_NUM      10
299 #define ATH11K_BW_NUM           4
300 #define ATH11K_NSS_NUM          4
301 #define ATH11K_LEGACY_NUM       12
302 #define ATH11K_GI_NUM           4
303 #define ATH11K_HT_MCS_NUM       32
304 
305 enum ath11k_pkt_rx_err {
306 	ATH11K_PKT_RX_ERR_FCS,
307 	ATH11K_PKT_RX_ERR_TKIP,
308 	ATH11K_PKT_RX_ERR_CRYPT,
309 	ATH11K_PKT_RX_ERR_PEER_IDX_INVAL,
310 	ATH11K_PKT_RX_ERR_MAX,
311 };
312 
313 enum ath11k_ampdu_subfrm_num {
314 	ATH11K_AMPDU_SUBFRM_NUM_10,
315 	ATH11K_AMPDU_SUBFRM_NUM_20,
316 	ATH11K_AMPDU_SUBFRM_NUM_30,
317 	ATH11K_AMPDU_SUBFRM_NUM_40,
318 	ATH11K_AMPDU_SUBFRM_NUM_50,
319 	ATH11K_AMPDU_SUBFRM_NUM_60,
320 	ATH11K_AMPDU_SUBFRM_NUM_MORE,
321 	ATH11K_AMPDU_SUBFRM_NUM_MAX,
322 };
323 
324 enum ath11k_amsdu_subfrm_num {
325 	ATH11K_AMSDU_SUBFRM_NUM_1,
326 	ATH11K_AMSDU_SUBFRM_NUM_2,
327 	ATH11K_AMSDU_SUBFRM_NUM_3,
328 	ATH11K_AMSDU_SUBFRM_NUM_4,
329 	ATH11K_AMSDU_SUBFRM_NUM_MORE,
330 	ATH11K_AMSDU_SUBFRM_NUM_MAX,
331 };
332 
333 enum ath11k_counter_type {
334 	ATH11K_COUNTER_TYPE_BYTES,
335 	ATH11K_COUNTER_TYPE_PKTS,
336 	ATH11K_COUNTER_TYPE_MAX,
337 };
338 
339 enum ath11k_stats_type {
340 	ATH11K_STATS_TYPE_SUCC,
341 	ATH11K_STATS_TYPE_FAIL,
342 	ATH11K_STATS_TYPE_RETRY,
343 	ATH11K_STATS_TYPE_AMPDU,
344 	ATH11K_STATS_TYPE_MAX,
345 };
346 
347 struct ath11k_htt_data_stats {
348 	u64 legacy[ATH11K_COUNTER_TYPE_MAX][ATH11K_LEGACY_NUM];
349 	u64 ht[ATH11K_COUNTER_TYPE_MAX][ATH11K_HT_MCS_NUM];
350 	u64 vht[ATH11K_COUNTER_TYPE_MAX][ATH11K_VHT_MCS_NUM];
351 	u64 he[ATH11K_COUNTER_TYPE_MAX][ATH11K_HE_MCS_NUM];
352 	u64 bw[ATH11K_COUNTER_TYPE_MAX][ATH11K_BW_NUM];
353 	u64 nss[ATH11K_COUNTER_TYPE_MAX][ATH11K_NSS_NUM];
354 	u64 gi[ATH11K_COUNTER_TYPE_MAX][ATH11K_GI_NUM];
355 };
356 
357 struct ath11k_htt_tx_stats {
358 	struct ath11k_htt_data_stats stats[ATH11K_STATS_TYPE_MAX];
359 	u64 tx_duration;
360 	u64 ba_fails;
361 	u64 ack_fails;
362 };
363 
364 struct ath11k_per_ppdu_tx_stats {
365 	u16 succ_pkts;
366 	u16 failed_pkts;
367 	u16 retry_pkts;
368 	u32 succ_bytes;
369 	u32 failed_bytes;
370 	u32 retry_bytes;
371 };
372 
373 struct ath11k_sta {
374 	struct ath11k_vif *arvif;
375 
376 	/* the following are protected by ar->data_lock */
377 	u32 changed; /* IEEE80211_RC_* */
378 	u32 bw;
379 	u32 nss;
380 	u32 smps;
381 	enum hal_pn_type pn_type;
382 
383 	struct work_struct update_wk;
384 	struct work_struct set_4addr_wk;
385 	struct rate_info txrate;
386 	u32 peer_nss;
387 	struct rate_info last_txrate;
388 	u64 rx_duration;
389 	u64 tx_duration;
390 	u8 rssi_comb;
391 	s8 rssi_beacon;
392 	s8 chain_signal[IEEE80211_MAX_CHAINS];
393 	struct ath11k_htt_tx_stats *tx_stats;
394 	struct ath11k_rx_peer_stats *rx_stats;
395 
396 #ifdef CONFIG_MAC80211_DEBUGFS
397 	/* protected by conf_mutex */
398 	bool aggr_mode;
399 #endif
400 
401 	bool use_4addr_set;
402 	u16 tcl_metadata;
403 };
404 
405 #define ATH11K_MIN_5G_FREQ 4150
406 #define ATH11K_MIN_6G_FREQ 5925
407 #define ATH11K_MAX_6G_FREQ 7115
408 #define ATH11K_NUM_CHANS 101
409 #define ATH11K_MAX_5G_CHAN 173
410 
411 enum ath11k_state {
412 	ATH11K_STATE_OFF,
413 	ATH11K_STATE_ON,
414 	ATH11K_STATE_RESTARTING,
415 	ATH11K_STATE_RESTARTED,
416 	ATH11K_STATE_WEDGED,
417 	/* Add other states as required */
418 };
419 
420 /* Antenna noise floor */
421 #define ATH11K_DEFAULT_NOISE_FLOOR -95
422 
423 #define ATH11K_INVALID_RSSI_FULL -1
424 
425 #define ATH11K_INVALID_RSSI_EMPTY -128
426 
427 struct ath11k_fw_stats {
428 	struct dentry *debugfs_fwstats;
429 	u32 pdev_id;
430 	u32 stats_id;
431 	struct list_head pdevs;
432 	struct list_head vdevs;
433 	struct list_head bcn;
434 };
435 
436 struct ath11k_dbg_htt_stats {
437 	u8 type;
438 	u8 reset;
439 	struct debug_htt_stats_req *stats_req;
440 	/* protects shared stats req buffer */
441 	spinlock_t lock;
442 };
443 
444 struct ath11k_debug {
445 	struct dentry *debugfs_pdev;
446 	struct ath11k_dbg_htt_stats htt_stats;
447 	u32 extd_tx_stats;
448 	struct ath11k_fw_stats fw_stats;
449 	struct completion fw_stats_complete;
450 	bool fw_stats_done;
451 	u32 extd_rx_stats;
452 	u32 pktlog_filter;
453 	u32 pktlog_mode;
454 	u32 pktlog_peer_valid;
455 	u8 pktlog_peer_addr[ETH_ALEN];
456 	u32 rx_filter;
457 };
458 
459 struct ath11k_per_peer_tx_stats {
460 	u32 succ_bytes;
461 	u32 retry_bytes;
462 	u32 failed_bytes;
463 	u16 succ_pkts;
464 	u16 retry_pkts;
465 	u16 failed_pkts;
466 	u32 duration;
467 	u8 ba_fails;
468 	bool is_ampdu;
469 };
470 
471 #define ATH11K_FLUSH_TIMEOUT (5 * HZ)
472 #define ATH11K_VDEV_DELETE_TIMEOUT_HZ (5 * HZ)
473 
474 struct ath11k {
475 	struct ath11k_base *ab;
476 	struct ath11k_pdev *pdev;
477 	struct ieee80211_hw *hw;
478 	struct ieee80211_ops *ops;
479 	struct ath11k_pdev_wmi *wmi;
480 	struct ath11k_pdev_dp dp;
481 	u8 mac_addr[ETH_ALEN];
482 	u32 ht_cap_info;
483 	u32 vht_cap_info;
484 	struct ath11k_he ar_he;
485 	enum ath11k_state state;
486 	bool supports_6ghz;
487 	struct {
488 		struct completion started;
489 		struct completion completed;
490 		struct completion on_channel;
491 		struct delayed_work timeout;
492 		enum ath11k_scan_state state;
493 		bool is_roc;
494 		int vdev_id;
495 		int roc_freq;
496 		bool roc_notify;
497 	} scan;
498 
499 	struct {
500 		struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
501 		struct ieee80211_sband_iftype_data
502 			iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
503 	} mac;
504 
505 	unsigned long dev_flags;
506 	unsigned int filter_flags;
507 	unsigned long monitor_flags;
508 	u32 min_tx_power;
509 	u32 max_tx_power;
510 	u32 txpower_limit_2g;
511 	u32 txpower_limit_5g;
512 	u32 txpower_scale;
513 	u32 power_scale;
514 	u32 chan_tx_pwr;
515 	u32 num_stations;
516 	u32 max_num_stations;
517 	/* To synchronize concurrent synchronous mac80211 callback operations,
518 	 * concurrent debugfs configuration and concurrent FW statistics events.
519 	 */
520 	struct mutex conf_mutex;
521 	/* protects the radio specific data like debug stats, ppdu_stats_info stats,
522 	 * vdev_stop_status info, scan data, ath11k_sta info, ath11k_vif info,
523 	 * channel context data, survey info, test mode data.
524 	 */
525 	spinlock_t data_lock;
526 
527 	struct list_head arvifs;
528 	/* should never be NULL; needed for regular htt rx */
529 	struct ieee80211_channel *rx_channel;
530 
531 	/* valid during scan; needed for mgmt rx during scan */
532 	struct ieee80211_channel *scan_channel;
533 
534 	u8 cfg_tx_chainmask;
535 	u8 cfg_rx_chainmask;
536 	u8 num_rx_chains;
537 	u8 num_tx_chains;
538 	/* pdev_idx starts from 0 whereas pdev->pdev_id starts with 1 */
539 	u8 pdev_idx;
540 	u8 lmac_id;
541 
542 	struct completion peer_assoc_done;
543 	struct completion peer_delete_done;
544 
545 	int install_key_status;
546 	struct completion install_key_done;
547 
548 	int last_wmi_vdev_start_status;
549 	struct completion vdev_setup_done;
550 	struct completion vdev_delete_done;
551 
552 	int num_peers;
553 	int max_num_peers;
554 	u32 num_started_vdevs;
555 	u32 num_created_vdevs;
556 	unsigned long long allocated_vdev_map;
557 
558 	struct idr txmgmt_idr;
559 	/* protects txmgmt_idr data */
560 	spinlock_t txmgmt_idr_lock;
561 	atomic_t num_pending_mgmt_tx;
562 	wait_queue_head_t txmgmt_empty_waitq;
563 
564 	/* cycle count is reported twice for each visited channel during scan.
565 	 * access protected by data_lock
566 	 */
567 	u32 survey_last_rx_clear_count;
568 	u32 survey_last_cycle_count;
569 
570 	/* Channel info events are expected to come in pairs without and with
571 	 * COMPLETE flag set respectively for each channel visit during scan.
572 	 *
573 	 * However there are deviations from this rule. This flag is used to
574 	 * avoid reporting garbage data.
575 	 */
576 	bool ch_info_can_report_survey;
577 	struct survey_info survey[ATH11K_NUM_CHANS];
578 	struct completion bss_survey_done;
579 
580 	struct work_struct regd_update_work;
581 
582 	struct work_struct wmi_mgmt_tx_work;
583 	struct sk_buff_head wmi_mgmt_tx_queue;
584 
585 	struct ath11k_per_peer_tx_stats peer_tx_stats;
586 	struct list_head ppdu_stats_info;
587 	u32 ppdu_stat_list_depth;
588 
589 	struct ath11k_per_peer_tx_stats cached_stats;
590 	u32 last_ppdu_id;
591 	u32 cached_ppdu_id;
592 	int monitor_vdev_id;
593 #ifdef CONFIG_ATH11K_DEBUGFS
594 	struct ath11k_debug debug;
595 #endif
596 #ifdef CONFIG_ATH11K_SPECTRAL
597 	struct ath11k_spectral spectral;
598 #endif
599 	bool dfs_block_radar_events;
600 	struct ath11k_thermal thermal;
601 	u32 vdev_id_11d_scan;
602 	struct completion finish_11d_scan;
603 	struct completion finish_11d_ch_list;
604 	bool pending_11d;
605 	bool regdom_set_by_user;
606 };
607 
608 struct ath11k_band_cap {
609 	u32 phy_id;
610 	u32 max_bw_supported;
611 	u32 ht_cap_info;
612 	u32 he_cap_info[2];
613 	u32 he_mcs;
614 	u32 he_cap_phy_info[PSOC_HOST_MAX_PHY_SIZE];
615 	struct ath11k_ppe_threshold he_ppet;
616 	u16 he_6ghz_capa;
617 };
618 
619 struct ath11k_pdev_cap {
620 	u32 supported_bands;
621 	u32 ampdu_density;
622 	u32 vht_cap;
623 	u32 vht_mcs;
624 	u32 he_mcs;
625 	u32 tx_chain_mask;
626 	u32 rx_chain_mask;
627 	u32 tx_chain_mask_shift;
628 	u32 rx_chain_mask_shift;
629 	struct ath11k_band_cap band[NUM_NL80211_BANDS];
630 	bool nss_ratio_enabled;
631 	u8 nss_ratio_info;
632 };
633 
634 struct ath11k_pdev {
635 	struct ath11k *ar;
636 	u32 pdev_id;
637 	struct ath11k_pdev_cap cap;
638 	u8 mac_addr[ETH_ALEN];
639 };
640 
641 struct ath11k_board_data {
642 	const struct firmware *fw;
643 	const void *data;
644 	size_t len;
645 };
646 
647 struct ath11k_bus_params {
648 	bool mhi_support;
649 	bool m3_fw_support;
650 	bool fixed_bdf_addr;
651 	bool fixed_mem_region;
652 	bool static_window_map;
653 };
654 
655 /* IPQ8074 HW channel counters frequency value in hertz */
656 #define IPQ8074_CC_FREQ_HERTZ 320000
657 
658 struct ath11k_bp_stats {
659 	/* Head Pointer reported by the last HTT Backpressure event for the ring */
660 	u16 hp;
661 
662 	/* Tail Pointer reported by the last HTT Backpressure event for the ring */
663 	u16 tp;
664 
665 	/* Number of Backpressure events received for the ring */
666 	u32 count;
667 
668 	/* Last recorded event timestamp */
669 	unsigned long jiffies;
670 };
671 
672 struct ath11k_dp_ring_bp_stats {
673 	struct ath11k_bp_stats umac_ring_bp_stats[HTT_SW_UMAC_RING_IDX_MAX];
674 	struct ath11k_bp_stats lmac_ring_bp_stats[HTT_SW_LMAC_RING_IDX_MAX][MAX_RADIOS];
675 };
676 
677 struct ath11k_soc_dp_tx_err_stats {
678 	/* TCL Ring Descriptor unavailable */
679 	u32 desc_na[DP_TCL_NUM_RING_MAX];
680 	/* Other failures during dp_tx due to mem allocation failure
681 	 * idr unavailable etc.
682 	 */
683 	atomic_t misc_fail;
684 };
685 
686 struct ath11k_soc_dp_stats {
687 	u32 err_ring_pkts;
688 	u32 invalid_rbm;
689 	u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX];
690 	u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX];
691 	u32 hal_reo_error[DP_REO_DST_RING_MAX];
692 	struct ath11k_soc_dp_tx_err_stats tx_err;
693 	struct ath11k_dp_ring_bp_stats bp_stats;
694 };
695 
696 /* Master structure to hold the hw data which may be used in core module */
697 struct ath11k_base {
698 	enum ath11k_hw_rev hw_rev;
699 	struct platform_device *pdev;
700 	struct device *dev;
701 	struct ath11k_qmi qmi;
702 	struct ath11k_wmi_base wmi_ab;
703 	struct completion fw_ready;
704 	int num_radios;
705 	/* HW channel counters frequency value in hertz common to all MACs */
706 	u32 cc_freq_hz;
707 
708 	struct ath11k_htc htc;
709 
710 	struct ath11k_dp dp;
711 
712 	void __iomem *mem;
713 	unsigned long mem_len;
714 
715 	struct {
716 		enum ath11k_bus bus;
717 		const struct ath11k_hif_ops *ops;
718 	} hif;
719 
720 	struct {
721 		struct completion wakeup_completed;
722 	} wow;
723 
724 	struct ath11k_ce ce;
725 	struct timer_list rx_replenish_retry;
726 	struct ath11k_hal hal;
727 	/* To synchronize core_start/core_stop */
728 	struct mutex core_lock;
729 	/* Protects data like peers */
730 	spinlock_t base_lock;
731 	struct ath11k_pdev pdevs[MAX_RADIOS];
732 	struct {
733 		enum WMI_HOST_WLAN_BAND supported_bands;
734 		u32 pdev_id;
735 	} target_pdev_ids[MAX_RADIOS];
736 	u8 target_pdev_count;
737 	struct ath11k_pdev __rcu *pdevs_active[MAX_RADIOS];
738 	struct ath11k_hal_reg_capabilities_ext hal_reg_cap[MAX_RADIOS];
739 	unsigned long long free_vdev_map;
740 	struct list_head peers;
741 	wait_queue_head_t peer_mapping_wq;
742 	u8 mac_addr[ETH_ALEN];
743 	bool wmi_ready;
744 	u32 wlan_init_status;
745 	int irq_num[ATH11K_IRQ_NUM_MAX];
746 	struct ath11k_ext_irq_grp ext_irq_grp[ATH11K_EXT_IRQ_GRP_NUM_MAX];
747 	struct ath11k_targ_cap target_caps;
748 	u32 ext_service_bitmap[WMI_SERVICE_EXT_BM_SIZE];
749 	bool pdevs_macaddr_valid;
750 	int bd_api;
751 
752 	struct ath11k_hw_params hw_params;
753 	struct ath11k_bus_params bus_params;
754 
755 	const struct firmware *cal_file;
756 
757 	/* Below regd's are protected by ab->data_lock */
758 	/* This is the regd set for every radio
759 	 * by the firmware during initializatin
760 	 */
761 	struct ieee80211_regdomain *default_regd[MAX_RADIOS];
762 	/* This regd is set during dynamic country setting
763 	 * This may or may not be used during the runtime
764 	 */
765 	struct ieee80211_regdomain *new_regd[MAX_RADIOS];
766 
767 	/* Current DFS Regulatory */
768 	enum ath11k_dfs_region dfs_region;
769 #ifdef CONFIG_ATH11K_DEBUGFS
770 	struct dentry *debugfs_soc;
771 	struct dentry *debugfs_ath11k;
772 #endif
773 	struct ath11k_soc_dp_stats soc_stats;
774 
775 	unsigned long dev_flags;
776 	struct completion driver_recovery;
777 	struct workqueue_struct *workqueue;
778 	struct work_struct restart_work;
779 	struct work_struct update_11d_work;
780 	u8 new_alpha2[3];
781 	struct {
782 		/* protected by data_lock */
783 		u32 fw_crash_counter;
784 	} stats;
785 	u32 pktlog_defs_checksum;
786 
787 	struct ath11k_dbring_cap *db_caps;
788 	u32 num_db_cap;
789 	struct work_struct rfkill_work;
790 
791 	/* true means radio is on */
792 	bool rfkill_radio_on;
793 
794 	/* To synchronize 11d scan vdev id */
795 	struct mutex vdev_id_11d_lock;
796 	struct timer_list mon_reap_timer;
797 
798 	struct completion htc_suspend;
799 
800 	struct {
801 		enum ath11k_bdf_search bdf_search;
802 		u32 vendor;
803 		u32 device;
804 		u32 subsystem_vendor;
805 		u32 subsystem_device;
806 	} id;
807 
808 	/* must be last */
809 	u8 drv_priv[0] __aligned(sizeof(void *));
810 };
811 
812 struct ath11k_fw_stats_pdev {
813 	struct list_head list;
814 
815 	/* PDEV stats */
816 	s32 ch_noise_floor;
817 	/* Cycles spent transmitting frames */
818 	u32 tx_frame_count;
819 	/* Cycles spent receiving frames */
820 	u32 rx_frame_count;
821 	/* Total channel busy time, evidently */
822 	u32 rx_clear_count;
823 	/* Total on-channel time */
824 	u32 cycle_count;
825 	u32 phy_err_count;
826 	u32 chan_tx_power;
827 	u32 ack_rx_bad;
828 	u32 rts_bad;
829 	u32 rts_good;
830 	u32 fcs_bad;
831 	u32 no_beacons;
832 	u32 mib_int_count;
833 
834 	/* PDEV TX stats */
835 	/* Num HTT cookies queued to dispatch list */
836 	s32 comp_queued;
837 	/* Num HTT cookies dispatched */
838 	s32 comp_delivered;
839 	/* Num MSDU queued to WAL */
840 	s32 msdu_enqued;
841 	/* Num MPDU queue to WAL */
842 	s32 mpdu_enqued;
843 	/* Num MSDUs dropped by WMM limit */
844 	s32 wmm_drop;
845 	/* Num Local frames queued */
846 	s32 local_enqued;
847 	/* Num Local frames done */
848 	s32 local_freed;
849 	/* Num queued to HW */
850 	s32 hw_queued;
851 	/* Num PPDU reaped from HW */
852 	s32 hw_reaped;
853 	/* Num underruns */
854 	s32 underrun;
855 	/* Num hw paused */
856 	u32 hw_paused;
857 	/* Num PPDUs cleaned up in TX abort */
858 	s32 tx_abort;
859 	/* Num MPDUs requeued by SW */
860 	s32 mpdus_requeued;
861 	/* excessive retries */
862 	u32 tx_ko;
863 	u32 tx_xretry;
864 	/* data hw rate code */
865 	u32 data_rc;
866 	/* Scheduler self triggers */
867 	u32 self_triggers;
868 	/* frames dropped due to excessive sw retries */
869 	u32 sw_retry_failure;
870 	/* illegal rate phy errors	*/
871 	u32 illgl_rate_phy_err;
872 	/* wal pdev continuous xretry */
873 	u32 pdev_cont_xretry;
874 	/* wal pdev tx timeouts */
875 	u32 pdev_tx_timeout;
876 	/* wal pdev resets */
877 	u32 pdev_resets;
878 	/* frames dropped due to non-availability of stateless TIDs */
879 	u32 stateless_tid_alloc_failure;
880 	/* PhY/BB underrun */
881 	u32 phy_underrun;
882 	/* MPDU is more than txop limit */
883 	u32 txop_ovf;
884 	/* Num sequences posted */
885 	u32 seq_posted;
886 	/* Num sequences failed in queueing */
887 	u32 seq_failed_queueing;
888 	/* Num sequences completed */
889 	u32 seq_completed;
890 	/* Num sequences restarted */
891 	u32 seq_restarted;
892 	/* Num of MU sequences posted */
893 	u32 mu_seq_posted;
894 	/* Num MPDUs flushed by SW, HWPAUSED, SW TXABORT
895 	 * (Reset,channel change)
896 	 */
897 	s32 mpdus_sw_flush;
898 	/* Num MPDUs filtered by HW, all filter condition (TTL expired) */
899 	s32 mpdus_hw_filter;
900 	/* Num MPDUs truncated by PDG (TXOP, TBTT,
901 	 * PPDU_duration based on rate, dyn_bw)
902 	 */
903 	s32 mpdus_truncated;
904 	/* Num MPDUs that was tried but didn't receive ACK or BA */
905 	s32 mpdus_ack_failed;
906 	/* Num MPDUs that was dropped du to expiry. */
907 	s32 mpdus_expired;
908 
909 	/* PDEV RX stats */
910 	/* Cnts any change in ring routing mid-ppdu */
911 	s32 mid_ppdu_route_change;
912 	/* Total number of statuses processed */
913 	s32 status_rcvd;
914 	/* Extra frags on rings 0-3 */
915 	s32 r0_frags;
916 	s32 r1_frags;
917 	s32 r2_frags;
918 	s32 r3_frags;
919 	/* MSDUs / MPDUs delivered to HTT */
920 	s32 htt_msdus;
921 	s32 htt_mpdus;
922 	/* MSDUs / MPDUs delivered to local stack */
923 	s32 loc_msdus;
924 	s32 loc_mpdus;
925 	/* AMSDUs that have more MSDUs than the status ring size */
926 	s32 oversize_amsdu;
927 	/* Number of PHY errors */
928 	s32 phy_errs;
929 	/* Number of PHY errors drops */
930 	s32 phy_err_drop;
931 	/* Number of mpdu errors - FCS, MIC, ENC etc. */
932 	s32 mpdu_errs;
933 	/* Num overflow errors */
934 	s32 rx_ovfl_errs;
935 };
936 
937 struct ath11k_fw_stats_vdev {
938 	struct list_head list;
939 
940 	u32 vdev_id;
941 	u32 beacon_snr;
942 	u32 data_snr;
943 	u32 num_tx_frames[WLAN_MAX_AC];
944 	u32 num_rx_frames;
945 	u32 num_tx_frames_retries[WLAN_MAX_AC];
946 	u32 num_tx_frames_failures[WLAN_MAX_AC];
947 	u32 num_rts_fail;
948 	u32 num_rts_success;
949 	u32 num_rx_err;
950 	u32 num_rx_discard;
951 	u32 num_tx_not_acked;
952 	u32 tx_rate_history[MAX_TX_RATE_VALUES];
953 	u32 beacon_rssi_history[MAX_TX_RATE_VALUES];
954 };
955 
956 struct ath11k_fw_stats_bcn {
957 	struct list_head list;
958 
959 	u32 vdev_id;
960 	u32 tx_bcn_succ_cnt;
961 	u32 tx_bcn_outage_cnt;
962 };
963 
964 extern const struct ce_pipe_config ath11k_target_ce_config_wlan_ipq8074[];
965 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_ipq8074[];
966 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_ipq6018[];
967 
968 extern const struct ce_pipe_config ath11k_target_ce_config_wlan_qca6390[];
969 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_qca6390[];
970 
971 extern const struct ce_pipe_config ath11k_target_ce_config_wlan_qcn9074[];
972 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_qcn9074[];
973 int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab);
974 int ath11k_core_pre_init(struct ath11k_base *ab);
975 int ath11k_core_init(struct ath11k_base *ath11k);
976 void ath11k_core_deinit(struct ath11k_base *ath11k);
977 struct ath11k_base *ath11k_core_alloc(struct device *dev, size_t priv_size,
978 				      enum ath11k_bus bus,
979 				      const struct ath11k_bus_params *bus_params);
980 void ath11k_core_free(struct ath11k_base *ath11k);
981 int ath11k_core_fetch_bdf(struct ath11k_base *ath11k,
982 			  struct ath11k_board_data *bd);
983 int ath11k_core_fetch_regdb(struct ath11k_base *ab, struct ath11k_board_data *bd);
984 int ath11k_core_fetch_board_data_api_1(struct ath11k_base *ab,
985 				       struct ath11k_board_data *bd,
986 				       const char *name);
987 void ath11k_core_free_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd);
988 int ath11k_core_check_dt(struct ath11k_base *ath11k);
989 
990 void ath11k_core_halt(struct ath11k *ar);
991 int ath11k_core_resume(struct ath11k_base *ab);
992 int ath11k_core_suspend(struct ath11k_base *ab);
993 
994 const struct firmware *ath11k_core_firmware_request(struct ath11k_base *ab,
995 						    const char *filename);
996 
997 static inline const char *ath11k_scan_state_str(enum ath11k_scan_state state)
998 {
999 	switch (state) {
1000 	case ATH11K_SCAN_IDLE:
1001 		return "idle";
1002 	case ATH11K_SCAN_STARTING:
1003 		return "starting";
1004 	case ATH11K_SCAN_RUNNING:
1005 		return "running";
1006 	case ATH11K_SCAN_ABORTING:
1007 		return "aborting";
1008 	}
1009 
1010 	return "unknown";
1011 }
1012 
1013 static inline struct ath11k_skb_cb *ATH11K_SKB_CB(struct sk_buff *skb)
1014 {
1015 	BUILD_BUG_ON(sizeof(struct ath11k_skb_cb) >
1016 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
1017 	return (struct ath11k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
1018 }
1019 
1020 static inline struct ath11k_skb_rxcb *ATH11K_SKB_RXCB(struct sk_buff *skb)
1021 {
1022 	BUILD_BUG_ON(sizeof(struct ath11k_skb_rxcb) > sizeof(skb->cb));
1023 	return (struct ath11k_skb_rxcb *)skb->cb;
1024 }
1025 
1026 static inline struct ath11k_vif *ath11k_vif_to_arvif(struct ieee80211_vif *vif)
1027 {
1028 	return (struct ath11k_vif *)vif->drv_priv;
1029 }
1030 
1031 static inline struct ath11k *ath11k_ab_to_ar(struct ath11k_base *ab,
1032 					     int mac_id)
1033 {
1034 	return ab->pdevs[ath11k_hw_mac_id_to_pdev_id(&ab->hw_params, mac_id)].ar;
1035 }
1036 
1037 static inline void ath11k_core_create_firmware_path(struct ath11k_base *ab,
1038 						    const char *filename,
1039 						    void *buf, size_t buf_len)
1040 {
1041 	snprintf(buf, buf_len, "%s/%s/%s", ATH11K_FW_DIR,
1042 		 ab->hw_params.fw.dir, filename);
1043 }
1044 
1045 static inline const char *ath11k_bus_str(enum ath11k_bus bus)
1046 {
1047 	switch (bus) {
1048 	case ATH11K_BUS_PCI:
1049 		return "pci";
1050 	case ATH11K_BUS_AHB:
1051 		return "ahb";
1052 	}
1053 
1054 	return "unknown";
1055 }
1056 
1057 #endif /* _CORE_H_ */
1058