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