xref: /openbmc/linux/drivers/infiniband/hw/hfi1/trace.c (revision b285d2ae)
1 /*
2  * Copyright(c) 2015 - 2020 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 #define CREATE_TRACE_POINTS
48 #include "trace.h"
49 #include "exp_rcv.h"
50 #include "ipoib.h"
51 
52 static u8 __get_ib_hdr_len(struct ib_header *hdr)
53 {
54 	struct ib_other_headers *ohdr;
55 	u8 opcode;
56 
57 	if (ib_get_lnh(hdr) == HFI1_LRH_BTH)
58 		ohdr = &hdr->u.oth;
59 	else
60 		ohdr = &hdr->u.l.oth;
61 	opcode = ib_bth_get_opcode(ohdr);
62 	return hdr_len_by_opcode[opcode] == 0 ?
63 	       0 : hdr_len_by_opcode[opcode] - (12 + 8);
64 }
65 
66 static u8 __get_16b_hdr_len(struct hfi1_16b_header *hdr)
67 {
68 	struct ib_other_headers *ohdr = NULL;
69 	u8 opcode;
70 	u8 l4 = hfi1_16B_get_l4(hdr);
71 
72 	if (l4 == OPA_16B_L4_FM) {
73 		opcode = IB_OPCODE_UD_SEND_ONLY;
74 		return (8 + 8); /* No BTH */
75 	}
76 
77 	if (l4 == OPA_16B_L4_IB_LOCAL)
78 		ohdr = &hdr->u.oth;
79 	else
80 		ohdr = &hdr->u.l.oth;
81 
82 	opcode = ib_bth_get_opcode(ohdr);
83 	return hdr_len_by_opcode[opcode] == 0 ?
84 	       0 : hdr_len_by_opcode[opcode] - (12 + 8 + 8);
85 }
86 
87 u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet)
88 {
89 	if (packet->etype != RHF_RCV_TYPE_BYPASS)
90 		return __get_ib_hdr_len(packet->hdr);
91 	else
92 		return __get_16b_hdr_len(packet->hdr);
93 }
94 
95 u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opa_hdr)
96 {
97 	if (!opa_hdr->hdr_type)
98 		return __get_ib_hdr_len(&opa_hdr->ibh);
99 	else
100 		return __get_16b_hdr_len(&opa_hdr->opah);
101 }
102 
103 const char *hfi1_trace_get_packet_l4_str(u8 l4)
104 {
105 	if (l4)
106 		return "16B";
107 	else
108 		return "9B";
109 }
110 
111 const char *hfi1_trace_get_packet_l2_str(u8 l2)
112 {
113 	switch (l2) {
114 	case 0:
115 		return "0";
116 	case 1:
117 		return "1";
118 	case 2:
119 		return "16B";
120 	case 3:
121 		return "9B";
122 	}
123 	return "";
124 }
125 
126 #define IMM_PRN  "imm:%d"
127 #define RETH_PRN "reth vaddr:0x%.16llx rkey:0x%.8x dlen:0x%.8x"
128 #define AETH_PRN "aeth syn:0x%.2x %s msn:0x%.8x"
129 #define DETH_PRN "deth qkey:0x%.8x sqpn:0x%.6x"
130 #define DETH_ENTROPY_PRN "deth qkey:0x%.8x sqpn:0x%.6x entropy:0x%.2x"
131 #define IETH_PRN "ieth rkey:0x%.8x"
132 #define ATOMICACKETH_PRN "origdata:%llx"
133 #define ATOMICETH_PRN "vaddr:0x%llx rkey:0x%.8x sdata:%llx cdata:%llx"
134 #define TID_RDMA_KDETH "kdeth0 0x%x kdeth1 0x%x"
135 #define TID_RDMA_KDETH_DATA "kdeth0 0x%x: kver %u sh %u intr %u tidctrl %u tid %x offset %x kdeth1 0x%x: jkey %x"
136 #define TID_READ_REQ_PRN "tid_flow_psn 0x%x tid_flow_qp 0x%x verbs_qp 0x%x"
137 #define TID_READ_RSP_PRN "verbs_qp 0x%x"
138 #define TID_WRITE_REQ_PRN "original_qp 0x%x"
139 #define TID_WRITE_RSP_PRN "tid_flow_psn 0x%x tid_flow_qp 0x%x verbs_qp 0x%x"
140 #define TID_WRITE_DATA_PRN "verbs_qp 0x%x"
141 #define TID_ACK_PRN "tid_flow_psn 0x%x verbs_psn 0x%x tid_flow_qp 0x%x verbs_qp 0x%x"
142 #define TID_RESYNC_PRN "verbs_qp 0x%x"
143 
144 #define OP(transport, op) IB_OPCODE_## transport ## _ ## op
145 
146 static const char *parse_syndrome(u8 syndrome)
147 {
148 	switch (syndrome >> 5) {
149 	case 0:
150 		return "ACK";
151 	case 1:
152 		return "RNRNAK";
153 	case 3:
154 		return "NAK";
155 	}
156 	return "";
157 }
158 
159 void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr,
160 			     u8 *ack, bool *becn, bool *fecn, u8 *mig,
161 			     u8 *se, u8 *pad, u8 *opcode, u8 *tver,
162 			     u16 *pkey, u32 *psn, u32 *qpn)
163 {
164 	*ack = ib_bth_get_ackreq(ohdr);
165 	*becn = ib_bth_get_becn(ohdr);
166 	*fecn = ib_bth_get_fecn(ohdr);
167 	*mig = ib_bth_get_migreq(ohdr);
168 	*se = ib_bth_get_se(ohdr);
169 	*pad = ib_bth_get_pad(ohdr);
170 	*opcode = ib_bth_get_opcode(ohdr);
171 	*tver = ib_bth_get_tver(ohdr);
172 	*pkey = ib_bth_get_pkey(ohdr);
173 	*psn = mask_psn(ib_bth_get_psn(ohdr));
174 	*qpn = ib_bth_get_qpn(ohdr);
175 }
176 
177 void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr,
178 			      u8 *ack, u8 *mig, u8 *opcode,
179 			      u8 *pad, u8 *se, u8 *tver,
180 			      u32 *psn, u32 *qpn)
181 {
182 	*ack = ib_bth_get_ackreq(ohdr);
183 	*mig = ib_bth_get_migreq(ohdr);
184 	*opcode = ib_bth_get_opcode(ohdr);
185 	*pad = ib_bth_get_pad(ohdr);
186 	*se = ib_bth_get_se(ohdr);
187 	*tver = ib_bth_get_tver(ohdr);
188 	*psn = mask_psn(ib_bth_get_psn(ohdr));
189 	*qpn = ib_bth_get_qpn(ohdr);
190 }
191 
192 void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5,
193 			     u8 *lnh, u8 *lver, u8 *sl, u8 *sc,
194 			     u16 *len, u32 *dlid, u32 *slid)
195 {
196 	*lnh = ib_get_lnh(hdr);
197 	*lver = ib_get_lver(hdr);
198 	*sl = ib_get_sl(hdr);
199 	*sc = ib_get_sc(hdr) | (sc5 << 4);
200 	*len = ib_get_len(hdr);
201 	*dlid = ib_get_dlid(hdr);
202 	*slid = ib_get_slid(hdr);
203 }
204 
205 void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr,
206 			      u8 *age, bool *becn, bool *fecn,
207 			      u8 *l4, u8 *rc, u8 *sc,
208 			      u16 *entropy, u16 *len, u16 *pkey,
209 			      u32 *dlid, u32 *slid)
210 {
211 	*age = hfi1_16B_get_age(hdr);
212 	*becn = hfi1_16B_get_becn(hdr);
213 	*fecn = hfi1_16B_get_fecn(hdr);
214 	*l4 = hfi1_16B_get_l4(hdr);
215 	*rc = hfi1_16B_get_rc(hdr);
216 	*sc = hfi1_16B_get_sc(hdr);
217 	*entropy = hfi1_16B_get_entropy(hdr);
218 	*len = hfi1_16B_get_len(hdr);
219 	*pkey = hfi1_16B_get_pkey(hdr);
220 	*dlid = hfi1_16B_get_dlid(hdr);
221 	*slid = hfi1_16B_get_slid(hdr);
222 }
223 
224 #define LRH_PRN "len:%d sc:%d dlid:0x%.4x slid:0x%.4x "
225 #define LRH_9B_PRN "lnh:%d,%s lver:%d sl:%d"
226 #define LRH_16B_PRN "age:%d becn:%d fecn:%d l4:%d " \
227 		    "rc:%d sc:%d pkey:0x%.4x entropy:0x%.4x"
228 const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass,
229 			       u8 age, bool becn, bool fecn, u8 l4,
230 			       u8 lnh, const char *lnh_name, u8 lver,
231 			       u8 rc, u8 sc, u8 sl, u16 entropy,
232 			       u16 len, u16 pkey, u32 dlid, u32 slid)
233 {
234 	const char *ret = trace_seq_buffer_ptr(p);
235 
236 	trace_seq_printf(p, LRH_PRN, len, sc, dlid, slid);
237 
238 	if (bypass)
239 		trace_seq_printf(p, LRH_16B_PRN,
240 				 age, becn, fecn, l4, rc, sc, pkey, entropy);
241 
242 	else
243 		trace_seq_printf(p, LRH_9B_PRN,
244 				 lnh, lnh_name, lver, sl);
245 	trace_seq_putc(p, 0);
246 
247 	return ret;
248 }
249 
250 #define BTH_9B_PRN \
251 	"op:0x%.2x,%s se:%d m:%d pad:%d tver:%d pkey:0x%.4x " \
252 	"f:%d b:%d qpn:0x%.6x a:%d psn:0x%.8x"
253 #define BTH_16B_PRN \
254 	"op:0x%.2x,%s se:%d m:%d pad:%d tver:%d " \
255 	"qpn:0x%.6x a:%d psn:0x%.8x"
256 #define L4_FM_16B_PRN \
257 	"op:0x%.2x,%s dest_qpn:0x%.6x src_qpn:0x%.6x"
258 const char *hfi1_trace_fmt_rest(struct trace_seq *p, bool bypass, u8 l4,
259 				u8 ack, bool becn, bool fecn, u8 mig,
260 				u8 se, u8 pad, u8 opcode, const char *opname,
261 				u8 tver, u16 pkey, u32 psn, u32 qpn,
262 				u32 dest_qpn, u32 src_qpn)
263 {
264 	const char *ret = trace_seq_buffer_ptr(p);
265 
266 	if (bypass)
267 		if (l4 == OPA_16B_L4_FM)
268 			trace_seq_printf(p, L4_FM_16B_PRN,
269 					 opcode, opname, dest_qpn, src_qpn);
270 		else
271 			trace_seq_printf(p, BTH_16B_PRN,
272 					 opcode, opname,
273 					 se, mig, pad, tver, qpn, ack, psn);
274 
275 	else
276 		trace_seq_printf(p, BTH_9B_PRN,
277 				 opcode, opname,
278 				 se, mig, pad, tver, pkey, fecn, becn,
279 				 qpn, ack, psn);
280 	trace_seq_putc(p, 0);
281 
282 	return ret;
283 }
284 
285 const char *parse_everbs_hdrs(
286 	struct trace_seq *p,
287 	u8 opcode, u8 l4, u32 dest_qpn, u32 src_qpn,
288 	void *ehdrs)
289 {
290 	union ib_ehdrs *eh = ehdrs;
291 	const char *ret = trace_seq_buffer_ptr(p);
292 
293 	if (l4 == OPA_16B_L4_FM) {
294 		trace_seq_printf(p, "mgmt pkt");
295 		goto out;
296 	}
297 
298 	switch (opcode) {
299 	/* imm */
300 	case OP(RC, SEND_LAST_WITH_IMMEDIATE):
301 	case OP(UC, SEND_LAST_WITH_IMMEDIATE):
302 	case OP(RC, SEND_ONLY_WITH_IMMEDIATE):
303 	case OP(UC, SEND_ONLY_WITH_IMMEDIATE):
304 	case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
305 	case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
306 		trace_seq_printf(p, IMM_PRN,
307 				 be32_to_cpu(eh->imm_data));
308 		break;
309 	/* reth + imm */
310 	case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
311 	case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
312 		trace_seq_printf(p, RETH_PRN " " IMM_PRN,
313 				 get_ib_reth_vaddr(&eh->rc.reth),
314 				 be32_to_cpu(eh->rc.reth.rkey),
315 				 be32_to_cpu(eh->rc.reth.length),
316 				 be32_to_cpu(eh->rc.imm_data));
317 		break;
318 	/* reth */
319 	case OP(RC, RDMA_READ_REQUEST):
320 	case OP(RC, RDMA_WRITE_FIRST):
321 	case OP(UC, RDMA_WRITE_FIRST):
322 	case OP(RC, RDMA_WRITE_ONLY):
323 	case OP(UC, RDMA_WRITE_ONLY):
324 		trace_seq_printf(p, RETH_PRN,
325 				 get_ib_reth_vaddr(&eh->rc.reth),
326 				 be32_to_cpu(eh->rc.reth.rkey),
327 				 be32_to_cpu(eh->rc.reth.length));
328 		break;
329 	case OP(RC, RDMA_READ_RESPONSE_FIRST):
330 	case OP(RC, RDMA_READ_RESPONSE_LAST):
331 	case OP(RC, RDMA_READ_RESPONSE_ONLY):
332 	case OP(RC, ACKNOWLEDGE):
333 		trace_seq_printf(p, AETH_PRN, be32_to_cpu(eh->aeth) >> 24,
334 				 parse_syndrome(be32_to_cpu(eh->aeth) >> 24),
335 				 be32_to_cpu(eh->aeth) & IB_MSN_MASK);
336 		break;
337 	case OP(TID_RDMA, WRITE_REQ):
338 		trace_seq_printf(p, TID_RDMA_KDETH " " RETH_PRN " "
339 				 TID_WRITE_REQ_PRN,
340 				 le32_to_cpu(eh->tid_rdma.w_req.kdeth0),
341 				 le32_to_cpu(eh->tid_rdma.w_req.kdeth1),
342 				 ib_u64_get(&eh->tid_rdma.w_req.reth.vaddr),
343 				 be32_to_cpu(eh->tid_rdma.w_req.reth.rkey),
344 				 be32_to_cpu(eh->tid_rdma.w_req.reth.length),
345 				 be32_to_cpu(eh->tid_rdma.w_req.verbs_qp));
346 		break;
347 	case OP(TID_RDMA, WRITE_RESP):
348 		trace_seq_printf(p, TID_RDMA_KDETH " " AETH_PRN " "
349 				 TID_WRITE_RSP_PRN,
350 				 le32_to_cpu(eh->tid_rdma.w_rsp.kdeth0),
351 				 le32_to_cpu(eh->tid_rdma.w_rsp.kdeth1),
352 				 be32_to_cpu(eh->tid_rdma.w_rsp.aeth) >> 24,
353 				 parse_syndrome(/* aeth */
354 					 be32_to_cpu(eh->tid_rdma.w_rsp.aeth)
355 					 >> 24),
356 				 (be32_to_cpu(eh->tid_rdma.w_rsp.aeth) &
357 				  IB_MSN_MASK),
358 				 be32_to_cpu(eh->tid_rdma.w_rsp.tid_flow_psn),
359 				 be32_to_cpu(eh->tid_rdma.w_rsp.tid_flow_qp),
360 				 be32_to_cpu(eh->tid_rdma.w_rsp.verbs_qp));
361 		break;
362 	case OP(TID_RDMA, WRITE_DATA_LAST):
363 	case OP(TID_RDMA, WRITE_DATA):
364 		trace_seq_printf(p, TID_RDMA_KDETH_DATA " " TID_WRITE_DATA_PRN,
365 				 le32_to_cpu(eh->tid_rdma.w_data.kdeth0),
366 				 KDETH_GET(eh->tid_rdma.w_data.kdeth0, KVER),
367 				 KDETH_GET(eh->tid_rdma.w_data.kdeth0, SH),
368 				 KDETH_GET(eh->tid_rdma.w_data.kdeth0, INTR),
369 				 KDETH_GET(eh->tid_rdma.w_data.kdeth0, TIDCTRL),
370 				 KDETH_GET(eh->tid_rdma.w_data.kdeth0, TID),
371 				 KDETH_GET(eh->tid_rdma.w_data.kdeth0, OFFSET),
372 				 le32_to_cpu(eh->tid_rdma.w_data.kdeth1),
373 				 KDETH_GET(eh->tid_rdma.w_data.kdeth1, JKEY),
374 				 be32_to_cpu(eh->tid_rdma.w_data.verbs_qp));
375 		break;
376 	case OP(TID_RDMA, READ_REQ):
377 		trace_seq_printf(p, TID_RDMA_KDETH " " RETH_PRN " "
378 				 TID_READ_REQ_PRN,
379 				 le32_to_cpu(eh->tid_rdma.r_req.kdeth0),
380 				 le32_to_cpu(eh->tid_rdma.r_req.kdeth1),
381 				 ib_u64_get(&eh->tid_rdma.r_req.reth.vaddr),
382 				 be32_to_cpu(eh->tid_rdma.r_req.reth.rkey),
383 				 be32_to_cpu(eh->tid_rdma.r_req.reth.length),
384 				 be32_to_cpu(eh->tid_rdma.r_req.tid_flow_psn),
385 				 be32_to_cpu(eh->tid_rdma.r_req.tid_flow_qp),
386 				 be32_to_cpu(eh->tid_rdma.r_req.verbs_qp));
387 		break;
388 	case OP(TID_RDMA, READ_RESP):
389 		trace_seq_printf(p, TID_RDMA_KDETH_DATA " " AETH_PRN " "
390 				 TID_READ_RSP_PRN,
391 				 le32_to_cpu(eh->tid_rdma.r_rsp.kdeth0),
392 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth0, KVER),
393 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth0, SH),
394 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth0, INTR),
395 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth0, TIDCTRL),
396 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth0, TID),
397 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth0, OFFSET),
398 				 le32_to_cpu(eh->tid_rdma.r_rsp.kdeth1),
399 				 KDETH_GET(eh->tid_rdma.r_rsp.kdeth1, JKEY),
400 				 be32_to_cpu(eh->tid_rdma.r_rsp.aeth) >> 24,
401 				 parse_syndrome(/* aeth */
402 					 be32_to_cpu(eh->tid_rdma.r_rsp.aeth)
403 					 >> 24),
404 				 (be32_to_cpu(eh->tid_rdma.r_rsp.aeth) &
405 				  IB_MSN_MASK),
406 				 be32_to_cpu(eh->tid_rdma.r_rsp.verbs_qp));
407 		break;
408 	case OP(TID_RDMA, ACK):
409 		trace_seq_printf(p, TID_RDMA_KDETH " " AETH_PRN " "
410 				 TID_ACK_PRN,
411 				 le32_to_cpu(eh->tid_rdma.ack.kdeth0),
412 				 le32_to_cpu(eh->tid_rdma.ack.kdeth1),
413 				 be32_to_cpu(eh->tid_rdma.ack.aeth) >> 24,
414 				 parse_syndrome(/* aeth */
415 					 be32_to_cpu(eh->tid_rdma.ack.aeth)
416 					 >> 24),
417 				 (be32_to_cpu(eh->tid_rdma.ack.aeth) &
418 				  IB_MSN_MASK),
419 				 be32_to_cpu(eh->tid_rdma.ack.tid_flow_psn),
420 				 be32_to_cpu(eh->tid_rdma.ack.verbs_psn),
421 				 be32_to_cpu(eh->tid_rdma.ack.tid_flow_qp),
422 				 be32_to_cpu(eh->tid_rdma.ack.verbs_qp));
423 		break;
424 	case OP(TID_RDMA, RESYNC):
425 		trace_seq_printf(p, TID_RDMA_KDETH " " TID_RESYNC_PRN,
426 				 le32_to_cpu(eh->tid_rdma.resync.kdeth0),
427 				 le32_to_cpu(eh->tid_rdma.resync.kdeth1),
428 				 be32_to_cpu(eh->tid_rdma.resync.verbs_qp));
429 		break;
430 	/* aeth + atomicacketh */
431 	case OP(RC, ATOMIC_ACKNOWLEDGE):
432 		trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN,
433 				 be32_to_cpu(eh->at.aeth) >> 24,
434 				 parse_syndrome(be32_to_cpu(eh->at.aeth) >> 24),
435 				 be32_to_cpu(eh->at.aeth) & IB_MSN_MASK,
436 				 ib_u64_get(&eh->at.atomic_ack_eth));
437 		break;
438 	/* atomiceth */
439 	case OP(RC, COMPARE_SWAP):
440 	case OP(RC, FETCH_ADD):
441 		trace_seq_printf(p, ATOMICETH_PRN,
442 				 get_ib_ateth_vaddr(&eh->atomic_eth),
443 				 eh->atomic_eth.rkey,
444 				 get_ib_ateth_swap(&eh->atomic_eth),
445 				 get_ib_ateth_compare(&eh->atomic_eth));
446 		break;
447 	/* deth */
448 	case OP(UD, SEND_ONLY):
449 		trace_seq_printf(p, DETH_ENTROPY_PRN,
450 				 be32_to_cpu(eh->ud.deth[0]),
451 				 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK,
452 				 be32_to_cpu(eh->ud.deth[1]) >>
453 					     HFI1_IPOIB_ENTROPY_SHIFT);
454 		break;
455 	case OP(UD, SEND_ONLY_WITH_IMMEDIATE):
456 		trace_seq_printf(p, DETH_PRN,
457 				 be32_to_cpu(eh->ud.deth[0]),
458 				 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK);
459 		break;
460 	/* ieth */
461 	case OP(RC, SEND_LAST_WITH_INVALIDATE):
462 	case OP(RC, SEND_ONLY_WITH_INVALIDATE):
463 		trace_seq_printf(p, IETH_PRN,
464 				 be32_to_cpu(eh->ieth));
465 		break;
466 	}
467 out:
468 	trace_seq_putc(p, 0);
469 	return ret;
470 }
471 
472 const char *parse_sdma_flags(
473 	struct trace_seq *p,
474 	u64 desc0, u64 desc1)
475 {
476 	const char *ret = trace_seq_buffer_ptr(p);
477 	char flags[5] = { 'x', 'x', 'x', 'x', 0 };
478 
479 	flags[0] = (desc1 & SDMA_DESC1_INT_REQ_FLAG) ? 'I' : '-';
480 	flags[1] = (desc1 & SDMA_DESC1_HEAD_TO_HOST_FLAG) ?  'H' : '-';
481 	flags[2] = (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) ? 'F' : '-';
482 	flags[3] = (desc0 & SDMA_DESC0_LAST_DESC_FLAG) ? 'L' : '-';
483 	trace_seq_printf(p, "%s", flags);
484 	if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG)
485 		trace_seq_printf(p, " amode:%u aidx:%u alen:%u",
486 				 (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) &
487 				      SDMA_DESC1_HEADER_MODE_MASK),
488 				 (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) &
489 				      SDMA_DESC1_HEADER_INDEX_MASK),
490 				 (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) &
491 				      SDMA_DESC1_HEADER_DWS_MASK));
492 	return ret;
493 }
494 
495 const char *print_u32_array(
496 	struct trace_seq *p,
497 	u32 *arr, int len)
498 {
499 	int i;
500 	const char *ret = trace_seq_buffer_ptr(p);
501 
502 	for (i = 0; i < len ; i++)
503 		trace_seq_printf(p, "%s%#x", i == 0 ? "" : " ", arr[i]);
504 	trace_seq_putc(p, 0);
505 	return ret;
506 }
507 
508 u8 hfi1_trace_get_tid_ctrl(u32 ent)
509 {
510 	return EXP_TID_GET(ent, CTRL);
511 }
512 
513 u16 hfi1_trace_get_tid_len(u32 ent)
514 {
515 	return EXP_TID_GET(ent, LEN);
516 }
517 
518 u16 hfi1_trace_get_tid_idx(u32 ent)
519 {
520 	return EXP_TID_GET(ent, IDX);
521 }
522 
523 struct hfi1_ctxt_hist {
524 	atomic_t count;
525 	atomic_t data[255];
526 };
527 
528 struct hfi1_ctxt_hist hist = {
529 	.count = ATOMIC_INIT(0)
530 };
531 
532 const char *hfi1_trace_print_rsm_hist(struct trace_seq *p, unsigned int ctxt)
533 {
534 	int i, len = ARRAY_SIZE(hist.data);
535 	const char *ret = trace_seq_buffer_ptr(p);
536 	unsigned long packet_count = atomic_fetch_inc(&hist.count);
537 
538 	trace_seq_printf(p, "packet[%lu]", packet_count);
539 	for (i = 0; i < len; ++i) {
540 		unsigned long val;
541 		atomic_t *count = &hist.data[i];
542 
543 		if (ctxt == i)
544 			val = atomic_fetch_inc(count);
545 		else
546 			val = atomic_read(count);
547 
548 		if (val)
549 			trace_seq_printf(p, "(%d:%lu)", i, val);
550 	}
551 	trace_seq_putc(p, 0);
552 	return ret;
553 }
554 
555 __hfi1_trace_fn(AFFINITY);
556 __hfi1_trace_fn(PKT);
557 __hfi1_trace_fn(PROC);
558 __hfi1_trace_fn(SDMA);
559 __hfi1_trace_fn(LINKVERB);
560 __hfi1_trace_fn(DEBUG);
561 __hfi1_trace_fn(SNOOP);
562 __hfi1_trace_fn(CNTR);
563 __hfi1_trace_fn(PIO);
564 __hfi1_trace_fn(DC8051);
565 __hfi1_trace_fn(FIRMWARE);
566 __hfi1_trace_fn(RCVCTRL);
567 __hfi1_trace_fn(TID);
568 __hfi1_trace_fn(MMU);
569 __hfi1_trace_fn(IOCTL);
570