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