1203c4805SLuis R. Rodriguez /*
25b68138eSSujith Manoharan  * Copyright (c) 2008-2011 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
38a9616f41SLuis R. Rodriguez  * @rxlp: RX with low priority RX
39a9616f41SLuis R. Rodriguez  * @rxhp: RX with high priority, uapsd only
40203c4805SLuis R. Rodriguez  * @rxeol: RX with no more RXDESC available
41203c4805SLuis R. Rodriguez  * @rxorn: RX FIFO overrun
42203c4805SLuis R. Rodriguez  * @txok: TX completed at the requested rate
43203c4805SLuis R. Rodriguez  * @txurn: TX FIFO underrun
44203c4805SLuis R. Rodriguez  * @mib: MIB regs reaching its threshold
45203c4805SLuis R. Rodriguez  * @rxphyerr: RX with phy errors
46203c4805SLuis R. Rodriguez  * @rx_keycache_miss: RX with key cache misses
47203c4805SLuis R. Rodriguez  * @swba: Software Beacon Alert
48203c4805SLuis R. Rodriguez  * @bmiss: Beacon Miss
49203c4805SLuis R. Rodriguez  * @bnr: Beacon Not Ready
50203c4805SLuis R. Rodriguez  * @cst: Carrier Sense TImeout
51203c4805SLuis R. Rodriguez  * @gtt: Global TX Timeout
52203c4805SLuis R. Rodriguez  * @tim: RX beacon TIM occurrence
53203c4805SLuis R. Rodriguez  * @cabend: RX End of CAB traffic
54203c4805SLuis R. Rodriguez  * @dtimsync: DTIM sync lossage
55203c4805SLuis R. Rodriguez  * @dtim: RX Beacon with DTIM
5608578b8fSLuis R. Rodriguez  * @bb_watchdog: Baseband watchdog
576dde1aabSMohammed Shafi Shajakhan  * @tsfoor: TSF out of range, indicates that the corrected TSF received
586dde1aabSMohammed Shafi Shajakhan  * from a beacon differs from the PCU's internal TSF by more than a
596dde1aabSMohammed Shafi Shajakhan  * (programmable) threshold
60203c4805SLuis R. Rodriguez  */
61203c4805SLuis R. Rodriguez struct ath_interrupt_stats {
62203c4805SLuis R. Rodriguez 	u32 total;
63203c4805SLuis R. Rodriguez 	u32 rxok;
64a9616f41SLuis R. Rodriguez 	u32 rxlp;
65a9616f41SLuis R. Rodriguez 	u32 rxhp;
66203c4805SLuis R. Rodriguez 	u32 rxeol;
67203c4805SLuis R. Rodriguez 	u32 rxorn;
68203c4805SLuis R. Rodriguez 	u32 txok;
69203c4805SLuis R. Rodriguez 	u32 txeol;
70203c4805SLuis R. Rodriguez 	u32 txurn;
71203c4805SLuis R. Rodriguez 	u32 mib;
72203c4805SLuis R. Rodriguez 	u32 rxphyerr;
73203c4805SLuis R. Rodriguez 	u32 rx_keycache_miss;
74203c4805SLuis R. Rodriguez 	u32 swba;
75203c4805SLuis R. Rodriguez 	u32 bmiss;
76203c4805SLuis R. Rodriguez 	u32 bnr;
77203c4805SLuis R. Rodriguez 	u32 cst;
78203c4805SLuis R. Rodriguez 	u32 gtt;
79203c4805SLuis R. Rodriguez 	u32 tim;
80203c4805SLuis R. Rodriguez 	u32 cabend;
81203c4805SLuis R. Rodriguez 	u32 dtimsync;
82203c4805SLuis R. Rodriguez 	u32 dtim;
8308578b8fSLuis R. Rodriguez 	u32 bb_watchdog;
846dde1aabSMohammed Shafi Shajakhan 	u32 tsfoor;
85203c4805SLuis R. Rodriguez };
86203c4805SLuis R. Rodriguez 
87fec247c0SSujith /**
88fec247c0SSujith  * struct ath_tx_stats - Statistics about TX
8999c15bf5SBen Greear  * @tx_pkts_all:  No. of total frames transmitted, including ones that
9099c15bf5SBen Greear 	may have had errors.
9199c15bf5SBen Greear  * @tx_bytes_all:  No. of total bytes transmitted, including ones that
9299c15bf5SBen Greear 	may have had errors.
93fec247c0SSujith  * @queued: Total MPDUs (non-aggr) queued
94fec247c0SSujith  * @completed: Total MPDUs (non-aggr) completed
95fec247c0SSujith  * @a_aggr: Total no. of aggregates queued
96bda8addaSBen Greear  * @a_queued_hw: Total AMPDUs queued to hardware
97bda8addaSBen Greear  * @a_queued_sw: Total AMPDUs queued to software queues
98fec247c0SSujith  * @a_completed: Total AMPDUs completed
99fec247c0SSujith  * @a_retries: No. of AMPDUs retried (SW)
100fec247c0SSujith  * @a_xretries: No. of AMPDUs dropped due to xretries
101fec247c0SSujith  * @fifo_underrun: FIFO underrun occurrences
102fec247c0SSujith 	Valid only for:
103fec247c0SSujith 		- non-aggregate condition.
104fec247c0SSujith 		- first packet of aggregate.
105fec247c0SSujith  * @xtxop: No. of frames filtered because of TXOP limit
106fec247c0SSujith  * @timer_exp: Transmit timer expiry
107fec247c0SSujith  * @desc_cfg_err: Descriptor configuration errors
108fec247c0SSujith  * @data_urn: TX data underrun errors
109fec247c0SSujith  * @delim_urn: TX delimiter underrun errors
1102dac4fb9SBen Greear  * @puttxbuf: Number of times hardware was given txbuf to write.
1112dac4fb9SBen Greear  * @txstart:  Number of times hardware was told to start tx.
1122dac4fb9SBen Greear  * @txprocdesc:  Number of times tx descriptor was processed
113fec247c0SSujith  */
114fec247c0SSujith struct ath_tx_stats {
11599c15bf5SBen Greear 	u32 tx_pkts_all;
11699c15bf5SBen Greear 	u32 tx_bytes_all;
117fec247c0SSujith 	u32 queued;
118fec247c0SSujith 	u32 completed;
1195a6f78afSFelix Fietkau 	u32 xretries;
120fec247c0SSujith 	u32 a_aggr;
121bda8addaSBen Greear 	u32 a_queued_hw;
122bda8addaSBen Greear 	u32 a_queued_sw;
123fec247c0SSujith 	u32 a_completed;
124fec247c0SSujith 	u32 a_retries;
125fec247c0SSujith 	u32 a_xretries;
126fec247c0SSujith 	u32 fifo_underrun;
127fec247c0SSujith 	u32 xtxop;
128fec247c0SSujith 	u32 timer_exp;
129fec247c0SSujith 	u32 desc_cfg_err;
130fec247c0SSujith 	u32 data_underrun;
131fec247c0SSujith 	u32 delim_underrun;
1322dac4fb9SBen Greear 	u32 puttxbuf;
1332dac4fb9SBen Greear 	u32 txstart;
1342dac4fb9SBen Greear 	u32 txprocdesc;
135fec247c0SSujith };
136fec247c0SSujith 
1371395d3f0SSujith /**
1381395d3f0SSujith  * struct ath_rx_stats - RX Statistics
13999c15bf5SBen Greear  * @rx_pkts_all:  No. of total frames received, including ones that
14099c15bf5SBen Greear 	may have had errors.
14199c15bf5SBen Greear  * @rx_bytes_all:  No. of total bytes received, including ones that
14299c15bf5SBen Greear 	may have had errors.
1431395d3f0SSujith  * @crc_err: No. of frames with incorrect CRC value
1441395d3f0SSujith  * @decrypt_crc_err: No. of frames whose CRC check failed after
1451395d3f0SSujith 	decryption process completed
1461395d3f0SSujith  * @phy_err: No. of frames whose reception failed because the PHY
1471395d3f0SSujith 	encountered an error
1481395d3f0SSujith  * @mic_err: No. of frames with incorrect TKIP MIC verification failure
1491395d3f0SSujith  * @pre_delim_crc_err: Pre-Frame delimiter CRC error detections
1501395d3f0SSujith  * @post_delim_crc_err: Post-Frame delimiter CRC error detections
1511395d3f0SSujith  * @decrypt_busy_err: Decryption interruptions counter
1521395d3f0SSujith  * @phy_err_stats: Individual PHY error statistics
1531395d3f0SSujith  */
1541395d3f0SSujith struct ath_rx_stats {
15599c15bf5SBen Greear 	u32 rx_pkts_all;
15699c15bf5SBen Greear 	u32 rx_bytes_all;
1571395d3f0SSujith 	u32 crc_err;
1581395d3f0SSujith 	u32 decrypt_crc_err;
1591395d3f0SSujith 	u32 phy_err;
1601395d3f0SSujith 	u32 mic_err;
1611395d3f0SSujith 	u32 pre_delim_crc_err;
1621395d3f0SSujith 	u32 post_delim_crc_err;
1631395d3f0SSujith 	u32 decrypt_busy_err;
1641395d3f0SSujith 	u32 phy_err_stats[ATH9K_PHYERR_MAX];
1657d755414SSenthil Balasubramanian 	int8_t rs_rssi_ctl0;
1667d755414SSenthil Balasubramanian 	int8_t rs_rssi_ctl1;
1677d755414SSenthil Balasubramanian 	int8_t rs_rssi_ctl2;
1687d755414SSenthil Balasubramanian 	int8_t rs_rssi_ext0;
1697d755414SSenthil Balasubramanian 	int8_t rs_rssi_ext1;
1707d755414SSenthil Balasubramanian 	int8_t rs_rssi_ext2;
1717d755414SSenthil Balasubramanian 	u8 rs_antenna;
1721395d3f0SSujith };
1731395d3f0SSujith 
174203c4805SLuis R. Rodriguez struct ath_stats {
175203c4805SLuis R. Rodriguez 	struct ath_interrupt_stats istats;
176fec247c0SSujith 	struct ath_tx_stats txstats[ATH9K_NUM_TX_QUEUES];
1771395d3f0SSujith 	struct ath_rx_stats rxstats;
178203c4805SLuis R. Rodriguez };
179203c4805SLuis R. Rodriguez 
180cf3af748SRajkumar Manoharan #define ATH_DBG_MAX_SAMPLES	10
181cf3af748SRajkumar Manoharan struct ath_dbg_bb_mac_samp {
182cf3af748SRajkumar Manoharan 	u32 dma_dbg_reg_vals[ATH9K_NUM_DMA_DEBUG_REGS];
183cf3af748SRajkumar Manoharan 	u32 pcu_obs, pcu_cr, noise;
184cf3af748SRajkumar Manoharan 	struct {
185cf3af748SRajkumar Manoharan 		u64 jiffies;
186cf3af748SRajkumar Manoharan 		int8_t rssi_ctl0;
187cf3af748SRajkumar Manoharan 		int8_t rssi_ctl1;
188cf3af748SRajkumar Manoharan 		int8_t rssi_ctl2;
189cf3af748SRajkumar Manoharan 		int8_t rssi_ext0;
190cf3af748SRajkumar Manoharan 		int8_t rssi_ext1;
191cf3af748SRajkumar Manoharan 		int8_t rssi_ext2;
192cf3af748SRajkumar Manoharan 		int8_t rssi;
193cf3af748SRajkumar Manoharan 		bool isok;
194cf3af748SRajkumar Manoharan 		u8 rts_fail_cnt;
195cf3af748SRajkumar Manoharan 		u8 data_fail_cnt;
196cf3af748SRajkumar Manoharan 		u8 rateindex;
197cf3af748SRajkumar Manoharan 		u8 qid;
198cf3af748SRajkumar Manoharan 		u8 tid;
19912932180SMohammed Shafi Shajakhan 		u32 ba_low;
20012932180SMohammed Shafi Shajakhan 		u32 ba_high;
201cf3af748SRajkumar Manoharan 	} ts[ATH_DBG_MAX_SAMPLES];
202cf3af748SRajkumar Manoharan 	struct {
203cf3af748SRajkumar Manoharan 		u64 jiffies;
204cf3af748SRajkumar Manoharan 		int8_t rssi_ctl0;
205cf3af748SRajkumar Manoharan 		int8_t rssi_ctl1;
206cf3af748SRajkumar Manoharan 		int8_t rssi_ctl2;
207cf3af748SRajkumar Manoharan 		int8_t rssi_ext0;
208cf3af748SRajkumar Manoharan 		int8_t rssi_ext1;
209cf3af748SRajkumar Manoharan 		int8_t rssi_ext2;
210cf3af748SRajkumar Manoharan 		int8_t rssi;
211cf3af748SRajkumar Manoharan 		bool is_mybeacon;
212cf3af748SRajkumar Manoharan 		u8 antenna;
213cf3af748SRajkumar Manoharan 		u8 rate;
214cf3af748SRajkumar Manoharan 	} rs[ATH_DBG_MAX_SAMPLES];
215cf3af748SRajkumar Manoharan 	struct ath_cycle_counters cc;
216cf3af748SRajkumar Manoharan 	struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
217cf3af748SRajkumar Manoharan };
218cf3af748SRajkumar Manoharan 
219203c4805SLuis R. Rodriguez struct ath9k_debug {
220203c4805SLuis R. Rodriguez 	struct dentry *debugfs_phy;
2219bff0bc4SFelix Fietkau 	u32 regidx;
222203c4805SLuis R. Rodriguez 	struct ath_stats stats;
223cf3af748SRajkumar Manoharan 	spinlock_t samp_lock;
224cf3af748SRajkumar Manoharan 	struct ath_dbg_bb_mac_samp bb_mac_samp[ATH_DBG_MAX_SAMPLES];
225cf3af748SRajkumar Manoharan 	u8 sampidx;
226cf3af748SRajkumar Manoharan 	u8 tsidx;
227cf3af748SRajkumar Manoharan 	u8 rsidx;
228203c4805SLuis R. Rodriguez };
229203c4805SLuis R. Rodriguez 
2304d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah);
2314d6b228dSLuis R. Rodriguez 
232cf3af748SRajkumar Manoharan void ath9k_debug_samp_bb_mac(struct ath_softc *sc);
233203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status);
234066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
23555797b1aSFelix Fietkau 		       struct ath_tx_status *ts, struct ath_txq *txq,
23655797b1aSFelix Fietkau 		       unsigned int flags);
2378e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs);
238203c4805SLuis R. Rodriguez 
239203c4805SLuis R. Rodriguez #else
240203c4805SLuis R. Rodriguez 
2414d6b228dSLuis R. Rodriguez static inline int ath9k_init_debug(struct ath_hw *ah)
242203c4805SLuis R. Rodriguez {
243203c4805SLuis R. Rodriguez 	return 0;
244203c4805SLuis R. Rodriguez }
245203c4805SLuis R. Rodriguez 
246cf3af748SRajkumar Manoharan static inline void ath9k_debug_samp_bb_mac(struct ath_softc *sc)
247cf3af748SRajkumar Manoharan {
248cf3af748SRajkumar Manoharan }
249cf3af748SRajkumar Manoharan 
250203c4805SLuis R. Rodriguez static inline void ath_debug_stat_interrupt(struct ath_softc *sc,
251203c4805SLuis R. Rodriguez 					    enum ath9k_int status)
252203c4805SLuis R. Rodriguez {
253203c4805SLuis R. Rodriguez }
254203c4805SLuis R. Rodriguez 
255fec247c0SSujith static inline void ath_debug_stat_tx(struct ath_softc *sc,
25632ffb1f4SFelix Fietkau 				     struct ath_buf *bf,
2573bf63e59SFelix Fietkau 				     struct ath_tx_status *ts,
25855797b1aSFelix Fietkau 				     struct ath_txq *txq,
25955797b1aSFelix Fietkau 				     unsigned int flags)
260fec247c0SSujith {
261fec247c0SSujith }
262fec247c0SSujith 
2631395d3f0SSujith static inline void ath_debug_stat_rx(struct ath_softc *sc,
26432ffb1f4SFelix Fietkau 				     struct ath_rx_status *rs)
2651395d3f0SSujith {
2661395d3f0SSujith }
2671395d3f0SSujith 
268a830df07SFelix Fietkau #endif /* CONFIG_ATH9K_DEBUGFS */
269203c4805SLuis R. Rodriguez 
270203c4805SLuis R. Rodriguez #endif /* DEBUG_H */
271