xref: /freebsd/sys/ofed/drivers/infiniband/ulp/sdp/sdp_dbg.h (revision 13ea0450a9c8742119d36f3bf8f47accdce46e54)
1 #ifndef _SDP_DBG_H_
2 #define _SDP_DBG_H_
3 
4 #define SDPSTATS_ON
5 
6 //#define GETNSTIMEODAY_SUPPORTED
7 
8 #define _sdp_printk(func, line, level, sk, format, arg...)	\
9 do {								\
10 	printk(level "%s:%d %p sdp_sock(%d:%d %d:%d): " format "\n",	\
11 	       func, line, sk ? sdp_sk(sk) : NULL,		\
12 	       curproc->p_pid, PCPU_GET(cpuid),			\
13 	       (sk) && sdp_sk(sk) ? ntohs(sdp_sk(sk)->lport) : -1,	\
14 	       (sk) && sdp_sk(sk) ? ntohs(sdp_sk(sk)->fport) : -1, ## arg);	\
15 } while (0)
16 #define sdp_printk(level, sk, format, arg...)                \
17 	_sdp_printk(__func__, __LINE__, level, sk, format, ## arg)
18 #define sdp_warn(sk, format, arg...)                         \
19 	sdp_printk(KERN_WARNING, sk, format , ## arg)
20 
21 #define SDP_MODPARAM_SINT(var, def_val, msg) \
22 	static int var = def_val; \
23 	module_param_named(var, var, int, 0644); \
24 	MODULE_PARM_DESC(var, msg " [" #def_val "]"); \
25 
26 #define SDP_MODPARAM_INT(var, def_val, msg) \
27 	int var = def_val; \
28 	module_param_named(var, var, int, 0644); \
29 	MODULE_PARM_DESC(var, msg " [" #def_val "]"); \
30 
31 #ifdef SDP_PROFILING
32 struct mbuf;
33 struct sdpprf_log {
34 	int 		idx;
35 	int 		pid;
36 	int 		cpu;
37 	int 		sk_num;
38 	int 		sk_dport;
39 	struct mbuf 	*mb;
40 	char		msg[256];
41 
42 	unsigned long long time;
43 
44 	const char 	*func;
45 	int 		line;
46 };
47 
48 #define SDPPRF_LOG_SIZE 0x20000 /* must be a power of 2 */
49 
50 extern struct sdpprf_log sdpprf_log[SDPPRF_LOG_SIZE];
51 extern int sdpprf_log_count;
52 
53 #ifdef GETNSTIMEODAY_SUPPORTED
54 static inline unsigned long long current_nsec(void)
55 {
56 	struct timespec tv;
57 	getnstimeofday(&tv);
58 	return tv.tv_sec * NSEC_PER_SEC + tv.tv_nsec;
59 }
60 #else
61 #define current_nsec() jiffies_to_usecs(jiffies)
62 #endif
63 
64 #define sdp_prf1(sk, s, format, arg...) ({ \
65 	struct sdpprf_log *l = \
66 		&sdpprf_log[sdpprf_log_count++ & (SDPPRF_LOG_SIZE - 1)]; \
67 	preempt_disable(); \
68 	l->idx = sdpprf_log_count - 1; \
69 	l->pid = current->pid; \
70 	l->sk_num = (sk) ? inet_sk(sk)->num : -1;                 \
71 	l->sk_dport = (sk) ? ntohs(inet_sk(sk)->dport) : -1; \
72 	l->cpu = smp_processor_id(); \
73 	l->mb = s; \
74 	snprintf(l->msg, sizeof(l->msg) - 1, format, ## arg); \
75 	l->time = current_nsec(); \
76 	l->func = __func__; \
77 	l->line = __LINE__; \
78 	preempt_enable(); \
79 	1; \
80 })
81 //#define sdp_prf(sk, s, format, arg...)
82 #define sdp_prf(sk, s, format, arg...) sdp_prf1(sk, s, format, ## arg)
83 
84 #else
85 #define sdp_prf1(sk, s, format, arg...)
86 #define sdp_prf(sk, s, format, arg...)
87 #endif
88 
89 #ifdef CONFIG_INFINIBAND_SDP_DEBUG
90 extern int sdp_debug_level;
91 
92 #define sdp_dbg(sk, format, arg...)                          \
93 	do {                                                 \
94 		if (sdp_debug_level > 0)                     \
95 		sdp_printk(KERN_WARNING, sk, format , ## arg); \
96 	} while (0)
97 
98 #else /* CONFIG_INFINIBAND_SDP_DEBUG */
99 #define sdp_dbg(priv, format, arg...)                        \
100 	do { (void) (priv); } while (0)
101 #define sock_ref(sk, msg, sock_op) sock_op(sk)
102 #endif /* CONFIG_INFINIBAND_SDP_DEBUG */
103 
104 #ifdef CONFIG_INFINIBAND_SDP_DEBUG_DATA
105 
106 extern int sdp_data_debug_level;
107 #define sdp_dbg_data(sk, format, arg...)                     		\
108 	do {                                                 		\
109 		if (sdp_data_debug_level & 0x2)                		\
110 			sdp_printk(KERN_WARNING, sk, format , ## arg); 	\
111 	} while (0)
112 #define SDP_DUMP_PACKET(sk, str, mb, h)                     		\
113 	do {                                                 		\
114 		if (sdp_data_debug_level & 0x1)                		\
115 			dump_packet(sk, str, mb, h); 			\
116 	} while (0)
117 #else
118 #define sdp_dbg_data(priv, format, arg...)
119 #define SDP_DUMP_PACKET(sk, str, mb, h)
120 #endif
121 
122 #define SOCK_REF_RESET "RESET"
123 #define SOCK_REF_ALIVE "ALIVE" /* sock_alloc -> destruct_sock */
124 #define SOCK_REF_CLONE "CLONE"
125 #define SOCK_REF_CMA "CMA" /* sdp_cma_handler() is expected to be invoked */
126 #define SOCK_REF_SEQ "SEQ" /* during proc read */
127 #define SOCK_REF_DREQ_TO "DREQ_TO" /* dreq timeout is pending */
128 #define SOCK_REF_ZCOPY "ZCOPY" /* zcopy send in process */
129 #define SOCK_REF_RDMA_RD "RDMA_RD" /* RDMA read in process */
130 
131 #define sock_hold(sk, msg)  sock_ref(sk, msg, sock_hold)
132 #define sock_put(sk, msg)  sock_ref(sk, msg, sock_put)
133 #define __sock_put(sk, msg)  sock_ref(sk, msg, __sock_put)
134 
135 #define ENUM2STR(e) [e] = #e
136 
137 static inline char *sdp_state_str(int state)
138 {
139 	static char *state2str[] = {
140 		ENUM2STR(TCPS_ESTABLISHED),
141 		ENUM2STR(TCPS_SYN_SENT),
142 		ENUM2STR(TCPS_SYN_RECEIVED),
143 		ENUM2STR(TCPS_FIN_WAIT_1),
144 		ENUM2STR(TCPS_FIN_WAIT_2),
145 		ENUM2STR(TCPS_TIME_WAIT),
146 		ENUM2STR(TCPS_CLOSED),
147 		ENUM2STR(TCPS_CLOSE_WAIT),
148 		ENUM2STR(TCPS_LAST_ACK),
149 		ENUM2STR(TCPS_LISTEN),
150 		ENUM2STR(TCPS_CLOSING),
151 	};
152 
153 	if (state < 0 || state >= ARRAY_SIZE(state2str))
154 		return "unknown";
155 
156 	return state2str[state];
157 }
158 
159 struct sdp_bsdh;
160 #ifdef CONFIG_INFINIBAND_SDP_DEBUG_DATA
161 void _dump_packet(const char *func, int line, struct socket *sk, char *str,
162 		struct mbuf *mb, const struct sdp_bsdh *h);
163 #define dump_packet(sk, str, mb, h) \
164 	_dump_packet(__func__, __LINE__, sk, str, mb, h)
165 #endif
166 
167 #endif
168