1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_NET_DEBUG_H
3 #define _LINUX_NET_DEBUG_H
6 #include <linux/kern_levels.h>
11 void netdev_printk(const char *level, const struct net_device *dev,
12 const char *format, ...);
14 void netdev_emerg(const struct net_device *dev, const char *format, ...);
16 void netdev_alert(const struct net_device *dev, const char *format, ...);
18 void netdev_crit(const struct net_device *dev, const char *format, ...);
20 void netdev_err(const struct net_device *dev, const char *format, ...);
22 void netdev_warn(const struct net_device *dev, const char *format, ...);
24 void netdev_notice(const struct net_device *dev, const char *format, ...);
26 void netdev_info(const struct net_device *dev, const char *format, ...);
28 #define netdev_level_once(level, dev, fmt, ...) \
30 static bool __section(".data.once") __print_once; \
32 if (!__print_once) { \
33 __print_once = true; \
34 netdev_printk(level, dev, fmt, ##__VA_ARGS__); \
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__)
53 #if defined(CONFIG_DYNAMIC_DEBUG) || \
54 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
55 #define netdev_dbg(__dev, format, args...) \
57 dynamic_netdev_dbg(__dev, format, ##args); \
60 #define netdev_dbg(__dev, format, args...) \
61 netdev_printk(KERN_DEBUG, __dev, format, ##args)
63 #define netdev_dbg(__dev, format, args...) \
66 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
70 #if defined(VERBOSE_DEBUG)
71 #define netdev_vdbg netdev_dbg
74 #define netdev_vdbg(dev, format, args...) \
77 netdev_printk(KERN_DEBUG, dev, format, ##args); \
82 /* netif printk helpers, similar to netdev_printk */
84 #define netif_printk(priv, type, level, dev, fmt, args...) \
86 if (netif_msg_##type(priv)) \
87 netdev_printk(level, (dev), fmt, ##args); \
90 #define netif_level(level, priv, type, dev, fmt, args...) \
92 if (netif_msg_##type(priv)) \
93 netdev_##level(dev, fmt, ##args); \
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)
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...) \
115 if (netif_msg_##type(priv)) \
116 dynamic_netdev_dbg(netdev, format, ##args); \
119 #define netif_dbg(priv, type, dev, format, args...) \
120 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
122 #define netif_dbg(priv, type, dev, format, args...) \
125 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
130 /* if @cond then downgrade to debug, else print at @level */
131 #define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \
134 netif_dbg(priv, type, netdev, fmt, ##args); \
136 netif_ ## level(priv, type, netdev, fmt, ##args); \
139 #if defined(VERBOSE_DEBUG)
140 #define netif_vdbg netif_dbg
142 #define netif_vdbg(priv, type, dev, format, args...) \
145 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
151 #if defined(CONFIG_DEBUG_NET)
152 #define DEBUG_NET_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
154 #define DEBUG_NET_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
157 #endif /* _LINUX_NET_DEBUG_H */