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