1 /*
2  * Copyright (c) 2017, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #if !defined(_MLX5_FS_TP_) || defined(TRACE_HEADER_MULTI_READ)
34 #define _MLX5_FS_TP_
35 
36 #include <linux/tracepoint.h>
37 #include <linux/trace_seq.h>
38 #include "../fs_core.h"
39 
40 #undef TRACE_SYSTEM
41 #define TRACE_SYSTEM mlx5
42 
43 #define __parse_fs_hdrs(match_criteria_enable, mouter, mmisc, minner, vouter, \
44 			vinner, vmisc)					      \
45 	parse_fs_hdrs(p, match_criteria_enable, mouter, mmisc, minner, vouter,\
46 		      vinner, vmisc)
47 
48 const char *parse_fs_hdrs(struct trace_seq *p,
49 			  u8 match_criteria_enable,
50 			  const u32 *mask_outer,
51 			  const u32 *mask_misc,
52 			  const u32 *mask_inner,
53 			  const u32 *value_outer,
54 			  const u32 *value_misc,
55 			  const u32 *value_inner);
56 
57 #define __parse_fs_dst(dst, counter_id) \
58 	parse_fs_dst(p, (const struct mlx5_flow_destination *)dst, counter_id)
59 
60 const char *parse_fs_dst(struct trace_seq *p,
61 			 const struct mlx5_flow_destination *dst,
62 			 u32 counter_id);
63 
64 TRACE_EVENT(mlx5_fs_add_ft,
65 	    TP_PROTO(const struct mlx5_flow_table *ft),
66 	    TP_ARGS(ft),
67 	    TP_STRUCT__entry(
68 		__field(const struct mlx5_flow_table *, ft)
69 		__field(u32, id)
70 		__field(u32, level)
71 		__field(u32, type)
72 	    ),
73 	    TP_fast_assign(
74 			   __entry->ft = ft;
75 			   __entry->id = ft->id;
76 			   __entry->level = ft->level;
77 			   __entry->type = ft->type;
78 	    ),
79 	    TP_printk("ft=%p id=%u level=%u type=%u \n",
80 		      __entry->ft, __entry->id, __entry->level, __entry->type)
81 	    );
82 
83 TRACE_EVENT(mlx5_fs_del_ft,
84 	    TP_PROTO(const struct mlx5_flow_table *ft),
85 	    TP_ARGS(ft),
86 	    TP_STRUCT__entry(
87 		__field(const struct mlx5_flow_table *, ft)
88 		__field(u32, id)
89 	    ),
90 	    TP_fast_assign(
91 			   __entry->ft = ft;
92 			   __entry->id = ft->id;
93 
94 	    ),
95 	    TP_printk("ft=%p id=%u\n",
96 		      __entry->ft, __entry->id)
97 	    );
98 
99 TRACE_EVENT(mlx5_fs_add_fg,
100 	    TP_PROTO(const struct mlx5_flow_group *fg),
101 	    TP_ARGS(fg),
102 	    TP_STRUCT__entry(
103 		__field(const struct mlx5_flow_group *, fg)
104 		__field(const struct mlx5_flow_table *, ft)
105 		__field(u32, start_index)
106 		__field(u32, end_index)
107 		__field(u32, id)
108 		__field(u8, mask_enable)
109 		__array(u32, mask_outer, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
110 		__array(u32, mask_inner, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
111 		__array(u32, mask_misc, MLX5_ST_SZ_DW(fte_match_set_misc))
112 	    ),
113 	    TP_fast_assign(
114 			   __entry->fg = fg;
115 			   fs_get_obj(__entry->ft, fg->node.parent);
116 			   __entry->start_index = fg->start_index;
117 			   __entry->end_index = fg->start_index + fg->max_ftes;
118 			   __entry->id = fg->id;
119 			   __entry->mask_enable = fg->mask.match_criteria_enable;
120 			   memcpy(__entry->mask_outer,
121 				  MLX5_ADDR_OF(fte_match_param,
122 					       &fg->mask.match_criteria,
123 					       outer_headers),
124 				  sizeof(__entry->mask_outer));
125 			   memcpy(__entry->mask_inner,
126 				  MLX5_ADDR_OF(fte_match_param,
127 					       &fg->mask.match_criteria,
128 					       inner_headers),
129 				  sizeof(__entry->mask_inner));
130 			   memcpy(__entry->mask_misc,
131 				  MLX5_ADDR_OF(fte_match_param,
132 					       &fg->mask.match_criteria,
133 					       misc_parameters),
134 				  sizeof(__entry->mask_misc));
135 
136 	    ),
137 	    TP_printk("fg=%p ft=%p id=%u start=%u end=%u bit_mask=%02x %s\n",
138 		      __entry->fg, __entry->ft, __entry->id,
139 		      __entry->start_index, __entry->end_index,
140 		      __entry->mask_enable,
141 		      __parse_fs_hdrs(__entry->mask_enable,
142 				      __entry->mask_outer,
143 				      __entry->mask_misc,
144 				      __entry->mask_inner,
145 				      __entry->mask_outer,
146 				      __entry->mask_misc,
147 				      __entry->mask_inner))
148 	    );
149 
150 TRACE_EVENT(mlx5_fs_del_fg,
151 	    TP_PROTO(const struct mlx5_flow_group *fg),
152 	    TP_ARGS(fg),
153 	    TP_STRUCT__entry(
154 		__field(const struct mlx5_flow_group *, fg)
155 		__field(u32, id)
156 	    ),
157 	    TP_fast_assign(
158 			   __entry->fg = fg;
159 			   __entry->id = fg->id;
160 
161 	    ),
162 	    TP_printk("fg=%p id=%u\n",
163 		      __entry->fg, __entry->id)
164 	    );
165 
166 #define ACTION_FLAGS \
167 	{MLX5_FLOW_CONTEXT_ACTION_ALLOW,	 "ALLOW"},\
168 	{MLX5_FLOW_CONTEXT_ACTION_DROP,		 "DROP"},\
169 	{MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,	 "FWD"},\
170 	{MLX5_FLOW_CONTEXT_ACTION_COUNT,	 "CNT"},\
171 	{MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT, "REFORMAT"},\
172 	{MLX5_FLOW_CONTEXT_ACTION_DECAP,	 "DECAP"},\
173 	{MLX5_FLOW_CONTEXT_ACTION_MOD_HDR,	 "MOD_HDR"},\
174 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH,	 "VLAN_PUSH"},\
175 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_POP,	 "VLAN_POP"},\
176 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH_2,	 "VLAN_PUSH_2"},\
177 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_POP_2,	 "VLAN_POP_2"},\
178 	{MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO, "NEXT_PRIO"}
179 
180 TRACE_EVENT(mlx5_fs_set_fte,
181 	    TP_PROTO(const struct fs_fte *fte, int new_fte),
182 	    TP_ARGS(fte, new_fte),
183 	    TP_STRUCT__entry(
184 		__field(const struct fs_fte *, fte)
185 		__field(const struct mlx5_flow_group *, fg)
186 		__field(u32, group_index)
187 		__field(u32, index)
188 		__field(u32, action)
189 		__field(u32, flow_tag)
190 		__field(u32, flow_source)
191 		__field(u8,  mask_enable)
192 		__field(int, new_fte)
193 		__array(u32, mask_outer, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
194 		__array(u32, mask_inner, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
195 		__array(u32, mask_misc, MLX5_ST_SZ_DW(fte_match_set_misc))
196 		__array(u32, value_outer, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
197 		__array(u32, value_inner, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
198 		__array(u32, value_misc, MLX5_ST_SZ_DW(fte_match_set_misc))
199 	    ),
200 	    TP_fast_assign(
201 			   __entry->fte = fte;
202 			   __entry->new_fte = new_fte;
203 			   fs_get_obj(__entry->fg, fte->node.parent);
204 			   __entry->group_index = __entry->fg->id;
205 			   __entry->index = fte->index;
206 			   __entry->action = fte->action.action;
207 			   __entry->mask_enable = __entry->fg->mask.match_criteria_enable;
208 			   __entry->flow_tag = fte->flow_context.flow_tag;
209 			   __entry->flow_source = fte->flow_context.flow_source;
210 			   memcpy(__entry->mask_outer,
211 				  MLX5_ADDR_OF(fte_match_param,
212 					       &__entry->fg->mask.match_criteria,
213 					       outer_headers),
214 				  sizeof(__entry->mask_outer));
215 			   memcpy(__entry->mask_inner,
216 				  MLX5_ADDR_OF(fte_match_param,
217 					       &__entry->fg->mask.match_criteria,
218 					       inner_headers),
219 				  sizeof(__entry->mask_inner));
220 			   memcpy(__entry->mask_misc,
221 				  MLX5_ADDR_OF(fte_match_param,
222 					       &__entry->fg->mask.match_criteria,
223 					       misc_parameters),
224 				  sizeof(__entry->mask_misc));
225 			   memcpy(__entry->value_outer,
226 				  MLX5_ADDR_OF(fte_match_param,
227 					       &fte->val,
228 					       outer_headers),
229 				  sizeof(__entry->value_outer));
230 			   memcpy(__entry->value_inner,
231 				  MLX5_ADDR_OF(fte_match_param,
232 					       &fte->val,
233 					       inner_headers),
234 				  sizeof(__entry->value_inner));
235 			   memcpy(__entry->value_misc,
236 				  MLX5_ADDR_OF(fte_match_param,
237 					       &fte->val,
238 					       misc_parameters),
239 				  sizeof(__entry->value_misc));
240 
241 	    ),
242 	    TP_printk("op=%s fte=%p fg=%p index=%u group_index=%u action=<%s> flow_tag=%x %s\n",
243 		      __entry->new_fte ? "add" : "set",
244 		      __entry->fte, __entry->fg, __entry->index,
245 		      __entry->group_index, __print_flags(__entry->action, "|",
246 							  ACTION_FLAGS),
247 		      __entry->flow_tag,
248 		      __parse_fs_hdrs(__entry->mask_enable,
249 				      __entry->mask_outer,
250 				      __entry->mask_misc,
251 				      __entry->mask_inner,
252 				      __entry->value_outer,
253 				      __entry->value_misc,
254 				      __entry->value_inner))
255 	    );
256 
257 TRACE_EVENT(mlx5_fs_del_fte,
258 	    TP_PROTO(const struct fs_fte *fte),
259 	    TP_ARGS(fte),
260 	    TP_STRUCT__entry(
261 		__field(const struct fs_fte *, fte)
262 		__field(u32, index)
263 	    ),
264 	    TP_fast_assign(
265 			   __entry->fte = fte;
266 			   __entry->index = fte->index;
267 
268 	    ),
269 	    TP_printk("fte=%p index=%u\n",
270 		      __entry->fte, __entry->index)
271 	    );
272 
273 TRACE_EVENT(mlx5_fs_add_rule,
274 	    TP_PROTO(const struct mlx5_flow_rule *rule),
275 	    TP_ARGS(rule),
276 	    TP_STRUCT__entry(
277 		__field(const struct mlx5_flow_rule *, rule)
278 		__field(const struct fs_fte *, fte)
279 		__field(u32, sw_action)
280 		__field(u32, index)
281 		__field(u32, counter_id)
282 		__array(u8, destination, sizeof(struct mlx5_flow_destination))
283 	    ),
284 	    TP_fast_assign(
285 			   __entry->rule = rule;
286 			   fs_get_obj(__entry->fte, rule->node.parent);
287 			   __entry->index = __entry->fte->dests_size - 1;
288 			   __entry->sw_action = rule->sw_action;
289 			   memcpy(__entry->destination,
290 				  &rule->dest_attr,
291 				  sizeof(__entry->destination));
292 			   if (rule->dest_attr.type &
293 			       MLX5_FLOW_DESTINATION_TYPE_COUNTER)
294 				__entry->counter_id =
295 					rule->dest_attr.counter_id;
296 	    ),
297 	    TP_printk("rule=%p fte=%p index=%u sw_action=<%s> [dst] %s\n",
298 		      __entry->rule, __entry->fte, __entry->index,
299 		      __print_flags(__entry->sw_action, "|", ACTION_FLAGS),
300 		      __parse_fs_dst(__entry->destination, __entry->counter_id))
301 	    );
302 
303 TRACE_EVENT(mlx5_fs_del_rule,
304 	    TP_PROTO(const struct mlx5_flow_rule *rule),
305 	    TP_ARGS(rule),
306 	    TP_STRUCT__entry(
307 		__field(const struct mlx5_flow_rule *, rule)
308 		__field(const struct fs_fte *, fte)
309 	    ),
310 	    TP_fast_assign(
311 			   __entry->rule = rule;
312 			   fs_get_obj(__entry->fte, rule->node.parent);
313 	    ),
314 	    TP_printk("rule=%p fte=%p\n",
315 		      __entry->rule, __entry->fte)
316 	    );
317 #endif
318 
319 #undef TRACE_INCLUDE_PATH
320 #define TRACE_INCLUDE_PATH ./diag
321 #undef TRACE_INCLUDE_FILE
322 #define TRACE_INCLUDE_FILE fs_tracepoint
323 #include <trace/define_trace.h>
324