xref: /openbmc/linux/drivers/infiniband/hw/hfi1/trace.c (revision 60772e48)
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 #define CREATE_TRACE_POINTS
48 #include "trace.h"
49 
50 static u8 __get_ib_hdr_len(struct ib_header *hdr)
51 {
52 	struct ib_other_headers *ohdr;
53 	u8 opcode;
54 
55 	if (ib_get_lnh(hdr) == HFI1_LRH_BTH)
56 		ohdr = &hdr->u.oth;
57 	else
58 		ohdr = &hdr->u.l.oth;
59 	opcode = ib_bth_get_opcode(ohdr);
60 	return hdr_len_by_opcode[opcode] == 0 ?
61 	       0 : hdr_len_by_opcode[opcode] - (12 + 8);
62 }
63 
64 static u8 __get_16b_hdr_len(struct hfi1_16b_header *hdr)
65 {
66 	struct ib_other_headers *ohdr;
67 	u8 opcode;
68 
69 	if (hfi1_16B_get_l4(hdr) == OPA_16B_L4_IB_LOCAL)
70 		ohdr = &hdr->u.oth;
71 	else
72 		ohdr = &hdr->u.l.oth;
73 	opcode = ib_bth_get_opcode(ohdr);
74 	return hdr_len_by_opcode[opcode] == 0 ?
75 	       0 : hdr_len_by_opcode[opcode] - (12 + 8 + 8);
76 }
77 
78 u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet)
79 {
80 	if (packet->etype != RHF_RCV_TYPE_BYPASS)
81 		return __get_ib_hdr_len(packet->hdr);
82 	else
83 		return __get_16b_hdr_len(packet->hdr);
84 }
85 
86 u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opa_hdr)
87 {
88 	if (!opa_hdr->hdr_type)
89 		return __get_ib_hdr_len(&opa_hdr->ibh);
90 	else
91 		return __get_16b_hdr_len(&opa_hdr->opah);
92 }
93 
94 const char *hfi1_trace_get_packet_l4_str(u8 l4)
95 {
96 	if (l4)
97 		return "16B";
98 	else
99 		return "9B";
100 }
101 
102 const char *hfi1_trace_get_packet_l2_str(u8 l2)
103 {
104 	switch (l2) {
105 	case 0:
106 		return "0";
107 	case 1:
108 		return "1";
109 	case 2:
110 		return "16B";
111 	case 3:
112 		return "9B";
113 	}
114 	return "";
115 }
116 
117 #define IMM_PRN  "imm:%d"
118 #define RETH_PRN "reth vaddr:0x%.16llx rkey:0x%.8x dlen:0x%.8x"
119 #define AETH_PRN "aeth syn:0x%.2x %s msn:0x%.8x"
120 #define DETH_PRN "deth qkey:0x%.8x sqpn:0x%.6x"
121 #define IETH_PRN "ieth rkey:0x%.8x"
122 #define ATOMICACKETH_PRN "origdata:%llx"
123 #define ATOMICETH_PRN "vaddr:0x%llx rkey:0x%.8x sdata:%llx cdata:%llx"
124 
125 #define OP(transport, op) IB_OPCODE_## transport ## _ ## op
126 
127 static const char *parse_syndrome(u8 syndrome)
128 {
129 	switch (syndrome >> 5) {
130 	case 0:
131 		return "ACK";
132 	case 1:
133 		return "RNRNAK";
134 	case 3:
135 		return "NAK";
136 	}
137 	return "";
138 }
139 
140 void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr,
141 			     u8 *ack, bool *becn, bool *fecn, u8 *mig,
142 			     u8 *se, u8 *pad, u8 *opcode, u8 *tver,
143 			     u16 *pkey, u32 *psn, u32 *qpn)
144 {
145 	*ack = ib_bth_get_ackreq(ohdr);
146 	*becn = ib_bth_get_becn(ohdr);
147 	*fecn = ib_bth_get_fecn(ohdr);
148 	*mig = ib_bth_get_migreq(ohdr);
149 	*se = ib_bth_get_se(ohdr);
150 	*pad = ib_bth_get_pad(ohdr);
151 	*opcode = ib_bth_get_opcode(ohdr);
152 	*tver = ib_bth_get_tver(ohdr);
153 	*pkey = ib_bth_get_pkey(ohdr);
154 	*psn = mask_psn(ib_bth_get_psn(ohdr));
155 	*qpn = ib_bth_get_qpn(ohdr);
156 }
157 
158 void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr,
159 			      u8 *ack, u8 *mig, u8 *opcode,
160 			      u8 *pad, u8 *se, u8 *tver,
161 			      u32 *psn, u32 *qpn)
162 {
163 	*ack = ib_bth_get_ackreq(ohdr);
164 	*mig = ib_bth_get_migreq(ohdr);
165 	*opcode = ib_bth_get_opcode(ohdr);
166 	*pad = ib_bth_get_pad(ohdr);
167 	*se = ib_bth_get_se(ohdr);
168 	*tver = ib_bth_get_tver(ohdr);
169 	*psn = mask_psn(ib_bth_get_psn(ohdr));
170 	*qpn = ib_bth_get_qpn(ohdr);
171 }
172 
173 void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5,
174 			     u8 *lnh, u8 *lver, u8 *sl, u8 *sc,
175 			     u16 *len, u32 *dlid, u32 *slid)
176 {
177 	*lnh = ib_get_lnh(hdr);
178 	*lver = ib_get_lver(hdr);
179 	*sl = ib_get_sl(hdr);
180 	*sc = ib_get_sc(hdr) | (sc5 << 4);
181 	*len = ib_get_len(hdr);
182 	*dlid = ib_get_dlid(hdr);
183 	*slid = ib_get_slid(hdr);
184 }
185 
186 void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr,
187 			      u8 *age, bool *becn, bool *fecn,
188 			      u8 *l4, u8 *rc, u8 *sc,
189 			      u16 *entropy, u16 *len, u16 *pkey,
190 			      u32 *dlid, u32 *slid)
191 {
192 	*age = hfi1_16B_get_age(hdr);
193 	*becn = hfi1_16B_get_becn(hdr);
194 	*fecn = hfi1_16B_get_fecn(hdr);
195 	*l4 = hfi1_16B_get_l4(hdr);
196 	*rc = hfi1_16B_get_rc(hdr);
197 	*sc = hfi1_16B_get_sc(hdr);
198 	*entropy = hfi1_16B_get_entropy(hdr);
199 	*len = hfi1_16B_get_len(hdr);
200 	*pkey = hfi1_16B_get_pkey(hdr);
201 	*dlid = hfi1_16B_get_dlid(hdr);
202 	*slid = hfi1_16B_get_slid(hdr);
203 }
204 
205 #define LRH_PRN "len:%d sc:%d dlid:0x%.4x slid:0x%.4x "
206 #define LRH_9B_PRN "lnh:%d,%s lver:%d sl:%d"
207 #define LRH_16B_PRN "age:%d becn:%d fecn:%d l4:%d " \
208 		    "rc:%d sc:%d pkey:0x%.4x entropy:0x%.4x"
209 const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass,
210 			       u8 age, bool becn, bool fecn, u8 l4,
211 			       u8 lnh, const char *lnh_name, u8 lver,
212 			       u8 rc, u8 sc, u8 sl, u16 entropy,
213 			       u16 len, u16 pkey, u32 dlid, u32 slid)
214 {
215 	const char *ret = trace_seq_buffer_ptr(p);
216 
217 	trace_seq_printf(p, LRH_PRN, len, sc, dlid, slid);
218 
219 	if (bypass)
220 		trace_seq_printf(p, LRH_16B_PRN,
221 				 age, becn, fecn, l4, rc, sc, pkey, entropy);
222 
223 	else
224 		trace_seq_printf(p, LRH_9B_PRN,
225 				 lnh, lnh_name, lver, sl);
226 	trace_seq_putc(p, 0);
227 
228 	return ret;
229 }
230 
231 #define BTH_9B_PRN \
232 	"op:0x%.2x,%s se:%d m:%d pad:%d tver:%d pkey:0x%.4x " \
233 	"f:%d b:%d qpn:0x%.6x a:%d psn:0x%.8x"
234 #define BTH_16B_PRN \
235 	"op:0x%.2x,%s se:%d m:%d pad:%d tver:%d " \
236 	"qpn:0x%.6x a:%d psn:0x%.8x"
237 const char *hfi1_trace_fmt_bth(struct trace_seq *p, bool bypass,
238 			       u8 ack, bool becn, bool fecn, u8 mig,
239 			       u8 se, u8 pad, u8 opcode, const char *opname,
240 			       u8 tver, u16 pkey, u32 psn, u32 qpn)
241 {
242 	const char *ret = trace_seq_buffer_ptr(p);
243 
244 	if (bypass)
245 		trace_seq_printf(p, BTH_16B_PRN,
246 				 opcode, opname,
247 				 se, mig, pad, tver, qpn, ack, psn);
248 
249 	else
250 		trace_seq_printf(p, BTH_9B_PRN,
251 				 opcode, opname,
252 				 se, mig, pad, tver, pkey, fecn, becn,
253 				 qpn, ack, psn);
254 	trace_seq_putc(p, 0);
255 
256 	return ret;
257 }
258 
259 const char *parse_everbs_hdrs(
260 	struct trace_seq *p,
261 	u8 opcode,
262 	void *ehdrs)
263 {
264 	union ib_ehdrs *eh = ehdrs;
265 	const char *ret = trace_seq_buffer_ptr(p);
266 
267 	switch (opcode) {
268 	/* imm */
269 	case OP(RC, SEND_LAST_WITH_IMMEDIATE):
270 	case OP(UC, SEND_LAST_WITH_IMMEDIATE):
271 	case OP(RC, SEND_ONLY_WITH_IMMEDIATE):
272 	case OP(UC, SEND_ONLY_WITH_IMMEDIATE):
273 	case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
274 	case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
275 		trace_seq_printf(p, IMM_PRN,
276 				 be32_to_cpu(eh->imm_data));
277 		break;
278 	/* reth + imm */
279 	case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
280 	case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
281 		trace_seq_printf(p, RETH_PRN " " IMM_PRN,
282 				 get_ib_reth_vaddr(&eh->rc.reth),
283 				 be32_to_cpu(eh->rc.reth.rkey),
284 				 be32_to_cpu(eh->rc.reth.length),
285 				 be32_to_cpu(eh->rc.imm_data));
286 		break;
287 	/* reth */
288 	case OP(RC, RDMA_READ_REQUEST):
289 	case OP(RC, RDMA_WRITE_FIRST):
290 	case OP(UC, RDMA_WRITE_FIRST):
291 	case OP(RC, RDMA_WRITE_ONLY):
292 	case OP(UC, RDMA_WRITE_ONLY):
293 		trace_seq_printf(p, RETH_PRN,
294 				 get_ib_reth_vaddr(&eh->rc.reth),
295 				 be32_to_cpu(eh->rc.reth.rkey),
296 				 be32_to_cpu(eh->rc.reth.length));
297 		break;
298 	case OP(RC, RDMA_READ_RESPONSE_FIRST):
299 	case OP(RC, RDMA_READ_RESPONSE_LAST):
300 	case OP(RC, RDMA_READ_RESPONSE_ONLY):
301 	case OP(RC, ACKNOWLEDGE):
302 		trace_seq_printf(p, AETH_PRN, be32_to_cpu(eh->aeth) >> 24,
303 				 parse_syndrome(be32_to_cpu(eh->aeth) >> 24),
304 				 be32_to_cpu(eh->aeth) & IB_MSN_MASK);
305 		break;
306 	/* aeth + atomicacketh */
307 	case OP(RC, ATOMIC_ACKNOWLEDGE):
308 		trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN,
309 				 be32_to_cpu(eh->at.aeth) >> 24,
310 				 parse_syndrome(be32_to_cpu(eh->at.aeth) >> 24),
311 				 be32_to_cpu(eh->at.aeth) & IB_MSN_MASK,
312 				 ib_u64_get(&eh->at.atomic_ack_eth));
313 		break;
314 	/* atomiceth */
315 	case OP(RC, COMPARE_SWAP):
316 	case OP(RC, FETCH_ADD):
317 		trace_seq_printf(p, ATOMICETH_PRN,
318 				 get_ib_ateth_vaddr(&eh->atomic_eth),
319 				 eh->atomic_eth.rkey,
320 				 get_ib_ateth_swap(&eh->atomic_eth),
321 				 get_ib_ateth_compare(&eh->atomic_eth));
322 		break;
323 	/* deth */
324 	case OP(UD, SEND_ONLY):
325 	case OP(UD, SEND_ONLY_WITH_IMMEDIATE):
326 		trace_seq_printf(p, DETH_PRN,
327 				 be32_to_cpu(eh->ud.deth[0]),
328 				 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK);
329 		break;
330 	/* ieth */
331 	case OP(RC, SEND_LAST_WITH_INVALIDATE):
332 	case OP(RC, SEND_ONLY_WITH_INVALIDATE):
333 		trace_seq_printf(p, IETH_PRN,
334 				 be32_to_cpu(eh->ieth));
335 		break;
336 	}
337 	trace_seq_putc(p, 0);
338 	return ret;
339 }
340 
341 const char *parse_sdma_flags(
342 	struct trace_seq *p,
343 	u64 desc0, u64 desc1)
344 {
345 	const char *ret = trace_seq_buffer_ptr(p);
346 	char flags[5] = { 'x', 'x', 'x', 'x', 0 };
347 
348 	flags[0] = (desc1 & SDMA_DESC1_INT_REQ_FLAG) ? 'I' : '-';
349 	flags[1] = (desc1 & SDMA_DESC1_HEAD_TO_HOST_FLAG) ?  'H' : '-';
350 	flags[2] = (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) ? 'F' : '-';
351 	flags[3] = (desc0 & SDMA_DESC0_LAST_DESC_FLAG) ? 'L' : '-';
352 	trace_seq_printf(p, "%s", flags);
353 	if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG)
354 		trace_seq_printf(p, " amode:%u aidx:%u alen:%u",
355 				 (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) &
356 				      SDMA_DESC1_HEADER_MODE_MASK),
357 				 (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) &
358 				      SDMA_DESC1_HEADER_INDEX_MASK),
359 				 (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) &
360 				      SDMA_DESC1_HEADER_DWS_MASK));
361 	return ret;
362 }
363 
364 const char *print_u32_array(
365 	struct trace_seq *p,
366 	u32 *arr, int len)
367 {
368 	int i;
369 	const char *ret = trace_seq_buffer_ptr(p);
370 
371 	for (i = 0; i < len ; i++)
372 		trace_seq_printf(p, "%s%#x", i == 0 ? "" : " ", arr[i]);
373 	trace_seq_putc(p, 0);
374 	return ret;
375 }
376 
377 __hfi1_trace_fn(PKT);
378 __hfi1_trace_fn(PROC);
379 __hfi1_trace_fn(SDMA);
380 __hfi1_trace_fn(LINKVERB);
381 __hfi1_trace_fn(DEBUG);
382 __hfi1_trace_fn(SNOOP);
383 __hfi1_trace_fn(CNTR);
384 __hfi1_trace_fn(PIO);
385 __hfi1_trace_fn(DC8051);
386 __hfi1_trace_fn(FIRMWARE);
387 __hfi1_trace_fn(RCVCTRL);
388 __hfi1_trace_fn(TID);
389 __hfi1_trace_fn(MMU);
390 __hfi1_trace_fn(IOCTL);
391