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,
100 			      u8 l4, u32 dest_qpn, u32 src_qpn,
101 			      void *ehdrs);
102 u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opah);
103 u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet);
104 const char *hfi1_trace_get_packet_l4_str(u8 l4);
105 void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr,
106 			     u8 *ack, bool *becn, bool *fecn, u8 *mig,
107 			     u8 *se, u8 *pad, u8 *opcode, u8 *tver,
108 			     u16 *pkey, u32 *psn, u32 *qpn);
109 void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5,
110 			     u8 *lnh, u8 *lver, u8 *sl, u8 *sc,
111 			     u16 *len, u32 *dlid, u32 *slid);
112 void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr,
113 			      u8 *ack, u8 *mig, u8 *opcode,
114 			      u8 *pad, u8 *se, u8 *tver,
115 			      u32 *psn, u32 *qpn);
116 void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr,
117 			      u8 *age, bool *becn, bool *fecn,
118 			      u8 *l4, u8 *rc, u8 *sc,
119 			      u16 *entropy, u16 *len, u16 *pkey,
120 			      u32 *dlid, u32 *slid);
121 
122 const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass,
123 			       u8 age, bool becn, bool fecn, u8 l4,
124 			       u8 lnh, const char *lnh_name, u8 lver,
125 			       u8 rc, u8 sc, u8 sl, u16 entropy,
126 			       u16 len, u16 pkey, u32 dlid, u32 slid);
127 
128 const char *hfi1_trace_fmt_rest(struct trace_seq *p, bool bypass, u8 l4,
129 				u8 ack, bool becn, bool fecn, u8 mig,
130 				u8 se, u8 pad, u8 opcode, const char *opname,
131 				u8 tver, u16 pkey, u32 psn, u32 qpn,
132 				u32 dest_qpn, u32 src_qpn);
133 
134 const char *hfi1_trace_get_packet_l2_str(u8 l2);
135 
136 #define __parse_ib_ehdrs(op, l4, dest_qpn, src_qpn, ehdrs) \
137 			 parse_everbs_hdrs(p, op, l4, dest_qpn, src_qpn, ehdrs)
138 
139 #define lrh_name(lrh) { HFI1_##lrh, #lrh }
140 #define show_lnh(lrh)                    \
141 __print_symbolic(lrh,                    \
142 	lrh_name(LRH_BTH),               \
143 	lrh_name(LRH_GRH))
144 
145 DECLARE_EVENT_CLASS(hfi1_input_ibhdr_template,
146 		    TP_PROTO(struct hfi1_devdata *dd,
147 			     struct hfi1_packet *packet,
148 			     bool sc5),
149 		    TP_ARGS(dd, packet, sc5),
150 		    TP_STRUCT__entry(
151 			DD_DEV_ENTRY(dd)
152 			__field(u8, etype)
153 			__field(u8, ack)
154 			__field(u8, age)
155 			__field(bool, becn)
156 			__field(bool, fecn)
157 			__field(u8, l2)
158 			__field(u8, l4)
159 			__field(u8, lnh)
160 			__field(u8, lver)
161 			__field(u8, mig)
162 			__field(u8, opcode)
163 			__field(u8, pad)
164 			__field(u8, rc)
165 			__field(u8, sc)
166 			__field(u8, se)
167 			__field(u8, sl)
168 			__field(u8, tver)
169 			__field(u16, entropy)
170 			__field(u16, len)
171 			__field(u16, pkey)
172 			__field(u32, dlid)
173 			__field(u32, psn)
174 			__field(u32, qpn)
175 			__field(u32, slid)
176 			__field(u32, dest_qpn)
177 			__field(u32, src_qpn)
178 			/* extended headers */
179 			__dynamic_array(u8, ehdrs,
180 					hfi1_trace_packet_hdr_len(packet))
181 			),
182 		    TP_fast_assign(
183 			DD_DEV_ASSIGN(dd);
184 
185 			__entry->etype = packet->etype;
186 			__entry->l2 = hfi1_16B_get_l2(packet->hdr);
187 			__entry->dest_qpn = 0;
188 			__entry->src_qpn = 0;
189 			if (__entry->etype == RHF_RCV_TYPE_BYPASS) {
190 				hfi1_trace_parse_16b_hdr(packet->hdr,
191 							 &__entry->age,
192 							 &__entry->becn,
193 							 &__entry->fecn,
194 							 &__entry->l4,
195 							 &__entry->rc,
196 							 &__entry->sc,
197 							 &__entry->entropy,
198 							 &__entry->len,
199 							 &__entry->pkey,
200 							 &__entry->dlid,
201 							 &__entry->slid);
202 
203 				if (__entry->l4 == OPA_16B_L4_FM) {
204 					__entry->opcode = IB_OPCODE_UD_SEND_ONLY;
205 					__entry->dest_qpn = hfi1_16B_get_dest_qpn(packet->mgmt);
206 					__entry->src_qpn = hfi1_16B_get_src_qpn(packet->mgmt);
207 				}  else {
208 					hfi1_trace_parse_16b_bth(packet->ohdr,
209 								 &__entry->ack,
210 								 &__entry->mig,
211 								 &__entry->opcode,
212 								 &__entry->pad,
213 								 &__entry->se,
214 								 &__entry->tver,
215 								 &__entry->psn,
216 								 &__entry->qpn);
217 				}
218 			} else {
219 				__entry->l4 = OPA_16B_L4_9B;
220 				hfi1_trace_parse_9b_hdr(packet->hdr, sc5,
221 							&__entry->lnh,
222 							&__entry->lver,
223 							&__entry->sl,
224 							&__entry->sc,
225 							&__entry->len,
226 							&__entry->dlid,
227 							&__entry->slid);
228 
229 				  hfi1_trace_parse_9b_bth(packet->ohdr,
230 							  &__entry->ack,
231 							  &__entry->becn,
232 							  &__entry->fecn,
233 							  &__entry->mig,
234 							  &__entry->se,
235 							  &__entry->pad,
236 							  &__entry->opcode,
237 							  &__entry->tver,
238 							  &__entry->pkey,
239 							  &__entry->psn,
240 							  &__entry->qpn);
241 			}
242 			/* extended headers */
243 			if (__entry->l4 != OPA_16B_L4_FM)
244 				memcpy(__get_dynamic_array(ehdrs),
245 				       &packet->ohdr->u,
246 				       __get_dynamic_array_len(ehdrs));
247 			 ),
248 		    TP_printk("[%s] (%s) %s %s hlen:%d %s",
249 			      __get_str(dev),
250 			      __entry->etype != RHF_RCV_TYPE_BYPASS ?
251 					show_packettype(__entry->etype) :
252 					hfi1_trace_get_packet_l2_str(
253 						__entry->l2),
254 			      hfi1_trace_fmt_lrh(p,
255 						 __entry->etype ==
256 							RHF_RCV_TYPE_BYPASS,
257 						 __entry->age,
258 						 __entry->becn,
259 						 __entry->fecn,
260 						 __entry->l4,
261 						 __entry->lnh,
262 						 show_lnh(__entry->lnh),
263 						 __entry->lver,
264 						 __entry->rc,
265 						 __entry->sc,
266 						 __entry->sl,
267 						 __entry->entropy,
268 						 __entry->len,
269 						 __entry->pkey,
270 						 __entry->dlid,
271 						 __entry->slid),
272 			      hfi1_trace_fmt_rest(p,
273 						  __entry->etype ==
274 							RHF_RCV_TYPE_BYPASS,
275 						  __entry->l4,
276 						  __entry->ack,
277 						  __entry->becn,
278 						  __entry->fecn,
279 						  __entry->mig,
280 						  __entry->se,
281 						  __entry->pad,
282 						  __entry->opcode,
283 						  show_ib_opcode(__entry->opcode),
284 						  __entry->tver,
285 						  __entry->pkey,
286 						  __entry->psn,
287 						  __entry->qpn,
288 						  __entry->dest_qpn,
289 						  __entry->src_qpn),
290 			      /* extended headers */
291 			      __get_dynamic_array_len(ehdrs),
292 			      __parse_ib_ehdrs(
293 					__entry->opcode,
294 					__entry->l4,
295 					__entry->dest_qpn,
296 					__entry->src_qpn,
297 					(void *)__get_dynamic_array(ehdrs))
298 			     )
299 );
300 
301 DEFINE_EVENT(hfi1_input_ibhdr_template, input_ibhdr,
302 	     TP_PROTO(struct hfi1_devdata *dd,
303 		      struct hfi1_packet *packet, bool sc5),
304 	     TP_ARGS(dd, packet, sc5));
305 
306 DECLARE_EVENT_CLASS(hfi1_output_ibhdr_template,
307 		    TP_PROTO(struct hfi1_devdata *dd,
308 			     struct hfi1_opa_header *opah, bool sc5),
309 		    TP_ARGS(dd, opah, sc5),
310 		    TP_STRUCT__entry(
311 			DD_DEV_ENTRY(dd)
312 			__field(u8, hdr_type)
313 			__field(u8, ack)
314 			__field(u8, age)
315 			__field(bool, becn)
316 			__field(bool, fecn)
317 			__field(u8, l4)
318 			__field(u8, lnh)
319 			__field(u8, lver)
320 			__field(u8, mig)
321 			__field(u8, opcode)
322 			__field(u8, pad)
323 			__field(u8, rc)
324 			__field(u8, sc)
325 			__field(u8, se)
326 			__field(u8, sl)
327 			__field(u8, tver)
328 			__field(u16, entropy)
329 			__field(u16, len)
330 			__field(u16, pkey)
331 			__field(u32, dlid)
332 			__field(u32, psn)
333 			__field(u32, qpn)
334 			__field(u32, slid)
335 			__field(u32, dest_qpn)
336 			__field(u32, src_qpn)
337 			/* extended headers */
338 			__dynamic_array(u8, ehdrs,
339 					hfi1_trace_opa_hdr_len(opah))
340 			),
341 		    TP_fast_assign(
342 			struct ib_other_headers *ohdr;
343 
344 			DD_DEV_ASSIGN(dd);
345 
346 			__entry->hdr_type = opah->hdr_type;
347 			__entry->dest_qpn = 0;
348 			__entry->src_qpn = 0;
349 			if (__entry->hdr_type)  {
350 				hfi1_trace_parse_16b_hdr(&opah->opah,
351 							 &__entry->age,
352 							 &__entry->becn,
353 							 &__entry->fecn,
354 							 &__entry->l4,
355 							 &__entry->rc,
356 							 &__entry->sc,
357 							 &__entry->entropy,
358 							 &__entry->len,
359 							 &__entry->pkey,
360 							 &__entry->dlid,
361 							 &__entry->slid);
362 
363 				if (__entry->l4 == OPA_16B_L4_FM) {
364 					ohdr = NULL;
365 					__entry->opcode = IB_OPCODE_UD_SEND_ONLY;
366 					__entry->dest_qpn = hfi1_16B_get_dest_qpn(&opah->opah.u.mgmt);
367 					__entry->src_qpn = hfi1_16B_get_src_qpn(&opah->opah.u.mgmt);
368 				} else {
369 					if (__entry->l4 == OPA_16B_L4_IB_LOCAL)
370 						ohdr = &opah->opah.u.oth;
371 					else
372 						ohdr = &opah->opah.u.l.oth;
373 					hfi1_trace_parse_16b_bth(ohdr,
374 								 &__entry->ack,
375 								 &__entry->mig,
376 								 &__entry->opcode,
377 								 &__entry->pad,
378 								 &__entry->se,
379 								 &__entry->tver,
380 								 &__entry->psn,
381 								 &__entry->qpn);
382 				}
383 			} else {
384 				__entry->l4 = OPA_16B_L4_9B;
385 				hfi1_trace_parse_9b_hdr(&opah->ibh, sc5,
386 							&__entry->lnh,
387 							&__entry->lver,
388 							&__entry->sl,
389 							&__entry->sc,
390 							&__entry->len,
391 							&__entry->dlid,
392 							&__entry->slid);
393 				if (__entry->lnh == HFI1_LRH_BTH)
394 					ohdr = &opah->ibh.u.oth;
395 				else
396 					ohdr = &opah->ibh.u.l.oth;
397 				hfi1_trace_parse_9b_bth(ohdr,
398 							&__entry->ack,
399 							&__entry->becn,
400 							&__entry->fecn,
401 							&__entry->mig,
402 							&__entry->se,
403 							&__entry->pad,
404 							&__entry->opcode,
405 							&__entry->tver,
406 							&__entry->pkey,
407 							&__entry->psn,
408 							&__entry->qpn);
409 			}
410 
411 			/* extended headers */
412 			if (__entry->l4 != OPA_16B_L4_FM)
413 				memcpy(__get_dynamic_array(ehdrs),
414 				       &ohdr->u, __get_dynamic_array_len(ehdrs));
415 		    ),
416 		    TP_printk("[%s] (%s) %s %s hlen:%d %s",
417 			      __get_str(dev),
418 			      hfi1_trace_get_packet_l4_str(__entry->l4),
419 			      hfi1_trace_fmt_lrh(p,
420 						 !!__entry->hdr_type,
421 						 __entry->age,
422 						 __entry->becn,
423 						 __entry->fecn,
424 						 __entry->l4,
425 						 __entry->lnh,
426 						 show_lnh(__entry->lnh),
427 						 __entry->lver,
428 						 __entry->rc,
429 						 __entry->sc,
430 						 __entry->sl,
431 						 __entry->entropy,
432 						 __entry->len,
433 						 __entry->pkey,
434 						 __entry->dlid,
435 						 __entry->slid),
436 			      hfi1_trace_fmt_rest(p,
437 						  !!__entry->hdr_type,
438 						  __entry->l4,
439 						  __entry->ack,
440 						  __entry->becn,
441 						  __entry->fecn,
442 						  __entry->mig,
443 						  __entry->se,
444 						  __entry->pad,
445 						  __entry->opcode,
446 						  show_ib_opcode(__entry->opcode),
447 						  __entry->tver,
448 						  __entry->pkey,
449 						  __entry->psn,
450 						  __entry->qpn,
451 						  __entry->dest_qpn,
452 						  __entry->src_qpn),
453 			      /* extended headers */
454 			      __get_dynamic_array_len(ehdrs),
455 			      __parse_ib_ehdrs(
456 					__entry->opcode,
457 					__entry->l4,
458 					__entry->dest_qpn,
459 					__entry->src_qpn,
460 					(void *)__get_dynamic_array(ehdrs))
461 			     )
462 );
463 
464 DEFINE_EVENT(hfi1_output_ibhdr_template, pio_output_ibhdr,
465 	     TP_PROTO(struct hfi1_devdata *dd,
466 		      struct hfi1_opa_header *opah, bool sc5),
467 	     TP_ARGS(dd, opah, sc5));
468 
469 DEFINE_EVENT(hfi1_output_ibhdr_template, ack_output_ibhdr,
470 	     TP_PROTO(struct hfi1_devdata *dd,
471 		      struct hfi1_opa_header *opah, bool sc5),
472 	     TP_ARGS(dd, opah, sc5));
473 
474 DEFINE_EVENT(hfi1_output_ibhdr_template, sdma_output_ibhdr,
475 	     TP_PROTO(struct hfi1_devdata *dd,
476 		      struct hfi1_opa_header *opah, bool sc5),
477 	     TP_ARGS(dd, opah, sc5));
478 
479 
480 #endif /* __HFI1_TRACE_IBHDRS_H */
481 
482 #undef TRACE_INCLUDE_PATH
483 #undef TRACE_INCLUDE_FILE
484 #define TRACE_INCLUDE_PATH .
485 #define TRACE_INCLUDE_FILE trace_ibhdrs
486 #include <trace/define_trace.h>
487