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