1*4882a593Smuzhiyun /* SPDX-License-Identifier: ISC */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2005-2011 Atheros Communications Inc.
4*4882a593Smuzhiyun * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5*4882a593Smuzhiyun * Copyright (c) 2018, The Linux Foundation. All rights reserved.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #ifndef _DEBUG_H_
9*4882a593Smuzhiyun #define _DEBUG_H_
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/types.h>
12*4882a593Smuzhiyun #include "trace.h"
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun enum ath10k_debug_mask {
15*4882a593Smuzhiyun ATH10K_DBG_PCI = 0x00000001,
16*4882a593Smuzhiyun ATH10K_DBG_WMI = 0x00000002,
17*4882a593Smuzhiyun ATH10K_DBG_HTC = 0x00000004,
18*4882a593Smuzhiyun ATH10K_DBG_HTT = 0x00000008,
19*4882a593Smuzhiyun ATH10K_DBG_MAC = 0x00000010,
20*4882a593Smuzhiyun ATH10K_DBG_BOOT = 0x00000020,
21*4882a593Smuzhiyun ATH10K_DBG_PCI_DUMP = 0x00000040,
22*4882a593Smuzhiyun ATH10K_DBG_HTT_DUMP = 0x00000080,
23*4882a593Smuzhiyun ATH10K_DBG_MGMT = 0x00000100,
24*4882a593Smuzhiyun ATH10K_DBG_DATA = 0x00000200,
25*4882a593Smuzhiyun ATH10K_DBG_BMI = 0x00000400,
26*4882a593Smuzhiyun ATH10K_DBG_REGULATORY = 0x00000800,
27*4882a593Smuzhiyun ATH10K_DBG_TESTMODE = 0x00001000,
28*4882a593Smuzhiyun ATH10K_DBG_WMI_PRINT = 0x00002000,
29*4882a593Smuzhiyun ATH10K_DBG_PCI_PS = 0x00004000,
30*4882a593Smuzhiyun ATH10K_DBG_AHB = 0x00008000,
31*4882a593Smuzhiyun ATH10K_DBG_SDIO = 0x00010000,
32*4882a593Smuzhiyun ATH10K_DBG_SDIO_DUMP = 0x00020000,
33*4882a593Smuzhiyun ATH10K_DBG_USB = 0x00040000,
34*4882a593Smuzhiyun ATH10K_DBG_USB_BULK = 0x00080000,
35*4882a593Smuzhiyun ATH10K_DBG_SNOC = 0x00100000,
36*4882a593Smuzhiyun ATH10K_DBG_QMI = 0x00200000,
37*4882a593Smuzhiyun ATH10K_DBG_ANY = 0xffffffff,
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun enum ath10k_pktlog_filter {
41*4882a593Smuzhiyun ATH10K_PKTLOG_RX = 0x000000001,
42*4882a593Smuzhiyun ATH10K_PKTLOG_TX = 0x000000002,
43*4882a593Smuzhiyun ATH10K_PKTLOG_RCFIND = 0x000000004,
44*4882a593Smuzhiyun ATH10K_PKTLOG_RCUPDATE = 0x000000008,
45*4882a593Smuzhiyun ATH10K_PKTLOG_DBG_PRINT = 0x000000010,
46*4882a593Smuzhiyun ATH10K_PKTLOG_PEER_STATS = 0x000000040,
47*4882a593Smuzhiyun ATH10K_PKTLOG_ANY = 0x00000005f,
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun enum ath10k_dbg_aggr_mode {
51*4882a593Smuzhiyun ATH10K_DBG_AGGR_MODE_AUTO,
52*4882a593Smuzhiyun ATH10K_DBG_AGGR_MODE_MANUAL,
53*4882a593Smuzhiyun ATH10K_DBG_AGGR_MODE_MAX,
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* Types of packet log events */
57*4882a593Smuzhiyun enum ath_pktlog_type {
58*4882a593Smuzhiyun ATH_PKTLOG_TYPE_TX_CTRL = 1,
59*4882a593Smuzhiyun ATH_PKTLOG_TYPE_TX_STAT,
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun struct ath10k_pktlog_hdr {
63*4882a593Smuzhiyun __le16 flags;
64*4882a593Smuzhiyun __le16 missed_cnt;
65*4882a593Smuzhiyun __le16 log_type; /* Type of log information foll this header */
66*4882a593Smuzhiyun __le16 size; /* Size of variable length log information in bytes */
67*4882a593Smuzhiyun __le32 timestamp;
68*4882a593Smuzhiyun u8 payload[];
69*4882a593Smuzhiyun } __packed;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* FIXME: How to calculate the buffer size sanely? */
72*4882a593Smuzhiyun #define ATH10K_FW_STATS_BUF_SIZE (1024 * 1024)
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #define ATH10K_TX_POWER_MAX_VAL 70
75*4882a593Smuzhiyun #define ATH10K_TX_POWER_MIN_VAL 0
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun extern unsigned int ath10k_debug_mask;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun __printf(2, 3) void ath10k_info(struct ath10k *ar, const char *fmt, ...);
80*4882a593Smuzhiyun __printf(2, 3) void ath10k_err(struct ath10k *ar, const char *fmt, ...);
81*4882a593Smuzhiyun __printf(2, 3) void ath10k_warn(struct ath10k *ar, const char *fmt, ...);
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun void ath10k_debug_print_hwfw_info(struct ath10k *ar);
84*4882a593Smuzhiyun void ath10k_debug_print_board_info(struct ath10k *ar);
85*4882a593Smuzhiyun void ath10k_debug_print_boot_info(struct ath10k *ar);
86*4882a593Smuzhiyun void ath10k_print_driver_info(struct ath10k *ar);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #ifdef CONFIG_ATH10K_DEBUGFS
89*4882a593Smuzhiyun int ath10k_debug_start(struct ath10k *ar);
90*4882a593Smuzhiyun void ath10k_debug_stop(struct ath10k *ar);
91*4882a593Smuzhiyun int ath10k_debug_create(struct ath10k *ar);
92*4882a593Smuzhiyun void ath10k_debug_destroy(struct ath10k *ar);
93*4882a593Smuzhiyun int ath10k_debug_register(struct ath10k *ar);
94*4882a593Smuzhiyun void ath10k_debug_unregister(struct ath10k *ar);
95*4882a593Smuzhiyun void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb);
96*4882a593Smuzhiyun void ath10k_debug_tpc_stats_process(struct ath10k *ar,
97*4882a593Smuzhiyun struct ath10k_tpc_stats *tpc_stats);
98*4882a593Smuzhiyun void
99*4882a593Smuzhiyun ath10k_debug_tpc_stats_final_process(struct ath10k *ar,
100*4882a593Smuzhiyun struct ath10k_tpc_stats_final *tpc_stats);
101*4882a593Smuzhiyun void ath10k_debug_dbglog_add(struct ath10k *ar, u8 *buffer, int len);
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #define ATH10K_DFS_STAT_INC(ar, c) (ar->debug.dfs_stats.c++)
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
106*4882a593Smuzhiyun struct ieee80211_vif *vif,
107*4882a593Smuzhiyun u32 sset, u8 *data);
108*4882a593Smuzhiyun int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
109*4882a593Smuzhiyun struct ieee80211_vif *vif, int sset);
110*4882a593Smuzhiyun void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
111*4882a593Smuzhiyun struct ieee80211_vif *vif,
112*4882a593Smuzhiyun struct ethtool_stats *stats, u64 *data);
113*4882a593Smuzhiyun
ath10k_debug_get_fw_dbglog_mask(struct ath10k * ar)114*4882a593Smuzhiyun static inline u64 ath10k_debug_get_fw_dbglog_mask(struct ath10k *ar)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun return ar->debug.fw_dbglog_mask;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun
ath10k_debug_get_fw_dbglog_level(struct ath10k * ar)119*4882a593Smuzhiyun static inline u32 ath10k_debug_get_fw_dbglog_level(struct ath10k *ar)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun return ar->debug.fw_dbglog_level;
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun
ath10k_debug_is_extd_tx_stats_enabled(struct ath10k * ar)124*4882a593Smuzhiyun static inline int ath10k_debug_is_extd_tx_stats_enabled(struct ath10k *ar)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun return ar->debug.enable_extd_tx_stats;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun int ath10k_debug_fw_stats_request(struct ath10k *ar);
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun #else
132*4882a593Smuzhiyun
ath10k_debug_start(struct ath10k * ar)133*4882a593Smuzhiyun static inline int ath10k_debug_start(struct ath10k *ar)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun return 0;
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
ath10k_debug_stop(struct ath10k * ar)138*4882a593Smuzhiyun static inline void ath10k_debug_stop(struct ath10k *ar)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun
ath10k_debug_create(struct ath10k * ar)142*4882a593Smuzhiyun static inline int ath10k_debug_create(struct ath10k *ar)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun return 0;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun
ath10k_debug_destroy(struct ath10k * ar)147*4882a593Smuzhiyun static inline void ath10k_debug_destroy(struct ath10k *ar)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun
ath10k_debug_register(struct ath10k * ar)151*4882a593Smuzhiyun static inline int ath10k_debug_register(struct ath10k *ar)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun return 0;
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun
ath10k_debug_unregister(struct ath10k * ar)156*4882a593Smuzhiyun static inline void ath10k_debug_unregister(struct ath10k *ar)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun
ath10k_debug_fw_stats_process(struct ath10k * ar,struct sk_buff * skb)160*4882a593Smuzhiyun static inline void ath10k_debug_fw_stats_process(struct ath10k *ar,
161*4882a593Smuzhiyun struct sk_buff *skb)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun
ath10k_debug_tpc_stats_process(struct ath10k * ar,struct ath10k_tpc_stats * tpc_stats)165*4882a593Smuzhiyun static inline void ath10k_debug_tpc_stats_process(struct ath10k *ar,
166*4882a593Smuzhiyun struct ath10k_tpc_stats *tpc_stats)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun kfree(tpc_stats);
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun static inline void
ath10k_debug_tpc_stats_final_process(struct ath10k * ar,struct ath10k_tpc_stats_final * tpc_stats)172*4882a593Smuzhiyun ath10k_debug_tpc_stats_final_process(struct ath10k *ar,
173*4882a593Smuzhiyun struct ath10k_tpc_stats_final *tpc_stats)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun kfree(tpc_stats);
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun
ath10k_debug_dbglog_add(struct ath10k * ar,u8 * buffer,int len)178*4882a593Smuzhiyun static inline void ath10k_debug_dbglog_add(struct ath10k *ar, u8 *buffer,
179*4882a593Smuzhiyun int len)
180*4882a593Smuzhiyun {
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun
ath10k_debug_get_fw_dbglog_mask(struct ath10k * ar)183*4882a593Smuzhiyun static inline u64 ath10k_debug_get_fw_dbglog_mask(struct ath10k *ar)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun return 0;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
ath10k_debug_get_fw_dbglog_level(struct ath10k * ar)188*4882a593Smuzhiyun static inline u32 ath10k_debug_get_fw_dbglog_level(struct ath10k *ar)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun return 0;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun
ath10k_debug_is_extd_tx_stats_enabled(struct ath10k * ar)193*4882a593Smuzhiyun static inline int ath10k_debug_is_extd_tx_stats_enabled(struct ath10k *ar)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun return 0;
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun
ath10k_debug_fw_stats_request(struct ath10k * ar)198*4882a593Smuzhiyun static inline int ath10k_debug_fw_stats_request(struct ath10k *ar)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun return 0;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun #define ATH10K_DFS_STAT_INC(ar, c) do { } while (0)
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun #define ath10k_debug_get_et_strings NULL
206*4882a593Smuzhiyun #define ath10k_debug_get_et_sset_count NULL
207*4882a593Smuzhiyun #define ath10k_debug_get_et_stats NULL
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun #endif /* CONFIG_ATH10K_DEBUGFS */
210*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_DEBUGFS
211*4882a593Smuzhiyun void ath10k_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
212*4882a593Smuzhiyun struct ieee80211_sta *sta, struct dentry *dir);
213*4882a593Smuzhiyun void ath10k_sta_update_rx_duration(struct ath10k *ar,
214*4882a593Smuzhiyun struct ath10k_fw_stats *stats);
215*4882a593Smuzhiyun void ath10k_sta_update_rx_tid_stats(struct ath10k *ar, u8 *first_hdr,
216*4882a593Smuzhiyun unsigned long num_msdus,
217*4882a593Smuzhiyun enum ath10k_pkt_rx_err err,
218*4882a593Smuzhiyun unsigned long unchain_cnt,
219*4882a593Smuzhiyun unsigned long drop_cnt,
220*4882a593Smuzhiyun unsigned long drop_cnt_filter,
221*4882a593Smuzhiyun unsigned long queued_msdus);
222*4882a593Smuzhiyun void ath10k_sta_update_rx_tid_stats_ampdu(struct ath10k *ar,
223*4882a593Smuzhiyun u16 peer_id, u8 tid,
224*4882a593Smuzhiyun struct htt_rx_indication_mpdu_range *ranges,
225*4882a593Smuzhiyun int num_ranges);
226*4882a593Smuzhiyun #else
227*4882a593Smuzhiyun static inline
ath10k_sta_update_rx_duration(struct ath10k * ar,struct ath10k_fw_stats * stats)228*4882a593Smuzhiyun void ath10k_sta_update_rx_duration(struct ath10k *ar,
229*4882a593Smuzhiyun struct ath10k_fw_stats *stats)
230*4882a593Smuzhiyun {
231*4882a593Smuzhiyun }
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun static inline
ath10k_sta_update_rx_tid_stats(struct ath10k * ar,u8 * first_hdr,unsigned long num_msdus,enum ath10k_pkt_rx_err err,unsigned long unchain_cnt,unsigned long drop_cnt,unsigned long drop_cnt_filter,unsigned long queued_msdus)234*4882a593Smuzhiyun void ath10k_sta_update_rx_tid_stats(struct ath10k *ar, u8 *first_hdr,
235*4882a593Smuzhiyun unsigned long num_msdus,
236*4882a593Smuzhiyun enum ath10k_pkt_rx_err err,
237*4882a593Smuzhiyun unsigned long unchain_cnt,
238*4882a593Smuzhiyun unsigned long drop_cnt,
239*4882a593Smuzhiyun unsigned long drop_cnt_filter,
240*4882a593Smuzhiyun unsigned long queued_msdus)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun static inline
ath10k_sta_update_rx_tid_stats_ampdu(struct ath10k * ar,u16 peer_id,u8 tid,struct htt_rx_indication_mpdu_range * ranges,int num_ranges)245*4882a593Smuzhiyun void ath10k_sta_update_rx_tid_stats_ampdu(struct ath10k *ar,
246*4882a593Smuzhiyun u16 peer_id, u8 tid,
247*4882a593Smuzhiyun struct htt_rx_indication_mpdu_range *ranges,
248*4882a593Smuzhiyun int num_ranges)
249*4882a593Smuzhiyun {
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun #endif /* CONFIG_MAC80211_DEBUGFS */
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun #ifdef CONFIG_ATH10K_DEBUG
254*4882a593Smuzhiyun __printf(3, 4) void __ath10k_dbg(struct ath10k *ar,
255*4882a593Smuzhiyun enum ath10k_debug_mask mask,
256*4882a593Smuzhiyun const char *fmt, ...);
257*4882a593Smuzhiyun void ath10k_dbg_dump(struct ath10k *ar,
258*4882a593Smuzhiyun enum ath10k_debug_mask mask,
259*4882a593Smuzhiyun const char *msg, const char *prefix,
260*4882a593Smuzhiyun const void *buf, size_t len);
261*4882a593Smuzhiyun #else /* CONFIG_ATH10K_DEBUG */
262*4882a593Smuzhiyun
__ath10k_dbg(struct ath10k * ar,enum ath10k_debug_mask dbg_mask,const char * fmt,...)263*4882a593Smuzhiyun static inline int __ath10k_dbg(struct ath10k *ar,
264*4882a593Smuzhiyun enum ath10k_debug_mask dbg_mask,
265*4882a593Smuzhiyun const char *fmt, ...)
266*4882a593Smuzhiyun {
267*4882a593Smuzhiyun return 0;
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
ath10k_dbg_dump(struct ath10k * ar,enum ath10k_debug_mask mask,const char * msg,const char * prefix,const void * buf,size_t len)270*4882a593Smuzhiyun static inline void ath10k_dbg_dump(struct ath10k *ar,
271*4882a593Smuzhiyun enum ath10k_debug_mask mask,
272*4882a593Smuzhiyun const char *msg, const char *prefix,
273*4882a593Smuzhiyun const void *buf, size_t len)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun #endif /* CONFIG_ATH10K_DEBUG */
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun /* Avoid calling __ath10k_dbg() if debug_mask is not set and tracing
279*4882a593Smuzhiyun * disabled.
280*4882a593Smuzhiyun */
281*4882a593Smuzhiyun #define ath10k_dbg(ar, dbg_mask, fmt, ...) \
282*4882a593Smuzhiyun do { \
283*4882a593Smuzhiyun if ((ath10k_debug_mask & dbg_mask) || \
284*4882a593Smuzhiyun trace_ath10k_log_dbg_enabled()) \
285*4882a593Smuzhiyun __ath10k_dbg(ar, dbg_mask, fmt, ##__VA_ARGS__); \
286*4882a593Smuzhiyun } while (0)
287*4882a593Smuzhiyun #endif /* _DEBUG_H_ */
288