xref: /openbmc/linux/include/trace/events/xdp.h (revision ba61bb17)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM xdp
4 
5 #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_XDP_H
7 
8 #include <linux/netdevice.h>
9 #include <linux/filter.h>
10 #include <linux/tracepoint.h>
11 #include <linux/bpf.h>
12 
13 #define __XDP_ACT_MAP(FN)	\
14 	FN(ABORTED)		\
15 	FN(DROP)		\
16 	FN(PASS)		\
17 	FN(TX)			\
18 	FN(REDIRECT)
19 
20 #define __XDP_ACT_TP_FN(x)	\
21 	TRACE_DEFINE_ENUM(XDP_##x);
22 #define __XDP_ACT_SYM_FN(x)	\
23 	{ XDP_##x, #x },
24 #define __XDP_ACT_SYM_TAB	\
25 	__XDP_ACT_MAP(__XDP_ACT_SYM_FN) { -1, 0 }
26 __XDP_ACT_MAP(__XDP_ACT_TP_FN)
27 
28 TRACE_EVENT(xdp_exception,
29 
30 	TP_PROTO(const struct net_device *dev,
31 		 const struct bpf_prog *xdp, u32 act),
32 
33 	TP_ARGS(dev, xdp, act),
34 
35 	TP_STRUCT__entry(
36 		__field(int, prog_id)
37 		__field(u32, act)
38 		__field(int, ifindex)
39 	),
40 
41 	TP_fast_assign(
42 		__entry->prog_id	= xdp->aux->id;
43 		__entry->act		= act;
44 		__entry->ifindex	= dev->ifindex;
45 	),
46 
47 	TP_printk("prog_id=%d action=%s ifindex=%d",
48 		  __entry->prog_id,
49 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
50 		  __entry->ifindex)
51 );
52 
53 DECLARE_EVENT_CLASS(xdp_redirect_template,
54 
55 	TP_PROTO(const struct net_device *dev,
56 		 const struct bpf_prog *xdp,
57 		 int to_ifindex, int err,
58 		 const struct bpf_map *map, u32 map_index),
59 
60 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
61 
62 	TP_STRUCT__entry(
63 		__field(int, prog_id)
64 		__field(u32, act)
65 		__field(int, ifindex)
66 		__field(int, err)
67 		__field(int, to_ifindex)
68 		__field(u32, map_id)
69 		__field(int, map_index)
70 	),
71 
72 	TP_fast_assign(
73 		__entry->prog_id	= xdp->aux->id;
74 		__entry->act		= XDP_REDIRECT;
75 		__entry->ifindex	= dev->ifindex;
76 		__entry->err		= err;
77 		__entry->to_ifindex	= to_ifindex;
78 		__entry->map_id		= map ? map->id : 0;
79 		__entry->map_index	= map_index;
80 	),
81 
82 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d",
83 		  __entry->prog_id,
84 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
85 		  __entry->ifindex, __entry->to_ifindex,
86 		  __entry->err)
87 );
88 
89 DEFINE_EVENT(xdp_redirect_template, xdp_redirect,
90 	TP_PROTO(const struct net_device *dev,
91 		 const struct bpf_prog *xdp,
92 		 int to_ifindex, int err,
93 		 const struct bpf_map *map, u32 map_index),
94 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
95 );
96 
97 DEFINE_EVENT(xdp_redirect_template, xdp_redirect_err,
98 	TP_PROTO(const struct net_device *dev,
99 		 const struct bpf_prog *xdp,
100 		 int to_ifindex, int err,
101 		 const struct bpf_map *map, u32 map_index),
102 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
103 );
104 
105 #define _trace_xdp_redirect(dev, xdp, to)		\
106 	 trace_xdp_redirect(dev, xdp, to, 0, NULL, 0);
107 
108 #define _trace_xdp_redirect_err(dev, xdp, to, err)	\
109 	 trace_xdp_redirect_err(dev, xdp, to, err, NULL, 0);
110 
111 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map,
112 	TP_PROTO(const struct net_device *dev,
113 		 const struct bpf_prog *xdp,
114 		 int to_ifindex, int err,
115 		 const struct bpf_map *map, u32 map_index),
116 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
117 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
118 		  " map_id=%d map_index=%d",
119 		  __entry->prog_id,
120 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
121 		  __entry->ifindex, __entry->to_ifindex,
122 		  __entry->err,
123 		  __entry->map_id, __entry->map_index)
124 );
125 
126 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err,
127 	TP_PROTO(const struct net_device *dev,
128 		 const struct bpf_prog *xdp,
129 		 int to_ifindex, int err,
130 		 const struct bpf_map *map, u32 map_index),
131 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
132 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
133 		  " map_id=%d map_index=%d",
134 		  __entry->prog_id,
135 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
136 		  __entry->ifindex, __entry->to_ifindex,
137 		  __entry->err,
138 		  __entry->map_id, __entry->map_index)
139 );
140 
141 #ifndef __DEVMAP_OBJ_TYPE
142 #define __DEVMAP_OBJ_TYPE
143 struct _bpf_dtab_netdev {
144 	struct net_device *dev;
145 };
146 #endif /* __DEVMAP_OBJ_TYPE */
147 
148 #define devmap_ifindex(fwd, map)				\
149 	(!fwd ? 0 :						\
150 	 (!map ? 0 :						\
151 	  ((map->map_type == BPF_MAP_TYPE_DEVMAP) ?		\
152 	   ((struct _bpf_dtab_netdev *)fwd)->dev->ifindex : 0)))
153 
154 #define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx)		\
155 	 trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map),	\
156 				0, map, idx)
157 
158 #define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err)	\
159 	 trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map),	\
160 				    err, map, idx)
161 
162 TRACE_EVENT(xdp_cpumap_kthread,
163 
164 	TP_PROTO(int map_id, unsigned int processed,  unsigned int drops,
165 		 int sched),
166 
167 	TP_ARGS(map_id, processed, drops, sched),
168 
169 	TP_STRUCT__entry(
170 		__field(int, map_id)
171 		__field(u32, act)
172 		__field(int, cpu)
173 		__field(unsigned int, drops)
174 		__field(unsigned int, processed)
175 		__field(int, sched)
176 	),
177 
178 	TP_fast_assign(
179 		__entry->map_id		= map_id;
180 		__entry->act		= XDP_REDIRECT;
181 		__entry->cpu		= smp_processor_id();
182 		__entry->drops		= drops;
183 		__entry->processed	= processed;
184 		__entry->sched	= sched;
185 	),
186 
187 	TP_printk("kthread"
188 		  " cpu=%d map_id=%d action=%s"
189 		  " processed=%u drops=%u"
190 		  " sched=%d",
191 		  __entry->cpu, __entry->map_id,
192 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
193 		  __entry->processed, __entry->drops,
194 		  __entry->sched)
195 );
196 
197 TRACE_EVENT(xdp_cpumap_enqueue,
198 
199 	TP_PROTO(int map_id, unsigned int processed,  unsigned int drops,
200 		 int to_cpu),
201 
202 	TP_ARGS(map_id, processed, drops, to_cpu),
203 
204 	TP_STRUCT__entry(
205 		__field(int, map_id)
206 		__field(u32, act)
207 		__field(int, cpu)
208 		__field(unsigned int, drops)
209 		__field(unsigned int, processed)
210 		__field(int, to_cpu)
211 	),
212 
213 	TP_fast_assign(
214 		__entry->map_id		= map_id;
215 		__entry->act		= XDP_REDIRECT;
216 		__entry->cpu		= smp_processor_id();
217 		__entry->drops		= drops;
218 		__entry->processed	= processed;
219 		__entry->to_cpu		= to_cpu;
220 	),
221 
222 	TP_printk("enqueue"
223 		  " cpu=%d map_id=%d action=%s"
224 		  " processed=%u drops=%u"
225 		  " to_cpu=%d",
226 		  __entry->cpu, __entry->map_id,
227 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
228 		  __entry->processed, __entry->drops,
229 		  __entry->to_cpu)
230 );
231 
232 TRACE_EVENT(xdp_devmap_xmit,
233 
234 	TP_PROTO(const struct bpf_map *map, u32 map_index,
235 		 int sent, int drops,
236 		 const struct net_device *from_dev,
237 		 const struct net_device *to_dev, int err),
238 
239 	TP_ARGS(map, map_index, sent, drops, from_dev, to_dev, err),
240 
241 	TP_STRUCT__entry(
242 		__field(int, map_id)
243 		__field(u32, act)
244 		__field(u32, map_index)
245 		__field(int, drops)
246 		__field(int, sent)
247 		__field(int, from_ifindex)
248 		__field(int, to_ifindex)
249 		__field(int, err)
250 	),
251 
252 	TP_fast_assign(
253 		__entry->map_id		= map->id;
254 		__entry->act		= XDP_REDIRECT;
255 		__entry->map_index	= map_index;
256 		__entry->drops		= drops;
257 		__entry->sent		= sent;
258 		__entry->from_ifindex	= from_dev->ifindex;
259 		__entry->to_ifindex	= to_dev->ifindex;
260 		__entry->err		= err;
261 	),
262 
263 	TP_printk("ndo_xdp_xmit"
264 		  " map_id=%d map_index=%d action=%s"
265 		  " sent=%d drops=%d"
266 		  " from_ifindex=%d to_ifindex=%d err=%d",
267 		  __entry->map_id, __entry->map_index,
268 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
269 		  __entry->sent, __entry->drops,
270 		  __entry->from_ifindex, __entry->to_ifindex, __entry->err)
271 );
272 
273 #endif /* _TRACE_XDP_H */
274 
275 #include <trace/define_trace.h>
276