1bdcd8170SKalle Valo /*
2bdcd8170SKalle Valo  * Copyright (c) 2011 Atheros Communications Inc.
3bdcd8170SKalle Valo  *
4bdcd8170SKalle Valo  * Permission to use, copy, modify, and/or distribute this software for any
5bdcd8170SKalle Valo  * purpose with or without fee is hereby granted, provided that the above
6bdcd8170SKalle Valo  * copyright notice and this permission notice appear in all copies.
7bdcd8170SKalle Valo  *
8bdcd8170SKalle Valo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9bdcd8170SKalle Valo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10bdcd8170SKalle Valo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11bdcd8170SKalle Valo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12bdcd8170SKalle Valo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13bdcd8170SKalle Valo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14bdcd8170SKalle Valo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15bdcd8170SKalle Valo  */
16bdcd8170SKalle Valo 
17bdcd8170SKalle Valo #ifndef DEBUG_H
18bdcd8170SKalle Valo #define DEBUG_H
19bdcd8170SKalle Valo 
202e1cb23cSKalle Valo #include "hif.h"
21bdcd8170SKalle Valo 
22bdcd8170SKalle Valo enum ATH6K_DEBUG_MASK {
2302f0d6fcSKalle Valo 	ATH6KL_DBG_CREDIT	= BIT(0),
24d23ace77SKalle Valo 	/* hole */
25bdcd8170SKalle Valo 	ATH6KL_DBG_WLAN_TX      = BIT(2),     /* wlan tx */
26bdcd8170SKalle Valo 	ATH6KL_DBG_WLAN_RX      = BIT(3),     /* wlan rx */
27bdcd8170SKalle Valo 	ATH6KL_DBG_BMI		= BIT(4),     /* bmi tracing */
28ebf29c95SKalle Valo 	ATH6KL_DBG_HTC		= BIT(5),
2983973e03SKalle Valo 	ATH6KL_DBG_HIF		= BIT(6),
30bdcd8170SKalle Valo 	ATH6KL_DBG_IRQ		= BIT(7),     /* interrupt processing */
31d23ace77SKalle Valo 	/* hole */
32d23ace77SKalle Valo 	/* hole */
33bdcd8170SKalle Valo 	ATH6KL_DBG_WMI          = BIT(10),    /* wmi tracing */
34bdcd8170SKalle Valo 	ATH6KL_DBG_TRC	        = BIT(11),    /* generic func tracing */
35bdcd8170SKalle Valo 	ATH6KL_DBG_SCATTER	= BIT(12),    /* hif scatter tracing */
36bdcd8170SKalle Valo 	ATH6KL_DBG_WLAN_CFG     = BIT(13),    /* cfg80211 i/f file tracing */
37b9b6ee60SKalle Valo 	ATH6KL_DBG_RAW_BYTES    = BIT(14),    /* dump tx/rx frames */
3837ca6335SKalle Valo 	ATH6KL_DBG_AGGR		= BIT(15),    /* aggregation */
39f7325b85SKalle Valo 	ATH6KL_DBG_SDIO		= BIT(16),
40f7325b85SKalle Valo 	ATH6KL_DBG_SDIO_DUMP	= BIT(17),
416bc36431SKalle Valo 	ATH6KL_DBG_BOOT		= BIT(18),    /* driver init and fw boot */
42b9b6ee60SKalle Valo 	ATH6KL_DBG_WMI_DUMP	= BIT(19),
43b4b2a0b1SKalle Valo 	ATH6KL_DBG_SUSPEND	= BIT(20),
44bdcd8170SKalle Valo 	ATH6KL_DBG_ANY	        = 0xffffffff  /* enable all logs */
45bdcd8170SKalle Valo };
46bdcd8170SKalle Valo 
47bdcd8170SKalle Valo extern unsigned int debug_mask;
48bdcd8170SKalle Valo extern int ath6kl_printk(const char *level, const char *fmt, ...)
49bdcd8170SKalle Valo 	__attribute__ ((format (printf, 2, 3)));
50bdcd8170SKalle Valo 
51bdcd8170SKalle Valo #define ath6kl_info(fmt, ...)				\
52bdcd8170SKalle Valo 	ath6kl_printk(KERN_INFO, fmt, ##__VA_ARGS__)
53bdcd8170SKalle Valo #define ath6kl_err(fmt, ...)					\
54bdcd8170SKalle Valo 	ath6kl_printk(KERN_ERR, fmt, ##__VA_ARGS__)
55bdcd8170SKalle Valo #define ath6kl_warn(fmt, ...)					\
56bdcd8170SKalle Valo 	ath6kl_printk(KERN_WARNING, fmt, ##__VA_ARGS__)
57bdcd8170SKalle Valo 
58bdcd8170SKalle Valo #define AR_DBG_LVL_CHECK(mask)	(debug_mask & mask)
59bdcd8170SKalle Valo 
609a730834SKalle Valo enum ath6kl_war {
619a730834SKalle Valo 	ATH6KL_WAR_INVALID_RATE,
629a730834SKalle Valo };
639a730834SKalle Valo 
64bdcd8170SKalle Valo #ifdef CONFIG_ATH6KL_DEBUG
65bdcd8170SKalle Valo #define ath6kl_dbg(mask, fmt, ...)					\
66bdcd8170SKalle Valo 	({								\
67bdcd8170SKalle Valo 	 int rtn;							\
68bdcd8170SKalle Valo 	 if (debug_mask & mask)						\
69bdcd8170SKalle Valo 		rtn = ath6kl_printk(KERN_DEBUG, fmt, ##__VA_ARGS__);	\
70bdcd8170SKalle Valo 	 else								\
71bdcd8170SKalle Valo 		rtn = 0;						\
72bdcd8170SKalle Valo 									\
73bdcd8170SKalle Valo 	 rtn;								\
74bdcd8170SKalle Valo 	 })
75bdcd8170SKalle Valo 
76bdcd8170SKalle Valo static inline void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
77ef094103SKalle Valo 				   const char *msg, const char *prefix,
78ef094103SKalle Valo 				   const void *buf, size_t len)
79bdcd8170SKalle Valo {
80bdcd8170SKalle Valo 	if (debug_mask & mask) {
81ef094103SKalle Valo 		if (msg)
82bdcd8170SKalle Valo 			ath6kl_dbg(mask, "%s\n", msg);
83ef094103SKalle Valo 
84ef094103SKalle Valo 		print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len);
85bdcd8170SKalle Valo 	}
86bdcd8170SKalle Valo }
87bdcd8170SKalle Valo 
88bdcd8170SKalle Valo void ath6kl_dump_registers(struct ath6kl_device *dev,
89bdcd8170SKalle Valo 			   struct ath6kl_irq_proc_registers *irq_proc_reg,
90bdcd8170SKalle Valo 			   struct ath6kl_irq_enable_reg *irq_en_reg);
91bdcd8170SKalle Valo void dump_cred_dist_stats(struct htc_target *target);
92bdf5396bSKalle Valo void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len);
939a730834SKalle Valo void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war);
944b28a80dSJouni Malinen int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
954b28a80dSJouni Malinen 				size_t len);
96ff0b0075SJouni Malinen void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive);
97ff0b0075SJouni Malinen void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout);
98d999ba3eSVasanthakumar Thiagarajan int ath6kl_debug_init(struct ath6kl *ar);
99bdf5396bSKalle Valo void ath6kl_debug_cleanup(struct ath6kl *ar);
100bdf5396bSKalle Valo 
101bdcd8170SKalle Valo #else
102bdcd8170SKalle Valo static inline int ath6kl_dbg(enum ATH6K_DEBUG_MASK dbg_mask,
103bdcd8170SKalle Valo 			     const char *fmt, ...)
104bdcd8170SKalle Valo {
105bdcd8170SKalle Valo 	return 0;
106bdcd8170SKalle Valo }
107bdcd8170SKalle Valo 
108bdcd8170SKalle Valo static inline void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
109ef094103SKalle Valo 				   const char *msg, const char *prefix,
110ef094103SKalle Valo 				   const void *buf, size_t len)
111bdcd8170SKalle Valo {
112bdcd8170SKalle Valo }
113bdcd8170SKalle Valo 
114bdcd8170SKalle Valo static inline void ath6kl_dump_registers(struct ath6kl_device *dev,
115bdcd8170SKalle Valo 		struct ath6kl_irq_proc_registers *irq_proc_reg,
116bdcd8170SKalle Valo 		struct ath6kl_irq_enable_reg *irq_en_reg)
117bdcd8170SKalle Valo {
118bdcd8170SKalle Valo 
119bdcd8170SKalle Valo }
120bdcd8170SKalle Valo static inline void dump_cred_dist_stats(struct htc_target *target)
121bdcd8170SKalle Valo {
122bdcd8170SKalle Valo }
123bdf5396bSKalle Valo 
1243038fac8SRajkumar Manoharan static inline void ath6kl_debug_fwlog_event(struct ath6kl *ar,
1253038fac8SRajkumar Manoharan 					    const void *buf, size_t len)
126bdf5396bSKalle Valo {
127bdf5396bSKalle Valo }
128bdf5396bSKalle Valo 
1299a730834SKalle Valo static inline void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
1309a730834SKalle Valo {
1319a730834SKalle Valo }
1329a730834SKalle Valo 
1334b28a80dSJouni Malinen static inline int ath6kl_debug_roam_tbl_event(struct ath6kl *ar,
1344b28a80dSJouni Malinen 					      const void *buf, size_t len)
1354b28a80dSJouni Malinen {
1364b28a80dSJouni Malinen 	return 0;
1374b28a80dSJouni Malinen }
1384b28a80dSJouni Malinen 
139ff0b0075SJouni Malinen static inline void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
140ff0b0075SJouni Malinen {
141ff0b0075SJouni Malinen }
142ff0b0075SJouni Malinen 
143ff0b0075SJouni Malinen static inline void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar,
144ff0b0075SJouni Malinen 						       u8 timeout)
145ff0b0075SJouni Malinen {
146ff0b0075SJouni Malinen }
147ff0b0075SJouni Malinen 
148d999ba3eSVasanthakumar Thiagarajan static inline int ath6kl_debug_init(struct ath6kl *ar)
149d999ba3eSVasanthakumar Thiagarajan {
150d999ba3eSVasanthakumar Thiagarajan 	return 0;
151d999ba3eSVasanthakumar Thiagarajan }
152bdf5396bSKalle Valo 
1533038fac8SRajkumar Manoharan static inline void ath6kl_debug_cleanup(struct ath6kl *ar)
154bdf5396bSKalle Valo {
155bdf5396bSKalle Valo }
156bdf5396bSKalle Valo 
157bdcd8170SKalle Valo #endif
158bdcd8170SKalle Valo #endif
159