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