1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef BRCMFMAC_DEBUG_H
18 #define BRCMFMAC_DEBUG_H
19 
20 #include <linux/net.h>	/* net_ratelimit() */
21 
22 /* message levels */
23 #define BRCMF_TRACE_VAL		0x00000002
24 #define BRCMF_INFO_VAL		0x00000004
25 #define BRCMF_DATA_VAL		0x00000008
26 #define BRCMF_CTL_VAL		0x00000010
27 #define BRCMF_TIMER_VAL		0x00000020
28 #define BRCMF_HDRS_VAL		0x00000040
29 #define BRCMF_BYTES_VAL		0x00000080
30 #define BRCMF_INTR_VAL		0x00000100
31 #define BRCMF_GLOM_VAL		0x00000200
32 #define BRCMF_EVENT_VAL		0x00000400
33 #define BRCMF_BTA_VAL		0x00000800
34 #define BRCMF_FIL_VAL		0x00001000
35 #define BRCMF_USB_VAL		0x00002000
36 #define BRCMF_SCAN_VAL		0x00004000
37 #define BRCMF_CONN_VAL		0x00008000
38 #define BRCMF_BCDC_VAL		0x00010000
39 #define BRCMF_SDIO_VAL		0x00020000
40 #define BRCMF_MSGBUF_VAL	0x00040000
41 #define BRCMF_PCIE_VAL		0x00080000
42 #define BRCMF_FWCON_VAL		0x00100000
43 
44 /* set default print format */
45 #undef pr_fmt
46 #define pr_fmt(fmt)		KBUILD_MODNAME ": " fmt
47 
48 struct brcmf_bus;
49 
50 __printf(3, 4)
51 void __brcmf_err(struct brcmf_bus *bus, const char *func, const char *fmt, ...);
52 /* Macro for error messages. When debugging / tracing the driver all error
53  * messages are important to us.
54  */
55 #ifndef brcmf_err
56 #define brcmf_err(fmt, ...)						\
57 	do {								\
58 		if (IS_ENABLED(CONFIG_BRCMDBG) ||			\
59 		    IS_ENABLED(CONFIG_BRCM_TRACING) ||			\
60 		    net_ratelimit())					\
61 			__brcmf_err(NULL, __func__, fmt, ##__VA_ARGS__);\
62 	} while (0)
63 #endif
64 
65 #define bphy_err(drvr, fmt, ...)					\
66 	do {								\
67 		if (IS_ENABLED(CONFIG_BRCMDBG) ||			\
68 		    IS_ENABLED(CONFIG_BRCM_TRACING) ||			\
69 		    net_ratelimit())					\
70 			wiphy_err((drvr)->wiphy, "%s: " fmt, __func__,	\
71 				  ##__VA_ARGS__);			\
72 	} while (0)
73 
74 #if defined(DEBUG) || defined(CONFIG_BRCM_TRACING)
75 
76 /* For debug/tracing purposes treat info messages as errors */
77 #define brcmf_info brcmf_err
78 
79 __printf(3, 4)
80 void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...);
81 #define brcmf_dbg(level, fmt, ...)				\
82 do {								\
83 	__brcmf_dbg(BRCMF_##level##_VAL, __func__,		\
84 		    fmt, ##__VA_ARGS__);			\
85 } while (0)
86 #define BRCMF_DATA_ON()		(brcmf_msg_level & BRCMF_DATA_VAL)
87 #define BRCMF_CTL_ON()		(brcmf_msg_level & BRCMF_CTL_VAL)
88 #define BRCMF_HDRS_ON()		(brcmf_msg_level & BRCMF_HDRS_VAL)
89 #define BRCMF_BYTES_ON()	(brcmf_msg_level & BRCMF_BYTES_VAL)
90 #define BRCMF_GLOM_ON()		(brcmf_msg_level & BRCMF_GLOM_VAL)
91 #define BRCMF_EVENT_ON()	(brcmf_msg_level & BRCMF_EVENT_VAL)
92 #define BRCMF_FIL_ON()		(brcmf_msg_level & BRCMF_FIL_VAL)
93 #define BRCMF_FWCON_ON()	(brcmf_msg_level & BRCMF_FWCON_VAL)
94 #define BRCMF_SCAN_ON()		(brcmf_msg_level & BRCMF_SCAN_VAL)
95 
96 #else /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
97 
98 #define brcmf_info(fmt, ...)						\
99 	do {								\
100 		pr_info("%s: " fmt, __func__, ##__VA_ARGS__);		\
101 	} while (0)
102 
103 #define brcmf_dbg(level, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
104 
105 #define BRCMF_DATA_ON()		0
106 #define BRCMF_CTL_ON()		0
107 #define BRCMF_HDRS_ON()		0
108 #define BRCMF_BYTES_ON()	0
109 #define BRCMF_GLOM_ON()		0
110 #define BRCMF_EVENT_ON()	0
111 #define BRCMF_FIL_ON()		0
112 #define BRCMF_FWCON_ON()	0
113 #define BRCMF_SCAN_ON()		0
114 
115 #endif /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
116 
117 #define brcmf_dbg_hex_dump(test, data, len, fmt, ...)			\
118 do {									\
119 	trace_brcmf_hexdump((void *)data, len);				\
120 	if (test)							\
121 		brcmu_dbg_hex_dump(data, len, fmt, ##__VA_ARGS__);	\
122 } while (0)
123 
124 extern int brcmf_msg_level;
125 
126 struct brcmf_bus;
127 struct brcmf_pub;
128 #ifdef DEBUG
129 struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr);
130 int brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
131 			    int (*read_fn)(struct seq_file *seq, void *data));
132 int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
133 			       size_t len);
134 #else
135 static inline
136 int brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
137 			    int (*read_fn)(struct seq_file *seq, void *data))
138 {
139 	return 0;
140 }
141 static inline
142 int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
143 			       size_t len)
144 {
145 	return 0;
146 }
147 #endif
148 
149 #endif /* BRCMFMAC_DEBUG_H */
150