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