1 /* SPDX-License-Identifier: ISC */
2 /*
3  * Copyright (c) 2005-2011 Atheros Communications Inc.
4  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5  * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
6  */
7 
8 #ifndef _CORE_H_
9 #define _CORE_H_
10 
11 #include <linux/completion.h>
12 #include <linux/if_ether.h>
13 #include <linux/types.h>
14 #include <linux/pci.h>
15 #include <linux/uuid.h>
16 #include <linux/time.h>
17 
18 #include "htt.h"
19 #include "htc.h"
20 #include "hw.h"
21 #include "targaddrs.h"
22 #include "wmi.h"
23 #include "../ath.h"
24 #include "../regd.h"
25 #include "../dfs_pattern_detector.h"
26 #include "spectral.h"
27 #include "thermal.h"
28 #include "wow.h"
29 #include "swap.h"
30 
31 #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
32 #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
33 #define WO(_f)      ((_f##_OFFSET) >> 2)
34 
35 #define ATH10K_SCAN_ID 0
36 #define ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD 10 /* msec */
37 #define WMI_READY_TIMEOUT (5 * HZ)
38 #define ATH10K_FLUSH_TIMEOUT_HZ (5 * HZ)
39 #define ATH10K_CONNECTION_LOSS_HZ (3 * HZ)
40 #define ATH10K_NUM_CHANS 41
41 #define ATH10K_MAX_5G_CHAN 173
42 
43 /* Antenna noise floor */
44 #define ATH10K_DEFAULT_NOISE_FLOOR -95
45 
46 #define ATH10K_INVALID_RSSI 128
47 
48 #define ATH10K_MAX_NUM_MGMT_PENDING 128
49 
50 /* number of failed packets (20 packets with 16 sw reties each) */
51 #define ATH10K_KICKOUT_THRESHOLD (20 * 16)
52 
53 /*
54  * Use insanely high numbers to make sure that the firmware implementation
55  * won't start, we have the same functionality already in hostapd. Unit
56  * is seconds.
57  */
58 #define ATH10K_KEEPALIVE_MIN_IDLE 3747
59 #define ATH10K_KEEPALIVE_MAX_IDLE 3895
60 #define ATH10K_KEEPALIVE_MAX_UNRESPONSIVE 3900
61 
62 /* NAPI poll budget */
63 #define ATH10K_NAPI_BUDGET      64
64 
65 /* SMBIOS type containing Board Data File Name Extension */
66 #define ATH10K_SMBIOS_BDF_EXT_TYPE 0xF8
67 
68 /* SMBIOS type structure length (excluding strings-set) */
69 #define ATH10K_SMBIOS_BDF_EXT_LENGTH 0x9
70 
71 /* Offset pointing to Board Data File Name Extension */
72 #define ATH10K_SMBIOS_BDF_EXT_OFFSET 0x8
73 
74 /* Board Data File Name Extension string length.
75  * String format: BDF_<Customer ID>_<Extension>\0
76  */
77 #define ATH10K_SMBIOS_BDF_EXT_STR_LENGTH 0x20
78 
79 /* The magic used by QCA spec */
80 #define ATH10K_SMBIOS_BDF_EXT_MAGIC "BDF_"
81 
82 /* Default Airtime weight multipler (Tuned for multiclient performance) */
83 #define ATH10K_AIRTIME_WEIGHT_MULTIPLIER  4
84 
85 struct ath10k;
86 
87 static inline const char *ath10k_bus_str(enum ath10k_bus bus)
88 {
89 	switch (bus) {
90 	case ATH10K_BUS_PCI:
91 		return "pci";
92 	case ATH10K_BUS_AHB:
93 		return "ahb";
94 	case ATH10K_BUS_SDIO:
95 		return "sdio";
96 	case ATH10K_BUS_USB:
97 		return "usb";
98 	case ATH10K_BUS_SNOC:
99 		return "snoc";
100 	}
101 
102 	return "unknown";
103 }
104 
105 enum ath10k_skb_flags {
106 	ATH10K_SKB_F_NO_HWCRYPT = BIT(0),
107 	ATH10K_SKB_F_DTIM_ZERO = BIT(1),
108 	ATH10K_SKB_F_DELIVER_CAB = BIT(2),
109 	ATH10K_SKB_F_MGMT = BIT(3),
110 	ATH10K_SKB_F_QOS = BIT(4),
111 	ATH10K_SKB_F_RAW_TX = BIT(5),
112 };
113 
114 struct ath10k_skb_cb {
115 	dma_addr_t paddr;
116 	u8 flags;
117 	u8 eid;
118 	u16 msdu_id;
119 	u16 airtime_est;
120 	struct ieee80211_vif *vif;
121 	struct ieee80211_txq *txq;
122 } __packed;
123 
124 struct ath10k_skb_rxcb {
125 	dma_addr_t paddr;
126 	struct hlist_node hlist;
127 	u8 eid;
128 };
129 
130 static inline struct ath10k_skb_cb *ATH10K_SKB_CB(struct sk_buff *skb)
131 {
132 	BUILD_BUG_ON(sizeof(struct ath10k_skb_cb) >
133 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
134 	return (struct ath10k_skb_cb *)&IEEE80211_SKB_CB(skb)->driver_data;
135 }
136 
137 static inline struct ath10k_skb_rxcb *ATH10K_SKB_RXCB(struct sk_buff *skb)
138 {
139 	BUILD_BUG_ON(sizeof(struct ath10k_skb_rxcb) > sizeof(skb->cb));
140 	return (struct ath10k_skb_rxcb *)skb->cb;
141 }
142 
143 #define ATH10K_RXCB_SKB(rxcb) \
144 		container_of((void *)rxcb, struct sk_buff, cb)
145 
146 static inline u32 host_interest_item_address(u32 item_offset)
147 {
148 	return QCA988X_HOST_INTEREST_ADDRESS + item_offset;
149 }
150 
151 struct ath10k_bmi {
152 	bool done_sent;
153 };
154 
155 struct ath10k_mem_chunk {
156 	void *vaddr;
157 	dma_addr_t paddr;
158 	u32 len;
159 	u32 req_id;
160 };
161 
162 struct ath10k_wmi {
163 	enum ath10k_htc_ep_id eid;
164 	struct completion service_ready;
165 	struct completion unified_ready;
166 	struct completion barrier;
167 	struct completion radar_confirm;
168 	wait_queue_head_t tx_credits_wq;
169 	DECLARE_BITMAP(svc_map, WMI_SERVICE_MAX);
170 	struct wmi_cmd_map *cmd;
171 	struct wmi_vdev_param_map *vdev_param;
172 	struct wmi_pdev_param_map *pdev_param;
173 	struct wmi_peer_param_map *peer_param;
174 	const struct wmi_ops *ops;
175 	const struct wmi_peer_flags_map *peer_flags;
176 
177 	u32 mgmt_max_num_pending_tx;
178 
179 	/* Protected by data_lock */
180 	struct idr mgmt_pending_tx;
181 
182 	u32 num_mem_chunks;
183 	u32 rx_decap_mode;
184 	struct ath10k_mem_chunk mem_chunks[WMI_MAX_MEM_REQS];
185 };
186 
187 struct ath10k_fw_stats_peer {
188 	struct list_head list;
189 
190 	u8 peer_macaddr[ETH_ALEN];
191 	u32 peer_rssi;
192 	u32 peer_tx_rate;
193 	u32 peer_rx_rate; /* 10x only */
194 	u64 rx_duration;
195 };
196 
197 struct ath10k_fw_extd_stats_peer {
198 	struct list_head list;
199 
200 	u8 peer_macaddr[ETH_ALEN];
201 	u64 rx_duration;
202 };
203 
204 struct ath10k_fw_stats_vdev {
205 	struct list_head list;
206 
207 	u32 vdev_id;
208 	u32 beacon_snr;
209 	u32 data_snr;
210 	u32 num_tx_frames[4];
211 	u32 num_rx_frames;
212 	u32 num_tx_frames_retries[4];
213 	u32 num_tx_frames_failures[4];
214 	u32 num_rts_fail;
215 	u32 num_rts_success;
216 	u32 num_rx_err;
217 	u32 num_rx_discard;
218 	u32 num_tx_not_acked;
219 	u32 tx_rate_history[10];
220 	u32 beacon_rssi_history[10];
221 };
222 
223 struct ath10k_fw_stats_vdev_extd {
224 	struct list_head list;
225 
226 	u32 vdev_id;
227 	u32 ppdu_aggr_cnt;
228 	u32 ppdu_noack;
229 	u32 mpdu_queued;
230 	u32 ppdu_nonaggr_cnt;
231 	u32 mpdu_sw_requeued;
232 	u32 mpdu_suc_retry;
233 	u32 mpdu_suc_multitry;
234 	u32 mpdu_fail_retry;
235 	u32 tx_ftm_suc;
236 	u32 tx_ftm_suc_retry;
237 	u32 tx_ftm_fail;
238 	u32 rx_ftmr_cnt;
239 	u32 rx_ftmr_dup_cnt;
240 	u32 rx_iftmr_cnt;
241 	u32 rx_iftmr_dup_cnt;
242 };
243 
244 struct ath10k_fw_stats_pdev {
245 	struct list_head list;
246 
247 	/* PDEV stats */
248 	s32 ch_noise_floor;
249 	u32 tx_frame_count; /* Cycles spent transmitting frames */
250 	u32 rx_frame_count; /* Cycles spent receiving frames */
251 	u32 rx_clear_count; /* Total channel busy time, evidently */
252 	u32 cycle_count; /* Total on-channel time */
253 	u32 phy_err_count;
254 	u32 chan_tx_power;
255 	u32 ack_rx_bad;
256 	u32 rts_bad;
257 	u32 rts_good;
258 	u32 fcs_bad;
259 	u32 no_beacons;
260 	u32 mib_int_count;
261 
262 	/* PDEV TX stats */
263 	s32 comp_queued;
264 	s32 comp_delivered;
265 	s32 msdu_enqued;
266 	s32 mpdu_enqued;
267 	s32 wmm_drop;
268 	s32 local_enqued;
269 	s32 local_freed;
270 	s32 hw_queued;
271 	s32 hw_reaped;
272 	s32 underrun;
273 	u32 hw_paused;
274 	s32 tx_abort;
275 	s32 mpdus_requed;
276 	u32 tx_ko;
277 	u32 data_rc;
278 	u32 self_triggers;
279 	u32 sw_retry_failure;
280 	u32 illgl_rate_phy_err;
281 	u32 pdev_cont_xretry;
282 	u32 pdev_tx_timeout;
283 	u32 pdev_resets;
284 	u32 phy_underrun;
285 	u32 txop_ovf;
286 	u32 seq_posted;
287 	u32 seq_failed_queueing;
288 	u32 seq_completed;
289 	u32 seq_restarted;
290 	u32 mu_seq_posted;
291 	u32 mpdus_sw_flush;
292 	u32 mpdus_hw_filter;
293 	u32 mpdus_truncated;
294 	u32 mpdus_ack_failed;
295 	u32 mpdus_expired;
296 
297 	/* PDEV RX stats */
298 	s32 mid_ppdu_route_change;
299 	s32 status_rcvd;
300 	s32 r0_frags;
301 	s32 r1_frags;
302 	s32 r2_frags;
303 	s32 r3_frags;
304 	s32 htt_msdus;
305 	s32 htt_mpdus;
306 	s32 loc_msdus;
307 	s32 loc_mpdus;
308 	s32 oversize_amsdu;
309 	s32 phy_errs;
310 	s32 phy_err_drop;
311 	s32 mpdu_errs;
312 	s32 rx_ovfl_errs;
313 };
314 
315 struct ath10k_fw_stats {
316 	bool extended;
317 	struct list_head pdevs;
318 	struct list_head vdevs;
319 	struct list_head peers;
320 	struct list_head peers_extd;
321 };
322 
323 #define ATH10K_TPC_TABLE_TYPE_FLAG	1
324 #define ATH10K_TPC_PREAM_TABLE_END	0xFFFF
325 
326 struct ath10k_tpc_table {
327 	u32 pream_idx[WMI_TPC_RATE_MAX];
328 	u8 rate_code[WMI_TPC_RATE_MAX];
329 	char tpc_value[WMI_TPC_RATE_MAX][WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
330 };
331 
332 struct ath10k_tpc_stats {
333 	u32 reg_domain;
334 	u32 chan_freq;
335 	u32 phy_mode;
336 	u32 twice_antenna_reduction;
337 	u32 twice_max_rd_power;
338 	s32 twice_antenna_gain;
339 	u32 power_limit;
340 	u32 num_tx_chain;
341 	u32 ctl;
342 	u32 rate_max;
343 	u8 flag[WMI_TPC_FLAG];
344 	struct ath10k_tpc_table tpc_table[WMI_TPC_FLAG];
345 };
346 
347 struct ath10k_tpc_table_final {
348 	u32 pream_idx[WMI_TPC_FINAL_RATE_MAX];
349 	u8 rate_code[WMI_TPC_FINAL_RATE_MAX];
350 	char tpc_value[WMI_TPC_FINAL_RATE_MAX][WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
351 };
352 
353 struct ath10k_tpc_stats_final {
354 	u32 reg_domain;
355 	u32 chan_freq;
356 	u32 phy_mode;
357 	u32 twice_antenna_reduction;
358 	u32 twice_max_rd_power;
359 	s32 twice_antenna_gain;
360 	u32 power_limit;
361 	u32 num_tx_chain;
362 	u32 ctl;
363 	u32 rate_max;
364 	u8 flag[WMI_TPC_FLAG];
365 	struct ath10k_tpc_table_final tpc_table_final[WMI_TPC_FLAG];
366 };
367 
368 struct ath10k_dfs_stats {
369 	u32 phy_errors;
370 	u32 pulses_total;
371 	u32 pulses_detected;
372 	u32 pulses_discarded;
373 	u32 radar_detected;
374 };
375 
376 enum ath10k_radar_confirmation_state {
377 	ATH10K_RADAR_CONFIRMATION_IDLE = 0,
378 	ATH10K_RADAR_CONFIRMATION_INPROGRESS,
379 	ATH10K_RADAR_CONFIRMATION_STOPPED,
380 };
381 
382 struct ath10k_radar_found_info {
383 	u32 pri_min;
384 	u32 pri_max;
385 	u32 width_min;
386 	u32 width_max;
387 	u32 sidx_min;
388 	u32 sidx_max;
389 };
390 
391 #define ATH10K_MAX_NUM_PEER_IDS (1 << 11) /* htt rx_desc limit */
392 
393 struct ath10k_peer {
394 	struct list_head list;
395 	struct ieee80211_vif *vif;
396 	struct ieee80211_sta *sta;
397 
398 	bool removed;
399 	int vdev_id;
400 	u8 addr[ETH_ALEN];
401 	DECLARE_BITMAP(peer_ids, ATH10K_MAX_NUM_PEER_IDS);
402 
403 	/* protected by ar->data_lock */
404 	struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1];
405 	union htt_rx_pn_t tids_last_pn[ATH10K_TXRX_NUM_EXT_TIDS];
406 	bool tids_last_pn_valid[ATH10K_TXRX_NUM_EXT_TIDS];
407 	union htt_rx_pn_t frag_tids_last_pn[ATH10K_TXRX_NUM_EXT_TIDS];
408 	u32 frag_tids_seq[ATH10K_TXRX_NUM_EXT_TIDS];
409 	struct {
410 		enum htt_security_types sec_type;
411 		int pn_len;
412 	} rx_pn[ATH10K_HTT_TXRX_PEER_SECURITY_MAX];
413 };
414 
415 struct ath10k_txq {
416 	struct list_head list;
417 	unsigned long num_fw_queued;
418 	unsigned long num_push_allowed;
419 };
420 
421 enum ath10k_pkt_rx_err {
422 	ATH10K_PKT_RX_ERR_FCS,
423 	ATH10K_PKT_RX_ERR_TKIP,
424 	ATH10K_PKT_RX_ERR_CRYPT,
425 	ATH10K_PKT_RX_ERR_PEER_IDX_INVAL,
426 	ATH10K_PKT_RX_ERR_MAX,
427 };
428 
429 enum ath10k_ampdu_subfrm_num {
430 	ATH10K_AMPDU_SUBFRM_NUM_10,
431 	ATH10K_AMPDU_SUBFRM_NUM_20,
432 	ATH10K_AMPDU_SUBFRM_NUM_30,
433 	ATH10K_AMPDU_SUBFRM_NUM_40,
434 	ATH10K_AMPDU_SUBFRM_NUM_50,
435 	ATH10K_AMPDU_SUBFRM_NUM_60,
436 	ATH10K_AMPDU_SUBFRM_NUM_MORE,
437 	ATH10K_AMPDU_SUBFRM_NUM_MAX,
438 };
439 
440 enum ath10k_amsdu_subfrm_num {
441 	ATH10K_AMSDU_SUBFRM_NUM_1,
442 	ATH10K_AMSDU_SUBFRM_NUM_2,
443 	ATH10K_AMSDU_SUBFRM_NUM_3,
444 	ATH10K_AMSDU_SUBFRM_NUM_4,
445 	ATH10K_AMSDU_SUBFRM_NUM_MORE,
446 	ATH10K_AMSDU_SUBFRM_NUM_MAX,
447 };
448 
449 struct ath10k_sta_tid_stats {
450 	unsigned long rx_pkt_from_fw;
451 	unsigned long rx_pkt_unchained;
452 	unsigned long rx_pkt_drop_chained;
453 	unsigned long rx_pkt_drop_filter;
454 	unsigned long rx_pkt_err[ATH10K_PKT_RX_ERR_MAX];
455 	unsigned long rx_pkt_queued_for_mac;
456 	unsigned long rx_pkt_ampdu[ATH10K_AMPDU_SUBFRM_NUM_MAX];
457 	unsigned long rx_pkt_amsdu[ATH10K_AMSDU_SUBFRM_NUM_MAX];
458 };
459 
460 enum ath10k_counter_type {
461 	ATH10K_COUNTER_TYPE_BYTES,
462 	ATH10K_COUNTER_TYPE_PKTS,
463 	ATH10K_COUNTER_TYPE_MAX,
464 };
465 
466 enum ath10k_stats_type {
467 	ATH10K_STATS_TYPE_SUCC,
468 	ATH10K_STATS_TYPE_FAIL,
469 	ATH10K_STATS_TYPE_RETRY,
470 	ATH10K_STATS_TYPE_AMPDU,
471 	ATH10K_STATS_TYPE_MAX,
472 };
473 
474 struct ath10k_htt_data_stats {
475 	u64 legacy[ATH10K_COUNTER_TYPE_MAX][ATH10K_LEGACY_NUM];
476 	u64 ht[ATH10K_COUNTER_TYPE_MAX][ATH10K_HT_MCS_NUM];
477 	u64 vht[ATH10K_COUNTER_TYPE_MAX][ATH10K_VHT_MCS_NUM];
478 	u64 bw[ATH10K_COUNTER_TYPE_MAX][ATH10K_BW_NUM];
479 	u64 nss[ATH10K_COUNTER_TYPE_MAX][ATH10K_NSS_NUM];
480 	u64 gi[ATH10K_COUNTER_TYPE_MAX][ATH10K_GI_NUM];
481 	u64 rate_table[ATH10K_COUNTER_TYPE_MAX][ATH10K_RATE_TABLE_NUM];
482 };
483 
484 struct ath10k_htt_tx_stats {
485 	struct ath10k_htt_data_stats stats[ATH10K_STATS_TYPE_MAX];
486 	u64 tx_duration;
487 	u64 ba_fails;
488 	u64 ack_fails;
489 };
490 
491 struct ath10k_sta {
492 	struct ath10k_vif *arvif;
493 
494 	/* the following are protected by ar->data_lock */
495 	u32 changed; /* IEEE80211_RC_* */
496 	u32 bw;
497 	u32 nss;
498 	u32 smps;
499 	u16 peer_id;
500 	struct rate_info txrate;
501 	struct ieee80211_tx_info tx_info;
502 	u32 last_tx_bitrate;
503 
504 	struct work_struct update_wk;
505 	u64 rx_duration;
506 	struct ath10k_htt_tx_stats *tx_stats;
507 
508 #ifdef CONFIG_MAC80211_DEBUGFS
509 	/* protected by conf_mutex */
510 	bool aggr_mode;
511 
512 	/* Protected with ar->data_lock */
513 	struct ath10k_sta_tid_stats tid_stats[IEEE80211_NUM_TIDS + 1];
514 #endif
515 	/* Protected with ar->data_lock */
516 	u32 peer_ps_state;
517 };
518 
519 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ	(5 * HZ)
520 #define ATH10K_VDEV_DELETE_TIMEOUT_HZ	(5 * HZ)
521 
522 enum ath10k_beacon_state {
523 	ATH10K_BEACON_SCHEDULED = 0,
524 	ATH10K_BEACON_SENDING,
525 	ATH10K_BEACON_SENT,
526 };
527 
528 struct ath10k_vif {
529 	struct list_head list;
530 
531 	u32 vdev_id;
532 	u16 peer_id;
533 	enum wmi_vdev_type vdev_type;
534 	enum wmi_vdev_subtype vdev_subtype;
535 	u32 beacon_interval;
536 	u32 dtim_period;
537 	struct sk_buff *beacon;
538 	/* protected by data_lock */
539 	enum ath10k_beacon_state beacon_state;
540 	void *beacon_buf;
541 	dma_addr_t beacon_paddr;
542 	unsigned long tx_paused; /* arbitrary values defined by target */
543 
544 	struct ath10k *ar;
545 	struct ieee80211_vif *vif;
546 
547 	bool is_started;
548 	bool is_up;
549 	bool spectral_enabled;
550 	bool ps;
551 	u32 aid;
552 	u8 bssid[ETH_ALEN];
553 
554 	struct ieee80211_key_conf *wep_keys[WMI_MAX_KEY_INDEX + 1];
555 	s8 def_wep_key_idx;
556 
557 	u16 tx_seq_no;
558 
559 	union {
560 		struct {
561 			u32 uapsd;
562 		} sta;
563 		struct {
564 			/* 512 stations */
565 			u8 tim_bitmap[64];
566 			u8 tim_len;
567 			u32 ssid_len;
568 			u8 ssid[IEEE80211_MAX_SSID_LEN];
569 			bool hidden_ssid;
570 			/* P2P_IE with NoA attribute for P2P_GO case */
571 			u32 noa_len;
572 			u8 *noa_data;
573 		} ap;
574 	} u;
575 
576 	bool use_cts_prot;
577 	bool nohwcrypt;
578 	int num_legacy_stations;
579 	int txpower;
580 	bool ftm_responder;
581 	struct wmi_wmm_params_all_arg wmm_params;
582 	struct work_struct ap_csa_work;
583 	struct delayed_work connection_loss_work;
584 	struct cfg80211_bitrate_mask bitrate_mask;
585 
586 	/* For setting VHT peer fixed rate, protected by conf_mutex */
587 	int vht_num_rates;
588 	u8 vht_pfr;
589 };
590 
591 struct ath10k_vif_iter {
592 	u32 vdev_id;
593 	struct ath10k_vif *arvif;
594 };
595 
596 /* Copy Engine register dump, protected by ce-lock */
597 struct ath10k_ce_crash_data {
598 	__le32 base_addr;
599 	__le32 src_wr_idx;
600 	__le32 src_r_idx;
601 	__le32 dst_wr_idx;
602 	__le32 dst_r_idx;
603 };
604 
605 struct ath10k_ce_crash_hdr {
606 	__le32 ce_count;
607 	__le32 reserved[3]; /* for future use */
608 	struct ath10k_ce_crash_data entries[];
609 };
610 
611 #define MAX_MEM_DUMP_TYPE	5
612 
613 /* used for crash-dump storage, protected by data-lock */
614 struct ath10k_fw_crash_data {
615 	guid_t guid;
616 	struct timespec64 timestamp;
617 	__le32 registers[REG_DUMP_COUNT_QCA988X];
618 	struct ath10k_ce_crash_data ce_crash_data[CE_COUNT_MAX];
619 
620 	u8 *ramdump_buf;
621 	size_t ramdump_buf_len;
622 };
623 
624 struct ath10k_debug {
625 	struct dentry *debugfs_phy;
626 
627 	struct ath10k_fw_stats fw_stats;
628 	struct completion fw_stats_complete;
629 	bool fw_stats_done;
630 
631 	unsigned long htt_stats_mask;
632 	unsigned long reset_htt_stats;
633 	struct delayed_work htt_stats_dwork;
634 	struct ath10k_dfs_stats dfs_stats;
635 	struct ath_dfs_pool_stats dfs_pool_stats;
636 
637 	/* used for tpc-dump storage, protected by data-lock */
638 	struct ath10k_tpc_stats *tpc_stats;
639 	struct ath10k_tpc_stats_final *tpc_stats_final;
640 
641 	struct completion tpc_complete;
642 
643 	/* protected by conf_mutex */
644 	u64 fw_dbglog_mask;
645 	u32 fw_dbglog_level;
646 	u32 reg_addr;
647 	u32 nf_cal_period;
648 	void *cal_data;
649 	u32 enable_extd_tx_stats;
650 	u8 fw_dbglog_mode;
651 };
652 
653 enum ath10k_state {
654 	ATH10K_STATE_OFF = 0,
655 	ATH10K_STATE_ON,
656 
657 	/* When doing firmware recovery the device is first powered down.
658 	 * mac80211 is supposed to call in to start() hook later on. It is
659 	 * however possible that driver unloading and firmware crash overlap.
660 	 * mac80211 can wait on conf_mutex in stop() while the device is
661 	 * stopped in ath10k_core_restart() work holding conf_mutex. The state
662 	 * RESTARTED means that the device is up and mac80211 has started hw
663 	 * reconfiguration. Once mac80211 is done with the reconfiguration we
664 	 * set the state to STATE_ON in reconfig_complete().
665 	 */
666 	ATH10K_STATE_RESTARTING,
667 	ATH10K_STATE_RESTARTED,
668 
669 	/* The device has crashed while restarting hw. This state is like ON
670 	 * but commands are blocked in HTC and -ECOMM response is given. This
671 	 * prevents completion timeouts and makes the driver more responsive to
672 	 * userspace commands. This is also prevents recursive recovery.
673 	 */
674 	ATH10K_STATE_WEDGED,
675 
676 	/* factory tests */
677 	ATH10K_STATE_UTF,
678 };
679 
680 enum ath10k_firmware_mode {
681 	/* the default mode, standard 802.11 functionality */
682 	ATH10K_FIRMWARE_MODE_NORMAL,
683 
684 	/* factory tests etc */
685 	ATH10K_FIRMWARE_MODE_UTF,
686 };
687 
688 enum ath10k_fw_features {
689 	/* wmi_mgmt_rx_hdr contains extra RSSI information */
690 	ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX = 0,
691 
692 	/* Firmware from 10X branch. Deprecated, don't use in new code. */
693 	ATH10K_FW_FEATURE_WMI_10X = 1,
694 
695 	/* firmware support tx frame management over WMI, otherwise it's HTT */
696 	ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX = 2,
697 
698 	/* Firmware does not support P2P */
699 	ATH10K_FW_FEATURE_NO_P2P = 3,
700 
701 	/* Firmware 10.2 feature bit. The ATH10K_FW_FEATURE_WMI_10X feature
702 	 * bit is required to be set as well. Deprecated, don't use in new
703 	 * code.
704 	 */
705 	ATH10K_FW_FEATURE_WMI_10_2 = 4,
706 
707 	/* Some firmware revisions lack proper multi-interface client powersave
708 	 * implementation. Enabling PS could result in connection drops,
709 	 * traffic stalls, etc.
710 	 */
711 	ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT = 5,
712 
713 	/* Some firmware revisions have an incomplete WoWLAN implementation
714 	 * despite WMI service bit being advertised. This feature flag is used
715 	 * to distinguish whether WoWLAN is really supported or not.
716 	 */
717 	ATH10K_FW_FEATURE_WOWLAN_SUPPORT = 6,
718 
719 	/* Don't trust error code from otp.bin */
720 	ATH10K_FW_FEATURE_IGNORE_OTP_RESULT = 7,
721 
722 	/* Some firmware revisions pad 4th hw address to 4 byte boundary making
723 	 * it 8 bytes long in Native Wifi Rx decap.
724 	 */
725 	ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING = 8,
726 
727 	/* Firmware supports bypassing PLL setting on init. */
728 	ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT = 9,
729 
730 	/* Raw mode support. If supported, FW supports receiving and trasmitting
731 	 * frames in raw mode.
732 	 */
733 	ATH10K_FW_FEATURE_RAW_MODE_SUPPORT = 10,
734 
735 	/* Firmware Supports Adaptive CCA*/
736 	ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA = 11,
737 
738 	/* Firmware supports management frame protection */
739 	ATH10K_FW_FEATURE_MFP_SUPPORT = 12,
740 
741 	/* Firmware supports pull-push model where host shares it's software
742 	 * queue state with firmware and firmware generates fetch requests
743 	 * telling host which queues to dequeue tx from.
744 	 *
745 	 * Primary function of this is improved MU-MIMO performance with
746 	 * multiple clients.
747 	 */
748 	ATH10K_FW_FEATURE_PEER_FLOW_CONTROL = 13,
749 
750 	/* Firmware supports BT-Coex without reloading firmware via pdev param.
751 	 * To support Bluetooth coexistence pdev param, WMI_COEX_GPIO_SUPPORT of
752 	 * extended resource config should be enabled always. This firmware IE
753 	 * is used to configure WMI_COEX_GPIO_SUPPORT.
754 	 */
755 	ATH10K_FW_FEATURE_BTCOEX_PARAM = 14,
756 
757 	/* Unused flag and proven to be not working, enable this if you want
758 	 * to experiment sending NULL func data frames in HTT TX
759 	 */
760 	ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR = 15,
761 
762 	/* Firmware allow other BSS mesh broadcast/multicast frames without
763 	 * creating monitor interface. Appropriate rxfilters are programmed for
764 	 * mesh vdev by firmware itself. This feature flags will be used for
765 	 * not creating monitor vdev while configuring mesh node.
766 	 */
767 	ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST = 16,
768 
769 	/* Firmware does not support power save in station mode. */
770 	ATH10K_FW_FEATURE_NO_PS = 17,
771 
772 	/* Firmware allows management tx by reference instead of by value. */
773 	ATH10K_FW_FEATURE_MGMT_TX_BY_REF = 18,
774 
775 	/* Firmware load is done externally, not by bmi */
776 	ATH10K_FW_FEATURE_NON_BMI = 19,
777 
778 	/* Firmware sends only one chan_info event per channel */
779 	ATH10K_FW_FEATURE_SINGLE_CHAN_INFO_PER_CHANNEL = 20,
780 
781 	/* Firmware allows setting peer fixed rate */
782 	ATH10K_FW_FEATURE_PEER_FIXED_RATE = 21,
783 
784 	/* keep last */
785 	ATH10K_FW_FEATURE_COUNT,
786 };
787 
788 enum ath10k_dev_flags {
789 	/* Indicates that ath10k device is during CAC phase of DFS */
790 	ATH10K_CAC_RUNNING,
791 	ATH10K_FLAG_CORE_REGISTERED,
792 
793 	/* Device has crashed and needs to restart. This indicates any pending
794 	 * waiters should immediately cancel instead of waiting for a time out.
795 	 */
796 	ATH10K_FLAG_CRASH_FLUSH,
797 
798 	/* Use Raw mode instead of native WiFi Tx/Rx encap mode.
799 	 * Raw mode supports both hardware and software crypto. Native WiFi only
800 	 * supports hardware crypto.
801 	 */
802 	ATH10K_FLAG_RAW_MODE,
803 
804 	/* Disable HW crypto engine */
805 	ATH10K_FLAG_HW_CRYPTO_DISABLED,
806 
807 	/* Bluetooth coexistance enabled */
808 	ATH10K_FLAG_BTCOEX,
809 
810 	/* Per Station statistics service */
811 	ATH10K_FLAG_PEER_STATS,
812 };
813 
814 enum ath10k_cal_mode {
815 	ATH10K_CAL_MODE_FILE,
816 	ATH10K_CAL_MODE_OTP,
817 	ATH10K_CAL_MODE_DT,
818 	ATH10K_PRE_CAL_MODE_FILE,
819 	ATH10K_PRE_CAL_MODE_DT,
820 	ATH10K_CAL_MODE_EEPROM,
821 };
822 
823 enum ath10k_crypt_mode {
824 	/* Only use hardware crypto engine */
825 	ATH10K_CRYPT_MODE_HW,
826 	/* Only use software crypto engine */
827 	ATH10K_CRYPT_MODE_SW,
828 };
829 
830 static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
831 {
832 	switch (mode) {
833 	case ATH10K_CAL_MODE_FILE:
834 		return "file";
835 	case ATH10K_CAL_MODE_OTP:
836 		return "otp";
837 	case ATH10K_CAL_MODE_DT:
838 		return "dt";
839 	case ATH10K_PRE_CAL_MODE_FILE:
840 		return "pre-cal-file";
841 	case ATH10K_PRE_CAL_MODE_DT:
842 		return "pre-cal-dt";
843 	case ATH10K_CAL_MODE_EEPROM:
844 		return "eeprom";
845 	}
846 
847 	return "unknown";
848 }
849 
850 enum ath10k_scan_state {
851 	ATH10K_SCAN_IDLE,
852 	ATH10K_SCAN_STARTING,
853 	ATH10K_SCAN_RUNNING,
854 	ATH10K_SCAN_ABORTING,
855 };
856 
857 static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
858 {
859 	switch (state) {
860 	case ATH10K_SCAN_IDLE:
861 		return "idle";
862 	case ATH10K_SCAN_STARTING:
863 		return "starting";
864 	case ATH10K_SCAN_RUNNING:
865 		return "running";
866 	case ATH10K_SCAN_ABORTING:
867 		return "aborting";
868 	}
869 
870 	return "unknown";
871 }
872 
873 enum ath10k_tx_pause_reason {
874 	ATH10K_TX_PAUSE_Q_FULL,
875 	ATH10K_TX_PAUSE_MAX,
876 };
877 
878 struct ath10k_fw_file {
879 	const struct firmware *firmware;
880 
881 	char fw_version[ETHTOOL_FWVERS_LEN];
882 
883 	DECLARE_BITMAP(fw_features, ATH10K_FW_FEATURE_COUNT);
884 
885 	enum ath10k_fw_wmi_op_version wmi_op_version;
886 	enum ath10k_fw_htt_op_version htt_op_version;
887 
888 	const void *firmware_data;
889 	size_t firmware_len;
890 
891 	const void *otp_data;
892 	size_t otp_len;
893 
894 	const void *codeswap_data;
895 	size_t codeswap_len;
896 
897 	/* The original idea of struct ath10k_fw_file was that it only
898 	 * contains struct firmware and pointers to various parts (actual
899 	 * firmware binary, otp, metadata etc) of the file. This seg_info
900 	 * is actually created separate but as this is used similarly as
901 	 * the other firmware components it's more convenient to have it
902 	 * here.
903 	 */
904 	struct ath10k_swap_code_seg_info *firmware_swap_code_seg_info;
905 };
906 
907 struct ath10k_fw_components {
908 	const struct firmware *board;
909 	const void *board_data;
910 	size_t board_len;
911 	const struct firmware *ext_board;
912 	const void *ext_board_data;
913 	size_t ext_board_len;
914 
915 	struct ath10k_fw_file fw_file;
916 };
917 
918 struct ath10k_per_peer_tx_stats {
919 	u32	succ_bytes;
920 	u32	retry_bytes;
921 	u32	failed_bytes;
922 	u8	ratecode;
923 	u8	flags;
924 	u16	peer_id;
925 	u16	succ_pkts;
926 	u16	retry_pkts;
927 	u16	failed_pkts;
928 	u16	duration;
929 	u32	reserved1;
930 	u32	reserved2;
931 };
932 
933 enum ath10k_dev_type {
934 	ATH10K_DEV_TYPE_LL,
935 	ATH10K_DEV_TYPE_HL,
936 };
937 
938 struct ath10k_bus_params {
939 	u32 chip_id;
940 	enum ath10k_dev_type dev_type;
941 	bool link_can_suspend;
942 	bool hl_msdu_ids;
943 };
944 
945 struct ath10k {
946 	struct ath_common ath_common;
947 	struct ieee80211_hw *hw;
948 	struct ieee80211_ops *ops;
949 	struct device *dev;
950 	u8 mac_addr[ETH_ALEN];
951 
952 	enum ath10k_hw_rev hw_rev;
953 	u16 dev_id;
954 	u32 chip_id;
955 	enum ath10k_dev_type dev_type;
956 	u32 target_version;
957 	u8 fw_version_major;
958 	u32 fw_version_minor;
959 	u16 fw_version_release;
960 	u16 fw_version_build;
961 	u32 fw_stats_req_mask;
962 	u32 phy_capability;
963 	u32 hw_min_tx_power;
964 	u32 hw_max_tx_power;
965 	u32 hw_eeprom_rd;
966 	u32 ht_cap_info;
967 	u32 vht_cap_info;
968 	u32 vht_supp_mcs;
969 	u32 num_rf_chains;
970 	u32 max_spatial_stream;
971 	/* protected by conf_mutex */
972 	u32 low_2ghz_chan;
973 	u32 high_2ghz_chan;
974 	u32 low_5ghz_chan;
975 	u32 high_5ghz_chan;
976 	bool ani_enabled;
977 	u32 sys_cap_info;
978 
979 	/* protected by data_lock */
980 	bool hw_rfkill_on;
981 
982 	/* protected by conf_mutex */
983 	u8 ps_state_enable;
984 
985 	bool nlo_enabled;
986 	bool p2p;
987 
988 	struct {
989 		enum ath10k_bus bus;
990 		const struct ath10k_hif_ops *ops;
991 	} hif;
992 
993 	struct completion target_suspend;
994 	struct completion driver_recovery;
995 
996 	const struct ath10k_hw_regs *regs;
997 	const struct ath10k_hw_ce_regs *hw_ce_regs;
998 	const struct ath10k_hw_values *hw_values;
999 	struct ath10k_bmi bmi;
1000 	struct ath10k_wmi wmi;
1001 	struct ath10k_htc htc;
1002 	struct ath10k_htt htt;
1003 
1004 	struct ath10k_hw_params hw_params;
1005 
1006 	/* contains the firmware images used with ATH10K_FIRMWARE_MODE_NORMAL */
1007 	struct ath10k_fw_components normal_mode_fw;
1008 
1009 	/* READ-ONLY images of the running firmware, which can be either
1010 	 * normal or UTF. Do not modify, release etc!
1011 	 */
1012 	const struct ath10k_fw_components *running_fw;
1013 
1014 	const struct firmware *pre_cal_file;
1015 	const struct firmware *cal_file;
1016 
1017 	struct {
1018 		u32 vendor;
1019 		u32 device;
1020 		u32 subsystem_vendor;
1021 		u32 subsystem_device;
1022 
1023 		bool bmi_ids_valid;
1024 		bool qmi_ids_valid;
1025 		u32 qmi_board_id;
1026 		u8 bmi_board_id;
1027 		u8 bmi_eboard_id;
1028 		u8 bmi_chip_id;
1029 		bool ext_bid_supported;
1030 
1031 		char bdf_ext[ATH10K_SMBIOS_BDF_EXT_STR_LENGTH];
1032 	} id;
1033 
1034 	int fw_api;
1035 	int bd_api;
1036 	enum ath10k_cal_mode cal_mode;
1037 
1038 	struct {
1039 		struct completion started;
1040 		struct completion completed;
1041 		struct completion on_channel;
1042 		struct delayed_work timeout;
1043 		enum ath10k_scan_state state;
1044 		bool is_roc;
1045 		int vdev_id;
1046 		int roc_freq;
1047 		bool roc_notify;
1048 	} scan;
1049 
1050 	struct {
1051 		struct ieee80211_supported_band sbands[NUM_NL80211_BANDS];
1052 	} mac;
1053 
1054 	/* should never be NULL; needed for regular htt rx */
1055 	struct ieee80211_channel *rx_channel;
1056 
1057 	/* valid during scan; needed for mgmt rx during scan */
1058 	struct ieee80211_channel *scan_channel;
1059 
1060 	/* current operating channel definition */
1061 	struct cfg80211_chan_def chandef;
1062 
1063 	/* currently configured operating channel in firmware */
1064 	struct ieee80211_channel *tgt_oper_chan;
1065 
1066 	unsigned long long free_vdev_map;
1067 	struct ath10k_vif *monitor_arvif;
1068 	bool monitor;
1069 	int monitor_vdev_id;
1070 	bool monitor_started;
1071 	unsigned int filter_flags;
1072 	unsigned long dev_flags;
1073 	bool dfs_block_radar_events;
1074 
1075 	/* protected by conf_mutex */
1076 	bool radar_enabled;
1077 	int num_started_vdevs;
1078 
1079 	/* Protected by conf-mutex */
1080 	u8 cfg_tx_chainmask;
1081 	u8 cfg_rx_chainmask;
1082 
1083 	struct completion install_key_done;
1084 
1085 	int last_wmi_vdev_start_status;
1086 	struct completion vdev_setup_done;
1087 	struct completion vdev_delete_done;
1088 
1089 	struct workqueue_struct *workqueue;
1090 	/* Auxiliary workqueue */
1091 	struct workqueue_struct *workqueue_aux;
1092 
1093 	/* prevents concurrent FW reconfiguration */
1094 	struct mutex conf_mutex;
1095 
1096 	/* protects coredump data */
1097 	struct mutex dump_mutex;
1098 
1099 	/* protects shared structure data */
1100 	spinlock_t data_lock;
1101 
1102 	struct list_head arvifs;
1103 	struct list_head peers;
1104 	struct ath10k_peer *peer_map[ATH10K_MAX_NUM_PEER_IDS];
1105 	wait_queue_head_t peer_mapping_wq;
1106 
1107 	/* protected by conf_mutex */
1108 	int num_peers;
1109 	int num_stations;
1110 
1111 	int max_num_peers;
1112 	int max_num_stations;
1113 	int max_num_vdevs;
1114 	int max_num_tdls_vdevs;
1115 	int num_active_peers;
1116 	int num_tids;
1117 
1118 	struct work_struct svc_rdy_work;
1119 	struct sk_buff *svc_rdy_skb;
1120 
1121 	struct work_struct offchan_tx_work;
1122 	struct sk_buff_head offchan_tx_queue;
1123 	struct completion offchan_tx_completed;
1124 	struct sk_buff *offchan_tx_skb;
1125 
1126 	struct work_struct wmi_mgmt_tx_work;
1127 	struct sk_buff_head wmi_mgmt_tx_queue;
1128 
1129 	enum ath10k_state state;
1130 
1131 	struct work_struct register_work;
1132 	struct work_struct restart_work;
1133 
1134 	/* cycle count is reported twice for each visited channel during scan.
1135 	 * access protected by data_lock
1136 	 */
1137 	u32 survey_last_rx_clear_count;
1138 	u32 survey_last_cycle_count;
1139 	struct survey_info survey[ATH10K_NUM_CHANS];
1140 
1141 	/* Channel info events are expected to come in pairs without and with
1142 	 * COMPLETE flag set respectively for each channel visit during scan.
1143 	 *
1144 	 * However there are deviations from this rule. This flag is used to
1145 	 * avoid reporting garbage data.
1146 	 */
1147 	bool ch_info_can_report_survey;
1148 	struct completion bss_survey_done;
1149 
1150 	struct dfs_pattern_detector *dfs_detector;
1151 
1152 	unsigned long tx_paused; /* see ATH10K_TX_PAUSE_ */
1153 
1154 #ifdef CONFIG_ATH10K_DEBUGFS
1155 	struct ath10k_debug debug;
1156 	struct {
1157 		/* relay(fs) channel for spectral scan */
1158 		struct rchan *rfs_chan_spec_scan;
1159 
1160 		/* spectral_mode and spec_config are protected by conf_mutex */
1161 		enum ath10k_spectral_mode mode;
1162 		struct ath10k_spec_scan config;
1163 	} spectral;
1164 #endif
1165 
1166 	u32 pktlog_filter;
1167 
1168 #ifdef CONFIG_DEV_COREDUMP
1169 	struct {
1170 		struct ath10k_fw_crash_data *fw_crash_data;
1171 	} coredump;
1172 #endif
1173 
1174 	struct {
1175 		/* protected by conf_mutex */
1176 		struct ath10k_fw_components utf_mode_fw;
1177 
1178 		/* protected by data_lock */
1179 		bool utf_monitor;
1180 	} testmode;
1181 
1182 	struct {
1183 		/* protected by data_lock */
1184 		u32 rx_crc_err_drop;
1185 		u32 fw_crash_counter;
1186 		u32 fw_warm_reset_counter;
1187 		u32 fw_cold_reset_counter;
1188 	} stats;
1189 
1190 	struct ath10k_thermal thermal;
1191 	struct ath10k_wow wow;
1192 	struct ath10k_per_peer_tx_stats peer_tx_stats;
1193 
1194 	/* NAPI */
1195 	struct net_device napi_dev;
1196 	struct napi_struct napi;
1197 
1198 	struct work_struct set_coverage_class_work;
1199 	/* protected by conf_mutex */
1200 	struct {
1201 		/* writing also protected by data_lock */
1202 		s16 coverage_class;
1203 
1204 		u32 reg_phyclk;
1205 		u32 reg_slottime_conf;
1206 		u32 reg_slottime_orig;
1207 		u32 reg_ack_cts_timeout_conf;
1208 		u32 reg_ack_cts_timeout_orig;
1209 	} fw_coverage;
1210 
1211 	u32 ampdu_reference;
1212 
1213 	const u8 *wmi_key_cipher;
1214 	void *ce_priv;
1215 
1216 	u32 sta_tid_stats_mask;
1217 
1218 	/* protected by data_lock */
1219 	enum ath10k_radar_confirmation_state radar_conf_state;
1220 	struct ath10k_radar_found_info last_radar_info;
1221 	struct work_struct radar_confirmation_work;
1222 	struct ath10k_bus_params bus_param;
1223 	struct completion peer_delete_done;
1224 
1225 	/* must be last */
1226 	u8 drv_priv[0] __aligned(sizeof(void *));
1227 };
1228 
1229 static inline bool ath10k_peer_stats_enabled(struct ath10k *ar)
1230 {
1231 	if (test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) &&
1232 	    test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
1233 		return true;
1234 
1235 	return false;
1236 }
1237 
1238 extern unsigned long ath10k_coredump_mask;
1239 
1240 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1241 				  enum ath10k_bus bus,
1242 				  enum ath10k_hw_rev hw_rev,
1243 				  const struct ath10k_hif_ops *hif_ops);
1244 void ath10k_core_destroy(struct ath10k *ar);
1245 void ath10k_core_get_fw_features_str(struct ath10k *ar,
1246 				     char *buf,
1247 				     size_t max_len);
1248 int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name,
1249 				     struct ath10k_fw_file *fw_file);
1250 
1251 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
1252 		      const struct ath10k_fw_components *fw_components);
1253 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt);
1254 void ath10k_core_stop(struct ath10k *ar);
1255 int ath10k_core_register(struct ath10k *ar,
1256 			 const struct ath10k_bus_params *bus_params);
1257 void ath10k_core_unregister(struct ath10k *ar);
1258 int ath10k_core_fetch_board_file(struct ath10k *ar, int bd_ie_type);
1259 void ath10k_core_free_board_files(struct ath10k *ar);
1260 
1261 #endif /* _CORE_H_ */
1262