1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_IB_MGT_IBCM_IBCM_TRACE_H
28 #define	_SYS_IB_MGT_IBCM_IBCM_TRACE_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * ibcm_trace.h
36  *
37  * This file contains all of the internal data structures and
38  * definitions for IBCM Trace implementation
39  */
40 
41 /* Defines event qualifiers for detailed traces per RC connection. */
42 typedef enum ibcm_state_rc_trace_qualifier_e {
43 
44 	/* Initial headers */
45 	IBCM_DISPLAY_SID		= 1,
46 	IBCM_DISPLAY_CHAN,
47 	IBCM_DISPLAY_LCID,
48 	IBCM_DISPLAY_LQPN,
49 	IBCM_DISPLAY_RCID,
50 	IBCM_DISPLAY_RQPN,
51 	IBCM_DISPLAY_TM,
52 
53 	/* List possible Incoming MADs */
54 	IBCM_TRACE_INCOMING_REQ,
55 	IBCM_TRACE_INCOMING_REP,
56 	IBCM_TRACE_INCOMING_RTU,
57 	IBCM_TRACE_INCOMING_COMEST,
58 	IBCM_TRACE_INCOMING_MRA,
59 	IBCM_TRACE_INCOMING_REJ,
60 	IBCM_TRACE_INCOMING_LAP,
61 	IBCM_TRACE_INCOMING_APR,
62 	IBCM_TRACE_INCOMING_DREQ,
63 	IBCM_TRACE_INCOMING_DREP,
64 
65 	/* List possible outgoing MADs */
66 	IBCM_TRACE_OUTGOING_REQ,
67 	IBCM_TRACE_OUTGOING_REP,
68 	IBCM_TRACE_OUTGOING_RTU,
69 	IBCM_TRACE_OUTGOING_LAP,
70 	IBCM_TRACE_OUTGOING_APR,
71 	IBCM_TRACE_OUTGOING_MRA,
72 	IBCM_TRACE_OUTGOING_REJ,
73 	IBCM_TRACE_OUTGOING_DREQ,
74 	IBCM_TRACE_OUTGOING_DREP,
75 
76 	/* List of ibmf send completions */
77 	IBCM_TRACE_REQ_POST_COMPLETE,
78 	IBCM_TRACE_REP_POST_COMPLETE,
79 	IBCM_TRACE_RTU_POST_COMPLETE,
80 	IBCM_TRACE_MRA_POST_COMPLETE,
81 	IBCM_TRACE_REJ_POST_COMPLETE,
82 	IBCM_TRACE_LAP_POST_COMPLETE,
83 	IBCM_TRACE_APR_POST_COMPLETE,
84 	IBCM_TRACE_DREQ_POST_COMPLETE,
85 	IBCM_TRACE_DREP_POST_COMPLETE,
86 
87 	/* List possible timeouts. Other timeouts always re-post MADs */
88 	IBCM_TRACE_TIMEOUT_REP,
89 
90 	/* client handler related */
91 	IBCM_TRACE_CALLED_REQ_RCVD_EVENT,
92 	IBCM_TRACE_RET_REQ_RCVD_EVENT,
93 
94 	IBCM_TRACE_CALLED_REP_RCVD_EVENT,
95 	IBCM_TRACE_RET_REP_RCVD_EVENT,
96 
97 	/* client handler related */
98 	IBCM_TRACE_CALLED_CONN_EST_EVENT,
99 	IBCM_TRACE_RET_CONN_EST_EVENT,
100 
101 	IBCM_TRACE_CALLED_CONN_FAIL_EVENT,
102 	IBCM_TRACE_RET_CONN_FAIL_EVENT,
103 
104 	IBCM_TRACE_CALLED_CONN_CLOSE_EVENT,
105 	IBCM_TRACE_RET_CONN_CLOSE_EVENT,
106 
107 	/* RC QP state change related */
108 	IBCM_TRACE_INIT_INIT,
109 	IBCM_TRACE_INIT_INIT_FAIL,
110 	IBCM_TRACE_INIT_RTR,
111 	IBCM_TRACE_INIT_RTR_FAIL,
112 	IBCM_TRACE_RTR_RTS,
113 	IBCM_TRACE_RTR_RTS_FAIL,
114 	IBCM_TRACE_RTS_RTS,
115 	IBCM_TRACE_RTS_RTS_FAIL,
116 	IBCM_TRACE_ERROR,
117 	IBCM_TRACE_ERROR_FAIL,
118 	IBCM_TRACE_SET_ALT,
119 	IBCM_TRACE_SET_ALT_FAIL,
120 
121 	/* special event related */
122 	IBCM_TRACE_STALE_DETECT,
123 
124 	IBCM_TRACE_OUT_REQ_RETRY,
125 	IBCM_TRACE_OUT_REP_RETRY,
126 	IBCM_TRACE_OUT_LAP_RETRY,
127 	IBCM_TRACE_OUT_MRA_RETRY,
128 	IBCM_TRACE_OUT_DREQ_RETRY,
129 
130 	/* End Marker */
131 	IBCM_TRACE_END_MARKER
132 
133 } ibcm_state_rc_trace_qualifier_t;
134 
135 /* Number of traces per connection chunk */
136 #define		IBCM_MAX_CONN_TRCNT		40
137 #define		IBCM_DEBUG_BUF_SIZE		4096
138 
139 /* If the trace time diff type is changed in the future, modify below */
140 #define		TM_DIFF_MAX			UINT32_MAX
141 typedef		uint32_t			tm_diff_type;
142 
143 /*
144  * The following structure stores the trace data per connection, and
145  * defined as a field in ibcm_state_data_t.
146  *
147  * conn_trace_options:
148  *	Stores various active trace options, like whether time stamp stored,
149  *	detailed trace data stored, etc.,
150  * conn_qpn:
151  *	QPN of channel used for connection
152  * conn_chan:
153  *	Channel used for connection
154  * conn_base_tm:
155  *	Base time stamp in usec, when the first trace for this connection has
156  *	been recorded. Gethrtime is used to record the base time stamp.
157  * conn_trace_events:
158  *	Trace events recorded for the connection
159  * conn_trace_event_times:
160  *	Trace event times recorded for the connection
161  * conn_trace_ind:
162  *	Index into trace_events, where the next trace event shall be stored
163  * conn_allocated_trcnt:
164  *	Allocated number of trace entries
165  */
166 typedef struct ibcm_conn_trace_s {
167 	hrtime_t		conn_base_tm;
168 	uint8_t			*conn_trace_events;
169 	tm_diff_type		*conn_trace_event_times;
170 	uint8_t			conn_trace_ind;
171 	uint16_t		conn_allocated_trcnt;
172 } ibcm_conn_trace_t;
173 
174 /* function that inserts a new trace into ibcm_conn_trace_t */
175 void	ibcm_insert_trace(void *statep,
176 	    ibcm_state_rc_trace_qualifier_t event_qualifier);
177 
178 /* dumps the connection trace into ibtf_debug_buf */
179 void	ibcm_dump_conn_trace(void *statep);
180 
181 extern char	ibcm_debug_buf[];
182 
183 extern kmutex_t	ibcm_trace_mutex;
184 extern kmutex_t	ibcm_trace_print_mutex;
185 extern int	ibcm_conn_max_trcnt;
186 
187 /*
188  *	ibcm_enable_trace has the following flag bits:
189  *
190  *		0	No tracing performed.
191  *		1	Tracing without timing.
192  *		2	Trace failed connections.
193  *		4	Trace all connections.
194  */
195 extern int	ibcm_enable_trace;
196 
197 extern char	*event_str[];
198 
199 #ifdef	__cplusplus
200 }
201 #endif
202 
203 #endif /* _SYS_IB_MGT_IBCM_IBCM_TRACE_H */
204