xref: /openbmc/linux/drivers/infiniband/hw/hfi1/trace.c (revision a36954f5)
1 /*
2  * Copyright(c) 2015, 2016 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 u8 ibhdr_exhdr_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 #define IMM_PRN  "imm %d"
65 #define RETH_PRN "reth vaddr 0x%.16llx rkey 0x%.8x dlen 0x%.8x"
66 #define AETH_PRN "aeth syn 0x%.2x %s msn 0x%.8x"
67 #define DETH_PRN "deth qkey 0x%.8x sqpn 0x%.6x"
68 #define IETH_PRN "ieth rkey 0x%.8x"
69 #define ATOMICACKETH_PRN "origdata %llx"
70 #define ATOMICETH_PRN "vaddr 0x%llx rkey 0x%.8x sdata %llx cdata %llx"
71 
72 #define OP(transport, op) IB_OPCODE_## transport ## _ ## op
73 
74 static const char *parse_syndrome(u8 syndrome)
75 {
76 	switch (syndrome >> 5) {
77 	case 0:
78 		return "ACK";
79 	case 1:
80 		return "RNRNAK";
81 	case 3:
82 		return "NAK";
83 	}
84 	return "";
85 }
86 
87 const char *parse_everbs_hdrs(
88 	struct trace_seq *p,
89 	u8 opcode,
90 	void *ehdrs)
91 {
92 	union ib_ehdrs *eh = ehdrs;
93 	const char *ret = trace_seq_buffer_ptr(p);
94 
95 	switch (opcode) {
96 	/* imm */
97 	case OP(RC, SEND_LAST_WITH_IMMEDIATE):
98 	case OP(UC, SEND_LAST_WITH_IMMEDIATE):
99 	case OP(RC, SEND_ONLY_WITH_IMMEDIATE):
100 	case OP(UC, SEND_ONLY_WITH_IMMEDIATE):
101 	case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
102 	case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
103 		trace_seq_printf(p, IMM_PRN,
104 				 be32_to_cpu(eh->imm_data));
105 		break;
106 	/* reth + imm */
107 	case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
108 	case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
109 		trace_seq_printf(p, RETH_PRN " " IMM_PRN,
110 				 get_ib_reth_vaddr(&eh->rc.reth),
111 				 be32_to_cpu(eh->rc.reth.rkey),
112 				 be32_to_cpu(eh->rc.reth.length),
113 				 be32_to_cpu(eh->rc.imm_data));
114 		break;
115 	/* reth */
116 	case OP(RC, RDMA_READ_REQUEST):
117 	case OP(RC, RDMA_WRITE_FIRST):
118 	case OP(UC, RDMA_WRITE_FIRST):
119 	case OP(RC, RDMA_WRITE_ONLY):
120 	case OP(UC, RDMA_WRITE_ONLY):
121 		trace_seq_printf(p, RETH_PRN,
122 				 get_ib_reth_vaddr(&eh->rc.reth),
123 				 be32_to_cpu(eh->rc.reth.rkey),
124 				 be32_to_cpu(eh->rc.reth.length));
125 		break;
126 	case OP(RC, RDMA_READ_RESPONSE_FIRST):
127 	case OP(RC, RDMA_READ_RESPONSE_LAST):
128 	case OP(RC, RDMA_READ_RESPONSE_ONLY):
129 	case OP(RC, ACKNOWLEDGE):
130 		trace_seq_printf(p, AETH_PRN, be32_to_cpu(eh->aeth) >> 24,
131 				 parse_syndrome(be32_to_cpu(eh->aeth) >> 24),
132 				 be32_to_cpu(eh->aeth) & IB_MSN_MASK);
133 		break;
134 	/* aeth + atomicacketh */
135 	case OP(RC, ATOMIC_ACKNOWLEDGE):
136 		trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN,
137 				 be32_to_cpu(eh->at.aeth) >> 24,
138 				 parse_syndrome(be32_to_cpu(eh->at.aeth) >> 24),
139 				 be32_to_cpu(eh->at.aeth) & IB_MSN_MASK,
140 				 ib_u64_get(&eh->at.atomic_ack_eth));
141 		break;
142 	/* atomiceth */
143 	case OP(RC, COMPARE_SWAP):
144 	case OP(RC, FETCH_ADD):
145 		trace_seq_printf(p, ATOMICETH_PRN,
146 				 get_ib_ateth_vaddr(&eh->atomic_eth),
147 				 eh->atomic_eth.rkey,
148 				 get_ib_ateth_swap(&eh->atomic_eth),
149 				 get_ib_ateth_compare(&eh->atomic_eth));
150 		break;
151 	/* deth */
152 	case OP(UD, SEND_ONLY):
153 	case OP(UD, SEND_ONLY_WITH_IMMEDIATE):
154 		trace_seq_printf(p, DETH_PRN,
155 				 be32_to_cpu(eh->ud.deth[0]),
156 				 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK);
157 		break;
158 	/* ieth */
159 	case OP(RC, SEND_LAST_WITH_INVALIDATE):
160 	case OP(RC, SEND_ONLY_WITH_INVALIDATE):
161 		trace_seq_printf(p, IETH_PRN,
162 				 be32_to_cpu(eh->ieth));
163 		break;
164 	}
165 	trace_seq_putc(p, 0);
166 	return ret;
167 }
168 
169 const char *parse_sdma_flags(
170 	struct trace_seq *p,
171 	u64 desc0, u64 desc1)
172 {
173 	const char *ret = trace_seq_buffer_ptr(p);
174 	char flags[5] = { 'x', 'x', 'x', 'x', 0 };
175 
176 	flags[0] = (desc1 & SDMA_DESC1_INT_REQ_FLAG) ? 'I' : '-';
177 	flags[1] = (desc1 & SDMA_DESC1_HEAD_TO_HOST_FLAG) ?  'H' : '-';
178 	flags[2] = (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) ? 'F' : '-';
179 	flags[3] = (desc0 & SDMA_DESC0_LAST_DESC_FLAG) ? 'L' : '-';
180 	trace_seq_printf(p, "%s", flags);
181 	if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG)
182 		trace_seq_printf(p, " amode:%u aidx:%u alen:%u",
183 				 (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) &
184 				      SDMA_DESC1_HEADER_MODE_MASK),
185 				 (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) &
186 				      SDMA_DESC1_HEADER_INDEX_MASK),
187 				 (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) &
188 				      SDMA_DESC1_HEADER_DWS_MASK));
189 	return ret;
190 }
191 
192 const char *print_u32_array(
193 	struct trace_seq *p,
194 	u32 *arr, int len)
195 {
196 	int i;
197 	const char *ret = trace_seq_buffer_ptr(p);
198 
199 	for (i = 0; i < len ; i++)
200 		trace_seq_printf(p, "%s%#x", i == 0 ? "" : " ", arr[i]);
201 	trace_seq_putc(p, 0);
202 	return ret;
203 }
204 
205 __hfi1_trace_fn(PKT);
206 __hfi1_trace_fn(PROC);
207 __hfi1_trace_fn(SDMA);
208 __hfi1_trace_fn(LINKVERB);
209 __hfi1_trace_fn(DEBUG);
210 __hfi1_trace_fn(SNOOP);
211 __hfi1_trace_fn(CNTR);
212 __hfi1_trace_fn(PIO);
213 __hfi1_trace_fn(DC8051);
214 __hfi1_trace_fn(FIRMWARE);
215 __hfi1_trace_fn(RCVCTRL);
216 __hfi1_trace_fn(TID);
217 __hfi1_trace_fn(MMU);
218 __hfi1_trace_fn(IOCTL);
219