Merge tag 'drm-fixes-2022-12-09' of git://anongit.freedesktop.org/drm/drm
[platform/kernel/linux-starfive.git] / net / tipc / trace.h
1 /*
2  * net/tipc/trace.h: TIPC tracepoints
3  *
4  * Copyright (c) 2018, Ericsson AB
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the names of the copyright holders nor the names of its
16  *    contributors may be used to endorse or promote products derived from
17  *    this software without specific prior written permission.
18  *
19  * Alternatively, this software may be distributed under the terms of the
20  * GNU General Public License ("GPL") version 2 as published by the Free
21  * Software Foundation.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 #undef TRACE_SYSTEM
37 #define TRACE_SYSTEM tipc
38
39 #if !defined(_TIPC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
40 #define _TIPC_TRACE_H
41
42 #include <linux/tracepoint.h>
43 #include "core.h"
44 #include "link.h"
45 #include "socket.h"
46 #include "node.h"
47
48 #define SKB_LMIN        (100)
49 #define SKB_LMAX        (SKB_LMIN * 2)
50 #define LIST_LMIN       (SKB_LMIN * 3)
51 #define LIST_LMAX       (SKB_LMIN * 11)
52 #define SK_LMIN         (SKB_LMIN * 2)
53 #define SK_LMAX         (SKB_LMIN * 11)
54 #define LINK_LMIN       (SKB_LMIN)
55 #define LINK_LMAX       (SKB_LMIN * 16)
56 #define NODE_LMIN       (SKB_LMIN)
57 #define NODE_LMAX       (SKB_LMIN * 11)
58
59 #ifndef __TIPC_TRACE_ENUM
60 #define __TIPC_TRACE_ENUM
61 enum {
62         TIPC_DUMP_NONE          = 0,
63
64         TIPC_DUMP_TRANSMQ       = 1,
65         TIPC_DUMP_BACKLOGQ      = (1 << 1),
66         TIPC_DUMP_DEFERDQ       = (1 << 2),
67         TIPC_DUMP_INPUTQ        = (1 << 3),
68         TIPC_DUMP_WAKEUP        = (1 << 4),
69
70         TIPC_DUMP_SK_SNDQ       = (1 << 8),
71         TIPC_DUMP_SK_RCVQ       = (1 << 9),
72         TIPC_DUMP_SK_BKLGQ      = (1 << 10),
73         TIPC_DUMP_ALL           = 0xffffu
74 };
75 #endif
76
77 /* Link & Node FSM states: */
78 #define state_sym(val)                                                    \
79         __print_symbolic(val,                                             \
80                         {(0xe),         "ESTABLISHED"                   },\
81                         {(0xe << 4),    "ESTABLISHING"                  },\
82                         {(0x1 << 8),    "RESET"                         },\
83                         {(0x2 << 12),   "RESETTING"                     },\
84                         {(0xd << 16),   "PEER_RESET"                    },\
85                         {(0xf << 20),   "FAILINGOVER"                   },\
86                         {(0xc << 24),   "SYNCHING"                      },\
87                         {(0xdd),        "SELF_DOWN_PEER_DOWN"           },\
88                         {(0xaa),        "SELF_UP_PEER_UP"               },\
89                         {(0xd1),        "SELF_DOWN_PEER_LEAVING"        },\
90                         {(0xac),        "SELF_UP_PEER_COMING"           },\
91                         {(0xca),        "SELF_COMING_PEER_UP"           },\
92                         {(0x1d),        "SELF_LEAVING_PEER_DOWN"        },\
93                         {(0xf0),        "FAILINGOVER"                   },\
94                         {(0xcc),        "SYNCHING"                      })
95
96 /* Link & Node FSM events: */
97 #define evt_sym(val)                                                      \
98         __print_symbolic(val,                                             \
99                         {(0xec1ab1e),   "ESTABLISH_EVT"                 },\
100                         {(0x9eed0e),    "PEER_RESET_EVT"                },\
101                         {(0xfa110e),    "FAILURE_EVT"                   },\
102                         {(0x10ca1d0e),  "RESET_EVT"                     },\
103                         {(0xfa110bee),  "FAILOVER_BEGIN_EVT"            },\
104                         {(0xfa110ede),  "FAILOVER_END_EVT"              },\
105                         {(0xc1ccbee),   "SYNCH_BEGIN_EVT"               },\
106                         {(0xc1ccede),   "SYNCH_END_EVT"                 },\
107                         {(0xece),       "SELF_ESTABL_CONTACT_EVT"       },\
108                         {(0x1ce),       "SELF_LOST_CONTACT_EVT"         },\
109                         {(0x9ece),      "PEER_ESTABL_CONTACT_EVT"       },\
110                         {(0x91ce),      "PEER_LOST_CONTACT_EVT"         },\
111                         {(0xfbe),       "FAILOVER_BEGIN_EVT"            },\
112                         {(0xfee),       "FAILOVER_END_EVT"              },\
113                         {(0xcbe),       "SYNCH_BEGIN_EVT"               },\
114                         {(0xcee),       "SYNCH_END_EVT"                 })
115
116 /* Bearer, net device events: */
117 #define dev_evt_sym(val)                                                  \
118         __print_symbolic(val,                                             \
119                         {(NETDEV_CHANGE),       "NETDEV_CHANGE"         },\
120                         {(NETDEV_GOING_DOWN),   "NETDEV_GOING_DOWN"     },\
121                         {(NETDEV_UP),           "NETDEV_UP"             },\
122                         {(NETDEV_CHANGEMTU),    "NETDEV_CHANGEMTU"      },\
123                         {(NETDEV_CHANGEADDR),   "NETDEV_CHANGEADDR"     },\
124                         {(NETDEV_UNREGISTER),   "NETDEV_UNREGISTER"     },\
125                         {(NETDEV_CHANGENAME),   "NETDEV_CHANGENAME"     })
126
127 extern unsigned long sysctl_tipc_sk_filter[5] __read_mostly;
128
129 int tipc_skb_dump(struct sk_buff *skb, bool more, char *buf);
130 int tipc_list_dump(struct sk_buff_head *list, bool more, char *buf);
131 int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf);
132 int tipc_link_dump(struct tipc_link *l, u16 dqueues, char *buf);
133 int tipc_node_dump(struct tipc_node *n, bool more, char *buf);
134 bool tipc_sk_filtering(struct sock *sk);
135
136 DECLARE_EVENT_CLASS(tipc_skb_class,
137
138         TP_PROTO(struct sk_buff *skb, bool more, const char *header),
139
140         TP_ARGS(skb, more, header),
141
142         TP_STRUCT__entry(
143                 __string(header, header)
144                 __dynamic_array(char, buf, (more) ? SKB_LMAX : SKB_LMIN)
145         ),
146
147         TP_fast_assign(
148                 __assign_str(header, header);
149                 tipc_skb_dump(skb, more, __get_str(buf));
150         ),
151
152         TP_printk("%s\n%s", __get_str(header), __get_str(buf))
153 )
154
155 #define DEFINE_SKB_EVENT(name) \
156 DEFINE_EVENT(tipc_skb_class, name, \
157         TP_PROTO(struct sk_buff *skb, bool more, const char *header), \
158         TP_ARGS(skb, more, header))
159 DEFINE_SKB_EVENT(tipc_skb_dump);
160 DEFINE_SKB_EVENT(tipc_proto_build);
161 DEFINE_SKB_EVENT(tipc_proto_rcv);
162
163 DECLARE_EVENT_CLASS(tipc_list_class,
164
165         TP_PROTO(struct sk_buff_head *list, bool more, const char *header),
166
167         TP_ARGS(list, more, header),
168
169         TP_STRUCT__entry(
170                 __string(header, header)
171                 __dynamic_array(char, buf, (more) ? LIST_LMAX : LIST_LMIN)
172         ),
173
174         TP_fast_assign(
175                 __assign_str(header, header);
176                 tipc_list_dump(list, more, __get_str(buf));
177         ),
178
179         TP_printk("%s\n%s", __get_str(header), __get_str(buf))
180 );
181
182 #define DEFINE_LIST_EVENT(name) \
183 DEFINE_EVENT(tipc_list_class, name, \
184         TP_PROTO(struct sk_buff_head *list, bool more, const char *header), \
185         TP_ARGS(list, more, header))
186 DEFINE_LIST_EVENT(tipc_list_dump);
187
188 DECLARE_EVENT_CLASS(tipc_sk_class,
189
190         TP_PROTO(struct sock *sk, struct sk_buff *skb, u16 dqueues,
191                  const char *header),
192
193         TP_ARGS(sk, skb, dqueues, header),
194
195         TP_STRUCT__entry(
196                 __string(header, header)
197                 __field(u32, portid)
198                 __dynamic_array(char, buf, (dqueues) ? SK_LMAX : SK_LMIN)
199                 __dynamic_array(char, skb_buf, (skb) ? SKB_LMIN : 1)
200         ),
201
202         TP_fast_assign(
203                 __assign_str(header, header);
204                 __entry->portid = tipc_sock_get_portid(sk);
205                 tipc_sk_dump(sk, dqueues, __get_str(buf));
206                 if (skb)
207                         tipc_skb_dump(skb, false, __get_str(skb_buf));
208                 else
209                         *(__get_str(skb_buf)) = '\0';
210         ),
211
212         TP_printk("<%u> %s\n%s%s", __entry->portid, __get_str(header),
213                   __get_str(skb_buf), __get_str(buf))
214 );
215
216 #define DEFINE_SK_EVENT_FILTER(name) \
217 DEFINE_EVENT_CONDITION(tipc_sk_class, name, \
218         TP_PROTO(struct sock *sk, struct sk_buff *skb, u16 dqueues, \
219                  const char *header), \
220         TP_ARGS(sk, skb, dqueues, header), \
221         TP_CONDITION(tipc_sk_filtering(sk)))
222 DEFINE_SK_EVENT_FILTER(tipc_sk_dump);
223 DEFINE_SK_EVENT_FILTER(tipc_sk_create);
224 DEFINE_SK_EVENT_FILTER(tipc_sk_sendmcast);
225 DEFINE_SK_EVENT_FILTER(tipc_sk_sendmsg);
226 DEFINE_SK_EVENT_FILTER(tipc_sk_sendstream);
227 DEFINE_SK_EVENT_FILTER(tipc_sk_poll);
228 DEFINE_SK_EVENT_FILTER(tipc_sk_filter_rcv);
229 DEFINE_SK_EVENT_FILTER(tipc_sk_advance_rx);
230 DEFINE_SK_EVENT_FILTER(tipc_sk_rej_msg);
231 DEFINE_SK_EVENT_FILTER(tipc_sk_drop_msg);
232 DEFINE_SK_EVENT_FILTER(tipc_sk_release);
233 DEFINE_SK_EVENT_FILTER(tipc_sk_shutdown);
234
235 #define DEFINE_SK_EVENT_FILTER_COND(name, cond) \
236 DEFINE_EVENT_CONDITION(tipc_sk_class, name, \
237         TP_PROTO(struct sock *sk, struct sk_buff *skb, u16 dqueues, \
238                  const char *header), \
239         TP_ARGS(sk, skb, dqueues, header), \
240         TP_CONDITION(tipc_sk_filtering(sk) && (cond)))
241 DEFINE_SK_EVENT_FILTER_COND(tipc_sk_overlimit1, tipc_sk_overlimit1(sk, skb));
242 DEFINE_SK_EVENT_FILTER_COND(tipc_sk_overlimit2, tipc_sk_overlimit2(sk, skb));
243
244 DECLARE_EVENT_CLASS(tipc_link_class,
245
246         TP_PROTO(struct tipc_link *l, u16 dqueues, const char *header),
247
248         TP_ARGS(l, dqueues, header),
249
250         TP_STRUCT__entry(
251                 __string(header, header)
252                 __array(char, name, TIPC_MAX_LINK_NAME)
253                 __dynamic_array(char, buf, (dqueues) ? LINK_LMAX : LINK_LMIN)
254         ),
255
256         TP_fast_assign(
257                 __assign_str(header, header);
258                 memcpy(__entry->name, tipc_link_name(l), TIPC_MAX_LINK_NAME);
259                 tipc_link_dump(l, dqueues, __get_str(buf));
260         ),
261
262         TP_printk("<%s> %s\n%s", __entry->name, __get_str(header),
263                   __get_str(buf))
264 );
265
266 #define DEFINE_LINK_EVENT(name) \
267 DEFINE_EVENT(tipc_link_class, name, \
268         TP_PROTO(struct tipc_link *l, u16 dqueues, const char *header), \
269         TP_ARGS(l, dqueues, header))
270 DEFINE_LINK_EVENT(tipc_link_dump);
271 DEFINE_LINK_EVENT(tipc_link_conges);
272 DEFINE_LINK_EVENT(tipc_link_timeout);
273 DEFINE_LINK_EVENT(tipc_link_reset);
274
275 #define DEFINE_LINK_EVENT_COND(name, cond) \
276 DEFINE_EVENT_CONDITION(tipc_link_class, name, \
277         TP_PROTO(struct tipc_link *l, u16 dqueues, const char *header), \
278         TP_ARGS(l, dqueues, header), \
279         TP_CONDITION(cond))
280 DEFINE_LINK_EVENT_COND(tipc_link_too_silent, tipc_link_too_silent(l));
281
282 DECLARE_EVENT_CLASS(tipc_link_transmq_class,
283
284         TP_PROTO(struct tipc_link *r, u16 f, u16 t, struct sk_buff_head *tq),
285
286         TP_ARGS(r, f, t, tq),
287
288         TP_STRUCT__entry(
289                 __array(char, name, TIPC_MAX_LINK_NAME)
290                 __field(u16, from)
291                 __field(u16, to)
292                 __field(u32, len)
293                 __field(u16, fseqno)
294                 __field(u16, lseqno)
295         ),
296
297         TP_fast_assign(
298                 memcpy(__entry->name, tipc_link_name(r), TIPC_MAX_LINK_NAME);
299                 __entry->from = f;
300                 __entry->to = t;
301                 __entry->len = skb_queue_len(tq);
302                 __entry->fseqno = __entry->len ?
303                                   msg_seqno(buf_msg(skb_peek(tq))) : 0;
304                 __entry->lseqno = __entry->len ?
305                                   msg_seqno(buf_msg(skb_peek_tail(tq))) : 0;
306         ),
307
308         TP_printk("<%s> retrans req: [%u-%u] transmq: %u [%u-%u]\n",
309                   __entry->name, __entry->from, __entry->to,
310                   __entry->len, __entry->fseqno, __entry->lseqno)
311 );
312
313 DEFINE_EVENT_CONDITION(tipc_link_transmq_class, tipc_link_retrans,
314         TP_PROTO(struct tipc_link *r, u16 f, u16 t, struct sk_buff_head *tq),
315         TP_ARGS(r, f, t, tq),
316         TP_CONDITION(less_eq(f, t))
317 );
318
319 DEFINE_EVENT_PRINT(tipc_link_transmq_class, tipc_link_bc_ack,
320         TP_PROTO(struct tipc_link *r, u16 f, u16 t, struct sk_buff_head *tq),
321         TP_ARGS(r, f, t, tq),
322         TP_printk("<%s> acked: %u gap: %u transmq: %u [%u-%u]\n",
323                   __entry->name, __entry->from, __entry->to,
324                   __entry->len, __entry->fseqno, __entry->lseqno)
325 );
326
327 DECLARE_EVENT_CLASS(tipc_node_class,
328
329         TP_PROTO(struct tipc_node *n, bool more, const char *header),
330
331         TP_ARGS(n, more, header),
332
333         TP_STRUCT__entry(
334                 __string(header, header)
335                 __field(u32, addr)
336                 __dynamic_array(char, buf, (more) ? NODE_LMAX : NODE_LMIN)
337         ),
338
339         TP_fast_assign(
340                 __assign_str(header, header);
341                 __entry->addr = tipc_node_get_addr(n);
342                 tipc_node_dump(n, more, __get_str(buf));
343         ),
344
345         TP_printk("<%x> %s\n%s", __entry->addr, __get_str(header),
346                   __get_str(buf))
347 );
348
349 #define DEFINE_NODE_EVENT(name) \
350 DEFINE_EVENT(tipc_node_class, name, \
351         TP_PROTO(struct tipc_node *n, bool more, const char *header), \
352         TP_ARGS(n, more, header))
353 DEFINE_NODE_EVENT(tipc_node_dump);
354 DEFINE_NODE_EVENT(tipc_node_create);
355 DEFINE_NODE_EVENT(tipc_node_delete);
356 DEFINE_NODE_EVENT(tipc_node_lost_contact);
357 DEFINE_NODE_EVENT(tipc_node_timeout);
358 DEFINE_NODE_EVENT(tipc_node_link_up);
359 DEFINE_NODE_EVENT(tipc_node_link_down);
360 DEFINE_NODE_EVENT(tipc_node_reset_links);
361 DEFINE_NODE_EVENT(tipc_node_check_state);
362
363 DECLARE_EVENT_CLASS(tipc_fsm_class,
364
365         TP_PROTO(const char *name, u32 os, u32 ns, int evt),
366
367         TP_ARGS(name, os, ns, evt),
368
369         TP_STRUCT__entry(
370                 __string(name, name)
371                 __field(u32, os)
372                 __field(u32, ns)
373                 __field(u32, evt)
374         ),
375
376         TP_fast_assign(
377                 __assign_str(name, name);
378                 __entry->os = os;
379                 __entry->ns = ns;
380                 __entry->evt = evt;
381         ),
382
383         TP_printk("<%s> %s--(%s)->%s\n", __get_str(name),
384                   state_sym(__entry->os), evt_sym(__entry->evt),
385                   state_sym(__entry->ns))
386 );
387
388 #define DEFINE_FSM_EVENT(fsm_name) \
389 DEFINE_EVENT(tipc_fsm_class, fsm_name, \
390         TP_PROTO(const char *name, u32 os, u32 ns, int evt), \
391         TP_ARGS(name, os, ns, evt))
392 DEFINE_FSM_EVENT(tipc_link_fsm);
393 DEFINE_FSM_EVENT(tipc_node_fsm);
394
395 TRACE_EVENT(tipc_l2_device_event,
396
397         TP_PROTO(struct net_device *dev, struct tipc_bearer *b,
398                  unsigned long evt),
399
400         TP_ARGS(dev, b, evt),
401
402         TP_STRUCT__entry(
403                 __string(dev_name, dev->name)
404                 __string(b_name, b->name)
405                 __field(unsigned long, evt)
406                 __field(u8, b_up)
407                 __field(u8, carrier)
408                 __field(u8, oper)
409         ),
410
411         TP_fast_assign(
412                 __assign_str(dev_name, dev->name);
413                 __assign_str(b_name, b->name);
414                 __entry->evt = evt;
415                 __entry->b_up = test_bit(0, &b->up);
416                 __entry->carrier = netif_carrier_ok(dev);
417                 __entry->oper = netif_oper_up(dev);
418         ),
419
420         TP_printk("%s on: <%s>/<%s> oper: %s carrier: %s bearer: %s\n",
421                   dev_evt_sym(__entry->evt), __get_str(dev_name),
422                   __get_str(b_name), (__entry->oper) ? "up" : "down",
423                   (__entry->carrier) ? "ok" : "notok",
424                   (__entry->b_up) ? "up" : "down")
425 );
426
427 #endif /* _TIPC_TRACE_H */
428
429 /* This part must be outside protection */
430 #undef TRACE_INCLUDE_PATH
431 #define TRACE_INCLUDE_PATH .
432 #undef TRACE_INCLUDE_FILE
433 #define TRACE_INCLUDE_FILE trace
434 #include <trace/define_trace.h>