1 /*
2  * Copyright(c) 2015 - 2017 Intel Corporation.
3  *
4  * This file is provided under a dual BSD/GPLv2 license.  When using or
5  * redistributing this file, you may do so under either license.
6  *
7  * GPL LICENSE SUMMARY
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of version 2 of the GNU General Public License as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * BSD LICENSE
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  *
24  *  - Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  *  - Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in
28  *    the documentation and/or other materials provided with the
29  *    distribution.
30  *  - Neither the name of Intel Corporation nor the names of its
31  *    contributors may be used to endorse or promote products derived
32  *    from this software without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  */
47 #if !defined(__HFI1_TRACE_IBHDRS_H) || defined(TRACE_HEADER_MULTI_READ)
48 #define __HFI1_TRACE_IBHDRS_H
49 
50 #include <linux/tracepoint.h>
51 #include <linux/trace_seq.h>
52 
53 #include "hfi.h"
54 
55 #undef TRACE_SYSTEM
56 #define TRACE_SYSTEM hfi1_ibhdrs
57 
58 #define ib_opcode_name(opcode) { IB_OPCODE_##opcode, #opcode  }
59 #define show_ib_opcode(opcode)                             \
60 __print_symbolic(opcode,                                   \
61 	ib_opcode_name(RC_SEND_FIRST),                     \
62 	ib_opcode_name(RC_SEND_MIDDLE),                    \
63 	ib_opcode_name(RC_SEND_LAST),                      \
64 	ib_opcode_name(RC_SEND_LAST_WITH_IMMEDIATE),       \
65 	ib_opcode_name(RC_SEND_ONLY),                      \
66 	ib_opcode_name(RC_SEND_ONLY_WITH_IMMEDIATE),       \
67 	ib_opcode_name(RC_RDMA_WRITE_FIRST),               \
68 	ib_opcode_name(RC_RDMA_WRITE_MIDDLE),              \
69 	ib_opcode_name(RC_RDMA_WRITE_LAST),                \
70 	ib_opcode_name(RC_RDMA_WRITE_LAST_WITH_IMMEDIATE), \
71 	ib_opcode_name(RC_RDMA_WRITE_ONLY),                \
72 	ib_opcode_name(RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \
73 	ib_opcode_name(RC_RDMA_READ_REQUEST),              \
74 	ib_opcode_name(RC_RDMA_READ_RESPONSE_FIRST),       \
75 	ib_opcode_name(RC_RDMA_READ_RESPONSE_MIDDLE),      \
76 	ib_opcode_name(RC_RDMA_READ_RESPONSE_LAST),        \
77 	ib_opcode_name(RC_RDMA_READ_RESPONSE_ONLY),        \
78 	ib_opcode_name(RC_ACKNOWLEDGE),                    \
79 	ib_opcode_name(RC_ATOMIC_ACKNOWLEDGE),             \
80 	ib_opcode_name(RC_COMPARE_SWAP),                   \
81 	ib_opcode_name(RC_FETCH_ADD),                      \
82 	ib_opcode_name(UC_SEND_FIRST),                     \
83 	ib_opcode_name(UC_SEND_MIDDLE),                    \
84 	ib_opcode_name(UC_SEND_LAST),                      \
85 	ib_opcode_name(UC_SEND_LAST_WITH_IMMEDIATE),       \
86 	ib_opcode_name(UC_SEND_ONLY),                      \
87 	ib_opcode_name(UC_SEND_ONLY_WITH_IMMEDIATE),       \
88 	ib_opcode_name(UC_RDMA_WRITE_FIRST),               \
89 	ib_opcode_name(UC_RDMA_WRITE_MIDDLE),              \
90 	ib_opcode_name(UC_RDMA_WRITE_LAST),                \
91 	ib_opcode_name(UC_RDMA_WRITE_LAST_WITH_IMMEDIATE), \
92 	ib_opcode_name(UC_RDMA_WRITE_ONLY),                \
93 	ib_opcode_name(UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \
94 	ib_opcode_name(UD_SEND_ONLY),                      \
95 	ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE),       \
96 	ib_opcode_name(CNP))
97 
98 u8 ibhdr_exhdr_len(struct ib_header *hdr);
99 const char *parse_everbs_hdrs(struct trace_seq *p, u8 opcode, void *ehdrs);
100 u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opah);
101 u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet);
102 const char *hfi1_trace_get_packet_l4_str(u8 l4);
103 void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr,
104 			     u8 *ack, bool *becn, bool *fecn, u8 *mig,
105 			     u8 *se, u8 *pad, u8 *opcode, u8 *tver,
106 			     u16 *pkey, u32 *psn, u32 *qpn);
107 void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5,
108 			     u8 *lnh, u8 *lver, u8 *sl, u8 *sc,
109 			     u16 *len, u32 *dlid, u32 *slid);
110 void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr,
111 			      u8 *ack, u8 *mig, u8 *opcode,
112 			      u8 *pad, u8 *se, u8 *tver,
113 			      u32 *psn, u32 *qpn);
114 void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr,
115 			      u8 *age, bool *becn, bool *fecn,
116 			      u8 *l4, u8 *rc, u8 *sc,
117 			      u16 *entropy, u16 *len, u16 *pkey,
118 			      u32 *dlid, u32 *slid);
119 
120 const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass,
121 			       u8 age, bool becn, bool fecn, u8 l4,
122 			       u8 lnh, const char *lnh_name, u8 lver,
123 			       u8 rc, u8 sc, u8 sl, u16 entropy,
124 			       u16 len, u16 pkey, u32 dlid, u32 slid);
125 
126 const char *hfi1_trace_fmt_bth(struct trace_seq *p, bool bypass,
127 			       u8 ack, bool becn, bool fecn, u8 mig,
128 			       u8 se, u8 pad, u8 opcode, const char *opname,
129 			       u8 tver, u16 pkey, u32 psn, u32 qpn);
130 
131 const char *hfi1_trace_get_packet_l2_str(u8 l2);
132 
133 #define __parse_ib_ehdrs(op, ehdrs) parse_everbs_hdrs(p, op, ehdrs)
134 
135 #define lrh_name(lrh) { HFI1_##lrh, #lrh }
136 #define show_lnh(lrh)                    \
137 __print_symbolic(lrh,                    \
138 	lrh_name(LRH_BTH),               \
139 	lrh_name(LRH_GRH))
140 
141 DECLARE_EVENT_CLASS(hfi1_input_ibhdr_template,
142 		    TP_PROTO(struct hfi1_devdata *dd,
143 			     struct hfi1_packet *packet,
144 			     bool sc5),
145 		    TP_ARGS(dd, packet, sc5),
146 		    TP_STRUCT__entry(
147 			DD_DEV_ENTRY(dd)
148 			__field(u8, etype)
149 			__field(u8, ack)
150 			__field(u8, age)
151 			__field(bool, becn)
152 			__field(bool, fecn)
153 			__field(u8, l2)
154 			__field(u8, l4)
155 			__field(u8, lnh)
156 			__field(u8, lver)
157 			__field(u8, mig)
158 			__field(u8, opcode)
159 			__field(u8, pad)
160 			__field(u8, rc)
161 			__field(u8, sc)
162 			__field(u8, se)
163 			__field(u8, sl)
164 			__field(u8, tver)
165 			__field(u16, entropy)
166 			__field(u16, len)
167 			__field(u16, pkey)
168 			__field(u32, dlid)
169 			__field(u32, psn)
170 			__field(u32, qpn)
171 			__field(u32, slid)
172 			/* extended headers */
173 			__dynamic_array(u8, ehdrs,
174 					hfi1_trace_packet_hdr_len(packet))
175 			),
176 		    TP_fast_assign(
177 			DD_DEV_ASSIGN(dd);
178 
179 			__entry->etype = packet->etype;
180 			__entry->l2 = hfi1_16B_get_l2(packet->hdr);
181 			if (__entry->etype == RHF_RCV_TYPE_BYPASS) {
182 				hfi1_trace_parse_16b_hdr(packet->hdr,
183 							 &__entry->age,
184 							 &__entry->becn,
185 							 &__entry->fecn,
186 							 &__entry->l4,
187 							 &__entry->rc,
188 							 &__entry->sc,
189 							 &__entry->entropy,
190 							 &__entry->len,
191 							 &__entry->pkey,
192 							 &__entry->dlid,
193 							 &__entry->slid);
194 
195 				  hfi1_trace_parse_16b_bth(packet->ohdr,
196 							   &__entry->ack,
197 							   &__entry->mig,
198 							   &__entry->opcode,
199 							   &__entry->pad,
200 							   &__entry->se,
201 							   &__entry->tver,
202 							   &__entry->psn,
203 							   &__entry->qpn);
204 			} else {
205 				hfi1_trace_parse_9b_hdr(packet->hdr, sc5,
206 							&__entry->lnh,
207 							&__entry->lver,
208 							&__entry->sl,
209 							&__entry->sc,
210 							&__entry->len,
211 							&__entry->dlid,
212 							&__entry->slid);
213 
214 				  hfi1_trace_parse_9b_bth(packet->ohdr,
215 							  &__entry->ack,
216 							  &__entry->becn,
217 							  &__entry->fecn,
218 							  &__entry->mig,
219 							  &__entry->se,
220 							  &__entry->pad,
221 							  &__entry->opcode,
222 							  &__entry->tver,
223 							  &__entry->pkey,
224 							  &__entry->psn,
225 							  &__entry->qpn);
226 				}
227 				/* extended headers */
228 				memcpy(__get_dynamic_array(ehdrs),
229 				       &packet->ohdr->u,
230 				       __get_dynamic_array_len(ehdrs));
231 			 ),
232 		    TP_printk("[%s] (%s) %s %s hlen:%d %s",
233 			      __get_str(dev),
234 			      __entry->etype != RHF_RCV_TYPE_BYPASS ?
235 					show_packettype(__entry->etype) :
236 					hfi1_trace_get_packet_l2_str(
237 						__entry->l2),
238 			      hfi1_trace_fmt_lrh(p,
239 						 __entry->etype ==
240 							RHF_RCV_TYPE_BYPASS,
241 						 __entry->age,
242 						 __entry->becn,
243 						 __entry->fecn,
244 						 __entry->l4,
245 						 __entry->lnh,
246 						 show_lnh(__entry->lnh),
247 						 __entry->lver,
248 						 __entry->rc,
249 						 __entry->sc,
250 						 __entry->sl,
251 						 __entry->entropy,
252 						 __entry->len,
253 						 __entry->pkey,
254 						 __entry->dlid,
255 						 __entry->slid),
256 			      hfi1_trace_fmt_bth(p,
257 						 __entry->etype ==
258 							RHF_RCV_TYPE_BYPASS,
259 						 __entry->ack,
260 						 __entry->becn,
261 						 __entry->fecn,
262 						 __entry->mig,
263 						 __entry->se,
264 						 __entry->pad,
265 						 __entry->opcode,
266 						 show_ib_opcode(__entry->opcode),
267 						 __entry->tver,
268 						 __entry->pkey,
269 						 __entry->psn,
270 						 __entry->qpn),
271 			      /* extended headers */
272 			      __get_dynamic_array_len(ehdrs),
273 			      __parse_ib_ehdrs(
274 					__entry->opcode,
275 					(void *)__get_dynamic_array(ehdrs))
276 			     )
277 );
278 
279 DEFINE_EVENT(hfi1_input_ibhdr_template, input_ibhdr,
280 	     TP_PROTO(struct hfi1_devdata *dd,
281 		      struct hfi1_packet *packet, bool sc5),
282 	     TP_ARGS(dd, packet, sc5));
283 
284 DECLARE_EVENT_CLASS(hfi1_output_ibhdr_template,
285 		    TP_PROTO(struct hfi1_devdata *dd,
286 			     struct hfi1_opa_header *opah, bool sc5),
287 		    TP_ARGS(dd, opah, sc5),
288 		    TP_STRUCT__entry(
289 			DD_DEV_ENTRY(dd)
290 			__field(u8, hdr_type)
291 			__field(u8, ack)
292 			__field(u8, age)
293 			__field(bool, becn)
294 			__field(bool, fecn)
295 			__field(u8, l4)
296 			__field(u8, lnh)
297 			__field(u8, lver)
298 			__field(u8, mig)
299 			__field(u8, opcode)
300 			__field(u8, pad)
301 			__field(u8, rc)
302 			__field(u8, sc)
303 			__field(u8, se)
304 			__field(u8, sl)
305 			__field(u8, tver)
306 			__field(u16, entropy)
307 			__field(u16, len)
308 			__field(u16, pkey)
309 			__field(u32, dlid)
310 			__field(u32, psn)
311 			__field(u32, qpn)
312 			__field(u32, slid)
313 			/* extended headers */
314 			__dynamic_array(u8, ehdrs,
315 					hfi1_trace_opa_hdr_len(opah))
316 			),
317 		    TP_fast_assign(
318 			struct ib_other_headers *ohdr;
319 
320 			DD_DEV_ASSIGN(dd);
321 
322 			__entry->hdr_type = opah->hdr_type;
323 			if (__entry->hdr_type)  {
324 				hfi1_trace_parse_16b_hdr(&opah->opah,
325 							 &__entry->age,
326 							 &__entry->becn,
327 							 &__entry->fecn,
328 							 &__entry->l4,
329 							 &__entry->rc,
330 							 &__entry->sc,
331 							 &__entry->entropy,
332 							 &__entry->len,
333 							 &__entry->pkey,
334 							 &__entry->dlid,
335 							 &__entry->slid);
336 
337 				if (__entry->l4 == OPA_16B_L4_IB_LOCAL)
338 					ohdr = &opah->opah.u.oth;
339 				else
340 					ohdr = &opah->opah.u.l.oth;
341 				hfi1_trace_parse_16b_bth(ohdr,
342 							 &__entry->ack,
343 							 &__entry->mig,
344 							 &__entry->opcode,
345 							 &__entry->pad,
346 							 &__entry->se,
347 							 &__entry->tver,
348 							 &__entry->psn,
349 							 &__entry->qpn);
350 			} else {
351 				__entry->l4 = OPA_16B_L4_9B;
352 				hfi1_trace_parse_9b_hdr(&opah->ibh, sc5,
353 							&__entry->lnh,
354 							&__entry->lver,
355 							&__entry->sl,
356 							&__entry->sc,
357 							&__entry->len,
358 							&__entry->dlid,
359 							&__entry->slid);
360 				if (__entry->lnh == HFI1_LRH_BTH)
361 					ohdr = &opah->ibh.u.oth;
362 				else
363 					ohdr = &opah->ibh.u.l.oth;
364 				hfi1_trace_parse_9b_bth(ohdr,
365 							&__entry->ack,
366 							&__entry->becn,
367 							&__entry->fecn,
368 							&__entry->mig,
369 							&__entry->se,
370 							&__entry->pad,
371 							&__entry->opcode,
372 							&__entry->tver,
373 							&__entry->pkey,
374 							&__entry->psn,
375 							&__entry->qpn);
376 			}
377 
378 			/* extended headers */
379 			memcpy(__get_dynamic_array(ehdrs),
380 			       &ohdr->u, __get_dynamic_array_len(ehdrs));
381 		    ),
382 		    TP_printk("[%s] (%s) %s %s hlen:%d %s",
383 			      __get_str(dev),
384 			      hfi1_trace_get_packet_l4_str(__entry->l4),
385 			      hfi1_trace_fmt_lrh(p,
386 						 !!__entry->hdr_type,
387 						 __entry->age,
388 						 __entry->becn,
389 						 __entry->fecn,
390 						 __entry->l4,
391 						 __entry->lnh,
392 						 show_lnh(__entry->lnh),
393 						 __entry->lver,
394 						 __entry->rc,
395 						 __entry->sc,
396 						 __entry->sl,
397 						 __entry->entropy,
398 						 __entry->len,
399 						 __entry->pkey,
400 						 __entry->dlid,
401 						 __entry->slid),
402 			      hfi1_trace_fmt_bth(p,
403 						 !!__entry->hdr_type,
404 						 __entry->ack,
405 						 __entry->becn,
406 						 __entry->fecn,
407 						 __entry->mig,
408 						 __entry->se,
409 						 __entry->pad,
410 						 __entry->opcode,
411 						 show_ib_opcode(__entry->opcode),
412 						 __entry->tver,
413 						 __entry->pkey,
414 						 __entry->psn,
415 						 __entry->qpn),
416 			      /* extended headers */
417 			      __get_dynamic_array_len(ehdrs),
418 			      __parse_ib_ehdrs(
419 					__entry->opcode,
420 					(void *)__get_dynamic_array(ehdrs))
421 			     )
422 );
423 
424 DEFINE_EVENT(hfi1_output_ibhdr_template, pio_output_ibhdr,
425 	     TP_PROTO(struct hfi1_devdata *dd,
426 		      struct hfi1_opa_header *opah, bool sc5),
427 	     TP_ARGS(dd, opah, sc5));
428 
429 DEFINE_EVENT(hfi1_output_ibhdr_template, ack_output_ibhdr,
430 	     TP_PROTO(struct hfi1_devdata *dd,
431 		      struct hfi1_opa_header *opah, bool sc5),
432 	     TP_ARGS(dd, opah, sc5));
433 
434 DEFINE_EVENT(hfi1_output_ibhdr_template, sdma_output_ibhdr,
435 	     TP_PROTO(struct hfi1_devdata *dd,
436 		      struct hfi1_opa_header *opah, bool sc5),
437 	     TP_ARGS(dd, opah, sc5));
438 
439 
440 #endif /* __HFI1_TRACE_IBHDRS_H */
441 
442 #undef TRACE_INCLUDE_PATH
443 #undef TRACE_INCLUDE_FILE
444 #define TRACE_INCLUDE_PATH .
445 #define TRACE_INCLUDE_FILE trace_ibhdrs
446 #include <trace/define_trace.h>
447