18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ISC */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2005-2011 Atheros Communications Inc.
48c2ecf20Sopenharmony_ci * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
58c2ecf20Sopenharmony_ci * Copyright (c) 2018, The Linux Foundation. All rights reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _DEBUG_H_
98c2ecf20Sopenharmony_ci#define _DEBUG_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/types.h>
128c2ecf20Sopenharmony_ci#include "trace.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cienum ath10k_debug_mask {
158c2ecf20Sopenharmony_ci	ATH10K_DBG_PCI		= 0x00000001,
168c2ecf20Sopenharmony_ci	ATH10K_DBG_WMI		= 0x00000002,
178c2ecf20Sopenharmony_ci	ATH10K_DBG_HTC		= 0x00000004,
188c2ecf20Sopenharmony_ci	ATH10K_DBG_HTT		= 0x00000008,
198c2ecf20Sopenharmony_ci	ATH10K_DBG_MAC		= 0x00000010,
208c2ecf20Sopenharmony_ci	ATH10K_DBG_BOOT		= 0x00000020,
218c2ecf20Sopenharmony_ci	ATH10K_DBG_PCI_DUMP	= 0x00000040,
228c2ecf20Sopenharmony_ci	ATH10K_DBG_HTT_DUMP	= 0x00000080,
238c2ecf20Sopenharmony_ci	ATH10K_DBG_MGMT		= 0x00000100,
248c2ecf20Sopenharmony_ci	ATH10K_DBG_DATA		= 0x00000200,
258c2ecf20Sopenharmony_ci	ATH10K_DBG_BMI		= 0x00000400,
268c2ecf20Sopenharmony_ci	ATH10K_DBG_REGULATORY	= 0x00000800,
278c2ecf20Sopenharmony_ci	ATH10K_DBG_TESTMODE	= 0x00001000,
288c2ecf20Sopenharmony_ci	ATH10K_DBG_WMI_PRINT	= 0x00002000,
298c2ecf20Sopenharmony_ci	ATH10K_DBG_PCI_PS	= 0x00004000,
308c2ecf20Sopenharmony_ci	ATH10K_DBG_AHB		= 0x00008000,
318c2ecf20Sopenharmony_ci	ATH10K_DBG_SDIO		= 0x00010000,
328c2ecf20Sopenharmony_ci	ATH10K_DBG_SDIO_DUMP	= 0x00020000,
338c2ecf20Sopenharmony_ci	ATH10K_DBG_USB		= 0x00040000,
348c2ecf20Sopenharmony_ci	ATH10K_DBG_USB_BULK	= 0x00080000,
358c2ecf20Sopenharmony_ci	ATH10K_DBG_SNOC		= 0x00100000,
368c2ecf20Sopenharmony_ci	ATH10K_DBG_QMI		= 0x00200000,
378c2ecf20Sopenharmony_ci	ATH10K_DBG_ANY		= 0xffffffff,
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cienum ath10k_pktlog_filter {
418c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_RX         = 0x000000001,
428c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_TX         = 0x000000002,
438c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_RCFIND     = 0x000000004,
448c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_RCUPDATE   = 0x000000008,
458c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_DBG_PRINT  = 0x000000010,
468c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_PEER_STATS = 0x000000040,
478c2ecf20Sopenharmony_ci	ATH10K_PKTLOG_ANY        = 0x00000005f,
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cienum ath10k_dbg_aggr_mode {
518c2ecf20Sopenharmony_ci	ATH10K_DBG_AGGR_MODE_AUTO,
528c2ecf20Sopenharmony_ci	ATH10K_DBG_AGGR_MODE_MANUAL,
538c2ecf20Sopenharmony_ci	ATH10K_DBG_AGGR_MODE_MAX,
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* Types of packet log events */
578c2ecf20Sopenharmony_cienum ath_pktlog_type {
588c2ecf20Sopenharmony_ci	ATH_PKTLOG_TYPE_TX_CTRL = 1,
598c2ecf20Sopenharmony_ci	ATH_PKTLOG_TYPE_TX_STAT,
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct ath10k_pktlog_hdr {
638c2ecf20Sopenharmony_ci	__le16 flags;
648c2ecf20Sopenharmony_ci	__le16 missed_cnt;
658c2ecf20Sopenharmony_ci	__le16 log_type; /* Type of log information foll this header */
668c2ecf20Sopenharmony_ci	__le16 size; /* Size of variable length log information in bytes */
678c2ecf20Sopenharmony_ci	__le32 timestamp;
688c2ecf20Sopenharmony_ci	u8 payload[];
698c2ecf20Sopenharmony_ci} __packed;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* FIXME: How to calculate the buffer size sanely? */
728c2ecf20Sopenharmony_ci#define ATH10K_FW_STATS_BUF_SIZE (1024 * 1024)
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define ATH10K_TX_POWER_MAX_VAL 70
758c2ecf20Sopenharmony_ci#define ATH10K_TX_POWER_MIN_VAL 0
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciextern unsigned int ath10k_debug_mask;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci__printf(2, 3) void ath10k_info(struct ath10k *ar, const char *fmt, ...);
808c2ecf20Sopenharmony_ci__printf(2, 3) void ath10k_err(struct ath10k *ar, const char *fmt, ...);
818c2ecf20Sopenharmony_ci__printf(2, 3) void ath10k_warn(struct ath10k *ar, const char *fmt, ...);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_civoid ath10k_debug_print_hwfw_info(struct ath10k *ar);
848c2ecf20Sopenharmony_civoid ath10k_debug_print_board_info(struct ath10k *ar);
858c2ecf20Sopenharmony_civoid ath10k_debug_print_boot_info(struct ath10k *ar);
868c2ecf20Sopenharmony_civoid ath10k_print_driver_info(struct ath10k *ar);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH10K_DEBUGFS
898c2ecf20Sopenharmony_ciint ath10k_debug_start(struct ath10k *ar);
908c2ecf20Sopenharmony_civoid ath10k_debug_stop(struct ath10k *ar);
918c2ecf20Sopenharmony_ciint ath10k_debug_create(struct ath10k *ar);
928c2ecf20Sopenharmony_civoid ath10k_debug_destroy(struct ath10k *ar);
938c2ecf20Sopenharmony_ciint ath10k_debug_register(struct ath10k *ar);
948c2ecf20Sopenharmony_civoid ath10k_debug_unregister(struct ath10k *ar);
958c2ecf20Sopenharmony_civoid ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb);
968c2ecf20Sopenharmony_civoid ath10k_debug_tpc_stats_process(struct ath10k *ar,
978c2ecf20Sopenharmony_ci				    struct ath10k_tpc_stats *tpc_stats);
988c2ecf20Sopenharmony_civoid
998c2ecf20Sopenharmony_ciath10k_debug_tpc_stats_final_process(struct ath10k *ar,
1008c2ecf20Sopenharmony_ci				     struct ath10k_tpc_stats_final *tpc_stats);
1018c2ecf20Sopenharmony_civoid ath10k_debug_dbglog_add(struct ath10k *ar, u8 *buffer, int len);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define ATH10K_DFS_STAT_INC(ar, c) (ar->debug.dfs_stats.c++)
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_civoid ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1068c2ecf20Sopenharmony_ci				 struct ieee80211_vif *vif,
1078c2ecf20Sopenharmony_ci				 u32 sset, u8 *data);
1088c2ecf20Sopenharmony_ciint ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1098c2ecf20Sopenharmony_ci				   struct ieee80211_vif *vif, int sset);
1108c2ecf20Sopenharmony_civoid ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1118c2ecf20Sopenharmony_ci			       struct ieee80211_vif *vif,
1128c2ecf20Sopenharmony_ci			       struct ethtool_stats *stats, u64 *data);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline u64 ath10k_debug_get_fw_dbglog_mask(struct ath10k *ar)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	return ar->debug.fw_dbglog_mask;
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistatic inline u32 ath10k_debug_get_fw_dbglog_level(struct ath10k *ar)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	return ar->debug.fw_dbglog_level;
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline int ath10k_debug_is_extd_tx_stats_enabled(struct ath10k *ar)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	return ar->debug.enable_extd_tx_stats;
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciint ath10k_debug_fw_stats_request(struct ath10k *ar);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#else
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic inline int ath10k_debug_start(struct ath10k *ar)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return 0;
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic inline void ath10k_debug_stop(struct ath10k *ar)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic inline int ath10k_debug_create(struct ath10k *ar)
1438c2ecf20Sopenharmony_ci{
1448c2ecf20Sopenharmony_ci	return 0;
1458c2ecf20Sopenharmony_ci}
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistatic inline void ath10k_debug_destroy(struct ath10k *ar)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistatic inline int ath10k_debug_register(struct ath10k *ar)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	return 0;
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistatic inline void ath10k_debug_unregister(struct ath10k *ar)
1578c2ecf20Sopenharmony_ci{
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic inline void ath10k_debug_fw_stats_process(struct ath10k *ar,
1618c2ecf20Sopenharmony_ci						 struct sk_buff *skb)
1628c2ecf20Sopenharmony_ci{
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1668c2ecf20Sopenharmony_ci						  struct ath10k_tpc_stats *tpc_stats)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	kfree(tpc_stats);
1698c2ecf20Sopenharmony_ci}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistatic inline void
1728c2ecf20Sopenharmony_ciath10k_debug_tpc_stats_final_process(struct ath10k *ar,
1738c2ecf20Sopenharmony_ci				     struct ath10k_tpc_stats_final *tpc_stats)
1748c2ecf20Sopenharmony_ci{
1758c2ecf20Sopenharmony_ci	kfree(tpc_stats);
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic inline void ath10k_debug_dbglog_add(struct ath10k *ar, u8 *buffer,
1798c2ecf20Sopenharmony_ci					   int len)
1808c2ecf20Sopenharmony_ci{
1818c2ecf20Sopenharmony_ci}
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic inline u64 ath10k_debug_get_fw_dbglog_mask(struct ath10k *ar)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	return 0;
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic inline u32 ath10k_debug_get_fw_dbglog_level(struct ath10k *ar)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	return 0;
1918c2ecf20Sopenharmony_ci}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistatic inline int ath10k_debug_is_extd_tx_stats_enabled(struct ath10k *ar)
1948c2ecf20Sopenharmony_ci{
1958c2ecf20Sopenharmony_ci	return 0;
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistatic inline int ath10k_debug_fw_stats_request(struct ath10k *ar)
1998c2ecf20Sopenharmony_ci{
2008c2ecf20Sopenharmony_ci	return 0;
2018c2ecf20Sopenharmony_ci}
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define ATH10K_DFS_STAT_INC(ar, c) do { } while (0)
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci#define ath10k_debug_get_et_strings NULL
2068c2ecf20Sopenharmony_ci#define ath10k_debug_get_et_sset_count NULL
2078c2ecf20Sopenharmony_ci#define ath10k_debug_get_et_stats NULL
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#endif /* CONFIG_ATH10K_DEBUGFS */
2108c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_DEBUGFS
2118c2ecf20Sopenharmony_civoid ath10k_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2128c2ecf20Sopenharmony_ci			    struct ieee80211_sta *sta, struct dentry *dir);
2138c2ecf20Sopenharmony_civoid ath10k_sta_update_rx_duration(struct ath10k *ar,
2148c2ecf20Sopenharmony_ci				   struct ath10k_fw_stats *stats);
2158c2ecf20Sopenharmony_civoid ath10k_sta_update_rx_tid_stats(struct ath10k *ar, u8 *first_hdr,
2168c2ecf20Sopenharmony_ci				    unsigned long num_msdus,
2178c2ecf20Sopenharmony_ci				    enum ath10k_pkt_rx_err err,
2188c2ecf20Sopenharmony_ci				    unsigned long unchain_cnt,
2198c2ecf20Sopenharmony_ci				    unsigned long drop_cnt,
2208c2ecf20Sopenharmony_ci				    unsigned long drop_cnt_filter,
2218c2ecf20Sopenharmony_ci				    unsigned long queued_msdus);
2228c2ecf20Sopenharmony_civoid ath10k_sta_update_rx_tid_stats_ampdu(struct ath10k *ar,
2238c2ecf20Sopenharmony_ci					  u16 peer_id, u8 tid,
2248c2ecf20Sopenharmony_ci					  struct htt_rx_indication_mpdu_range *ranges,
2258c2ecf20Sopenharmony_ci					  int num_ranges);
2268c2ecf20Sopenharmony_ci#else
2278c2ecf20Sopenharmony_cistatic inline
2288c2ecf20Sopenharmony_civoid ath10k_sta_update_rx_duration(struct ath10k *ar,
2298c2ecf20Sopenharmony_ci				   struct ath10k_fw_stats *stats)
2308c2ecf20Sopenharmony_ci{
2318c2ecf20Sopenharmony_ci}
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_cistatic inline
2348c2ecf20Sopenharmony_civoid ath10k_sta_update_rx_tid_stats(struct ath10k *ar, u8 *first_hdr,
2358c2ecf20Sopenharmony_ci				    unsigned long num_msdus,
2368c2ecf20Sopenharmony_ci				    enum ath10k_pkt_rx_err err,
2378c2ecf20Sopenharmony_ci				    unsigned long unchain_cnt,
2388c2ecf20Sopenharmony_ci				    unsigned long drop_cnt,
2398c2ecf20Sopenharmony_ci				    unsigned long drop_cnt_filter,
2408c2ecf20Sopenharmony_ci				    unsigned long queued_msdus)
2418c2ecf20Sopenharmony_ci{
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistatic inline
2458c2ecf20Sopenharmony_civoid ath10k_sta_update_rx_tid_stats_ampdu(struct ath10k *ar,
2468c2ecf20Sopenharmony_ci					  u16 peer_id, u8 tid,
2478c2ecf20Sopenharmony_ci					  struct htt_rx_indication_mpdu_range *ranges,
2488c2ecf20Sopenharmony_ci					  int num_ranges)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_ci#endif /* CONFIG_MAC80211_DEBUGFS */
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH10K_DEBUG
2548c2ecf20Sopenharmony_ci__printf(3, 4) void __ath10k_dbg(struct ath10k *ar,
2558c2ecf20Sopenharmony_ci				 enum ath10k_debug_mask mask,
2568c2ecf20Sopenharmony_ci				 const char *fmt, ...);
2578c2ecf20Sopenharmony_civoid ath10k_dbg_dump(struct ath10k *ar,
2588c2ecf20Sopenharmony_ci		     enum ath10k_debug_mask mask,
2598c2ecf20Sopenharmony_ci		     const char *msg, const char *prefix,
2608c2ecf20Sopenharmony_ci		     const void *buf, size_t len);
2618c2ecf20Sopenharmony_ci#else /* CONFIG_ATH10K_DEBUG */
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_cistatic inline int __ath10k_dbg(struct ath10k *ar,
2648c2ecf20Sopenharmony_ci			       enum ath10k_debug_mask dbg_mask,
2658c2ecf20Sopenharmony_ci			       const char *fmt, ...)
2668c2ecf20Sopenharmony_ci{
2678c2ecf20Sopenharmony_ci	return 0;
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic inline void ath10k_dbg_dump(struct ath10k *ar,
2718c2ecf20Sopenharmony_ci				   enum ath10k_debug_mask mask,
2728c2ecf20Sopenharmony_ci				   const char *msg, const char *prefix,
2738c2ecf20Sopenharmony_ci				   const void *buf, size_t len)
2748c2ecf20Sopenharmony_ci{
2758c2ecf20Sopenharmony_ci}
2768c2ecf20Sopenharmony_ci#endif /* CONFIG_ATH10K_DEBUG */
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci/* Avoid calling __ath10k_dbg() if debug_mask is not set and tracing
2798c2ecf20Sopenharmony_ci * disabled.
2808c2ecf20Sopenharmony_ci */
2818c2ecf20Sopenharmony_ci#define ath10k_dbg(ar, dbg_mask, fmt, ...)			\
2828c2ecf20Sopenharmony_cido {								\
2838c2ecf20Sopenharmony_ci	if ((ath10k_debug_mask & dbg_mask) ||			\
2848c2ecf20Sopenharmony_ci	    trace_ath10k_log_dbg_enabled())			\
2858c2ecf20Sopenharmony_ci		__ath10k_dbg(ar, dbg_mask, fmt, ##__VA_ARGS__); \
2868c2ecf20Sopenharmony_ci} while (0)
2878c2ecf20Sopenharmony_ci#endif /* _DEBUG_H_ */
288