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