1203c4805SLuis R. Rodriguez /*
2203c4805SLuis R. Rodriguez  * Copyright (c) 2008-2009 Atheros Communications Inc.
3203c4805SLuis R. Rodriguez  *
4203c4805SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
5203c4805SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
6203c4805SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
7203c4805SLuis R. Rodriguez  *
8203c4805SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9203c4805SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10203c4805SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11203c4805SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12203c4805SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13203c4805SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14203c4805SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15203c4805SLuis R. Rodriguez  */
16203c4805SLuis R. Rodriguez 
17203c4805SLuis R. Rodriguez #ifndef DEBUG_H
18203c4805SLuis R. Rodriguez #define DEBUG_H
19203c4805SLuis R. Rodriguez 
204d6b228dSLuis R. Rodriguez #include "hw.h"
21545750d3SFelix Fietkau #include "rc.h"
224d6b228dSLuis R. Rodriguez 
23fec247c0SSujith struct ath_txq;
24fec247c0SSujith struct ath_buf;
25fec247c0SSujith 
26a830df07SFelix Fietkau #ifdef CONFIG_ATH9K_DEBUGFS
27fec247c0SSujith #define TX_STAT_INC(q, c) sc->debug.stats.txstats[q].c++
28fec247c0SSujith #else
29fec247c0SSujith #define TX_STAT_INC(q, c) do { } while (0)
30fec247c0SSujith #endif
31fec247c0SSujith 
32a830df07SFelix Fietkau #ifdef CONFIG_ATH9K_DEBUGFS
33203c4805SLuis R. Rodriguez 
34203c4805SLuis R. Rodriguez /**
35203c4805SLuis R. Rodriguez  * struct ath_interrupt_stats - Contains statistics about interrupts
36203c4805SLuis R. Rodriguez  * @total: Total no. of interrupts generated so far
37203c4805SLuis R. Rodriguez  * @rxok: RX with no errors
38203c4805SLuis R. Rodriguez  * @rxeol: RX with no more RXDESC available
39203c4805SLuis R. Rodriguez  * @rxorn: RX FIFO overrun
40203c4805SLuis R. Rodriguez  * @txok: TX completed at the requested rate
41203c4805SLuis R. Rodriguez  * @txurn: TX FIFO underrun
42203c4805SLuis R. Rodriguez  * @mib: MIB regs reaching its threshold
43203c4805SLuis R. Rodriguez  * @rxphyerr: RX with phy errors
44203c4805SLuis R. Rodriguez  * @rx_keycache_miss: RX with key cache misses
45203c4805SLuis R. Rodriguez  * @swba: Software Beacon Alert
46203c4805SLuis R. Rodriguez  * @bmiss: Beacon Miss
47203c4805SLuis R. Rodriguez  * @bnr: Beacon Not Ready
48203c4805SLuis R. Rodriguez  * @cst: Carrier Sense TImeout
49203c4805SLuis R. Rodriguez  * @gtt: Global TX Timeout
50203c4805SLuis R. Rodriguez  * @tim: RX beacon TIM occurrence
51203c4805SLuis R. Rodriguez  * @cabend: RX End of CAB traffic
52203c4805SLuis R. Rodriguez  * @dtimsync: DTIM sync lossage
53203c4805SLuis R. Rodriguez  * @dtim: RX Beacon with DTIM
54203c4805SLuis R. Rodriguez  */
55203c4805SLuis R. Rodriguez struct ath_interrupt_stats {
56203c4805SLuis R. Rodriguez 	u32 total;
57203c4805SLuis R. Rodriguez 	u32 rxok;
58203c4805SLuis R. Rodriguez 	u32 rxeol;
59203c4805SLuis R. Rodriguez 	u32 rxorn;
60203c4805SLuis R. Rodriguez 	u32 txok;
61203c4805SLuis R. Rodriguez 	u32 txeol;
62203c4805SLuis R. Rodriguez 	u32 txurn;
63203c4805SLuis R. Rodriguez 	u32 mib;
64203c4805SLuis R. Rodriguez 	u32 rxphyerr;
65203c4805SLuis R. Rodriguez 	u32 rx_keycache_miss;
66203c4805SLuis R. Rodriguez 	u32 swba;
67203c4805SLuis R. Rodriguez 	u32 bmiss;
68203c4805SLuis R. Rodriguez 	u32 bnr;
69203c4805SLuis R. Rodriguez 	u32 cst;
70203c4805SLuis R. Rodriguez 	u32 gtt;
71203c4805SLuis R. Rodriguez 	u32 tim;
72203c4805SLuis R. Rodriguez 	u32 cabend;
73203c4805SLuis R. Rodriguez 	u32 dtimsync;
74203c4805SLuis R. Rodriguez 	u32 dtim;
75203c4805SLuis R. Rodriguez };
76203c4805SLuis R. Rodriguez 
77bedf087aSJeff Hansen struct ath_rc_stats {
78203c4805SLuis R. Rodriguez 	u32 success;
79203c4805SLuis R. Rodriguez 	u32 retries;
80203c4805SLuis R. Rodriguez 	u32 xretries;
81203c4805SLuis R. Rodriguez 	u8 per;
82203c4805SLuis R. Rodriguez };
83203c4805SLuis R. Rodriguez 
84fec247c0SSujith /**
85fec247c0SSujith  * struct ath_tx_stats - Statistics about TX
86fec247c0SSujith  * @queued: Total MPDUs (non-aggr) queued
87fec247c0SSujith  * @completed: Total MPDUs (non-aggr) completed
88fec247c0SSujith  * @a_aggr: Total no. of aggregates queued
89fec247c0SSujith  * @a_queued: Total AMPDUs queued
90fec247c0SSujith  * @a_completed: Total AMPDUs completed
91fec247c0SSujith  * @a_retries: No. of AMPDUs retried (SW)
92fec247c0SSujith  * @a_xretries: No. of AMPDUs dropped due to xretries
93fec247c0SSujith  * @fifo_underrun: FIFO underrun occurrences
94fec247c0SSujith 	Valid only for:
95fec247c0SSujith 		- non-aggregate condition.
96fec247c0SSujith 		- first packet of aggregate.
97fec247c0SSujith  * @xtxop: No. of frames filtered because of TXOP limit
98fec247c0SSujith  * @timer_exp: Transmit timer expiry
99fec247c0SSujith  * @desc_cfg_err: Descriptor configuration errors
100fec247c0SSujith  * @data_urn: TX data underrun errors
101fec247c0SSujith  * @delim_urn: TX delimiter underrun errors
102fec247c0SSujith  */
103fec247c0SSujith struct ath_tx_stats {
104fec247c0SSujith 	u32 queued;
105fec247c0SSujith 	u32 completed;
106fec247c0SSujith 	u32 a_aggr;
107fec247c0SSujith 	u32 a_queued;
108fec247c0SSujith 	u32 a_completed;
109fec247c0SSujith 	u32 a_retries;
110fec247c0SSujith 	u32 a_xretries;
111fec247c0SSujith 	u32 fifo_underrun;
112fec247c0SSujith 	u32 xtxop;
113fec247c0SSujith 	u32 timer_exp;
114fec247c0SSujith 	u32 desc_cfg_err;
115fec247c0SSujith 	u32 data_underrun;
116fec247c0SSujith 	u32 delim_underrun;
117fec247c0SSujith };
118fec247c0SSujith 
1191395d3f0SSujith /**
1201395d3f0SSujith  * struct ath_rx_stats - RX Statistics
1211395d3f0SSujith  * @crc_err: No. of frames with incorrect CRC value
1221395d3f0SSujith  * @decrypt_crc_err: No. of frames whose CRC check failed after
1231395d3f0SSujith 	decryption process completed
1241395d3f0SSujith  * @phy_err: No. of frames whose reception failed because the PHY
1251395d3f0SSujith 	encountered an error
1261395d3f0SSujith  * @mic_err: No. of frames with incorrect TKIP MIC verification failure
1271395d3f0SSujith  * @pre_delim_crc_err: Pre-Frame delimiter CRC error detections
1281395d3f0SSujith  * @post_delim_crc_err: Post-Frame delimiter CRC error detections
1291395d3f0SSujith  * @decrypt_busy_err: Decryption interruptions counter
1301395d3f0SSujith  * @phy_err_stats: Individual PHY error statistics
1311395d3f0SSujith  */
1321395d3f0SSujith struct ath_rx_stats {
1331395d3f0SSujith 	u32 crc_err;
1341395d3f0SSujith 	u32 decrypt_crc_err;
1351395d3f0SSujith 	u32 phy_err;
1361395d3f0SSujith 	u32 mic_err;
1371395d3f0SSujith 	u32 pre_delim_crc_err;
1381395d3f0SSujith 	u32 post_delim_crc_err;
1391395d3f0SSujith 	u32 decrypt_busy_err;
1401395d3f0SSujith 	u32 phy_err_stats[ATH9K_PHYERR_MAX];
1411395d3f0SSujith };
1421395d3f0SSujith 
143203c4805SLuis R. Rodriguez struct ath_stats {
144203c4805SLuis R. Rodriguez 	struct ath_interrupt_stats istats;
145bedf087aSJeff Hansen 	struct ath_rc_stats rcstats[RATE_TABLE_SIZE];
146fec247c0SSujith 	struct ath_tx_stats txstats[ATH9K_NUM_TX_QUEUES];
1471395d3f0SSujith 	struct ath_rx_stats rxstats;
148203c4805SLuis R. Rodriguez };
149203c4805SLuis R. Rodriguez 
150203c4805SLuis R. Rodriguez struct ath9k_debug {
151203c4805SLuis R. Rodriguez 	struct dentry *debugfs_phy;
1522493928eSJeff Hansen 	struct dentry *debugfs_debug;
153203c4805SLuis R. Rodriguez 	struct dentry *debugfs_dma;
154203c4805SLuis R. Rodriguez 	struct dentry *debugfs_interrupt;
155203c4805SLuis R. Rodriguez 	struct dentry *debugfs_rcstat;
156203c4805SLuis R. Rodriguez 	struct dentry *debugfs_wiphy;
157fec247c0SSujith 	struct dentry *debugfs_xmit;
1581395d3f0SSujith 	struct dentry *debugfs_recv;
159203c4805SLuis R. Rodriguez 	struct ath_stats stats;
160203c4805SLuis R. Rodriguez };
161203c4805SLuis R. Rodriguez 
1624d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah);
1634d6b228dSLuis R. Rodriguez void ath9k_exit_debug(struct ath_hw *ah);
1644d6b228dSLuis R. Rodriguez 
165203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void);
166203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void);
167203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status);
168545750d3SFelix Fietkau void ath_debug_stat_rc(struct ath_softc *sc, int final_rate);
169fec247c0SSujith void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
170db1a052bSFelix Fietkau 		       struct ath_buf *bf, struct ath_tx_status *ts);
1718e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs);
172203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix,
173203c4805SLuis R. Rodriguez 			    int xretries, int retries, u8 per);
174203c4805SLuis R. Rodriguez 
175203c4805SLuis R. Rodriguez #else
176203c4805SLuis R. Rodriguez 
1774d6b228dSLuis R. Rodriguez static inline int ath9k_init_debug(struct ath_hw *ah)
178203c4805SLuis R. Rodriguez {
179203c4805SLuis R. Rodriguez 	return 0;
180203c4805SLuis R. Rodriguez }
181203c4805SLuis R. Rodriguez 
1824d6b228dSLuis R. Rodriguez static inline void ath9k_exit_debug(struct ath_hw *ah)
183203c4805SLuis R. Rodriguez {
184203c4805SLuis R. Rodriguez }
185203c4805SLuis R. Rodriguez 
186203c4805SLuis R. Rodriguez static inline int ath9k_debug_create_root(void)
187203c4805SLuis R. Rodriguez {
188203c4805SLuis R. Rodriguez 	return 0;
189203c4805SLuis R. Rodriguez }
190203c4805SLuis R. Rodriguez 
191203c4805SLuis R. Rodriguez static inline void ath9k_debug_remove_root(void)
192203c4805SLuis R. Rodriguez {
193203c4805SLuis R. Rodriguez }
194203c4805SLuis R. Rodriguez 
195203c4805SLuis R. Rodriguez static inline void ath_debug_stat_interrupt(struct ath_softc *sc,
196203c4805SLuis R. Rodriguez 					    enum ath9k_int status)
197203c4805SLuis R. Rodriguez {
198203c4805SLuis R. Rodriguez }
199203c4805SLuis R. Rodriguez 
200203c4805SLuis R. Rodriguez static inline void ath_debug_stat_rc(struct ath_softc *sc,
201545750d3SFelix Fietkau 				     int final_rate)
202203c4805SLuis R. Rodriguez {
203203c4805SLuis R. Rodriguez }
204203c4805SLuis R. Rodriguez 
205fec247c0SSujith static inline void ath_debug_stat_tx(struct ath_softc *sc,
206fec247c0SSujith 				     struct ath_txq *txq,
20732ffb1f4SFelix Fietkau 				     struct ath_buf *bf,
20832ffb1f4SFelix Fietkau 				     struct ath_tx_status *ts)
209fec247c0SSujith {
210fec247c0SSujith }
211fec247c0SSujith 
2121395d3f0SSujith static inline void ath_debug_stat_rx(struct ath_softc *sc,
21332ffb1f4SFelix Fietkau 				     struct ath_rx_status *rs)
2141395d3f0SSujith {
2151395d3f0SSujith }
2161395d3f0SSujith 
217203c4805SLuis R. Rodriguez static inline void ath_debug_stat_retries(struct ath_softc *sc, int rix,
218203c4805SLuis R. Rodriguez 					  int xretries, int retries, u8 per)
219203c4805SLuis R. Rodriguez {
220203c4805SLuis R. Rodriguez }
221203c4805SLuis R. Rodriguez 
222a830df07SFelix Fietkau #endif /* CONFIG_ATH9K_DEBUGFS */
223203c4805SLuis R. Rodriguez 
224203c4805SLuis R. Rodriguez #endif /* DEBUG_H */
225