18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Atheros CARL9170 driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * debug header
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright 2010, Christian Lamparter <chunkeey@googlemail.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
98c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
108c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
118c2ecf20Sopenharmony_ci * (at your option) any later version.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
148c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
158c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168c2ecf20Sopenharmony_ci * GNU General Public License for more details.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
198c2ecf20Sopenharmony_ci * along with this program; see the file COPYING.  If not, see
208c2ecf20Sopenharmony_ci * http://www.gnu.org/licenses/.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and
238c2ecf20Sopenharmony_ci * permission notice:
248c2ecf20Sopenharmony_ci *    Copyright (c) 2007-2008 Atheros Communications, Inc.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *    Permission to use, copy, modify, and/or distribute this software for any
278c2ecf20Sopenharmony_ci *    purpose with or without fee is hereby granted, provided that the above
288c2ecf20Sopenharmony_ci *    copyright notice and this permission notice appear in all copies.
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
318c2ecf20Sopenharmony_ci *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
328c2ecf20Sopenharmony_ci *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
338c2ecf20Sopenharmony_ci *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
348c2ecf20Sopenharmony_ci *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
358c2ecf20Sopenharmony_ci *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
368c2ecf20Sopenharmony_ci *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci#ifndef __DEBUG_H
398c2ecf20Sopenharmony_ci#define __DEBUG_H
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#include "eeprom.h"
428c2ecf20Sopenharmony_ci#include "wlan.h"
438c2ecf20Sopenharmony_ci#include "hw.h"
448c2ecf20Sopenharmony_ci#include "fwdesc.h"
458c2ecf20Sopenharmony_ci#include "fwcmd.h"
468c2ecf20Sopenharmony_ci#include "../regd.h"
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct hw_stat_reg_entry {
498c2ecf20Sopenharmony_ci	u32 reg;
508c2ecf20Sopenharmony_ci	char nreg[32];
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define	STAT_MAC_REG(reg)	\
548c2ecf20Sopenharmony_ci	{ (AR9170_MAC_REG_##reg), #reg }
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define	STAT_PTA_REG(reg)	\
578c2ecf20Sopenharmony_ci	{ (AR9170_PTA_REG_##reg), #reg }
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define	STAT_USB_REG(reg)	\
608c2ecf20Sopenharmony_ci	{ (AR9170_USB_REG_##reg), #reg }
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic const struct hw_stat_reg_entry hw_rx_tally_regs[] = {
638c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_CRC32),		STAT_MAC_REG(RX_CRC16),
648c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_TIMEOUT_COUNT),	STAT_MAC_REG(RX_ERR_DECRYPTION_UNI),
658c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_ERR_DECRYPTION_MUL), STAT_MAC_REG(RX_MPDU),
668c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_DROPPED_MPDU),	STAT_MAC_REG(RX_DEL_MPDU),
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic const struct hw_stat_reg_entry hw_phy_errors_regs[] = {
708c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_PHY_MISC_ERROR), STAT_MAC_REG(RX_PHY_XR_ERROR),
718c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_PHY_OFDM_ERROR), STAT_MAC_REG(RX_PHY_CCK_ERROR),
728c2ecf20Sopenharmony_ci	STAT_MAC_REG(RX_PHY_HT_ERROR), STAT_MAC_REG(RX_PHY_TOTAL),
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic const struct hw_stat_reg_entry hw_tx_tally_regs[] = {
768c2ecf20Sopenharmony_ci	STAT_MAC_REG(TX_TOTAL),		STAT_MAC_REG(TX_UNDERRUN),
778c2ecf20Sopenharmony_ci	STAT_MAC_REG(TX_RETRY),
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic const struct hw_stat_reg_entry hw_wlan_queue_regs[] = {
818c2ecf20Sopenharmony_ci	STAT_MAC_REG(DMA_STATUS),	STAT_MAC_REG(DMA_TRIGGER),
828c2ecf20Sopenharmony_ci	STAT_MAC_REG(DMA_TXQ0_ADDR),	STAT_MAC_REG(DMA_TXQ0_CURR_ADDR),
838c2ecf20Sopenharmony_ci	STAT_MAC_REG(DMA_TXQ1_ADDR),	STAT_MAC_REG(DMA_TXQ1_CURR_ADDR),
848c2ecf20Sopenharmony_ci	STAT_MAC_REG(DMA_TXQ2_ADDR),	STAT_MAC_REG(DMA_TXQ2_CURR_ADDR),
858c2ecf20Sopenharmony_ci	STAT_MAC_REG(DMA_TXQ3_ADDR),	STAT_MAC_REG(DMA_TXQ3_CURR_ADDR),
868c2ecf20Sopenharmony_ci	STAT_MAC_REG(DMA_RXQ_ADDR),	STAT_MAC_REG(DMA_RXQ_CURR_ADDR),
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic const struct hw_stat_reg_entry hw_ampdu_info_regs[] = {
908c2ecf20Sopenharmony_ci	STAT_MAC_REG(AMPDU_DENSITY),	STAT_MAC_REG(AMPDU_FACTOR),
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic const struct hw_stat_reg_entry hw_pta_queue_regs[] = {
948c2ecf20Sopenharmony_ci	STAT_PTA_REG(DN_CURR_ADDRH),	STAT_PTA_REG(DN_CURR_ADDRL),
958c2ecf20Sopenharmony_ci	STAT_PTA_REG(UP_CURR_ADDRH),	STAT_PTA_REG(UP_CURR_ADDRL),
968c2ecf20Sopenharmony_ci	STAT_PTA_REG(DMA_STATUS),	STAT_PTA_REG(DMA_MODE_CTRL),
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define	DEFINE_TALLY(name)					\
1008c2ecf20Sopenharmony_ci	u32 name##_sum[ARRAY_SIZE(name##_regs)],		\
1018c2ecf20Sopenharmony_ci	    name##_counter[ARRAY_SIZE(name##_regs)]		\
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define	DEFINE_STAT(name)					\
1048c2ecf20Sopenharmony_ci	u32 name##_counter[ARRAY_SIZE(name##_regs)]		\
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistruct ath_stats {
1078c2ecf20Sopenharmony_ci	DEFINE_TALLY(hw_tx_tally);
1088c2ecf20Sopenharmony_ci	DEFINE_TALLY(hw_rx_tally);
1098c2ecf20Sopenharmony_ci	DEFINE_TALLY(hw_phy_errors);
1108c2ecf20Sopenharmony_ci	DEFINE_STAT(hw_wlan_queue);
1118c2ecf20Sopenharmony_ci	DEFINE_STAT(hw_pta_queue);
1128c2ecf20Sopenharmony_ci	DEFINE_STAT(hw_ampdu_info);
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistruct carl9170_debug_mem_rbe {
1168c2ecf20Sopenharmony_ci	u32 reg;
1178c2ecf20Sopenharmony_ci	u32 value;
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define	CARL9170_DEBUG_RING_SIZE			64
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct carl9170_debug {
1238c2ecf20Sopenharmony_ci	struct ath_stats stats;
1248c2ecf20Sopenharmony_ci	struct carl9170_debug_mem_rbe ring[CARL9170_DEBUG_RING_SIZE];
1258c2ecf20Sopenharmony_ci	struct mutex ring_lock;
1268c2ecf20Sopenharmony_ci	unsigned int ring_head, ring_tail;
1278c2ecf20Sopenharmony_ci	struct delayed_work update_tally;
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cistruct ar9170;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_civoid carl9170_debugfs_register(struct ar9170 *ar);
1338c2ecf20Sopenharmony_civoid carl9170_debugfs_unregister(struct ar9170 *ar);
1348c2ecf20Sopenharmony_ci#endif /* __DEBUG_H */
135