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 #if !defined(__HFI1_TRACE_IBHDRS_H) || defined(TRACE_HEADER_MULTI_READ)
48 #define __HFI1_TRACE_IBHDRS_H
49 
50 #include <linux/tracepoint.h>
51 #include <linux/trace_seq.h>
52 
53 #include "hfi.h"
54 
55 #undef TRACE_SYSTEM
56 #define TRACE_SYSTEM hfi1_ibhdrs
57 
58 u8 ibhdr_exhdr_len(struct hfi1_ib_header *hdr);
59 const char *parse_everbs_hdrs(struct trace_seq *p, u8 opcode, void *ehdrs);
60 
61 #define __parse_ib_ehdrs(op, ehdrs) parse_everbs_hdrs(p, op, ehdrs)
62 
63 #define lrh_name(lrh) { HFI1_##lrh, #lrh }
64 #define show_lnh(lrh)                    \
65 __print_symbolic(lrh,                    \
66 	lrh_name(LRH_BTH),               \
67 	lrh_name(LRH_GRH))
68 
69 #define LRH_PRN "vl %d lver %d sl %d lnh %d,%s dlid %.4x len %d slid %.4x"
70 #define BTH_PRN \
71 	"op 0x%.2x,%s se %d m %d pad %d tver %d pkey 0x%.4x " \
72 	"f %d b %d qpn 0x%.6x a %d psn 0x%.8x"
73 #define EHDR_PRN "%s"
74 
75 DECLARE_EVENT_CLASS(hfi1_ibhdr_template,
76 		    TP_PROTO(struct hfi1_devdata *dd,
77 			     struct hfi1_ib_header *hdr),
78 		    TP_ARGS(dd, hdr),
79 		    TP_STRUCT__entry(
80 			DD_DEV_ENTRY(dd)
81 			/* LRH */
82 			__field(u8, vl)
83 			__field(u8, lver)
84 			__field(u8, sl)
85 			__field(u8, lnh)
86 			__field(u16, dlid)
87 			__field(u16, len)
88 			__field(u16, slid)
89 			/* BTH */
90 			__field(u8, opcode)
91 			__field(u8, se)
92 			__field(u8, m)
93 			__field(u8, pad)
94 			__field(u8, tver)
95 			__field(u16, pkey)
96 			__field(u8, f)
97 			__field(u8, b)
98 			__field(u32, qpn)
99 			__field(u8, a)
100 			__field(u32, psn)
101 			/* extended headers */
102 			__dynamic_array(u8, ehdrs, ibhdr_exhdr_len(hdr))
103 			),
104 		      TP_fast_assign(
105 			struct hfi1_other_headers *ohdr;
106 
107 			DD_DEV_ASSIGN(dd);
108 			/* LRH */
109 			__entry->vl =
110 			(u8)(be16_to_cpu(hdr->lrh[0]) >> 12);
111 			__entry->lver =
112 			(u8)(be16_to_cpu(hdr->lrh[0]) >> 8) & 0xf;
113 			__entry->sl =
114 			(u8)(be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf;
115 			__entry->lnh =
116 			(u8)(be16_to_cpu(hdr->lrh[0]) & 3);
117 			__entry->dlid =
118 			be16_to_cpu(hdr->lrh[1]);
119 			/* allow for larger len */
120 			__entry->len =
121 			be16_to_cpu(hdr->lrh[2]);
122 			__entry->slid =
123 			be16_to_cpu(hdr->lrh[3]);
124 			/* BTH */
125 			if (__entry->lnh == HFI1_LRH_BTH)
126 			ohdr = &hdr->u.oth;
127 			else
128 			ohdr = &hdr->u.l.oth;
129 			__entry->opcode =
130 			(be32_to_cpu(ohdr->bth[0]) >> 24) & 0xff;
131 			__entry->se =
132 			(be32_to_cpu(ohdr->bth[0]) >> 23) & 1;
133 			__entry->m =
134 			(be32_to_cpu(ohdr->bth[0]) >> 22) & 1;
135 			__entry->pad =
136 			(be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
137 			__entry->tver =
138 			(be32_to_cpu(ohdr->bth[0]) >> 16) & 0xf;
139 			__entry->pkey =
140 			be32_to_cpu(ohdr->bth[0]) & 0xffff;
141 			__entry->f =
142 			(be32_to_cpu(ohdr->bth[1]) >> HFI1_FECN_SHIFT) &
143 			HFI1_FECN_MASK;
144 			__entry->b =
145 			(be32_to_cpu(ohdr->bth[1]) >> HFI1_BECN_SHIFT) &
146 			HFI1_BECN_MASK;
147 			__entry->qpn =
148 			be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
149 			__entry->a =
150 			(be32_to_cpu(ohdr->bth[2]) >> 31) & 1;
151 			/* allow for larger PSN */
152 			__entry->psn =
153 			be32_to_cpu(ohdr->bth[2]) & 0x7fffffff;
154 			/* extended headers */
155 			memcpy(__get_dynamic_array(ehdrs), &ohdr->u,
156 			       ibhdr_exhdr_len(hdr));
157 			),
158 		TP_printk("[%s] " LRH_PRN " " BTH_PRN " " EHDR_PRN,
159 			  __get_str(dev),
160 			  /* LRH */
161 			  __entry->vl,
162 			  __entry->lver,
163 			  __entry->sl,
164 			  __entry->lnh, show_lnh(__entry->lnh),
165 			  __entry->dlid,
166 			  __entry->len,
167 			  __entry->slid,
168 			  /* BTH */
169 			  __entry->opcode, show_ib_opcode(__entry->opcode),
170 			  __entry->se,
171 			  __entry->m,
172 			  __entry->pad,
173 			  __entry->tver,
174 			  __entry->pkey,
175 			  __entry->f,
176 			  __entry->b,
177 			  __entry->qpn,
178 			  __entry->a,
179 			  __entry->psn,
180 			  /* extended headers */
181 			  __parse_ib_ehdrs(
182 				__entry->opcode,
183 				(void *)__get_dynamic_array(ehdrs))
184 			)
185 );
186 
187 DEFINE_EVENT(hfi1_ibhdr_template, input_ibhdr,
188 	     TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
189 	     TP_ARGS(dd, hdr));
190 
191 DEFINE_EVENT(hfi1_ibhdr_template, pio_output_ibhdr,
192 	     TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
193 	     TP_ARGS(dd, hdr));
194 
195 DEFINE_EVENT(hfi1_ibhdr_template, ack_output_ibhdr,
196 	     TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
197 	     TP_ARGS(dd, hdr));
198 
199 DEFINE_EVENT(hfi1_ibhdr_template, sdma_output_ibhdr,
200 	     TP_PROTO(struct hfi1_devdata *dd, struct hfi1_ib_header *hdr),
201 	     TP_ARGS(dd, hdr));
202 
203 #endif /* __HFI1_TRACE_IBHDRS_H */
204 
205 #undef TRACE_INCLUDE_PATH
206 #undef TRACE_INCLUDE_FILE
207 #define TRACE_INCLUDE_PATH .
208 #define TRACE_INCLUDE_FILE trace_ibhdrs
209 #include <trace/define_trace.h>
210