1 /* SPDX-License-Identifier: GPL-2.0 */
2 #if IS_ENABLED(CONFIG_NET_DEVLINK)
3 
4 #undef TRACE_SYSTEM
5 #define TRACE_SYSTEM devlink
6 
7 #if !defined(_TRACE_DEVLINK_H) || defined(TRACE_HEADER_MULTI_READ)
8 #define _TRACE_DEVLINK_H
9 
10 #include <linux/device.h>
11 #include <net/devlink.h>
12 #include <linux/tracepoint.h>
13 
14 /*
15  * Tracepoint for devlink hardware message:
16  */
17 TRACE_EVENT(devlink_hwmsg,
18 	TP_PROTO(const struct devlink *devlink, bool incoming,
19 		 unsigned long type, const u8 *buf, size_t len),
20 
21 	TP_ARGS(devlink, incoming, type, buf, len),
22 
23 	TP_STRUCT__entry(
24 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
25 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
26 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
27 		__field(bool, incoming)
28 		__field(unsigned long, type)
29 		__dynamic_array(u8, buf, len)
30 		__field(size_t, len)
31 	),
32 
33 	TP_fast_assign(
34 		__assign_str(bus_name, devlink_to_dev(devlink)->bus->name);
35 		__assign_str(dev_name, dev_name(devlink_to_dev(devlink)));
36 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
37 		__entry->incoming = incoming;
38 		__entry->type = type;
39 		memcpy(__get_dynamic_array(buf), buf, len);
40 		__entry->len = len;
41 	),
42 
43 	TP_printk("bus_name=%s dev_name=%s driver_name=%s incoming=%d type=%lu buf=0x[%*phD] len=%zu",
44 		  __get_str(bus_name), __get_str(dev_name),
45 		  __get_str(driver_name), __entry->incoming, __entry->type,
46 		  (int) __entry->len, __get_dynamic_array(buf), __entry->len)
47 );
48 
49 /*
50  * Tracepoint for devlink hardware error:
51  */
52 TRACE_EVENT(devlink_hwerr,
53 	TP_PROTO(const struct devlink *devlink, int err, const char *msg),
54 
55 	TP_ARGS(devlink, err, msg),
56 
57 	TP_STRUCT__entry(
58 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
59 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
60 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
61 		__field(int, err)
62 		__string(msg, msg)
63 		),
64 
65 	TP_fast_assign(
66 		__assign_str(bus_name, devlink_to_dev(devlink)->bus->name);
67 		__assign_str(dev_name, dev_name(devlink_to_dev(devlink)));
68 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
69 		__entry->err = err;
70 		__assign_str(msg, msg);
71 		),
72 
73 	TP_printk("bus_name=%s dev_name=%s driver_name=%s err=%d %s",
74 			__get_str(bus_name), __get_str(dev_name),
75 			__get_str(driver_name), __entry->err, __get_str(msg))
76 );
77 
78 /*
79  * Tracepoint for devlink health message:
80  */
81 TRACE_EVENT(devlink_health_report,
82 	TP_PROTO(const struct devlink *devlink, const char *reporter_name,
83 		 const char *msg),
84 
85 	TP_ARGS(devlink, reporter_name, msg),
86 
87 	TP_STRUCT__entry(
88 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
89 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
90 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
91 		__string(reporter_name, msg)
92 		__string(msg, msg)
93 	),
94 
95 	TP_fast_assign(
96 		__assign_str(bus_name, devlink_to_dev(devlink)->bus->name);
97 		__assign_str(dev_name, dev_name(devlink_to_dev(devlink)));
98 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
99 		__assign_str(reporter_name, reporter_name);
100 		__assign_str(msg, msg);
101 	),
102 
103 	TP_printk("bus_name=%s dev_name=%s driver_name=%s reporter_name=%s: %s",
104 		  __get_str(bus_name), __get_str(dev_name),
105 		  __get_str(driver_name), __get_str(reporter_name),
106 		  __get_str(msg))
107 );
108 
109 /*
110  * Tracepoint for devlink health recover aborted message:
111  */
112 TRACE_EVENT(devlink_health_recover_aborted,
113 	TP_PROTO(const struct devlink *devlink, const char *reporter_name,
114 		 bool health_state, u64 time_since_last_recover),
115 
116 	TP_ARGS(devlink, reporter_name, health_state, time_since_last_recover),
117 
118 	TP_STRUCT__entry(
119 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
120 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
121 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
122 		__string(reporter_name, reporter_name)
123 		__field(bool, health_state)
124 		__field(u64, time_since_last_recover)
125 	),
126 
127 	TP_fast_assign(
128 		__assign_str(bus_name, devlink_to_dev(devlink)->bus->name);
129 		__assign_str(dev_name, dev_name(devlink_to_dev(devlink)));
130 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
131 		__assign_str(reporter_name, reporter_name);
132 		__entry->health_state = health_state;
133 		__entry->time_since_last_recover = time_since_last_recover;
134 	),
135 
136 	TP_printk("bus_name=%s dev_name=%s driver_name=%s reporter_name=%s: health_state=%d time_since_last_recover=%llu recover aborted",
137 		  __get_str(bus_name), __get_str(dev_name),
138 		  __get_str(driver_name), __get_str(reporter_name),
139 		  __entry->health_state,
140 		  __entry->time_since_last_recover)
141 );
142 
143 /*
144  * Tracepoint for devlink health reporter state update:
145  */
146 TRACE_EVENT(devlink_health_reporter_state_update,
147 	TP_PROTO(const struct devlink *devlink, const char *reporter_name,
148 		 bool new_state),
149 
150 	TP_ARGS(devlink, reporter_name, new_state),
151 
152 	TP_STRUCT__entry(
153 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
154 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
155 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
156 		__string(reporter_name, reporter_name)
157 		__field(u8, new_state)
158 	),
159 
160 	TP_fast_assign(
161 		__assign_str(bus_name, devlink_to_dev(devlink)->bus->name);
162 		__assign_str(dev_name, dev_name(devlink_to_dev(devlink)));
163 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
164 		__assign_str(reporter_name, reporter_name);
165 		__entry->new_state = new_state;
166 	),
167 
168 	TP_printk("bus_name=%s dev_name=%s driver_name=%s reporter_name=%s: new_state=%d",
169 		  __get_str(bus_name), __get_str(dev_name),
170 		  __get_str(driver_name), __get_str(reporter_name),
171 		  __entry->new_state)
172 );
173 
174 /*
175  * Tracepoint for devlink packet trap:
176  */
177 TRACE_EVENT(devlink_trap_report,
178 	TP_PROTO(const struct devlink *devlink, struct sk_buff *skb,
179 		 const struct devlink_trap_metadata *metadata),
180 
181 	TP_ARGS(devlink, skb, metadata),
182 
183 	TP_STRUCT__entry(
184 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
185 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
186 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
187 		__string(trap_name, metadata->trap_name)
188 		__string(trap_group_name, metadata->trap_group_name)
189 		__array(char, input_dev_name, IFNAMSIZ)
190 	),
191 
192 	TP_fast_assign(
193 		struct net_device *input_dev = metadata->input_dev;
194 
195 		__assign_str(bus_name, devlink_to_dev(devlink)->bus->name);
196 		__assign_str(dev_name, dev_name(devlink_to_dev(devlink)));
197 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
198 		__assign_str(trap_name, metadata->trap_name);
199 		__assign_str(trap_group_name, metadata->trap_group_name);
200 		strscpy(__entry->input_dev_name, input_dev ? input_dev->name : "NULL", IFNAMSIZ);
201 	),
202 
203 	TP_printk("bus_name=%s dev_name=%s driver_name=%s trap_name=%s "
204 		  "trap_group_name=%s input_dev_name=%s", __get_str(bus_name),
205 		  __get_str(dev_name), __get_str(driver_name),
206 		  __get_str(trap_name), __get_str(trap_group_name),
207 		  __entry->input_dev_name)
208 );
209 
210 #endif /* _TRACE_DEVLINK_H */
211 
212 /* This part must be outside protection */
213 #include <trace/define_trace.h>
214 
215 #else /* CONFIG_NET_DEVLINK */
216 
217 #if !defined(_TRACE_DEVLINK_H)
218 #define _TRACE_DEVLINK_H
219 
220 #include <net/devlink.h>
221 
trace_devlink_hwmsg(const struct devlink * devlink,bool incoming,unsigned long type,const u8 * buf,size_t len)222 static inline void trace_devlink_hwmsg(const struct devlink *devlink,
223 				       bool incoming, unsigned long type,
224 				       const u8 *buf, size_t len)
225 {
226 }
227 
trace_devlink_hwerr(const struct devlink * devlink,int err,const char * msg)228 static inline void trace_devlink_hwerr(const struct devlink *devlink,
229 				       int err, const char *msg)
230 {
231 }
232 #endif /* _TRACE_DEVLINK_H */
233 
234 #endif
235