xref: /linux/drivers/net/wireless/ath/ath11k/core.h (revision 6015fb905d89063231ed33bc15be19ef0fc339b8)
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 	int hw_rate_code;
607 };
608 
609 struct ath11k_band_cap {
610 	u32 phy_id;
611 	u32 max_bw_supported;
612 	u32 ht_cap_info;
613 	u32 he_cap_info[2];
614 	u32 he_mcs;
615 	u32 he_cap_phy_info[PSOC_HOST_MAX_PHY_SIZE];
616 	struct ath11k_ppe_threshold he_ppet;
617 	u16 he_6ghz_capa;
618 };
619 
620 struct ath11k_pdev_cap {
621 	u32 supported_bands;
622 	u32 ampdu_density;
623 	u32 vht_cap;
624 	u32 vht_mcs;
625 	u32 he_mcs;
626 	u32 tx_chain_mask;
627 	u32 rx_chain_mask;
628 	u32 tx_chain_mask_shift;
629 	u32 rx_chain_mask_shift;
630 	struct ath11k_band_cap band[NUM_NL80211_BANDS];
631 	bool nss_ratio_enabled;
632 	u8 nss_ratio_info;
633 };
634 
635 struct ath11k_pdev {
636 	struct ath11k *ar;
637 	u32 pdev_id;
638 	struct ath11k_pdev_cap cap;
639 	u8 mac_addr[ETH_ALEN];
640 };
641 
642 struct ath11k_board_data {
643 	const struct firmware *fw;
644 	const void *data;
645 	size_t len;
646 };
647 
648 struct ath11k_bus_params {
649 	bool mhi_support;
650 	bool m3_fw_support;
651 	bool fixed_bdf_addr;
652 	bool fixed_mem_region;
653 	bool static_window_map;
654 };
655 
656 /* IPQ8074 HW channel counters frequency value in hertz */
657 #define IPQ8074_CC_FREQ_HERTZ 320000
658 
659 struct ath11k_bp_stats {
660 	/* Head Pointer reported by the last HTT Backpressure event for the ring */
661 	u16 hp;
662 
663 	/* Tail Pointer reported by the last HTT Backpressure event for the ring */
664 	u16 tp;
665 
666 	/* Number of Backpressure events received for the ring */
667 	u32 count;
668 
669 	/* Last recorded event timestamp */
670 	unsigned long jiffies;
671 };
672 
673 struct ath11k_dp_ring_bp_stats {
674 	struct ath11k_bp_stats umac_ring_bp_stats[HTT_SW_UMAC_RING_IDX_MAX];
675 	struct ath11k_bp_stats lmac_ring_bp_stats[HTT_SW_LMAC_RING_IDX_MAX][MAX_RADIOS];
676 };
677 
678 struct ath11k_soc_dp_tx_err_stats {
679 	/* TCL Ring Descriptor unavailable */
680 	u32 desc_na[DP_TCL_NUM_RING_MAX];
681 	/* Other failures during dp_tx due to mem allocation failure
682 	 * idr unavailable etc.
683 	 */
684 	atomic_t misc_fail;
685 };
686 
687 struct ath11k_soc_dp_stats {
688 	u32 err_ring_pkts;
689 	u32 invalid_rbm;
690 	u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX];
691 	u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX];
692 	u32 hal_reo_error[DP_REO_DST_RING_MAX];
693 	struct ath11k_soc_dp_tx_err_stats tx_err;
694 	struct ath11k_dp_ring_bp_stats bp_stats;
695 };
696 
697 /* Master structure to hold the hw data which may be used in core module */
698 struct ath11k_base {
699 	enum ath11k_hw_rev hw_rev;
700 	struct platform_device *pdev;
701 	struct device *dev;
702 	struct ath11k_qmi qmi;
703 	struct ath11k_wmi_base wmi_ab;
704 	struct completion fw_ready;
705 	int num_radios;
706 	/* HW channel counters frequency value in hertz common to all MACs */
707 	u32 cc_freq_hz;
708 
709 	struct ath11k_htc htc;
710 
711 	struct ath11k_dp dp;
712 
713 	void __iomem *mem;
714 	unsigned long mem_len;
715 
716 	struct {
717 		enum ath11k_bus bus;
718 		const struct ath11k_hif_ops *ops;
719 	} hif;
720 
721 	struct {
722 		struct completion wakeup_completed;
723 	} wow;
724 
725 	struct ath11k_ce ce;
726 	struct timer_list rx_replenish_retry;
727 	struct ath11k_hal hal;
728 	/* To synchronize core_start/core_stop */
729 	struct mutex core_lock;
730 	/* Protects data like peers */
731 	spinlock_t base_lock;
732 	struct ath11k_pdev pdevs[MAX_RADIOS];
733 	struct {
734 		enum WMI_HOST_WLAN_BAND supported_bands;
735 		u32 pdev_id;
736 	} target_pdev_ids[MAX_RADIOS];
737 	u8 target_pdev_count;
738 	struct ath11k_pdev __rcu *pdevs_active[MAX_RADIOS];
739 	struct ath11k_hal_reg_capabilities_ext hal_reg_cap[MAX_RADIOS];
740 	unsigned long long free_vdev_map;
741 	struct list_head peers;
742 	wait_queue_head_t peer_mapping_wq;
743 	u8 mac_addr[ETH_ALEN];
744 	bool wmi_ready;
745 	u32 wlan_init_status;
746 	int irq_num[ATH11K_IRQ_NUM_MAX];
747 	struct ath11k_ext_irq_grp ext_irq_grp[ATH11K_EXT_IRQ_GRP_NUM_MAX];
748 	struct ath11k_targ_cap target_caps;
749 	u32 ext_service_bitmap[WMI_SERVICE_EXT_BM_SIZE];
750 	bool pdevs_macaddr_valid;
751 	int bd_api;
752 
753 	struct ath11k_hw_params hw_params;
754 	struct ath11k_bus_params bus_params;
755 
756 	const struct firmware *cal_file;
757 
758 	/* Below regd's are protected by ab->data_lock */
759 	/* This is the regd set for every radio
760 	 * by the firmware during initializatin
761 	 */
762 	struct ieee80211_regdomain *default_regd[MAX_RADIOS];
763 	/* This regd is set during dynamic country setting
764 	 * This may or may not be used during the runtime
765 	 */
766 	struct ieee80211_regdomain *new_regd[MAX_RADIOS];
767 
768 	/* Current DFS Regulatory */
769 	enum ath11k_dfs_region dfs_region;
770 #ifdef CONFIG_ATH11K_DEBUGFS
771 	struct dentry *debugfs_soc;
772 	struct dentry *debugfs_ath11k;
773 #endif
774 	struct ath11k_soc_dp_stats soc_stats;
775 
776 	unsigned long dev_flags;
777 	struct completion driver_recovery;
778 	struct workqueue_struct *workqueue;
779 	struct work_struct restart_work;
780 	struct work_struct update_11d_work;
781 	u8 new_alpha2[3];
782 	struct {
783 		/* protected by data_lock */
784 		u32 fw_crash_counter;
785 	} stats;
786 	u32 pktlog_defs_checksum;
787 
788 	struct ath11k_dbring_cap *db_caps;
789 	u32 num_db_cap;
790 	struct work_struct rfkill_work;
791 
792 	/* true means radio is on */
793 	bool rfkill_radio_on;
794 
795 	/* To synchronize 11d scan vdev id */
796 	struct mutex vdev_id_11d_lock;
797 	struct timer_list mon_reap_timer;
798 
799 	struct completion htc_suspend;
800 
801 	struct {
802 		enum ath11k_bdf_search bdf_search;
803 		u32 vendor;
804 		u32 device;
805 		u32 subsystem_vendor;
806 		u32 subsystem_device;
807 	} id;
808 
809 	/* must be last */
810 	u8 drv_priv[0] __aligned(sizeof(void *));
811 };
812 
813 struct ath11k_fw_stats_pdev {
814 	struct list_head list;
815 
816 	/* PDEV stats */
817 	s32 ch_noise_floor;
818 	/* Cycles spent transmitting frames */
819 	u32 tx_frame_count;
820 	/* Cycles spent receiving frames */
821 	u32 rx_frame_count;
822 	/* Total channel busy time, evidently */
823 	u32 rx_clear_count;
824 	/* Total on-channel time */
825 	u32 cycle_count;
826 	u32 phy_err_count;
827 	u32 chan_tx_power;
828 	u32 ack_rx_bad;
829 	u32 rts_bad;
830 	u32 rts_good;
831 	u32 fcs_bad;
832 	u32 no_beacons;
833 	u32 mib_int_count;
834 
835 	/* PDEV TX stats */
836 	/* Num HTT cookies queued to dispatch list */
837 	s32 comp_queued;
838 	/* Num HTT cookies dispatched */
839 	s32 comp_delivered;
840 	/* Num MSDU queued to WAL */
841 	s32 msdu_enqued;
842 	/* Num MPDU queue to WAL */
843 	s32 mpdu_enqued;
844 	/* Num MSDUs dropped by WMM limit */
845 	s32 wmm_drop;
846 	/* Num Local frames queued */
847 	s32 local_enqued;
848 	/* Num Local frames done */
849 	s32 local_freed;
850 	/* Num queued to HW */
851 	s32 hw_queued;
852 	/* Num PPDU reaped from HW */
853 	s32 hw_reaped;
854 	/* Num underruns */
855 	s32 underrun;
856 	/* Num hw paused */
857 	u32 hw_paused;
858 	/* Num PPDUs cleaned up in TX abort */
859 	s32 tx_abort;
860 	/* Num MPDUs requeued by SW */
861 	s32 mpdus_requeued;
862 	/* excessive retries */
863 	u32 tx_ko;
864 	u32 tx_xretry;
865 	/* data hw rate code */
866 	u32 data_rc;
867 	/* Scheduler self triggers */
868 	u32 self_triggers;
869 	/* frames dropped due to excessive sw retries */
870 	u32 sw_retry_failure;
871 	/* illegal rate phy errors	*/
872 	u32 illgl_rate_phy_err;
873 	/* wal pdev continuous xretry */
874 	u32 pdev_cont_xretry;
875 	/* wal pdev tx timeouts */
876 	u32 pdev_tx_timeout;
877 	/* wal pdev resets */
878 	u32 pdev_resets;
879 	/* frames dropped due to non-availability of stateless TIDs */
880 	u32 stateless_tid_alloc_failure;
881 	/* PhY/BB underrun */
882 	u32 phy_underrun;
883 	/* MPDU is more than txop limit */
884 	u32 txop_ovf;
885 	/* Num sequences posted */
886 	u32 seq_posted;
887 	/* Num sequences failed in queueing */
888 	u32 seq_failed_queueing;
889 	/* Num sequences completed */
890 	u32 seq_completed;
891 	/* Num sequences restarted */
892 	u32 seq_restarted;
893 	/* Num of MU sequences posted */
894 	u32 mu_seq_posted;
895 	/* Num MPDUs flushed by SW, HWPAUSED, SW TXABORT
896 	 * (Reset,channel change)
897 	 */
898 	s32 mpdus_sw_flush;
899 	/* Num MPDUs filtered by HW, all filter condition (TTL expired) */
900 	s32 mpdus_hw_filter;
901 	/* Num MPDUs truncated by PDG (TXOP, TBTT,
902 	 * PPDU_duration based on rate, dyn_bw)
903 	 */
904 	s32 mpdus_truncated;
905 	/* Num MPDUs that was tried but didn't receive ACK or BA */
906 	s32 mpdus_ack_failed;
907 	/* Num MPDUs that was dropped du to expiry. */
908 	s32 mpdus_expired;
909 
910 	/* PDEV RX stats */
911 	/* Cnts any change in ring routing mid-ppdu */
912 	s32 mid_ppdu_route_change;
913 	/* Total number of statuses processed */
914 	s32 status_rcvd;
915 	/* Extra frags on rings 0-3 */
916 	s32 r0_frags;
917 	s32 r1_frags;
918 	s32 r2_frags;
919 	s32 r3_frags;
920 	/* MSDUs / MPDUs delivered to HTT */
921 	s32 htt_msdus;
922 	s32 htt_mpdus;
923 	/* MSDUs / MPDUs delivered to local stack */
924 	s32 loc_msdus;
925 	s32 loc_mpdus;
926 	/* AMSDUs that have more MSDUs than the status ring size */
927 	s32 oversize_amsdu;
928 	/* Number of PHY errors */
929 	s32 phy_errs;
930 	/* Number of PHY errors drops */
931 	s32 phy_err_drop;
932 	/* Number of mpdu errors - FCS, MIC, ENC etc. */
933 	s32 mpdu_errs;
934 	/* Num overflow errors */
935 	s32 rx_ovfl_errs;
936 };
937 
938 struct ath11k_fw_stats_vdev {
939 	struct list_head list;
940 
941 	u32 vdev_id;
942 	u32 beacon_snr;
943 	u32 data_snr;
944 	u32 num_tx_frames[WLAN_MAX_AC];
945 	u32 num_rx_frames;
946 	u32 num_tx_frames_retries[WLAN_MAX_AC];
947 	u32 num_tx_frames_failures[WLAN_MAX_AC];
948 	u32 num_rts_fail;
949 	u32 num_rts_success;
950 	u32 num_rx_err;
951 	u32 num_rx_discard;
952 	u32 num_tx_not_acked;
953 	u32 tx_rate_history[MAX_TX_RATE_VALUES];
954 	u32 beacon_rssi_history[MAX_TX_RATE_VALUES];
955 };
956 
957 struct ath11k_fw_stats_bcn {
958 	struct list_head list;
959 
960 	u32 vdev_id;
961 	u32 tx_bcn_succ_cnt;
962 	u32 tx_bcn_outage_cnt;
963 };
964 
965 extern const struct ce_pipe_config ath11k_target_ce_config_wlan_ipq8074[];
966 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_ipq8074[];
967 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_ipq6018[];
968 
969 extern const struct ce_pipe_config ath11k_target_ce_config_wlan_qca6390[];
970 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_qca6390[];
971 
972 extern const struct ce_pipe_config ath11k_target_ce_config_wlan_qcn9074[];
973 extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_qcn9074[];
974 int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab);
975 int ath11k_core_pre_init(struct ath11k_base *ab);
976 int ath11k_core_init(struct ath11k_base *ath11k);
977 void ath11k_core_deinit(struct ath11k_base *ath11k);
978 struct ath11k_base *ath11k_core_alloc(struct device *dev, size_t priv_size,
979 				      enum ath11k_bus bus,
980 				      const struct ath11k_bus_params *bus_params);
981 void ath11k_core_free(struct ath11k_base *ath11k);
982 int ath11k_core_fetch_bdf(struct ath11k_base *ath11k,
983 			  struct ath11k_board_data *bd);
984 int ath11k_core_fetch_regdb(struct ath11k_base *ab, struct ath11k_board_data *bd);
985 int ath11k_core_fetch_board_data_api_1(struct ath11k_base *ab,
986 				       struct ath11k_board_data *bd,
987 				       const char *name);
988 void ath11k_core_free_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd);
989 int ath11k_core_check_dt(struct ath11k_base *ath11k);
990 
991 void ath11k_core_halt(struct ath11k *ar);
992 int ath11k_core_resume(struct ath11k_base *ab);
993 int ath11k_core_suspend(struct ath11k_base *ab);
994 
995 const struct firmware *ath11k_core_firmware_request(struct ath11k_base *ab,
996 						    const char *filename);
997 
998 static inline const char *ath11k_scan_state_str(enum ath11k_scan_state state)
999 {
1000 	switch (state) {
1001 	case ATH11K_SCAN_IDLE:
1002 		return "idle";
1003 	case ATH11K_SCAN_STARTING:
1004 		return "starting";
1005 	case ATH11K_SCAN_RUNNING:
1006 		return "running";
1007 	case ATH11K_SCAN_ABORTING:
1008 		return "aborting";
1009 	}
1010 
1011 	return "unknown";
1012 }
1013 
1014 static inline struct ath11k_skb_cb *ATH11K_SKB_CB(struct sk_buff *skb)
1015 {
1016 	BUILD_BUG_ON(sizeof(struct ath11k_skb_cb) >
1017 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
1018 	return (struct ath11k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
1019 }
1020 
1021 static inline struct ath11k_skb_rxcb *ATH11K_SKB_RXCB(struct sk_buff *skb)
1022 {
1023 	BUILD_BUG_ON(sizeof(struct ath11k_skb_rxcb) > sizeof(skb->cb));
1024 	return (struct ath11k_skb_rxcb *)skb->cb;
1025 }
1026 
1027 static inline struct ath11k_vif *ath11k_vif_to_arvif(struct ieee80211_vif *vif)
1028 {
1029 	return (struct ath11k_vif *)vif->drv_priv;
1030 }
1031 
1032 static inline struct ath11k *ath11k_ab_to_ar(struct ath11k_base *ab,
1033 					     int mac_id)
1034 {
1035 	return ab->pdevs[ath11k_hw_mac_id_to_pdev_id(&ab->hw_params, mac_id)].ar;
1036 }
1037 
1038 static inline void ath11k_core_create_firmware_path(struct ath11k_base *ab,
1039 						    const char *filename,
1040 						    void *buf, size_t buf_len)
1041 {
1042 	snprintf(buf, buf_len, "%s/%s/%s", ATH11K_FW_DIR,
1043 		 ab->hw_params.fw.dir, filename);
1044 }
1045 
1046 static inline const char *ath11k_bus_str(enum ath11k_bus bus)
1047 {
1048 	switch (bus) {
1049 	case ATH11K_BUS_PCI:
1050 		return "pci";
1051 	case ATH11K_BUS_AHB:
1052 		return "ahb";
1053 	}
1054 
1055 	return "unknown";
1056 }
1057 
1058 #endif /* _CORE_H_ */
1059