xref: /openbmc/linux/net/dsa/trace.h (revision 2a598d0b)
1 /* SPDX-License-Identifier: GPL-2.0
2  * Copyright 2022-2023 NXP
3  */
4 
5 #undef TRACE_SYSTEM
6 #define TRACE_SYSTEM	dsa
7 
8 #if !defined(_NET_DSA_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
9 #define _NET_DSA_TRACE_H
10 
11 #include <net/dsa.h>
12 #include <net/switchdev.h>
13 #include <linux/etherdevice.h>
14 #include <linux/if_bridge.h>
15 #include <linux/refcount.h>
16 #include <linux/tracepoint.h>
17 
18 /* Enough to fit "bridge %s num %d" where num has 3 digits */
19 #define DSA_DB_BUFSIZ	(IFNAMSIZ + 16)
20 
21 void dsa_db_print(const struct dsa_db *db, char buf[DSA_DB_BUFSIZ]);
22 const char *dsa_port_kind(const struct dsa_port *dp);
23 
24 DECLARE_EVENT_CLASS(dsa_port_addr_op_hw,
25 
26 	TP_PROTO(const struct dsa_port *dp, const unsigned char *addr, u16 vid,
27 		 const struct dsa_db *db, int err),
28 
29 	TP_ARGS(dp, addr, vid, db, err),
30 
31 	TP_STRUCT__entry(
32 		__string(dev, dev_name(dp->ds->dev))
33 		__string(kind, dsa_port_kind(dp))
34 		__field(int, port)
35 		__array(unsigned char, addr, ETH_ALEN)
36 		__field(u16, vid)
37 		__array(char, db_buf, DSA_DB_BUFSIZ)
38 		__field(int, err)
39 	),
40 
41 	TP_fast_assign(
42 		__assign_str(dev, dev_name(dp->ds->dev));
43 		__assign_str(kind, dsa_port_kind(dp));
44 		__entry->port = dp->index;
45 		ether_addr_copy(__entry->addr, addr);
46 		__entry->vid = vid;
47 		dsa_db_print(db, __entry->db_buf);
48 		__entry->err = err;
49 	),
50 
51 	TP_printk("%s %s port %d addr %pM vid %u db \"%s\" err %d",
52 		  __get_str(dev), __get_str(kind), __entry->port, __entry->addr,
53 		  __entry->vid, __entry->db_buf, __entry->err)
54 );
55 
56 /* Add unicast/multicast address to hardware, either on user ports
57  * (where no refcounting is kept), or on shared ports when the entry
58  * is first seen and its refcount is 1.
59  */
60 DEFINE_EVENT(dsa_port_addr_op_hw, dsa_fdb_add_hw,
61 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
62 		      u16 vid, const struct dsa_db *db, int err),
63 	     TP_ARGS(dp, addr, vid, db, err));
64 
65 DEFINE_EVENT(dsa_port_addr_op_hw, dsa_mdb_add_hw,
66 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
67 		      u16 vid, const struct dsa_db *db, int err),
68 	     TP_ARGS(dp, addr, vid, db, err));
69 
70 /* Delete unicast/multicast address from hardware, either on user ports or
71  * when the refcount on shared ports reaches 0
72  */
73 DEFINE_EVENT(dsa_port_addr_op_hw, dsa_fdb_del_hw,
74 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
75 		      u16 vid, const struct dsa_db *db, int err),
76 	     TP_ARGS(dp, addr, vid, db, err));
77 
78 DEFINE_EVENT(dsa_port_addr_op_hw, dsa_mdb_del_hw,
79 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
80 		      u16 vid, const struct dsa_db *db, int err),
81 	     TP_ARGS(dp, addr, vid, db, err));
82 
83 DECLARE_EVENT_CLASS(dsa_port_addr_op_refcount,
84 
85 	TP_PROTO(const struct dsa_port *dp, const unsigned char *addr, u16 vid,
86 		 const struct dsa_db *db, const refcount_t *refcount),
87 
88 	TP_ARGS(dp, addr, vid, db, refcount),
89 
90 	TP_STRUCT__entry(
91 		__string(dev, dev_name(dp->ds->dev))
92 		__string(kind, dsa_port_kind(dp))
93 		__field(int, port)
94 		__array(unsigned char, addr, ETH_ALEN)
95 		__field(u16, vid)
96 		__array(char, db_buf, DSA_DB_BUFSIZ)
97 		__field(unsigned int, refcount)
98 	),
99 
100 	TP_fast_assign(
101 		__assign_str(dev, dev_name(dp->ds->dev));
102 		__assign_str(kind, dsa_port_kind(dp));
103 		__entry->port = dp->index;
104 		ether_addr_copy(__entry->addr, addr);
105 		__entry->vid = vid;
106 		dsa_db_print(db, __entry->db_buf);
107 		__entry->refcount = refcount_read(refcount);
108 	),
109 
110 	TP_printk("%s %s port %d addr %pM vid %u db \"%s\" refcount %u",
111 		  __get_str(dev), __get_str(kind), __entry->port, __entry->addr,
112 		  __entry->vid, __entry->db_buf, __entry->refcount)
113 );
114 
115 /* Bump the refcount of an existing unicast/multicast address on shared ports */
116 DEFINE_EVENT(dsa_port_addr_op_refcount, dsa_fdb_add_bump,
117 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
118 		      u16 vid, const struct dsa_db *db,
119 		      const refcount_t *refcount),
120 	     TP_ARGS(dp, addr, vid, db, refcount));
121 
122 DEFINE_EVENT(dsa_port_addr_op_refcount, dsa_mdb_add_bump,
123 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
124 		      u16 vid, const struct dsa_db *db,
125 		      const refcount_t *refcount),
126 	     TP_ARGS(dp, addr, vid, db, refcount));
127 
128 /* Drop the refcount of a multicast address that we still keep on
129  * shared ports
130  */
131 DEFINE_EVENT(dsa_port_addr_op_refcount, dsa_fdb_del_drop,
132 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
133 		      u16 vid, const struct dsa_db *db,
134 		      const refcount_t *refcount),
135 	     TP_ARGS(dp, addr, vid, db, refcount));
136 
137 DEFINE_EVENT(dsa_port_addr_op_refcount, dsa_mdb_del_drop,
138 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
139 		      u16 vid, const struct dsa_db *db,
140 		      const refcount_t *refcount),
141 	     TP_ARGS(dp, addr, vid, db, refcount));
142 
143 DECLARE_EVENT_CLASS(dsa_port_addr_del_not_found,
144 
145 	TP_PROTO(const struct dsa_port *dp, const unsigned char *addr, u16 vid,
146 		 const struct dsa_db *db),
147 
148 	TP_ARGS(dp, addr, vid, db),
149 
150 	TP_STRUCT__entry(
151 		__string(dev, dev_name(dp->ds->dev))
152 		__string(kind, dsa_port_kind(dp))
153 		__field(int, port)
154 		__array(unsigned char, addr, ETH_ALEN)
155 		__field(u16, vid)
156 		__array(char, db_buf, DSA_DB_BUFSIZ)
157 	),
158 
159 	TP_fast_assign(
160 		__assign_str(dev, dev_name(dp->ds->dev));
161 		__assign_str(kind, dsa_port_kind(dp));
162 		__entry->port = dp->index;
163 		ether_addr_copy(__entry->addr, addr);
164 		__entry->vid = vid;
165 		dsa_db_print(db, __entry->db_buf);
166 	),
167 
168 	TP_printk("%s %s port %d addr %pM vid %u db \"%s\"",
169 		  __get_str(dev), __get_str(kind), __entry->port,
170 		  __entry->addr, __entry->vid, __entry->db_buf)
171 );
172 
173 /* Attempt to delete a unicast/multicast address on shared ports for which
174  * the delete operation was called more times than the addition
175  */
176 DEFINE_EVENT(dsa_port_addr_del_not_found, dsa_fdb_del_not_found,
177 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
178 		      u16 vid, const struct dsa_db *db),
179 	     TP_ARGS(dp, addr, vid, db));
180 
181 DEFINE_EVENT(dsa_port_addr_del_not_found, dsa_mdb_del_not_found,
182 	     TP_PROTO(const struct dsa_port *dp, const unsigned char *addr,
183 		      u16 vid, const struct dsa_db *db),
184 	     TP_ARGS(dp, addr, vid, db));
185 
186 TRACE_EVENT(dsa_lag_fdb_add_hw,
187 
188 	TP_PROTO(const struct net_device *lag_dev, const unsigned char *addr,
189 		 u16 vid, const struct dsa_db *db, int err),
190 
191 	TP_ARGS(lag_dev, addr, vid, db, err),
192 
193 	TP_STRUCT__entry(
194 		__string(dev, lag_dev->name)
195 		__array(unsigned char, addr, ETH_ALEN)
196 		__field(u16, vid)
197 		__array(char, db_buf, DSA_DB_BUFSIZ)
198 		__field(int, err)
199 	),
200 
201 	TP_fast_assign(
202 		__assign_str(dev, lag_dev->name);
203 		ether_addr_copy(__entry->addr, addr);
204 		__entry->vid = vid;
205 		dsa_db_print(db, __entry->db_buf);
206 		__entry->err = err;
207 	),
208 
209 	TP_printk("%s addr %pM vid %u db \"%s\" err %d",
210 		  __get_str(dev), __entry->addr, __entry->vid,
211 		  __entry->db_buf, __entry->err)
212 );
213 
214 TRACE_EVENT(dsa_lag_fdb_add_bump,
215 
216 	TP_PROTO(const struct net_device *lag_dev, const unsigned char *addr,
217 		 u16 vid, const struct dsa_db *db, const refcount_t *refcount),
218 
219 	TP_ARGS(lag_dev, addr, vid, db, refcount),
220 
221 	TP_STRUCT__entry(
222 		__string(dev, lag_dev->name)
223 		__array(unsigned char, addr, ETH_ALEN)
224 		__field(u16, vid)
225 		__array(char, db_buf, DSA_DB_BUFSIZ)
226 		__field(unsigned int, refcount)
227 	),
228 
229 	TP_fast_assign(
230 		__assign_str(dev, lag_dev->name);
231 		ether_addr_copy(__entry->addr, addr);
232 		__entry->vid = vid;
233 		dsa_db_print(db, __entry->db_buf);
234 		__entry->refcount = refcount_read(refcount);
235 	),
236 
237 	TP_printk("%s addr %pM vid %u db \"%s\" refcount %u",
238 		  __get_str(dev), __entry->addr, __entry->vid,
239 		  __entry->db_buf, __entry->refcount)
240 );
241 
242 TRACE_EVENT(dsa_lag_fdb_del_hw,
243 
244 	TP_PROTO(const struct net_device *lag_dev, const unsigned char *addr,
245 		 u16 vid, const struct dsa_db *db, int err),
246 
247 	TP_ARGS(lag_dev, addr, vid, db, err),
248 
249 	TP_STRUCT__entry(
250 		__string(dev, lag_dev->name)
251 		__array(unsigned char, addr, ETH_ALEN)
252 		__field(u16, vid)
253 		__array(char, db_buf, DSA_DB_BUFSIZ)
254 		__field(int, err)
255 	),
256 
257 	TP_fast_assign(
258 		__assign_str(dev, lag_dev->name);
259 		ether_addr_copy(__entry->addr, addr);
260 		__entry->vid = vid;
261 		dsa_db_print(db, __entry->db_buf);
262 		__entry->err = err;
263 	),
264 
265 	TP_printk("%s addr %pM vid %u db \"%s\" err %d",
266 		  __get_str(dev), __entry->addr, __entry->vid,
267 		  __entry->db_buf, __entry->err)
268 );
269 
270 TRACE_EVENT(dsa_lag_fdb_del_drop,
271 
272 	TP_PROTO(const struct net_device *lag_dev, const unsigned char *addr,
273 		 u16 vid, const struct dsa_db *db, const refcount_t *refcount),
274 
275 	TP_ARGS(lag_dev, addr, vid, db, refcount),
276 
277 	TP_STRUCT__entry(
278 		__string(dev, lag_dev->name)
279 		__array(unsigned char, addr, ETH_ALEN)
280 		__field(u16, vid)
281 		__array(char, db_buf, DSA_DB_BUFSIZ)
282 		__field(unsigned int, refcount)
283 	),
284 
285 	TP_fast_assign(
286 		__assign_str(dev, lag_dev->name);
287 		ether_addr_copy(__entry->addr, addr);
288 		__entry->vid = vid;
289 		dsa_db_print(db, __entry->db_buf);
290 		__entry->refcount = refcount_read(refcount);
291 	),
292 
293 	TP_printk("%s addr %pM vid %u db \"%s\" refcount %u",
294 		  __get_str(dev), __entry->addr, __entry->vid,
295 		  __entry->db_buf, __entry->refcount)
296 );
297 
298 TRACE_EVENT(dsa_lag_fdb_del_not_found,
299 
300 	TP_PROTO(const struct net_device *lag_dev, const unsigned char *addr,
301 		 u16 vid, const struct dsa_db *db),
302 
303 	TP_ARGS(lag_dev, addr, vid, db),
304 
305 	TP_STRUCT__entry(
306 		__string(dev, lag_dev->name)
307 		__array(unsigned char, addr, ETH_ALEN)
308 		__field(u16, vid)
309 		__array(char, db_buf, DSA_DB_BUFSIZ)
310 	),
311 
312 	TP_fast_assign(
313 		__assign_str(dev, lag_dev->name);
314 		ether_addr_copy(__entry->addr, addr);
315 		__entry->vid = vid;
316 		dsa_db_print(db, __entry->db_buf);
317 	),
318 
319 	TP_printk("%s addr %pM vid %u db \"%s\"",
320 		  __get_str(dev), __entry->addr, __entry->vid, __entry->db_buf)
321 );
322 
323 DECLARE_EVENT_CLASS(dsa_vlan_op_hw,
324 
325 	TP_PROTO(const struct dsa_port *dp,
326 		 const struct switchdev_obj_port_vlan *vlan, int err),
327 
328 	TP_ARGS(dp, vlan, err),
329 
330 	TP_STRUCT__entry(
331 		__string(dev, dev_name(dp->ds->dev))
332 		__string(kind, dsa_port_kind(dp))
333 		__field(int, port)
334 		__field(u16, vid)
335 		__field(u16, flags)
336 		__field(bool, changed)
337 		__field(int, err)
338 	),
339 
340 	TP_fast_assign(
341 		__assign_str(dev, dev_name(dp->ds->dev));
342 		__assign_str(kind, dsa_port_kind(dp));
343 		__entry->port = dp->index;
344 		__entry->vid = vlan->vid;
345 		__entry->flags = vlan->flags;
346 		__entry->changed = vlan->changed;
347 		__entry->err = err;
348 	),
349 
350 	TP_printk("%s %s port %d vid %u%s%s%s",
351 		  __get_str(dev), __get_str(kind), __entry->port, __entry->vid,
352 		  __entry->flags & BRIDGE_VLAN_INFO_PVID ? " pvid" : "",
353 		  __entry->flags & BRIDGE_VLAN_INFO_UNTAGGED ? " untagged" : "",
354 		  __entry->changed ? " (changed)" : "")
355 );
356 
357 DEFINE_EVENT(dsa_vlan_op_hw, dsa_vlan_add_hw,
358 	     TP_PROTO(const struct dsa_port *dp,
359 		      const struct switchdev_obj_port_vlan *vlan, int err),
360 	     TP_ARGS(dp, vlan, err));
361 
362 DEFINE_EVENT(dsa_vlan_op_hw, dsa_vlan_del_hw,
363 	     TP_PROTO(const struct dsa_port *dp,
364 		      const struct switchdev_obj_port_vlan *vlan, int err),
365 	     TP_ARGS(dp, vlan, err));
366 
367 DECLARE_EVENT_CLASS(dsa_vlan_op_refcount,
368 
369 	TP_PROTO(const struct dsa_port *dp,
370 		 const struct switchdev_obj_port_vlan *vlan,
371 		 const refcount_t *refcount),
372 
373 	TP_ARGS(dp, vlan, refcount),
374 
375 	TP_STRUCT__entry(
376 		__string(dev, dev_name(dp->ds->dev))
377 		__string(kind, dsa_port_kind(dp))
378 		__field(int, port)
379 		__field(u16, vid)
380 		__field(u16, flags)
381 		__field(bool, changed)
382 		__field(unsigned int, refcount)
383 	),
384 
385 	TP_fast_assign(
386 		__assign_str(dev, dev_name(dp->ds->dev));
387 		__assign_str(kind, dsa_port_kind(dp));
388 		__entry->port = dp->index;
389 		__entry->vid = vlan->vid;
390 		__entry->flags = vlan->flags;
391 		__entry->changed = vlan->changed;
392 		__entry->refcount = refcount_read(refcount);
393 	),
394 
395 	TP_printk("%s %s port %d vid %u%s%s%s refcount %u",
396 		  __get_str(dev), __get_str(kind), __entry->port, __entry->vid,
397 		  __entry->flags & BRIDGE_VLAN_INFO_PVID ? " pvid" : "",
398 		  __entry->flags & BRIDGE_VLAN_INFO_UNTAGGED ? " untagged" : "",
399 		  __entry->changed ? " (changed)" : "", __entry->refcount)
400 );
401 
402 DEFINE_EVENT(dsa_vlan_op_refcount, dsa_vlan_add_bump,
403 	     TP_PROTO(const struct dsa_port *dp,
404 		      const struct switchdev_obj_port_vlan *vlan,
405 		      const refcount_t *refcount),
406 	     TP_ARGS(dp, vlan, refcount));
407 
408 DEFINE_EVENT(dsa_vlan_op_refcount, dsa_vlan_del_drop,
409 	     TP_PROTO(const struct dsa_port *dp,
410 		      const struct switchdev_obj_port_vlan *vlan,
411 		      const refcount_t *refcount),
412 	     TP_ARGS(dp, vlan, refcount));
413 
414 TRACE_EVENT(dsa_vlan_del_not_found,
415 
416 	TP_PROTO(const struct dsa_port *dp,
417 		 const struct switchdev_obj_port_vlan *vlan),
418 
419 	TP_ARGS(dp, vlan),
420 
421 	TP_STRUCT__entry(
422 		__string(dev, dev_name(dp->ds->dev))
423 		__string(kind, dsa_port_kind(dp))
424 		__field(int, port)
425 		__field(u16, vid)
426 	),
427 
428 	TP_fast_assign(
429 		__assign_str(dev, dev_name(dp->ds->dev));
430 		__assign_str(kind, dsa_port_kind(dp));
431 		__entry->port = dp->index;
432 		__entry->vid = vlan->vid;
433 	),
434 
435 	TP_printk("%s %s port %d vid %u",
436 		  __get_str(dev), __get_str(kind), __entry->port, __entry->vid)
437 );
438 
439 #endif /* _NET_DSA_TRACE_H */
440 
441 /* We don't want to use include/trace/events */
442 #undef TRACE_INCLUDE_PATH
443 #define TRACE_INCLUDE_PATH .
444 #undef TRACE_INCLUDE_FILE
445 #define TRACE_INCLUDE_FILE	trace
446 /* This part must be outside protection */
447 #include <trace/define_trace.h>
448