non-upstream: support DS1 exit firmware re-download
[platform/kernel/linux-rpi.git] / drivers / net / wireless / broadcom / brcm80211 / brcmfmac / debug.h
1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2010 Broadcom Corporation
4  */
5
6 #ifndef BRCMFMAC_DEBUG_H
7 #define BRCMFMAC_DEBUG_H
8
9 #include <linux/net.h>  /* net_ratelimit() */
10
11 /* message levels */
12 #define BRCMF_TRACE_VAL         0x00000002
13 #define BRCMF_INFO_VAL          0x00000004
14 #define BRCMF_DATA_VAL          0x00000008
15 #define BRCMF_CTL_VAL           0x00000010
16 #define BRCMF_TIMER_VAL         0x00000020
17 #define BRCMF_HDRS_VAL          0x00000040
18 #define BRCMF_BYTES_VAL         0x00000080
19 #define BRCMF_INTR_VAL          0x00000100
20 #define BRCMF_GLOM_VAL          0x00000200
21 #define BRCMF_EVENT_VAL         0x00000400
22 #define BRCMF_BTA_VAL           0x00000800
23 #define BRCMF_FIL_VAL           0x00001000
24 #define BRCMF_USB_VAL           0x00002000
25 #define BRCMF_SCAN_VAL          0x00004000
26 #define BRCMF_CONN_VAL          0x00008000
27 #define BRCMF_BCDC_VAL          0x00010000
28 #define BRCMF_SDIO_VAL          0x00020000
29 #define BRCMF_MSGBUF_VAL        0x00040000
30 #define BRCMF_PCIE_VAL          0x00080000
31 #define BRCMF_FWCON_VAL         0x00100000
32 #define BRCMF_ULP_VAL           0x00200000
33
34 /* set default print format */
35 #undef pr_fmt
36 #define pr_fmt(fmt)             KBUILD_MODNAME ": " fmt
37
38 struct brcmf_bus;
39
40 __printf(3, 4)
41 void __brcmf_err(struct brcmf_bus *bus, const char *func, const char *fmt, ...);
42 /* Macro for error messages. When debugging / tracing the driver all error
43  * messages are important to us.
44  */
45 #ifndef brcmf_err
46 #define brcmf_err(fmt, ...)                                             \
47         do {                                                            \
48                 if (IS_ENABLED(CONFIG_BRCMDBG) ||                       \
49                     IS_ENABLED(CONFIG_BRCM_TRACING) ||                  \
50                     net_ratelimit())                                    \
51                         __brcmf_err(NULL, __func__, fmt, ##__VA_ARGS__);\
52         } while (0)
53 #endif
54
55 #define bphy_err(drvr, fmt, ...)                                        \
56         do {                                                            \
57                 if (IS_ENABLED(CONFIG_BRCMDBG) ||                       \
58                     IS_ENABLED(CONFIG_BRCM_TRACING) ||                  \
59                     net_ratelimit())                                    \
60                         wiphy_err((drvr)->wiphy, "%s: " fmt, __func__,  \
61                                   ##__VA_ARGS__);                       \
62         } while (0)
63
64 #define bphy_info_once(drvr, fmt, ...)                                  \
65         wiphy_info_once((drvr)->wiphy, "%s: " fmt, __func__,            \
66                         ##__VA_ARGS__)
67
68 #if defined(DEBUG) || defined(CONFIG_BRCM_TRACING)
69
70 /* For debug/tracing purposes treat info messages as errors */
71 // #define brcmf_info brcmf_err
72
73 #define brcmf_info(fmt, ...)                                            \
74         do {                                                            \
75                 pr_info("%s: " fmt, __func__, ##__VA_ARGS__);           \
76         } while (0)
77
78 __printf(3, 4)
79 void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...);
80 #define brcmf_dbg(level, fmt, ...)                              \
81 do {                                                            \
82         __brcmf_dbg(BRCMF_##level##_VAL, __func__,              \
83                     fmt, ##__VA_ARGS__);                        \
84 } while (0)
85 #define BRCMF_DATA_ON()         (brcmf_msg_level & BRCMF_DATA_VAL)
86 #define BRCMF_CTL_ON()          (brcmf_msg_level & BRCMF_CTL_VAL)
87 #define BRCMF_HDRS_ON()         (brcmf_msg_level & BRCMF_HDRS_VAL)
88 #define BRCMF_BYTES_ON()        (brcmf_msg_level & BRCMF_BYTES_VAL)
89 #define BRCMF_GLOM_ON()         (brcmf_msg_level & BRCMF_GLOM_VAL)
90 #define BRCMF_EVENT_ON()        (brcmf_msg_level & BRCMF_EVENT_VAL)
91 #define BRCMF_FIL_ON()          (brcmf_msg_level & BRCMF_FIL_VAL)
92 #define BRCMF_FWCON_ON()        (brcmf_msg_level & BRCMF_FWCON_VAL)
93 #define BRCMF_SCAN_ON()         (brcmf_msg_level & BRCMF_SCAN_VAL)
94
95 #else /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
96
97 #define brcmf_info(fmt, ...)                                            \
98         do {                                                            \
99                 pr_info("%s: " fmt, __func__, ##__VA_ARGS__);           \
100         } while (0)
101
102 #define brcmf_dbg(level, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
103
104 #define BRCMF_DATA_ON()         0
105 #define BRCMF_CTL_ON()          0
106 #define BRCMF_HDRS_ON()         0
107 #define BRCMF_BYTES_ON()        0
108 #define BRCMF_GLOM_ON()         0
109 #define BRCMF_EVENT_ON()        0
110 #define BRCMF_FIL_ON()          0
111 #define BRCMF_FWCON_ON()        0
112 #define BRCMF_SCAN_ON()         0
113
114 #endif /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
115
116 #define brcmf_dbg_hex_dump(test, data, len, fmt, ...)                   \
117 do {                                                                    \
118         trace_brcmf_hexdump((void *)data, len);                         \
119         if (test)                                                       \
120                 brcmu_dbg_hex_dump(data, len, fmt, ##__VA_ARGS__);      \
121 } while (0)
122
123 extern int brcmf_msg_level;
124
125 struct brcmf_pub;
126 #ifdef DEBUG
127 struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr);
128 void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
129                              int (*read_fn)(struct seq_file *seq, void *data));
130 int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
131                                size_t len);
132 #else
133 static inline struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr)
134 {
135         return ERR_PTR(-ENOENT);
136 }
137 static inline
138 void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
139                              int (*read_fn)(struct seq_file *seq, void *data))
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 */