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" 2229942bc1SZefir Kurtisi #include "dfs_debug.h" 234d6b228dSLuis R. Rodriguez 24fec247c0SSujith struct ath_txq; 25fec247c0SSujith struct ath_buf; 26fec247c0SSujith 27a830df07SFelix Fietkau #ifdef CONFIG_ATH9K_DEBUGFS 28fec247c0SSujith #define TX_STAT_INC(q, c) sc->debug.stats.txstats[q].c++ 29030d6294SFelix Fietkau #define RESET_STAT_INC(sc, type) sc->debug.stats.reset[type]++ 30fec247c0SSujith #else 31fec247c0SSujith #define TX_STAT_INC(q, c) do { } while (0) 32030d6294SFelix Fietkau #define RESET_STAT_INC(sc, type) do { } while (0) 33fec247c0SSujith #endif 34fec247c0SSujith 35124b979bSRajkumar Manoharan enum ath_reset_type { 36124b979bSRajkumar Manoharan RESET_TYPE_BB_HANG, 37124b979bSRajkumar Manoharan RESET_TYPE_BB_WATCHDOG, 38124b979bSRajkumar Manoharan RESET_TYPE_FATAL_INT, 39124b979bSRajkumar Manoharan RESET_TYPE_TX_ERROR, 40124b979bSRajkumar Manoharan RESET_TYPE_TX_HANG, 41124b979bSRajkumar Manoharan RESET_TYPE_PLL_HANG, 42124b979bSRajkumar Manoharan RESET_TYPE_MAC_HANG, 43124b979bSRajkumar Manoharan RESET_TYPE_BEACON_STUCK, 44124b979bSRajkumar Manoharan RESET_TYPE_MCI, 45124b979bSRajkumar Manoharan __RESET_TYPE_MAX 46124b979bSRajkumar Manoharan }; 47124b979bSRajkumar Manoharan 48a830df07SFelix Fietkau #ifdef CONFIG_ATH9K_DEBUGFS 49203c4805SLuis R. Rodriguez 50203c4805SLuis R. Rodriguez /** 51203c4805SLuis R. Rodriguez * struct ath_interrupt_stats - Contains statistics about interrupts 52203c4805SLuis R. Rodriguez * @total: Total no. of interrupts generated so far 53203c4805SLuis R. Rodriguez * @rxok: RX with no errors 54a9616f41SLuis R. Rodriguez * @rxlp: RX with low priority RX 55a9616f41SLuis R. Rodriguez * @rxhp: RX with high priority, uapsd only 56203c4805SLuis R. Rodriguez * @rxeol: RX with no more RXDESC available 57203c4805SLuis R. Rodriguez * @rxorn: RX FIFO overrun 58203c4805SLuis R. Rodriguez * @txok: TX completed at the requested rate 59203c4805SLuis R. Rodriguez * @txurn: TX FIFO underrun 60203c4805SLuis R. Rodriguez * @mib: MIB regs reaching its threshold 61203c4805SLuis R. Rodriguez * @rxphyerr: RX with phy errors 62203c4805SLuis R. Rodriguez * @rx_keycache_miss: RX with key cache misses 63203c4805SLuis R. Rodriguez * @swba: Software Beacon Alert 64203c4805SLuis R. Rodriguez * @bmiss: Beacon Miss 65203c4805SLuis R. Rodriguez * @bnr: Beacon Not Ready 66203c4805SLuis R. Rodriguez * @cst: Carrier Sense TImeout 67203c4805SLuis R. Rodriguez * @gtt: Global TX Timeout 68203c4805SLuis R. Rodriguez * @tim: RX beacon TIM occurrence 69203c4805SLuis R. Rodriguez * @cabend: RX End of CAB traffic 70203c4805SLuis R. Rodriguez * @dtimsync: DTIM sync lossage 71203c4805SLuis R. Rodriguez * @dtim: RX Beacon with DTIM 7208578b8fSLuis R. Rodriguez * @bb_watchdog: Baseband watchdog 736dde1aabSMohammed Shafi Shajakhan * @tsfoor: TSF out of range, indicates that the corrected TSF received 746dde1aabSMohammed Shafi Shajakhan * from a beacon differs from the PCU's internal TSF by more than a 756dde1aabSMohammed Shafi Shajakhan * (programmable) threshold 76462e58f2SBen Greear * @local_timeout: Internal bus timeout. 77203c4805SLuis R. Rodriguez */ 78203c4805SLuis R. Rodriguez struct ath_interrupt_stats { 79203c4805SLuis R. Rodriguez u32 total; 80203c4805SLuis R. Rodriguez u32 rxok; 81a9616f41SLuis R. Rodriguez u32 rxlp; 82a9616f41SLuis R. Rodriguez u32 rxhp; 83203c4805SLuis R. Rodriguez u32 rxeol; 84203c4805SLuis R. Rodriguez u32 rxorn; 85203c4805SLuis R. Rodriguez u32 txok; 86203c4805SLuis R. Rodriguez u32 txeol; 87203c4805SLuis R. Rodriguez u32 txurn; 88203c4805SLuis R. Rodriguez u32 mib; 89203c4805SLuis R. Rodriguez u32 rxphyerr; 90203c4805SLuis R. Rodriguez u32 rx_keycache_miss; 91203c4805SLuis R. Rodriguez u32 swba; 92203c4805SLuis R. Rodriguez u32 bmiss; 93203c4805SLuis R. Rodriguez u32 bnr; 94203c4805SLuis R. Rodriguez u32 cst; 95203c4805SLuis R. Rodriguez u32 gtt; 96203c4805SLuis R. Rodriguez u32 tim; 97203c4805SLuis R. Rodriguez u32 cabend; 98203c4805SLuis R. Rodriguez u32 dtimsync; 99203c4805SLuis R. Rodriguez u32 dtim; 10008578b8fSLuis R. Rodriguez u32 bb_watchdog; 1016dde1aabSMohammed Shafi Shajakhan u32 tsfoor; 10297ba515aSSujith Manoharan u32 mci; 103462e58f2SBen Greear 104462e58f2SBen Greear /* Sync-cause stats */ 105462e58f2SBen Greear u32 sync_cause_all; 106462e58f2SBen Greear u32 sync_rtc_irq; 107462e58f2SBen Greear u32 sync_mac_irq; 108462e58f2SBen Greear u32 eeprom_illegal_access; 109462e58f2SBen Greear u32 apb_timeout; 110462e58f2SBen Greear u32 pci_mode_conflict; 111462e58f2SBen Greear u32 host1_fatal; 112462e58f2SBen Greear u32 host1_perr; 113462e58f2SBen Greear u32 trcv_fifo_perr; 114462e58f2SBen Greear u32 radm_cpl_ep; 115462e58f2SBen Greear u32 radm_cpl_dllp_abort; 116462e58f2SBen Greear u32 radm_cpl_tlp_abort; 117462e58f2SBen Greear u32 radm_cpl_ecrc_err; 118462e58f2SBen Greear u32 radm_cpl_timeout; 119462e58f2SBen Greear u32 local_timeout; 120462e58f2SBen Greear u32 pm_access; 121462e58f2SBen Greear u32 mac_awake; 122462e58f2SBen Greear u32 mac_asleep; 123462e58f2SBen Greear u32 mac_sleep_access; 124203c4805SLuis R. Rodriguez }; 125203c4805SLuis R. Rodriguez 126462e58f2SBen Greear 127fec247c0SSujith /** 128fec247c0SSujith * struct ath_tx_stats - Statistics about TX 12999c15bf5SBen Greear * @tx_pkts_all: No. of total frames transmitted, including ones that 13099c15bf5SBen Greear may have had errors. 13199c15bf5SBen Greear * @tx_bytes_all: No. of total bytes transmitted, including ones that 13299c15bf5SBen Greear may have had errors. 133fec247c0SSujith * @queued: Total MPDUs (non-aggr) queued 134fec247c0SSujith * @completed: Total MPDUs (non-aggr) completed 135fec247c0SSujith * @a_aggr: Total no. of aggregates queued 136bda8addaSBen Greear * @a_queued_hw: Total AMPDUs queued to hardware 137bda8addaSBen Greear * @a_queued_sw: Total AMPDUs queued to software queues 138fec247c0SSujith * @a_completed: Total AMPDUs completed 139fec247c0SSujith * @a_retries: No. of AMPDUs retried (SW) 140fec247c0SSujith * @a_xretries: No. of AMPDUs dropped due to xretries 141fec247c0SSujith * @fifo_underrun: FIFO underrun occurrences 142fec247c0SSujith Valid only for: 143fec247c0SSujith - non-aggregate condition. 144fec247c0SSujith - first packet of aggregate. 145fec247c0SSujith * @xtxop: No. of frames filtered because of TXOP limit 146fec247c0SSujith * @timer_exp: Transmit timer expiry 147fec247c0SSujith * @desc_cfg_err: Descriptor configuration errors 148fec247c0SSujith * @data_urn: TX data underrun errors 149fec247c0SSujith * @delim_urn: TX delimiter underrun errors 1502dac4fb9SBen Greear * @puttxbuf: Number of times hardware was given txbuf to write. 1512dac4fb9SBen Greear * @txstart: Number of times hardware was told to start tx. 1522dac4fb9SBen Greear * @txprocdesc: Number of times tx descriptor was processed 153a5a0bca1SBen Greear * @txfailed: Out-of-memory or other errors in xmit path. 154fec247c0SSujith */ 155fec247c0SSujith struct ath_tx_stats { 15699c15bf5SBen Greear u32 tx_pkts_all; 15799c15bf5SBen Greear u32 tx_bytes_all; 158fec247c0SSujith u32 queued; 159fec247c0SSujith u32 completed; 1605a6f78afSFelix Fietkau u32 xretries; 161fec247c0SSujith u32 a_aggr; 162bda8addaSBen Greear u32 a_queued_hw; 163bda8addaSBen Greear u32 a_queued_sw; 164fec247c0SSujith u32 a_completed; 165fec247c0SSujith u32 a_retries; 166fec247c0SSujith u32 a_xretries; 167fec247c0SSujith u32 fifo_underrun; 168fec247c0SSujith u32 xtxop; 169fec247c0SSujith u32 timer_exp; 170fec247c0SSujith u32 desc_cfg_err; 171fec247c0SSujith u32 data_underrun; 172fec247c0SSujith u32 delim_underrun; 1732dac4fb9SBen Greear u32 puttxbuf; 1742dac4fb9SBen Greear u32 txstart; 1752dac4fb9SBen Greear u32 txprocdesc; 176a5a0bca1SBen Greear u32 txfailed; 177fec247c0SSujith }; 178fec247c0SSujith 17915072189SBen Greear #define RX_STAT_INC(c) (sc->debug.stats.rxstats.c++) 18015072189SBen Greear 1811395d3f0SSujith /** 1821395d3f0SSujith * struct ath_rx_stats - RX Statistics 18399c15bf5SBen Greear * @rx_pkts_all: No. of total frames received, including ones that 18499c15bf5SBen Greear may have had errors. 18599c15bf5SBen Greear * @rx_bytes_all: No. of total bytes received, including ones that 18699c15bf5SBen Greear may have had errors. 1871395d3f0SSujith * @crc_err: No. of frames with incorrect CRC value 1881395d3f0SSujith * @decrypt_crc_err: No. of frames whose CRC check failed after 1891395d3f0SSujith decryption process completed 1901395d3f0SSujith * @phy_err: No. of frames whose reception failed because the PHY 1911395d3f0SSujith encountered an error 1921395d3f0SSujith * @mic_err: No. of frames with incorrect TKIP MIC verification failure 1931395d3f0SSujith * @pre_delim_crc_err: Pre-Frame delimiter CRC error detections 1941395d3f0SSujith * @post_delim_crc_err: Post-Frame delimiter CRC error detections 1951395d3f0SSujith * @decrypt_busy_err: Decryption interruptions counter 1961395d3f0SSujith * @phy_err_stats: Individual PHY error statistics 19715072189SBen Greear * @rx_len_err: No. of frames discarded due to bad length. 19815072189SBen Greear * @rx_oom_err: No. of frames dropped due to OOM issues. 19915072189SBen Greear * @rx_rate_err: No. of frames dropped due to rate errors. 20015072189SBen Greear * @rx_too_many_frags_err: Frames dropped due to too-many-frags received. 20115072189SBen Greear * @rx_drop_rxflush: No. of frames dropped due to RX-FLUSH. 20215072189SBen Greear * @rx_beacons: No. of beacons received. 20315072189SBen Greear * @rx_frags: No. of rx-fragements received. 2041395d3f0SSujith */ 2051395d3f0SSujith struct ath_rx_stats { 20699c15bf5SBen Greear u32 rx_pkts_all; 20799c15bf5SBen Greear u32 rx_bytes_all; 2081395d3f0SSujith u32 crc_err; 2091395d3f0SSujith u32 decrypt_crc_err; 2101395d3f0SSujith u32 phy_err; 2111395d3f0SSujith u32 mic_err; 2121395d3f0SSujith u32 pre_delim_crc_err; 2131395d3f0SSujith u32 post_delim_crc_err; 2141395d3f0SSujith u32 decrypt_busy_err; 2151395d3f0SSujith u32 phy_err_stats[ATH9K_PHYERR_MAX]; 21615072189SBen Greear u32 rx_len_err; 21715072189SBen Greear u32 rx_oom_err; 21815072189SBen Greear u32 rx_rate_err; 21915072189SBen Greear u32 rx_too_many_frags_err; 22015072189SBen Greear u32 rx_drop_rxflush; 22115072189SBen Greear u32 rx_beacons; 22215072189SBen Greear u32 rx_frags; 2231395d3f0SSujith }; 2241395d3f0SSujith 225203c4805SLuis R. Rodriguez struct ath_stats { 226203c4805SLuis R. Rodriguez struct ath_interrupt_stats istats; 227fec247c0SSujith struct ath_tx_stats txstats[ATH9K_NUM_TX_QUEUES]; 2281395d3f0SSujith struct ath_rx_stats rxstats; 22929942bc1SZefir Kurtisi struct ath_dfs_stats dfs_stats; 230030d6294SFelix Fietkau u32 reset[__RESET_TYPE_MAX]; 231203c4805SLuis R. Rodriguez }; 232203c4805SLuis R. Rodriguez 233cf3af748SRajkumar Manoharan #define ATH_DBG_MAX_SAMPLES 10 234cf3af748SRajkumar Manoharan struct ath_dbg_bb_mac_samp { 235cf3af748SRajkumar Manoharan u32 dma_dbg_reg_vals[ATH9K_NUM_DMA_DEBUG_REGS]; 236cf3af748SRajkumar Manoharan u32 pcu_obs, pcu_cr, noise; 237cf3af748SRajkumar Manoharan struct { 238cf3af748SRajkumar Manoharan u64 jiffies; 239cf3af748SRajkumar Manoharan int8_t rssi_ctl0; 240cf3af748SRajkumar Manoharan int8_t rssi_ctl1; 241cf3af748SRajkumar Manoharan int8_t rssi_ctl2; 242cf3af748SRajkumar Manoharan int8_t rssi_ext0; 243cf3af748SRajkumar Manoharan int8_t rssi_ext1; 244cf3af748SRajkumar Manoharan int8_t rssi_ext2; 245cf3af748SRajkumar Manoharan int8_t rssi; 246cf3af748SRajkumar Manoharan bool isok; 247cf3af748SRajkumar Manoharan u8 rts_fail_cnt; 248cf3af748SRajkumar Manoharan u8 data_fail_cnt; 249cf3af748SRajkumar Manoharan u8 rateindex; 250cf3af748SRajkumar Manoharan u8 qid; 251cf3af748SRajkumar Manoharan u8 tid; 25212932180SMohammed Shafi Shajakhan u32 ba_low; 25312932180SMohammed Shafi Shajakhan u32 ba_high; 254cf3af748SRajkumar Manoharan } ts[ATH_DBG_MAX_SAMPLES]; 255cf3af748SRajkumar Manoharan struct { 256cf3af748SRajkumar Manoharan u64 jiffies; 257cf3af748SRajkumar Manoharan int8_t rssi_ctl0; 258cf3af748SRajkumar Manoharan int8_t rssi_ctl1; 259cf3af748SRajkumar Manoharan int8_t rssi_ctl2; 260cf3af748SRajkumar Manoharan int8_t rssi_ext0; 261cf3af748SRajkumar Manoharan int8_t rssi_ext1; 262cf3af748SRajkumar Manoharan int8_t rssi_ext2; 263cf3af748SRajkumar Manoharan int8_t rssi; 264cf3af748SRajkumar Manoharan bool is_mybeacon; 265cf3af748SRajkumar Manoharan u8 antenna; 266cf3af748SRajkumar Manoharan u8 rate; 267cf3af748SRajkumar Manoharan } rs[ATH_DBG_MAX_SAMPLES]; 268cf3af748SRajkumar Manoharan struct ath_cycle_counters cc; 269cf3af748SRajkumar Manoharan struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS]; 270cf3af748SRajkumar Manoharan }; 271cf3af748SRajkumar Manoharan 272203c4805SLuis R. Rodriguez struct ath9k_debug { 273203c4805SLuis R. Rodriguez struct dentry *debugfs_phy; 2749bff0bc4SFelix Fietkau u32 regidx; 275203c4805SLuis R. Rodriguez struct ath_stats stats; 2765baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG 277cf3af748SRajkumar Manoharan spinlock_t samp_lock; 278cf3af748SRajkumar Manoharan struct ath_dbg_bb_mac_samp bb_mac_samp[ATH_DBG_MAX_SAMPLES]; 279cf3af748SRajkumar Manoharan u8 sampidx; 280cf3af748SRajkumar Manoharan u8 tsidx; 281cf3af748SRajkumar Manoharan u8 rsidx; 2825baec742SFelix Fietkau #endif 283203c4805SLuis R. Rodriguez }; 284203c4805SLuis R. Rodriguez 2854d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah); 2864d6b228dSLuis R. Rodriguez 287203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status); 288066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf, 28955797b1aSFelix Fietkau struct ath_tx_status *ts, struct ath_txq *txq, 29055797b1aSFelix Fietkau unsigned int flags); 2918e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs); 292203c4805SLuis R. Rodriguez 293203c4805SLuis R. Rodriguez #else 294203c4805SLuis R. Rodriguez 29515072189SBen Greear #define RX_STAT_INC(c) /* NOP */ 29615072189SBen Greear 2974d6b228dSLuis R. Rodriguez static inline int ath9k_init_debug(struct ath_hw *ah) 298203c4805SLuis R. Rodriguez { 299203c4805SLuis R. Rodriguez return 0; 300203c4805SLuis R. Rodriguez } 301203c4805SLuis R. Rodriguez 302203c4805SLuis R. Rodriguez static inline void ath_debug_stat_interrupt(struct ath_softc *sc, 303203c4805SLuis R. Rodriguez enum ath9k_int status) 304203c4805SLuis R. Rodriguez { 305203c4805SLuis R. Rodriguez } 306203c4805SLuis R. Rodriguez 307fec247c0SSujith static inline void ath_debug_stat_tx(struct ath_softc *sc, 30832ffb1f4SFelix Fietkau struct ath_buf *bf, 3093bf63e59SFelix Fietkau struct ath_tx_status *ts, 31055797b1aSFelix Fietkau struct ath_txq *txq, 31155797b1aSFelix Fietkau unsigned int flags) 312fec247c0SSujith { 313fec247c0SSujith } 314fec247c0SSujith 3151395d3f0SSujith static inline void ath_debug_stat_rx(struct ath_softc *sc, 31632ffb1f4SFelix Fietkau struct ath_rx_status *rs) 3171395d3f0SSujith { 3181395d3f0SSujith } 3191395d3f0SSujith 320a830df07SFelix Fietkau #endif /* CONFIG_ATH9K_DEBUGFS */ 321203c4805SLuis R. Rodriguez 3225baec742SFelix Fietkau #ifdef CONFIG_ATH9K_MAC_DEBUG 3235baec742SFelix Fietkau 3245baec742SFelix Fietkau void ath9k_debug_samp_bb_mac(struct ath_softc *sc); 3255baec742SFelix Fietkau 3265baec742SFelix Fietkau #else 3275baec742SFelix Fietkau 3285baec742SFelix Fietkau static inline void ath9k_debug_samp_bb_mac(struct ath_softc *sc) 3295baec742SFelix Fietkau { 3305baec742SFelix Fietkau } 3315baec742SFelix Fietkau 3325baec742SFelix Fietkau #endif 3335baec742SFelix Fietkau 3345baec742SFelix Fietkau 335203c4805SLuis R. Rodriguez #endif /* DEBUG_H */ 336