1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM xdp
5 #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/netdevice.h>
9 #include <linux/filter.h>
10 #include <linux/tracepoint.h>
11 #include <linux/bpf.h>
13 #define __XDP_ACT_MAP(FN) \
20 #define __XDP_ACT_TP_FN(x) \
21 TRACE_DEFINE_ENUM(XDP_##x);
22 #define __XDP_ACT_SYM_FN(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)
28 TRACE_EVENT(xdp_exception,
30 TP_PROTO(const struct net_device *dev,
31 const struct bpf_prog *xdp, u32 act),
33 TP_ARGS(dev, xdp, act),
42 __entry->prog_id = xdp->aux->id;
44 __entry->ifindex = dev->ifindex;
47 TP_printk("prog_id=%d action=%s ifindex=%d",
49 __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
53 DECLARE_EVENT_CLASS(xdp_redirect_template,
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),
60 TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
67 __field(int, to_ifindex)
69 __field(int, map_index)
73 __entry->prog_id = xdp->aux->id;
74 __entry->act = XDP_REDIRECT;
75 __entry->ifindex = dev->ifindex;
77 __entry->to_ifindex = to_ifindex;
78 __entry->map_id = map ? map->id : 0;
79 __entry->map_index = map_index;
82 TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d",
84 __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
85 __entry->ifindex, __entry->to_ifindex,
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)
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)
105 #define _trace_xdp_redirect(dev, xdp, to) \
106 trace_xdp_redirect(dev, xdp, to, 0, NULL, 0);
108 #define _trace_xdp_redirect_err(dev, xdp, to, err) \
109 trace_xdp_redirect_err(dev, xdp, to, err, NULL, 0);
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",
120 __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
121 __entry->ifindex, __entry->to_ifindex,
123 __entry->map_id, __entry->map_index)
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",
135 __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
136 __entry->ifindex, __entry->to_ifindex,
138 __entry->map_id, __entry->map_index)
141 #define devmap_ifindex(fwd, map) \
144 ((map->map_type == BPF_MAP_TYPE_DEVMAP) ? \
145 ((struct net_device *)fwd)->ifindex : 0)))
147 #define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx) \
148 trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map), \
151 #define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err) \
152 trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map), \
155 TRACE_EVENT(xdp_cpumap_kthread,
157 TP_PROTO(int map_id, unsigned int processed, unsigned int drops,
160 TP_ARGS(map_id, processed, drops, sched),
166 __field(unsigned int, drops)
167 __field(unsigned int, processed)
172 __entry->map_id = map_id;
173 __entry->act = XDP_REDIRECT;
174 __entry->cpu = smp_processor_id();
175 __entry->drops = drops;
176 __entry->processed = processed;
177 __entry->sched = sched;
181 " cpu=%d map_id=%d action=%s"
182 " processed=%u drops=%u"
184 __entry->cpu, __entry->map_id,
185 __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
186 __entry->processed, __entry->drops,
190 TRACE_EVENT(xdp_cpumap_enqueue,
192 TP_PROTO(int map_id, unsigned int processed, unsigned int drops,
195 TP_ARGS(map_id, processed, drops, to_cpu),
201 __field(unsigned int, drops)
202 __field(unsigned int, processed)
207 __entry->map_id = map_id;
208 __entry->act = XDP_REDIRECT;
209 __entry->cpu = smp_processor_id();
210 __entry->drops = drops;
211 __entry->processed = processed;
212 __entry->to_cpu = to_cpu;
216 " cpu=%d map_id=%d action=%s"
217 " processed=%u drops=%u"
219 __entry->cpu, __entry->map_id,
220 __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
221 __entry->processed, __entry->drops,
225 #endif /* _TRACE_XDP_H */
227 #include <trace/define_trace.h>