1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_NET_DEBUG_H
3#define _LINUX_NET_DEBUG_H
4
5#include <linux/bug.h>
6#include <linux/kern_levels.h>
7
8struct net_device;
9
10__printf(3, 4) __cold
11void netdev_printk(const char *level, const struct net_device *dev,
12 const char *format, ...);
13__printf(2, 3) __cold
14void netdev_emerg(const struct net_device *dev, const char *format, ...);
15__printf(2, 3) __cold
16void netdev_alert(const struct net_device *dev, const char *format, ...);
17__printf(2, 3) __cold
18void netdev_crit(const struct net_device *dev, const char *format, ...);
19__printf(2, 3) __cold
20void netdev_err(const struct net_device *dev, const char *format, ...);
21__printf(2, 3) __cold
22void netdev_warn(const struct net_device *dev, const char *format, ...);
23__printf(2, 3) __cold
24void netdev_notice(const struct net_device *dev, const char *format, ...);
25__printf(2, 3) __cold
26void netdev_info(const struct net_device *dev, const char *format, ...);
27
28#define netdev_level_once(level, dev, fmt, ...) \
29do { \
30 static bool __section(".data.once") __print_once; \
31 \
32 if (!__print_once) { \
33 __print_once = true; \
34 netdev_printk(level, dev, fmt, ##__VA_ARGS__); \
35 } \
36} while (0)
37
38#define netdev_emerg_once(dev, fmt, ...) \
39 netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__)
40#define netdev_alert_once(dev, fmt, ...) \
41 netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__)
42#define netdev_crit_once(dev, fmt, ...) \
43 netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__)
44#define netdev_err_once(dev, fmt, ...) \
45 netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__)
46#define netdev_warn_once(dev, fmt, ...) \
47 netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__)
48#define netdev_notice_once(dev, fmt, ...) \
49 netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__)
50#define netdev_info_once(dev, fmt, ...) \
51 netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__)
52
53#if defined(CONFIG_DYNAMIC_DEBUG) || \
54 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
55#define netdev_dbg(__dev, format, args...) \
56do { \
57 dynamic_netdev_dbg(__dev, format, ##args); \
58} while (0)
59#elif defined(DEBUG)
60#define netdev_dbg(__dev, format, args...) \
61 netdev_printk(KERN_DEBUG, __dev, format, ##args)
62#else
63#define netdev_dbg(__dev, format, args...) \
64({ \
65 if (0) \
66 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
67})
68#endif
69
70#if defined(VERBOSE_DEBUG)
71#define netdev_vdbg netdev_dbg
72#else
73
74#define netdev_vdbg(dev, format, args...) \
75({ \
76 if (0) \
77 netdev_printk(KERN_DEBUG, dev, format, ##args); \
78 0; \
79})
80#endif
81
82/* netif printk helpers, similar to netdev_printk */
83
84#define netif_printk(priv, type, level, dev, fmt, args...) \
85do { \
86 if (netif_msg_##type(priv)) \
87 netdev_printk(level, (dev), fmt, ##args); \
88} while (0)
89
90#define netif_level(level, priv, type, dev, fmt, args...) \
91do { \
92 if (netif_msg_##type(priv)) \
93 netdev_##level(dev, fmt, ##args); \
94} while (0)
95
96#define netif_emerg(priv, type, dev, fmt, args...) \
97 netif_level(emerg, priv, type, dev, fmt, ##args)
98#define netif_alert(priv, type, dev, fmt, args...) \
99 netif_level(alert, priv, type, dev, fmt, ##args)
100#define netif_crit(priv, type, dev, fmt, args...) \
101 netif_level(crit, priv, type, dev, fmt, ##args)
102#define netif_err(priv, type, dev, fmt, args...) \
103 netif_level(err, priv, type, dev, fmt, ##args)
104#define netif_warn(priv, type, dev, fmt, args...) \
105 netif_level(warn, priv, type, dev, fmt, ##args)
106#define netif_notice(priv, type, dev, fmt, args...) \
107 netif_level(notice, priv, type, dev, fmt, ##args)
108#define netif_info(priv, type, dev, fmt, args...) \
109 netif_level(info, priv, type, dev, fmt, ##args)
110
111#if defined(CONFIG_DYNAMIC_DEBUG) || \
112 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
113#define netif_dbg(priv, type, netdev, format, args...) \
114do { \
115 if (netif_msg_##type(priv)) \
116 dynamic_netdev_dbg(netdev, format, ##args); \
117} while (0)
118#elif defined(DEBUG)
119#define netif_dbg(priv, type, dev, format, args...) \
120 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
121#else
122#define netif_dbg(priv, type, dev, format, args...) \
123({ \
124 if (0) \
125 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
126 0; \
127})
128#endif
129
130/* if @cond then downgrade to debug, else print at @level */
131#define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \
132 do { \
133 if (cond) \
134 netif_dbg(priv, type, netdev, fmt, ##args); \
135 else \
136 netif_ ## level(priv, type, netdev, fmt, ##args); \
137 } while (0)
138
139#if defined(VERBOSE_DEBUG)
140#define netif_vdbg netif_dbg
141#else
142#define netif_vdbg(priv, type, dev, format, args...) \
143({ \
144 if (0) \
145 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
146 0; \
147})
148#endif
149
150
151#if defined(CONFIG_DEBUG_NET)
152#define DEBUG_NET_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
153#else
154#define DEBUG_NET_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
155#endif
156
157#endif /* _LINUX_NET_DEBUG_H */
158

source code of linux/include/net/net_debug.h