xref: /linux/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1daeccac2SArend van Spriel // SPDX-License-Identifier: ISC
205491d2cSKalle Valo /*
305491d2cSKalle Valo  * Copyright (c) 2010 Broadcom Corporation
405491d2cSKalle Valo  */
505491d2cSKalle Valo 
605491d2cSKalle Valo #ifndef BRCMFMAC_DEBUG_H
705491d2cSKalle Valo #define BRCMFMAC_DEBUG_H
805491d2cSKalle Valo 
9b4fd63c6SArend van Spriel #include <linux/net.h>	/* net_ratelimit() */
10b4fd63c6SArend van Spriel 
1105491d2cSKalle Valo /* message levels */
1205491d2cSKalle Valo #define BRCMF_TRACE_VAL		0x00000002
1305491d2cSKalle Valo #define BRCMF_INFO_VAL		0x00000004
1405491d2cSKalle Valo #define BRCMF_DATA_VAL		0x00000008
1505491d2cSKalle Valo #define BRCMF_CTL_VAL		0x00000010
1605491d2cSKalle Valo #define BRCMF_TIMER_VAL		0x00000020
1705491d2cSKalle Valo #define BRCMF_HDRS_VAL		0x00000040
1805491d2cSKalle Valo #define BRCMF_BYTES_VAL		0x00000080
1905491d2cSKalle Valo #define BRCMF_INTR_VAL		0x00000100
2005491d2cSKalle Valo #define BRCMF_GLOM_VAL		0x00000200
2105491d2cSKalle Valo #define BRCMF_EVENT_VAL		0x00000400
2205491d2cSKalle Valo #define BRCMF_BTA_VAL		0x00000800
2305491d2cSKalle Valo #define BRCMF_FIL_VAL		0x00001000
2405491d2cSKalle Valo #define BRCMF_USB_VAL		0x00002000
2505491d2cSKalle Valo #define BRCMF_SCAN_VAL		0x00004000
2605491d2cSKalle Valo #define BRCMF_CONN_VAL		0x00008000
2705491d2cSKalle Valo #define BRCMF_BCDC_VAL		0x00010000
2805491d2cSKalle Valo #define BRCMF_SDIO_VAL		0x00020000
2905491d2cSKalle Valo #define BRCMF_MSGBUF_VAL	0x00040000
3005491d2cSKalle Valo #define BRCMF_PCIE_VAL		0x00080000
3105491d2cSKalle Valo #define BRCMF_FWCON_VAL		0x00100000
3205491d2cSKalle Valo 
3305491d2cSKalle Valo /* set default print format */
3405491d2cSKalle Valo #undef pr_fmt
3505491d2cSKalle Valo #define pr_fmt(fmt)		KBUILD_MODNAME ": " fmt
3605491d2cSKalle Valo 
375cc898fbSRafał Miłecki struct brcmf_bus;
385cc898fbSRafał Miłecki 
395cc898fbSRafał Miłecki __printf(3, 4)
405cc898fbSRafał Miłecki void __brcmf_err(struct brcmf_bus *bus, const char *func, const char *fmt, ...);
41d0630555SRafał Miłecki /* Macro for error messages. When debugging / tracing the driver all error
42d0630555SRafał Miłecki  * messages are important to us.
4305491d2cSKalle Valo  */
448602e624SRafał Miłecki #ifndef brcmf_err
4505491d2cSKalle Valo #define brcmf_err(fmt, ...)						\
4605491d2cSKalle Valo 	do {								\
47d0630555SRafał Miłecki 		if (IS_ENABLED(CONFIG_BRCMDBG) ||			\
48d0630555SRafał Miłecki 		    IS_ENABLED(CONFIG_BRCM_TRACING) ||			\
49d0630555SRafał Miłecki 		    net_ratelimit())					\
505cc898fbSRafał Miłecki 			__brcmf_err(NULL, __func__, fmt, ##__VA_ARGS__);\
5105491d2cSKalle Valo 	} while (0)
528602e624SRafał Miłecki #endif
5305491d2cSKalle Valo 
5416e64676SRafał Miłecki #define bphy_err(drvr, fmt, ...)					\
553ef005b8SRafał Miłecki 	do {								\
563ef005b8SRafał Miłecki 		if (IS_ENABLED(CONFIG_BRCMDBG) ||			\
573ef005b8SRafał Miłecki 		    IS_ENABLED(CONFIG_BRCM_TRACING) ||			\
583ef005b8SRafał Miłecki 		    net_ratelimit())					\
5916e64676SRafał Miłecki 			wiphy_err((drvr)->wiphy, "%s: " fmt, __func__,	\
603ef005b8SRafał Miłecki 				  ##__VA_ARGS__);			\
613ef005b8SRafał Miłecki 	} while (0)
623ef005b8SRafał Miłecki 
63*78f0a64fSDmitry Osipenko #define bphy_info_once(drvr, fmt, ...)					\
64*78f0a64fSDmitry Osipenko 	wiphy_info_once((drvr)->wiphy, "%s: " fmt, __func__,		\
65*78f0a64fSDmitry Osipenko 			##__VA_ARGS__)
66*78f0a64fSDmitry Osipenko 
6705491d2cSKalle Valo #if defined(DEBUG) || defined(CONFIG_BRCM_TRACING)
68d79fe4cbSHans de Goede 
69d79fe4cbSHans de Goede /* For debug/tracing purposes treat info messages as errors */
70d79fe4cbSHans de Goede #define brcmf_info brcmf_err
71d79fe4cbSHans de Goede 
7205491d2cSKalle Valo __printf(3, 4)
7305491d2cSKalle Valo void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...);
7405491d2cSKalle Valo #define brcmf_dbg(level, fmt, ...)				\
7505491d2cSKalle Valo do {								\
7605491d2cSKalle Valo 	__brcmf_dbg(BRCMF_##level##_VAL, __func__,		\
7705491d2cSKalle Valo 		    fmt, ##__VA_ARGS__);			\
7805491d2cSKalle Valo } while (0)
7905491d2cSKalle Valo #define BRCMF_DATA_ON()		(brcmf_msg_level & BRCMF_DATA_VAL)
8005491d2cSKalle Valo #define BRCMF_CTL_ON()		(brcmf_msg_level & BRCMF_CTL_VAL)
8105491d2cSKalle Valo #define BRCMF_HDRS_ON()		(brcmf_msg_level & BRCMF_HDRS_VAL)
8205491d2cSKalle Valo #define BRCMF_BYTES_ON()	(brcmf_msg_level & BRCMF_BYTES_VAL)
8305491d2cSKalle Valo #define BRCMF_GLOM_ON()		(brcmf_msg_level & BRCMF_GLOM_VAL)
8405491d2cSKalle Valo #define BRCMF_EVENT_ON()	(brcmf_msg_level & BRCMF_EVENT_VAL)
8505491d2cSKalle Valo #define BRCMF_FIL_ON()		(brcmf_msg_level & BRCMF_FIL_VAL)
8605491d2cSKalle Valo #define BRCMF_FWCON_ON()	(brcmf_msg_level & BRCMF_FWCON_VAL)
87efc2c1faSArend Van Spriel #define BRCMF_SCAN_ON()		(brcmf_msg_level & BRCMF_SCAN_VAL)
8805491d2cSKalle Valo 
8905491d2cSKalle Valo #else /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
9005491d2cSKalle Valo 
91d79fe4cbSHans de Goede #define brcmf_info(fmt, ...)						\
92d79fe4cbSHans de Goede 	do {								\
93d79fe4cbSHans de Goede 		pr_info("%s: " fmt, __func__, ##__VA_ARGS__);		\
94d79fe4cbSHans de Goede 	} while (0)
95d79fe4cbSHans de Goede 
9605491d2cSKalle Valo #define brcmf_dbg(level, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
9705491d2cSKalle Valo 
9805491d2cSKalle Valo #define BRCMF_DATA_ON()		0
9905491d2cSKalle Valo #define BRCMF_CTL_ON()		0
10005491d2cSKalle Valo #define BRCMF_HDRS_ON()		0
10105491d2cSKalle Valo #define BRCMF_BYTES_ON()	0
10205491d2cSKalle Valo #define BRCMF_GLOM_ON()		0
10305491d2cSKalle Valo #define BRCMF_EVENT_ON()	0
10405491d2cSKalle Valo #define BRCMF_FIL_ON()		0
10505491d2cSKalle Valo #define BRCMF_FWCON_ON()	0
106efc2c1faSArend Van Spriel #define BRCMF_SCAN_ON()		0
10705491d2cSKalle Valo 
10805491d2cSKalle Valo #endif /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
10905491d2cSKalle Valo 
11005491d2cSKalle Valo #define brcmf_dbg_hex_dump(test, data, len, fmt, ...)			\
11105491d2cSKalle Valo do {									\
11205491d2cSKalle Valo 	trace_brcmf_hexdump((void *)data, len);				\
11305491d2cSKalle Valo 	if (test)							\
11405491d2cSKalle Valo 		brcmu_dbg_hex_dump(data, len, fmt, ##__VA_ARGS__);	\
11505491d2cSKalle Valo } while (0)
11605491d2cSKalle Valo 
11705491d2cSKalle Valo extern int brcmf_msg_level;
11805491d2cSKalle Valo 
11905491d2cSKalle Valo struct brcmf_pub;
12005491d2cSKalle Valo #ifdef DEBUG
12105491d2cSKalle Valo struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr);
122ea1b3bc6SGreg Kroah-Hartman void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
12305491d2cSKalle Valo 			     int (*read_fn)(struct seq_file *seq, void *data));
124f1ac3aa2SRafał Miłecki int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
125f1ac3aa2SRafał Miłecki 			       size_t len);
12605491d2cSKalle Valo #else
brcmf_debugfs_get_devdir(struct brcmf_pub * drvr)127cb34212bSRafał Miłecki static inline struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr)
128cb34212bSRafał Miłecki {
129cb34212bSRafał Miłecki 	return ERR_PTR(-ENOENT);
130cb34212bSRafał Miłecki }
13105491d2cSKalle Valo static inline
brcmf_debugfs_add_entry(struct brcmf_pub * drvr,const char * fn,int (* read_fn)(struct seq_file * seq,void * data))132ea1b3bc6SGreg Kroah-Hartman void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
13305491d2cSKalle Valo 			     int (*read_fn)(struct seq_file *seq, void *data))
134ea1b3bc6SGreg Kroah-Hartman { }
135f1ac3aa2SRafał Miłecki static inline
brcmf_debug_create_memdump(struct brcmf_bus * bus,const void * data,size_t len)136f1ac3aa2SRafał Miłecki int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
137f1ac3aa2SRafał Miłecki 			       size_t len)
138f1ac3aa2SRafał Miłecki {
139f1ac3aa2SRafał Miłecki 	return 0;
140f1ac3aa2SRafał Miłecki }
14105491d2cSKalle Valo #endif
14205491d2cSKalle Valo 
14305491d2cSKalle Valo #endif /* BRCMFMAC_DEBUG_H */
144