1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef _NET_BATMAN_ADV_LOG_H_
20#define _NET_BATMAN_ADV_LOG_H_
21
22#include "main.h"
23
24#include <linux/bitops.h>
25#include <linux/compiler.h>
26#include <linux/printk.h>
27
28#ifdef CONFIG_BATMAN_ADV_DEBUG
29
30int batadv_debug_log_setup(struct batadv_priv *bat_priv);
31void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
32
33#else
34
35static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
36{
37 return 0;
38}
39
40static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
41{
42}
43
44#endif
45
46
47
48
49enum batadv_dbg_level {
50
51 BATADV_DBG_BATMAN = BIT(0),
52
53
54 BATADV_DBG_ROUTES = BIT(1),
55
56
57 BATADV_DBG_TT = BIT(2),
58
59
60 BATADV_DBG_BLA = BIT(3),
61
62
63 BATADV_DBG_DAT = BIT(4),
64
65
66 BATADV_DBG_NC = BIT(5),
67
68
69 BATADV_DBG_MCAST = BIT(6),
70
71
72 BATADV_DBG_TP_METER = BIT(7),
73
74
75 BATADV_DBG_ALL = 255,
76};
77
78#ifdef CONFIG_BATMAN_ADV_DEBUG
79int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
80__printf(2, 3);
81
82
83
84
85
86
87
88
89
90#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
91 do { \
92 struct batadv_priv *__batpriv = (bat_priv); \
93 if (atomic_read(&__batpriv->log_level) & (type) && \
94 (!(ratelimited) || net_ratelimit())) \
95 batadv_debug_log(__batpriv, fmt, ## arg); \
96 } \
97 while (0)
98#else
99__printf(4, 5)
100static inline void _batadv_dbg(int type __always_unused,
101 struct batadv_priv *bat_priv __always_unused,
102 int ratelimited __always_unused,
103 const char *fmt __always_unused, ...)
104{
105}
106#endif
107
108
109
110
111
112
113
114#define batadv_dbg(type, bat_priv, arg...) \
115 _batadv_dbg(type, bat_priv, 0, ## arg)
116
117
118
119
120
121
122
123#define batadv_dbg_ratelimited(type, bat_priv, arg...) \
124 _batadv_dbg(type, bat_priv, 1, ## arg)
125
126
127
128
129
130
131
132#define batadv_info(net_dev, fmt, arg...) \
133 do { \
134 struct net_device *_netdev = (net_dev); \
135 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
136 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
137 pr_info("%s: " fmt, _netdev->name, ## arg); \
138 } while (0)
139
140
141
142
143
144
145
146#define batadv_err(net_dev, fmt, arg...) \
147 do { \
148 struct net_device *_netdev = (net_dev); \
149 struct batadv_priv *_batpriv = netdev_priv(_netdev); \
150 batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
151 pr_err("%s: " fmt, _netdev->name, ## arg); \
152 } while (0)
153
154#endif
155