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