1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2019-2020 Realtek Corporation
3 */
4
5 #ifndef __RTW89_DEBUG_H__
6 #define __RTW89_DEBUG_H__
7
8 #include "core.h"
9
10 #if defined(__FreeBSD__)
11 #include <linux/printk.h>
12 #ifndef DUMP_PREFIX_OFFSET
13 #define DUMP_PREFIX_OFFSET 0
14 #endif
15 #endif
16
17 enum rtw89_debug_mask {
18 RTW89_DBG_TXRX = BIT(0),
19 RTW89_DBG_RFK = BIT(1),
20 RTW89_DBG_RFK_TRACK = BIT(2),
21 RTW89_DBG_CFO = BIT(3),
22 RTW89_DBG_TSSI = BIT(4),
23 RTW89_DBG_TXPWR = BIT(5),
24 RTW89_DBG_HCI = BIT(6),
25 RTW89_DBG_RA = BIT(7),
26 RTW89_DBG_REGD = BIT(8),
27 RTW89_DBG_PHY_TRACK = BIT(9),
28 RTW89_DBG_DIG = BIT(10),
29 RTW89_DBG_SER = BIT(11),
30 RTW89_DBG_FW = BIT(12),
31 RTW89_DBG_BTC = BIT(13),
32 RTW89_DBG_BF = BIT(14),
33 RTW89_DBG_HW_SCAN = BIT(15),
34 RTW89_DBG_SAR = BIT(16),
35 RTW89_DBG_STATE = BIT(17),
36 RTW89_DBG_WOW = BIT(18),
37 RTW89_DBG_UL_TB = BIT(19),
38 RTW89_DBG_CHAN = BIT(20),
39 RTW89_DBG_ACPI = BIT(21),
40 RTW89_DBG_EDCCA = BIT(22),
41
42 #if defined(__FreeBSD__)
43 RTW89_DBG_IO_RW = BIT(30),
44 #endif
45 RTW89_DBG_UNEXP = BIT(31),
46 };
47
48 enum rtw89_debug_mac_reg_sel {
49 RTW89_DBG_SEL_MAC_00,
50 RTW89_DBG_SEL_MAC_30,
51 RTW89_DBG_SEL_MAC_40,
52 RTW89_DBG_SEL_MAC_80,
53 RTW89_DBG_SEL_MAC_C0,
54 RTW89_DBG_SEL_MAC_E0,
55 RTW89_DBG_SEL_BB,
56 RTW89_DBG_SEL_IQK,
57 RTW89_DBG_SEL_RFC,
58 };
59
60 #ifdef CONFIG_RTW89_DEBUGFS
61 void rtw89_debugfs_init(struct rtw89_dev *rtwdev);
62 void rtw89_debugfs_deinit(struct rtw89_dev *rtwdev);
63 #else
rtw89_debugfs_init(struct rtw89_dev * rtwdev)64 static inline void rtw89_debugfs_init(struct rtw89_dev *rtwdev) {}
rtw89_debugfs_deinit(struct rtw89_dev * rtwdev)65 static inline void rtw89_debugfs_deinit(struct rtw89_dev *rtwdev) {}
66 #endif
67
68 #define rtw89_info(rtwdev, a...) dev_info((rtwdev)->dev, ##a)
69 #define rtw89_info_once(rtwdev, a...) dev_info_once((rtwdev)->dev, ##a)
70 #define rtw89_warn(rtwdev, a...) dev_warn((rtwdev)->dev, ##a)
71 #define rtw89_err(rtwdev, a...) dev_err((rtwdev)->dev, ##a)
72
73 #ifdef CONFIG_RTW89_DEBUGMSG
74 extern unsigned int rtw89_debug_mask;
75
76 __printf(3, 4)
77 void rtw89_debug(struct rtw89_dev *rtwdev, enum rtw89_debug_mask mask,
78 const char *fmt, ...);
rtw89_hex_dump(struct rtw89_dev * rtwdev,enum rtw89_debug_mask mask,const char * prefix_str,const void * buf,size_t len)79 static inline void rtw89_hex_dump(struct rtw89_dev *rtwdev,
80 enum rtw89_debug_mask mask,
81 const char *prefix_str,
82 const void *buf, size_t len)
83 {
84 if (!(rtw89_debug_mask & mask))
85 return;
86
87 print_hex_dump_bytes(prefix_str, DUMP_PREFIX_OFFSET, buf, len);
88 }
89
rtw89_debug_is_enabled(struct rtw89_dev * rtwdev,enum rtw89_debug_mask mask)90 static inline bool rtw89_debug_is_enabled(struct rtw89_dev *rtwdev,
91 enum rtw89_debug_mask mask)
92 {
93 return !!(rtw89_debug_mask & mask);
94 }
95 #else
rtw89_debug(struct rtw89_dev * rtwdev,enum rtw89_debug_mask mask,const char * fmt,...)96 static inline void rtw89_debug(struct rtw89_dev *rtwdev,
97 enum rtw89_debug_mask mask,
98 const char *fmt, ...) {}
rtw89_hex_dump(struct rtw89_dev * rtwdev,enum rtw89_debug_mask mask,const char * prefix_str,const void * buf,size_t len)99 static inline void rtw89_hex_dump(struct rtw89_dev *rtwdev,
100 enum rtw89_debug_mask mask,
101 const char *prefix_str,
102 const void *buf, size_t len) {}
rtw89_debug_is_enabled(struct rtw89_dev * rtwdev,enum rtw89_debug_mask mask)103 static inline bool rtw89_debug_is_enabled(struct rtw89_dev *rtwdev,
104 enum rtw89_debug_mask mask)
105 {
106 return false;
107 }
108 #endif
109
110 #endif
111