xref: /linux/drivers/infiniband/hw/hfi1/trace_ibhdrs.h (revision 4b911a9690d72641879ea6d13cce1de31d346d79)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright(c) 2015 - 2017 Intel Corporation.
4  */
5 
6 #if !defined(__HFI1_TRACE_IBHDRS_H) || defined(TRACE_HEADER_MULTI_READ)
7 #define __HFI1_TRACE_IBHDRS_H
8 
9 #include <linux/tracepoint.h>
10 #include <linux/trace_seq.h>
11 
12 #include "hfi.h"
13 
14 #undef TRACE_SYSTEM
15 #define TRACE_SYSTEM hfi1_ibhdrs
16 
17 #define ib_opcode_name(opcode) { IB_OPCODE_##opcode, #opcode  }
18 #define show_ib_opcode(opcode)                             \
19 __print_symbolic(opcode,                                   \
20 	ib_opcode_name(RC_SEND_FIRST),                     \
21 	ib_opcode_name(RC_SEND_MIDDLE),                    \
22 	ib_opcode_name(RC_SEND_LAST),                      \
23 	ib_opcode_name(RC_SEND_LAST_WITH_IMMEDIATE),       \
24 	ib_opcode_name(RC_SEND_ONLY),                      \
25 	ib_opcode_name(RC_SEND_ONLY_WITH_IMMEDIATE),       \
26 	ib_opcode_name(RC_RDMA_WRITE_FIRST),               \
27 	ib_opcode_name(RC_RDMA_WRITE_MIDDLE),              \
28 	ib_opcode_name(RC_RDMA_WRITE_LAST),                \
29 	ib_opcode_name(RC_RDMA_WRITE_LAST_WITH_IMMEDIATE), \
30 	ib_opcode_name(RC_RDMA_WRITE_ONLY),                \
31 	ib_opcode_name(RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \
32 	ib_opcode_name(RC_RDMA_READ_REQUEST),              \
33 	ib_opcode_name(RC_RDMA_READ_RESPONSE_FIRST),       \
34 	ib_opcode_name(RC_RDMA_READ_RESPONSE_MIDDLE),      \
35 	ib_opcode_name(RC_RDMA_READ_RESPONSE_LAST),        \
36 	ib_opcode_name(RC_RDMA_READ_RESPONSE_ONLY),        \
37 	ib_opcode_name(RC_ACKNOWLEDGE),                    \
38 	ib_opcode_name(RC_ATOMIC_ACKNOWLEDGE),             \
39 	ib_opcode_name(RC_COMPARE_SWAP),                   \
40 	ib_opcode_name(RC_FETCH_ADD),                      \
41 	ib_opcode_name(RC_SEND_LAST_WITH_INVALIDATE),      \
42 	ib_opcode_name(RC_SEND_ONLY_WITH_INVALIDATE),      \
43 	ib_opcode_name(TID_RDMA_WRITE_REQ),	           \
44 	ib_opcode_name(TID_RDMA_WRITE_RESP),	           \
45 	ib_opcode_name(TID_RDMA_WRITE_DATA),	           \
46 	ib_opcode_name(TID_RDMA_WRITE_DATA_LAST),          \
47 	ib_opcode_name(TID_RDMA_READ_REQ),	           \
48 	ib_opcode_name(TID_RDMA_READ_RESP),	           \
49 	ib_opcode_name(TID_RDMA_RESYNC),	           \
50 	ib_opcode_name(TID_RDMA_ACK),                      \
51 	ib_opcode_name(UC_SEND_FIRST),                     \
52 	ib_opcode_name(UC_SEND_MIDDLE),                    \
53 	ib_opcode_name(UC_SEND_LAST),                      \
54 	ib_opcode_name(UC_SEND_LAST_WITH_IMMEDIATE),       \
55 	ib_opcode_name(UC_SEND_ONLY),                      \
56 	ib_opcode_name(UC_SEND_ONLY_WITH_IMMEDIATE),       \
57 	ib_opcode_name(UC_RDMA_WRITE_FIRST),               \
58 	ib_opcode_name(UC_RDMA_WRITE_MIDDLE),              \
59 	ib_opcode_name(UC_RDMA_WRITE_LAST),                \
60 	ib_opcode_name(UC_RDMA_WRITE_LAST_WITH_IMMEDIATE), \
61 	ib_opcode_name(UC_RDMA_WRITE_ONLY),                \
62 	ib_opcode_name(UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \
63 	ib_opcode_name(UD_SEND_ONLY),                      \
64 	ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE),       \
65 	ib_opcode_name(CNP))
66 
67 u8 ibhdr_exhdr_len(struct ib_header *hdr);
68 const char *parse_everbs_hdrs(struct trace_seq *p, u8 opcode,
69 			      u8 l4, u32 dest_qpn, u32 src_qpn,
70 			      void *ehdrs);
71 u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opah);
72 u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet);
73 const char *hfi1_trace_get_packet_l4_str(u8 l4);
74 void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr,
75 			     u8 *ack, bool *becn, bool *fecn, u8 *mig,
76 			     u8 *se, u8 *pad, u8 *opcode, u8 *tver,
77 			     u16 *pkey, u32 *psn, u32 *qpn);
78 void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5,
79 			     u8 *lnh, u8 *lver, u8 *sl, u8 *sc,
80 			     u16 *len, u32 *dlid, u32 *slid);
81 void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr,
82 			      u8 *ack, u8 *mig, u8 *opcode,
83 			      u8 *pad, u8 *se, u8 *tver,
84 			      u32 *psn, u32 *qpn);
85 void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr,
86 			      u8 *age, bool *becn, bool *fecn,
87 			      u8 *l4, u8 *rc, u8 *sc,
88 			      u16 *entropy, u16 *len, u16 *pkey,
89 			      u32 *dlid, u32 *slid);
90 
91 const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass,
92 			       u8 age, bool becn, bool fecn, u8 l4,
93 			       u8 lnh, const char *lnh_name, u8 lver,
94 			       u8 rc, u8 sc, u8 sl, u16 entropy,
95 			       u16 len, u16 pkey, u32 dlid, u32 slid);
96 
97 const char *hfi1_trace_fmt_rest(struct trace_seq *p, bool bypass, u8 l4,
98 				u8 ack, bool becn, bool fecn, u8 mig,
99 				u8 se, u8 pad, u8 opcode, const char *opname,
100 				u8 tver, u16 pkey, u32 psn, u32 qpn,
101 				u32 dest_qpn, u32 src_qpn);
102 
103 const char *hfi1_trace_get_packet_l2_str(u8 l2);
104 
105 #define __parse_ib_ehdrs(op, l4, dest_qpn, src_qpn, ehdrs) \
106 			 parse_everbs_hdrs(p, op, l4, dest_qpn, src_qpn, ehdrs)
107 
108 #define lrh_name(lrh) { HFI1_##lrh, #lrh }
109 #define show_lnh(lrh)                    \
110 __print_symbolic(lrh,                    \
111 	lrh_name(LRH_BTH),               \
112 	lrh_name(LRH_GRH))
113 
114 DECLARE_EVENT_CLASS(hfi1_input_ibhdr_template,
115 		    TP_PROTO(struct hfi1_devdata *dd,
116 			     struct hfi1_packet *packet,
117 			     bool sc5),
118 		    TP_ARGS(dd, packet, sc5),
119 		    TP_STRUCT__entry(
120 			DD_DEV_ENTRY(dd)
121 			__field(u8, etype)
122 			__field(u8, ack)
123 			__field(u8, age)
124 			__field(bool, becn)
125 			__field(bool, fecn)
126 			__field(u8, l2)
127 			__field(u8, l4)
128 			__field(u8, lnh)
129 			__field(u8, lver)
130 			__field(u8, mig)
131 			__field(u8, opcode)
132 			__field(u8, pad)
133 			__field(u8, rc)
134 			__field(u8, sc)
135 			__field(u8, se)
136 			__field(u8, sl)
137 			__field(u8, tver)
138 			__field(u16, entropy)
139 			__field(u16, len)
140 			__field(u16, pkey)
141 			__field(u32, dlid)
142 			__field(u32, psn)
143 			__field(u32, qpn)
144 			__field(u32, slid)
145 			__field(u32, dest_qpn)
146 			__field(u32, src_qpn)
147 			/* extended headers */
148 			__dynamic_array(u8, ehdrs,
149 					hfi1_trace_packet_hdr_len(packet))
150 			),
151 		    TP_fast_assign(
152 			DD_DEV_ASSIGN(dd);
153 
154 			__entry->etype = packet->etype;
155 			__entry->l2 = hfi1_16B_get_l2(packet->hdr);
156 			__entry->dest_qpn = 0;
157 			__entry->src_qpn = 0;
158 			if (__entry->etype == RHF_RCV_TYPE_BYPASS) {
159 				hfi1_trace_parse_16b_hdr(packet->hdr,
160 							 &__entry->age,
161 							 &__entry->becn,
162 							 &__entry->fecn,
163 							 &__entry->l4,
164 							 &__entry->rc,
165 							 &__entry->sc,
166 							 &__entry->entropy,
167 							 &__entry->len,
168 							 &__entry->pkey,
169 							 &__entry->dlid,
170 							 &__entry->slid);
171 
172 				if (__entry->l4 == OPA_16B_L4_FM) {
173 					__entry->opcode = IB_OPCODE_UD_SEND_ONLY;
174 					__entry->dest_qpn = hfi1_16B_get_dest_qpn(packet->mgmt);
175 					__entry->src_qpn = hfi1_16B_get_src_qpn(packet->mgmt);
176 				}  else {
177 					hfi1_trace_parse_16b_bth(packet->ohdr,
178 								 &__entry->ack,
179 								 &__entry->mig,
180 								 &__entry->opcode,
181 								 &__entry->pad,
182 								 &__entry->se,
183 								 &__entry->tver,
184 								 &__entry->psn,
185 								 &__entry->qpn);
186 				}
187 			} else {
188 				__entry->l4 = OPA_16B_L4_9B;
189 				hfi1_trace_parse_9b_hdr(packet->hdr, sc5,
190 							&__entry->lnh,
191 							&__entry->lver,
192 							&__entry->sl,
193 							&__entry->sc,
194 							&__entry->len,
195 							&__entry->dlid,
196 							&__entry->slid);
197 
198 				  hfi1_trace_parse_9b_bth(packet->ohdr,
199 							  &__entry->ack,
200 							  &__entry->becn,
201 							  &__entry->fecn,
202 							  &__entry->mig,
203 							  &__entry->se,
204 							  &__entry->pad,
205 							  &__entry->opcode,
206 							  &__entry->tver,
207 							  &__entry->pkey,
208 							  &__entry->psn,
209 							  &__entry->qpn);
210 			}
211 			/* extended headers */
212 			if (__entry->l4 != OPA_16B_L4_FM)
213 				memcpy(__get_dynamic_array(ehdrs),
214 				       &packet->ohdr->u,
215 				       __get_dynamic_array_len(ehdrs));
216 			 ),
217 		    TP_printk("[%s] (%s) %s %s hlen:%d %s",
218 			      __get_str(dev),
219 			      __entry->etype != RHF_RCV_TYPE_BYPASS ?
220 					show_packettype(__entry->etype) :
221 					hfi1_trace_get_packet_l2_str(
222 						__entry->l2),
223 			      hfi1_trace_fmt_lrh(p,
224 						 __entry->etype ==
225 							RHF_RCV_TYPE_BYPASS,
226 						 __entry->age,
227 						 __entry->becn,
228 						 __entry->fecn,
229 						 __entry->l4,
230 						 __entry->lnh,
231 						 show_lnh(__entry->lnh),
232 						 __entry->lver,
233 						 __entry->rc,
234 						 __entry->sc,
235 						 __entry->sl,
236 						 __entry->entropy,
237 						 __entry->len,
238 						 __entry->pkey,
239 						 __entry->dlid,
240 						 __entry->slid),
241 			      hfi1_trace_fmt_rest(p,
242 						  __entry->etype ==
243 							RHF_RCV_TYPE_BYPASS,
244 						  __entry->l4,
245 						  __entry->ack,
246 						  __entry->becn,
247 						  __entry->fecn,
248 						  __entry->mig,
249 						  __entry->se,
250 						  __entry->pad,
251 						  __entry->opcode,
252 						  show_ib_opcode(__entry->opcode),
253 						  __entry->tver,
254 						  __entry->pkey,
255 						  __entry->psn,
256 						  __entry->qpn,
257 						  __entry->dest_qpn,
258 						  __entry->src_qpn),
259 			      /* extended headers */
260 			      __get_dynamic_array_len(ehdrs),
261 			      __parse_ib_ehdrs(
262 					__entry->opcode,
263 					__entry->l4,
264 					__entry->dest_qpn,
265 					__entry->src_qpn,
266 					(void *)__get_dynamic_array(ehdrs))
267 			     )
268 );
269 
270 DEFINE_EVENT(hfi1_input_ibhdr_template, input_ibhdr,
271 	     TP_PROTO(struct hfi1_devdata *dd,
272 		      struct hfi1_packet *packet, bool sc5),
273 	     TP_ARGS(dd, packet, sc5));
274 
275 DECLARE_EVENT_CLASS(hfi1_output_ibhdr_template,
276 		    TP_PROTO(struct hfi1_devdata *dd,
277 			     struct hfi1_opa_header *opah, bool sc5),
278 		    TP_ARGS(dd, opah, sc5),
279 		    TP_STRUCT__entry(
280 			DD_DEV_ENTRY(dd)
281 			__field(u8, hdr_type)
282 			__field(u8, ack)
283 			__field(u8, age)
284 			__field(bool, becn)
285 			__field(bool, fecn)
286 			__field(u8, l4)
287 			__field(u8, lnh)
288 			__field(u8, lver)
289 			__field(u8, mig)
290 			__field(u8, opcode)
291 			__field(u8, pad)
292 			__field(u8, rc)
293 			__field(u8, sc)
294 			__field(u8, se)
295 			__field(u8, sl)
296 			__field(u8, tver)
297 			__field(u16, entropy)
298 			__field(u16, len)
299 			__field(u16, pkey)
300 			__field(u32, dlid)
301 			__field(u32, psn)
302 			__field(u32, qpn)
303 			__field(u32, slid)
304 			__field(u32, dest_qpn)
305 			__field(u32, src_qpn)
306 			/* extended headers */
307 			__dynamic_array(u8, ehdrs,
308 					hfi1_trace_opa_hdr_len(opah))
309 			),
310 		    TP_fast_assign(
311 			struct ib_other_headers *ohdr;
312 
313 			DD_DEV_ASSIGN(dd);
314 
315 			__entry->hdr_type = opah->hdr_type;
316 			__entry->dest_qpn = 0;
317 			__entry->src_qpn = 0;
318 			if (__entry->hdr_type)  {
319 				hfi1_trace_parse_16b_hdr(&opah->opah,
320 							 &__entry->age,
321 							 &__entry->becn,
322 							 &__entry->fecn,
323 							 &__entry->l4,
324 							 &__entry->rc,
325 							 &__entry->sc,
326 							 &__entry->entropy,
327 							 &__entry->len,
328 							 &__entry->pkey,
329 							 &__entry->dlid,
330 							 &__entry->slid);
331 
332 				if (__entry->l4 == OPA_16B_L4_FM) {
333 					ohdr = NULL;
334 					__entry->opcode = IB_OPCODE_UD_SEND_ONLY;
335 					__entry->dest_qpn = hfi1_16B_get_dest_qpn(&opah->opah.u.mgmt);
336 					__entry->src_qpn = hfi1_16B_get_src_qpn(&opah->opah.u.mgmt);
337 				} else {
338 					if (__entry->l4 == OPA_16B_L4_IB_LOCAL)
339 						ohdr = &opah->opah.u.oth;
340 					else
341 						ohdr = &opah->opah.u.l.oth;
342 					hfi1_trace_parse_16b_bth(ohdr,
343 								 &__entry->ack,
344 								 &__entry->mig,
345 								 &__entry->opcode,
346 								 &__entry->pad,
347 								 &__entry->se,
348 								 &__entry->tver,
349 								 &__entry->psn,
350 								 &__entry->qpn);
351 				}
352 			} else {
353 				__entry->l4 = OPA_16B_L4_9B;
354 				hfi1_trace_parse_9b_hdr(&opah->ibh, sc5,
355 							&__entry->lnh,
356 							&__entry->lver,
357 							&__entry->sl,
358 							&__entry->sc,
359 							&__entry->len,
360 							&__entry->dlid,
361 							&__entry->slid);
362 				if (__entry->lnh == HFI1_LRH_BTH)
363 					ohdr = &opah->ibh.u.oth;
364 				else
365 					ohdr = &opah->ibh.u.l.oth;
366 				hfi1_trace_parse_9b_bth(ohdr,
367 							&__entry->ack,
368 							&__entry->becn,
369 							&__entry->fecn,
370 							&__entry->mig,
371 							&__entry->se,
372 							&__entry->pad,
373 							&__entry->opcode,
374 							&__entry->tver,
375 							&__entry->pkey,
376 							&__entry->psn,
377 							&__entry->qpn);
378 			}
379 
380 			/* extended headers */
381 			if (__entry->l4 != OPA_16B_L4_FM)
382 				memcpy(__get_dynamic_array(ehdrs),
383 				       &ohdr->u, __get_dynamic_array_len(ehdrs));
384 		    ),
385 		    TP_printk("[%s] (%s) %s %s hlen:%d %s",
386 			      __get_str(dev),
387 			      hfi1_trace_get_packet_l4_str(__entry->l4),
388 			      hfi1_trace_fmt_lrh(p,
389 						 !!__entry->hdr_type,
390 						 __entry->age,
391 						 __entry->becn,
392 						 __entry->fecn,
393 						 __entry->l4,
394 						 __entry->lnh,
395 						 show_lnh(__entry->lnh),
396 						 __entry->lver,
397 						 __entry->rc,
398 						 __entry->sc,
399 						 __entry->sl,
400 						 __entry->entropy,
401 						 __entry->len,
402 						 __entry->pkey,
403 						 __entry->dlid,
404 						 __entry->slid),
405 			      hfi1_trace_fmt_rest(p,
406 						  !!__entry->hdr_type,
407 						  __entry->l4,
408 						  __entry->ack,
409 						  __entry->becn,
410 						  __entry->fecn,
411 						  __entry->mig,
412 						  __entry->se,
413 						  __entry->pad,
414 						  __entry->opcode,
415 						  show_ib_opcode(__entry->opcode),
416 						  __entry->tver,
417 						  __entry->pkey,
418 						  __entry->psn,
419 						  __entry->qpn,
420 						  __entry->dest_qpn,
421 						  __entry->src_qpn),
422 			      /* extended headers */
423 			      __get_dynamic_array_len(ehdrs),
424 			      __parse_ib_ehdrs(
425 					__entry->opcode,
426 					__entry->l4,
427 					__entry->dest_qpn,
428 					__entry->src_qpn,
429 					(void *)__get_dynamic_array(ehdrs))
430 			     )
431 );
432 
433 DEFINE_EVENT(hfi1_output_ibhdr_template, pio_output_ibhdr,
434 	     TP_PROTO(struct hfi1_devdata *dd,
435 		      struct hfi1_opa_header *opah, bool sc5),
436 	     TP_ARGS(dd, opah, sc5));
437 
438 DEFINE_EVENT(hfi1_output_ibhdr_template, ack_output_ibhdr,
439 	     TP_PROTO(struct hfi1_devdata *dd,
440 		      struct hfi1_opa_header *opah, bool sc5),
441 	     TP_ARGS(dd, opah, sc5));
442 
443 DEFINE_EVENT(hfi1_output_ibhdr_template, sdma_output_ibhdr,
444 	     TP_PROTO(struct hfi1_devdata *dd,
445 		      struct hfi1_opa_header *opah, bool sc5),
446 	     TP_ARGS(dd, opah, sc5));
447 
448 
449 #endif /* __HFI1_TRACE_IBHDRS_H */
450 
451 #undef TRACE_INCLUDE_PATH
452 #undef TRACE_INCLUDE_FILE
453 #define TRACE_INCLUDE_PATH .
454 #define TRACE_INCLUDE_FILE trace_ibhdrs
455 #include <trace/define_trace.h>
456