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 #if defined(__FreeBSD__) 10 #include <linux/printk.h> 11 #endif 12 #include <linux/net.h> /* net_ratelimit() */ 13 14 /* message levels */ 15 #define BRCMF_TRACE_VAL 0x00000002 16 #define BRCMF_INFO_VAL 0x00000004 17 #define BRCMF_DATA_VAL 0x00000008 18 #define BRCMF_CTL_VAL 0x00000010 19 #define BRCMF_TIMER_VAL 0x00000020 20 #define BRCMF_HDRS_VAL 0x00000040 21 #define BRCMF_BYTES_VAL 0x00000080 22 #define BRCMF_INTR_VAL 0x00000100 23 #define BRCMF_GLOM_VAL 0x00000200 24 #define BRCMF_EVENT_VAL 0x00000400 25 #define BRCMF_BTA_VAL 0x00000800 26 #define BRCMF_FIL_VAL 0x00001000 27 #define BRCMF_USB_VAL 0x00002000 28 #define BRCMF_SCAN_VAL 0x00004000 29 #define BRCMF_CONN_VAL 0x00008000 30 #define BRCMF_BCDC_VAL 0x00010000 31 #define BRCMF_SDIO_VAL 0x00020000 32 #define BRCMF_MSGBUF_VAL 0x00040000 33 #define BRCMF_PCIE_VAL 0x00080000 34 #define BRCMF_FWCON_VAL 0x00100000 35 36 /* set default print format */ 37 #undef pr_fmt 38 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 39 40 struct brcmf_bus; 41 42 __printf(3, 4) 43 void __brcmf_err(struct brcmf_bus *bus, const char *func, const char *fmt, ...); 44 /* Macro for error messages. When debugging / tracing the driver all error 45 * messages are important to us. 46 */ 47 #ifndef brcmf_err 48 #define brcmf_err(fmt, ...) \ 49 do { \ 50 if (IS_ENABLED(CONFIG_BRCMDBG) || \ 51 IS_ENABLED(CONFIG_BRCM_TRACING) || \ 52 net_ratelimit()) \ 53 __brcmf_err(NULL, __func__, fmt, ##__VA_ARGS__);\ 54 } while (0) 55 #endif 56 57 #define bphy_err(drvr, fmt, ...) \ 58 do { \ 59 if (IS_ENABLED(CONFIG_BRCMDBG) || \ 60 IS_ENABLED(CONFIG_BRCM_TRACING) || \ 61 net_ratelimit()) \ 62 wiphy_err((drvr)->wiphy, "%s: " fmt, __func__, \ 63 ##__VA_ARGS__); \ 64 } while (0) 65 66 #define bphy_info_once(drvr, fmt, ...) \ 67 wiphy_info_once((drvr)->wiphy, "%s: " fmt, __func__, \ 68 ##__VA_ARGS__) 69 70 /* #if defined(__linux__) 71 #if defined(DEBUG) || defined(CONFIG_BRCM_TRACING) 72 #elif defined(__FreeBSD__) */ 73 #if defined(DEBUG) || defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG) 74 /* #endif */ 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 #if defined(__linux__) 82 #define brcmf_dbg(level, fmt, ...) \ 83 do { \ 84 __brcmf_dbg(BRCMF_##level##_VAL, __func__, \ 85 fmt, ##__VA_ARGS__); \ 86 } while (0) 87 #elif defined(__FreeBSD__) 88 #define brcmf_dbg(level, ...) \ 89 do { \ 90 __brcmf_dbg(BRCMF_##level##_VAL, __func__, \ 91 __VA_ARGS__); \ 92 } while (0) 93 #endif 94 #define BRCMF_DATA_ON() (brcmf_msg_level & BRCMF_DATA_VAL) 95 #define BRCMF_CTL_ON() (brcmf_msg_level & BRCMF_CTL_VAL) 96 #define BRCMF_HDRS_ON() (brcmf_msg_level & BRCMF_HDRS_VAL) 97 #define BRCMF_BYTES_ON() (brcmf_msg_level & BRCMF_BYTES_VAL) 98 #define BRCMF_GLOM_ON() (brcmf_msg_level & BRCMF_GLOM_VAL) 99 #define BRCMF_EVENT_ON() (brcmf_msg_level & BRCMF_EVENT_VAL) 100 #define BRCMF_FIL_ON() (brcmf_msg_level & BRCMF_FIL_VAL) 101 #define BRCMF_FWCON_ON() (brcmf_msg_level & BRCMF_FWCON_VAL) 102 #define BRCMF_SCAN_ON() (brcmf_msg_level & BRCMF_SCAN_VAL) 103 104 #else /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */ 105 106 #define brcmf_info(fmt, ...) \ 107 do { \ 108 pr_info("%s: " fmt, __func__, ##__VA_ARGS__); \ 109 } while (0) 110 111 #define brcmf_dbg(level, fmt, ...) no_printk(fmt, ##__VA_ARGS__) 112 113 #define BRCMF_DATA_ON() 0 114 #define BRCMF_CTL_ON() 0 115 #define BRCMF_HDRS_ON() 0 116 #define BRCMF_BYTES_ON() 0 117 #define BRCMF_GLOM_ON() 0 118 #define BRCMF_EVENT_ON() 0 119 #define BRCMF_FIL_ON() 0 120 #define BRCMF_FWCON_ON() 0 121 #define BRCMF_SCAN_ON() 0 122 123 #endif /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */ 124 125 #if defined(__linux__) 126 #define brcmf_dbg_hex_dump(test, data, len, fmt, ...) \ 127 do { \ 128 trace_brcmf_hexdump((void *)data, len); \ 129 if (test) \ 130 brcmu_dbg_hex_dump(data, len, fmt, ##__VA_ARGS__); \ 131 } while (0) 132 #elif defined(__FreeBSD__) 133 #define brcmf_dbg_hex_dump(test, data, len, fmt, ...) \ 134 do { \ 135 trace_brcmf_hexdump(data, len); \ 136 if (test) \ 137 brcmu_dbg_hex_dump(data, len, fmt, ##__VA_ARGS__); \ 138 } while (0) 139 #endif 140 141 extern int brcmf_msg_level; 142 143 struct brcmf_pub; 144 #ifdef DEBUG 145 struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr); 146 void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn, 147 int (*read_fn)(struct seq_file *seq, void *data)); 148 int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data, 149 size_t len); 150 #else 151 static inline struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr) 152 { 153 return ERR_PTR(-ENOENT); 154 } 155 static inline 156 void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn, 157 int (*read_fn)(struct seq_file *seq, void *data)) 158 { } 159 static inline 160 int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data, 161 size_t len) 162 { 163 return 0; 164 } 165 #endif 166 167 #endif /* BRCMFMAC_DEBUG_H */ 168