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_fg,
65 	    TP_PROTO(const struct mlx5_flow_group *fg),
66 	    TP_ARGS(fg),
67 	    TP_STRUCT__entry(
68 		__field(const struct mlx5_flow_group *, fg)
69 		__field(const struct mlx5_flow_table *, ft)
70 		__field(u32, start_index)
71 		__field(u32, end_index)
72 		__field(u32, id)
73 		__field(u8, mask_enable)
74 		__array(u32, mask_outer, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
75 		__array(u32, mask_inner, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
76 		__array(u32, mask_misc, MLX5_ST_SZ_DW(fte_match_set_misc))
77 	    ),
78 	    TP_fast_assign(
79 			   __entry->fg = fg;
80 			   fs_get_obj(__entry->ft, fg->node.parent);
81 			   __entry->start_index = fg->start_index;
82 			   __entry->end_index = fg->start_index + fg->max_ftes;
83 			   __entry->id = fg->id;
84 			   __entry->mask_enable = fg->mask.match_criteria_enable;
85 			   memcpy(__entry->mask_outer,
86 				  MLX5_ADDR_OF(fte_match_param,
87 					       &fg->mask.match_criteria,
88 					       outer_headers),
89 				  sizeof(__entry->mask_outer));
90 			   memcpy(__entry->mask_inner,
91 				  MLX5_ADDR_OF(fte_match_param,
92 					       &fg->mask.match_criteria,
93 					       inner_headers),
94 				  sizeof(__entry->mask_inner));
95 			   memcpy(__entry->mask_misc,
96 				  MLX5_ADDR_OF(fte_match_param,
97 					       &fg->mask.match_criteria,
98 					       misc_parameters),
99 				  sizeof(__entry->mask_misc));
100 
101 	    ),
102 	    TP_printk("fg=%p ft=%p id=%u start=%u end=%u bit_mask=%02x %s\n",
103 		      __entry->fg, __entry->ft, __entry->id,
104 		      __entry->start_index, __entry->end_index,
105 		      __entry->mask_enable,
106 		      __parse_fs_hdrs(__entry->mask_enable,
107 				      __entry->mask_outer,
108 				      __entry->mask_misc,
109 				      __entry->mask_inner,
110 				      __entry->mask_outer,
111 				      __entry->mask_misc,
112 				      __entry->mask_inner))
113 	    );
114 
115 TRACE_EVENT(mlx5_fs_del_fg,
116 	    TP_PROTO(const struct mlx5_flow_group *fg),
117 	    TP_ARGS(fg),
118 	    TP_STRUCT__entry(
119 		__field(const struct mlx5_flow_group *, fg)
120 		__field(u32, id)
121 	    ),
122 	    TP_fast_assign(
123 			   __entry->fg = fg;
124 			   __entry->id = fg->id;
125 
126 	    ),
127 	    TP_printk("fg=%p id=%u\n",
128 		      __entry->fg, __entry->id)
129 	    );
130 
131 #define ACTION_FLAGS \
132 	{MLX5_FLOW_CONTEXT_ACTION_ALLOW,	 "ALLOW"},\
133 	{MLX5_FLOW_CONTEXT_ACTION_DROP,		 "DROP"},\
134 	{MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,	 "FWD"},\
135 	{MLX5_FLOW_CONTEXT_ACTION_COUNT,	 "CNT"},\
136 	{MLX5_FLOW_CONTEXT_ACTION_ENCAP,	 "ENCAP"},\
137 	{MLX5_FLOW_CONTEXT_ACTION_DECAP,	 "DECAP"},\
138 	{MLX5_FLOW_CONTEXT_ACTION_MOD_HDR,	 "MOD_HDR"},\
139 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH,	 "VLAN_PUSH"},\
140 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_POP,	 "VLAN_POP"},\
141 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH_2,	 "VLAN_PUSH_2"},\
142 	{MLX5_FLOW_CONTEXT_ACTION_VLAN_POP_2,	 "VLAN_POP_2"},\
143 	{MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO, "NEXT_PRIO"}
144 
145 TRACE_EVENT(mlx5_fs_set_fte,
146 	    TP_PROTO(const struct fs_fte *fte, int new_fte),
147 	    TP_ARGS(fte, new_fte),
148 	    TP_STRUCT__entry(
149 		__field(const struct fs_fte *, fte)
150 		__field(const struct mlx5_flow_group *, fg)
151 		__field(u32, group_index)
152 		__field(u32, index)
153 		__field(u32, action)
154 		__field(u32, flow_tag)
155 		__field(u8,  mask_enable)
156 		__field(int, new_fte)
157 		__array(u32, mask_outer, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
158 		__array(u32, mask_inner, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
159 		__array(u32, mask_misc, MLX5_ST_SZ_DW(fte_match_set_misc))
160 		__array(u32, value_outer, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
161 		__array(u32, value_inner, MLX5_ST_SZ_DW(fte_match_set_lyr_2_4))
162 		__array(u32, value_misc, MLX5_ST_SZ_DW(fte_match_set_misc))
163 	    ),
164 	    TP_fast_assign(
165 			   __entry->fte = fte;
166 			   __entry->new_fte = new_fte;
167 			   fs_get_obj(__entry->fg, fte->node.parent);
168 			   __entry->group_index = __entry->fg->id;
169 			   __entry->index = fte->index;
170 			   __entry->action = fte->action.action;
171 			   __entry->mask_enable = __entry->fg->mask.match_criteria_enable;
172 			   __entry->flow_tag = fte->action.flow_tag;
173 			   memcpy(__entry->mask_outer,
174 				  MLX5_ADDR_OF(fte_match_param,
175 					       &__entry->fg->mask.match_criteria,
176 					       outer_headers),
177 				  sizeof(__entry->mask_outer));
178 			   memcpy(__entry->mask_inner,
179 				  MLX5_ADDR_OF(fte_match_param,
180 					       &__entry->fg->mask.match_criteria,
181 					       inner_headers),
182 				  sizeof(__entry->mask_inner));
183 			   memcpy(__entry->mask_misc,
184 				  MLX5_ADDR_OF(fte_match_param,
185 					       &__entry->fg->mask.match_criteria,
186 					       misc_parameters),
187 				  sizeof(__entry->mask_misc));
188 			   memcpy(__entry->value_outer,
189 				  MLX5_ADDR_OF(fte_match_param,
190 					       &fte->val,
191 					       outer_headers),
192 				  sizeof(__entry->value_outer));
193 			   memcpy(__entry->value_inner,
194 				  MLX5_ADDR_OF(fte_match_param,
195 					       &fte->val,
196 					       inner_headers),
197 				  sizeof(__entry->value_inner));
198 			   memcpy(__entry->value_misc,
199 				  MLX5_ADDR_OF(fte_match_param,
200 					       &fte->val,
201 					       misc_parameters),
202 				  sizeof(__entry->value_misc));
203 
204 	    ),
205 	    TP_printk("op=%s fte=%p fg=%p index=%u group_index=%u action=<%s> flow_tag=%x %s\n",
206 		      __entry->new_fte ? "add" : "set",
207 		      __entry->fte, __entry->fg, __entry->index,
208 		      __entry->group_index, __print_flags(__entry->action, "|",
209 							  ACTION_FLAGS),
210 		      __entry->flow_tag,
211 		      __parse_fs_hdrs(__entry->mask_enable,
212 				      __entry->mask_outer,
213 				      __entry->mask_misc,
214 				      __entry->mask_inner,
215 				      __entry->value_outer,
216 				      __entry->value_misc,
217 				      __entry->value_inner))
218 	    );
219 
220 TRACE_EVENT(mlx5_fs_del_fte,
221 	    TP_PROTO(const struct fs_fte *fte),
222 	    TP_ARGS(fte),
223 	    TP_STRUCT__entry(
224 		__field(const struct fs_fte *, fte)
225 		__field(u32, index)
226 	    ),
227 	    TP_fast_assign(
228 			   __entry->fte = fte;
229 			   __entry->index = fte->index;
230 
231 	    ),
232 	    TP_printk("fte=%p index=%u\n",
233 		      __entry->fte, __entry->index)
234 	    );
235 
236 TRACE_EVENT(mlx5_fs_add_rule,
237 	    TP_PROTO(const struct mlx5_flow_rule *rule),
238 	    TP_ARGS(rule),
239 	    TP_STRUCT__entry(
240 		__field(const struct mlx5_flow_rule *, rule)
241 		__field(const struct fs_fte *, fte)
242 		__field(u32, sw_action)
243 		__field(u32, index)
244 		__field(u32, counter_id)
245 		__array(u8, destination, sizeof(struct mlx5_flow_destination))
246 	    ),
247 	    TP_fast_assign(
248 			   __entry->rule = rule;
249 			   fs_get_obj(__entry->fte, rule->node.parent);
250 			   __entry->index = __entry->fte->dests_size - 1;
251 			   __entry->sw_action = rule->sw_action;
252 			   memcpy(__entry->destination,
253 				  &rule->dest_attr,
254 				  sizeof(__entry->destination));
255 			   if (rule->dest_attr.type & MLX5_FLOW_DESTINATION_TYPE_COUNTER &&
256 			       rule->dest_attr.counter)
257 				__entry->counter_id =
258 				rule->dest_attr.counter->id;
259 	    ),
260 	    TP_printk("rule=%p fte=%p index=%u sw_action=<%s> [dst] %s\n",
261 		      __entry->rule, __entry->fte, __entry->index,
262 		      __print_flags(__entry->sw_action, "|", ACTION_FLAGS),
263 		      __parse_fs_dst(__entry->destination, __entry->counter_id))
264 	    );
265 
266 TRACE_EVENT(mlx5_fs_del_rule,
267 	    TP_PROTO(const struct mlx5_flow_rule *rule),
268 	    TP_ARGS(rule),
269 	    TP_STRUCT__entry(
270 		__field(const struct mlx5_flow_rule *, rule)
271 		__field(const struct fs_fte *, fte)
272 	    ),
273 	    TP_fast_assign(
274 			   __entry->rule = rule;
275 			   fs_get_obj(__entry->fte, rule->node.parent);
276 	    ),
277 	    TP_printk("rule=%p fte=%p\n",
278 		      __entry->rule, __entry->fte)
279 	    );
280 #endif
281 
282 #undef TRACE_INCLUDE_PATH
283 #define TRACE_INCLUDE_PATH ./diag
284 #undef TRACE_INCLUDE_FILE
285 #define TRACE_INCLUDE_FILE fs_tracepoint
286 #include <trace/define_trace.h>
287