1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  linux/drivers/message/fusion/mptdebug.h
4  *      For use with LSI PCI chip/adapter(s)
5  *      running LSI Fusion MPT (Message Passing Technology) firmware.
6  *
7  *  Copyright (c) 1999-2008 LSI Corporation
8  *  (mailto:DL-MPTFusionLinux@lsi.com)
9  *
10  */
11 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
12 
13 #ifndef MPTDEBUG_H_INCLUDED
14 #define MPTDEBUG_H_INCLUDED
15 
16 /*
17  * debug level can be programmed on the fly via SysFS (hex values)
18  *
19  * Example:  (programming for MPT_DEBUG_EVENTS on host 5)
20  *
21  * echo 8 > /sys/class/scsi_host/host5/debug_level
22  *
23  * --------------------------------------------------------
24  * mpt_debug_level - command line parameter
25  * this allow enabling debug at driver load time (for all iocs)
26  *
27  * Example  (programming for MPT_DEBUG_EVENTS)
28  *
29  * insmod mptbase.ko mpt_debug_level=8
30  *
31  * --------------------------------------------------------
32  * CONFIG_FUSION_LOGGING - enables compiling debug into driver
33  * this can be enabled in the driver Makefile
34  *
35  *
36  * --------------------------------------------------------
37  * Please note most debug prints are set to logging priority = debug
38  * This is the lowest level, and most verbose.  Please refer to manual
39  * pages for syslogd or syslogd-ng on how to configure this.
40  */
41 
42 #define MPT_DEBUG			0x00000001
43 #define MPT_DEBUG_MSG_FRAME		0x00000002
44 #define MPT_DEBUG_SG			0x00000004
45 #define MPT_DEBUG_EVENTS		0x00000008
46 #define MPT_DEBUG_VERBOSE_EVENTS	0x00000010
47 #define MPT_DEBUG_INIT			0x00000020
48 #define MPT_DEBUG_EXIT			0x00000040
49 #define MPT_DEBUG_FAIL			0x00000080
50 #define MPT_DEBUG_TM			0x00000100
51 #define MPT_DEBUG_DV			0x00000200
52 #define MPT_DEBUG_REPLY			0x00000400
53 #define MPT_DEBUG_HANDSHAKE		0x00000800
54 #define MPT_DEBUG_CONFIG		0x00001000
55 #define MPT_DEBUG_DL			0x00002000
56 #define MPT_DEBUG_RESET			0x00008000
57 #define MPT_DEBUG_SCSI			0x00010000
58 #define MPT_DEBUG_IOCTL			0x00020000
59 #define MPT_DEBUG_FC			0x00080000
60 #define MPT_DEBUG_SAS			0x00100000
61 #define MPT_DEBUG_SAS_WIDE		0x00200000
62 #define MPT_DEBUG_36GB_MEM              0x00400000
63 
64 /*
65  * CONFIG_FUSION_LOGGING - enabled in Kconfig
66  */
67 
68 #ifdef CONFIG_FUSION_LOGGING
69 #define MPT_CHECK_LOGGING(IOC, CMD, BITS)			\
70 {								\
71 	if (IOC->debug_level & BITS)				\
72 		CMD;						\
73 }
74 #else
75 #define MPT_CHECK_LOGGING(IOC, CMD, BITS)
76 #endif
77 
78 
79 /*
80  * debug macros
81  */
82 
83 #define dprintk(IOC, CMD)			\
84 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG)
85 
86 #define dsgprintk(IOC, CMD)			\
87 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SG)
88 
89 #define devtprintk(IOC, CMD)			\
90 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_EVENTS)
91 
92 #define devtverboseprintk(IOC, CMD)		\
93 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_VERBOSE_EVENTS)
94 
95 #define dinitprintk(IOC, CMD)			\
96 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_INIT)
97 
98 #define dexitprintk(IOC, CMD)			\
99 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_EXIT)
100 
101 #define dfailprintk(IOC, CMD)			\
102 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_FAIL)
103 
104 #define dtmprintk(IOC, CMD)			\
105 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_TM)
106 
107 #define ddvprintk(IOC, CMD)			\
108 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_DV)
109 
110 #define dreplyprintk(IOC, CMD)			\
111 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_REPLY)
112 
113 #define dhsprintk(IOC, CMD)			\
114 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_HANDSHAKE)
115 
116 #define dcprintk(IOC, CMD)			\
117 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_CONFIG)
118 
119 #define ddlprintk(IOC, CMD)			\
120 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_DL)
121 
122 #define drsprintk(IOC, CMD)			\
123 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_RESET)
124 
125 #define dsprintk(IOC, CMD)			\
126 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SCSI)
127 
128 #define dctlprintk(IOC, CMD)			\
129 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_IOCTL)
130 
131 #define dfcprintk(IOC, CMD)			\
132 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_FC)
133 
134 #define dsasprintk(IOC, CMD)			\
135 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SAS)
136 
137 #define dsaswideprintk(IOC, CMD)		\
138 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SAS_WIDE)
139 
140 #define d36memprintk(IOC, CMD)		\
141 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_36GB_MEM)
142 
143 
144 /*
145  * Verbose logging
146  */
147 #if defined(MPT_DEBUG_VERBOSE) && defined(CONFIG_FUSION_LOGGING)
148 static inline void
DBG_DUMP_FW_DOWNLOAD(MPT_ADAPTER * ioc,u32 * mfp,int numfrags)149 DBG_DUMP_FW_DOWNLOAD(MPT_ADAPTER *ioc, u32  *mfp, int numfrags)
150 {
151 	int i;
152 
153 	if (!(ioc->debug_level & MPT_DEBUG))
154 		return;
155 	printk(KERN_DEBUG "F/W download request:\n");
156 	for (i=0; i < 7+numfrags*2; i++)
157 		printk(" %08x", le32_to_cpu(mfp[i]));
158 	printk("\n");
159 }
160 
161 static inline void
DBG_DUMP_PUT_MSG_FRAME(MPT_ADAPTER * ioc,u32 * mfp)162 DBG_DUMP_PUT_MSG_FRAME(MPT_ADAPTER *ioc, u32 *mfp)
163 {
164 	int	 ii, n;
165 
166 	if (!(ioc->debug_level & MPT_DEBUG_MSG_FRAME))
167 		return;
168 	printk(KERN_DEBUG "%s: About to Put msg frame @ %p:\n",
169 		ioc->name, mfp);
170 	n = ioc->req_sz/4 - 1;
171 	while (mfp[n] == 0)
172 		n--;
173 	for (ii=0; ii<=n; ii++) {
174 		if (ii && ((ii%8)==0))
175 			printk("\n");
176 		printk(" %08x", le32_to_cpu(mfp[ii]));
177 	}
178 	printk("\n");
179 }
180 
181 static inline void
DBG_DUMP_FW_REQUEST_FRAME(MPT_ADAPTER * ioc,u32 * mfp)182 DBG_DUMP_FW_REQUEST_FRAME(MPT_ADAPTER *ioc, u32 *mfp)
183 {
184 	int  i, n;
185 
186 	if (!(ioc->debug_level & MPT_DEBUG_MSG_FRAME))
187 		return;
188 	n = 10;
189 	printk(KERN_INFO " ");
190 	for (i = 0; i < n; i++)
191 		printk(" %08x", le32_to_cpu(mfp[i]));
192 	printk("\n");
193 }
194 
195 static inline void
DBG_DUMP_REQUEST_FRAME(MPT_ADAPTER * ioc,u32 * mfp)196 DBG_DUMP_REQUEST_FRAME(MPT_ADAPTER *ioc, u32 *mfp)
197 {
198 	int  i, n;
199 
200 	if (!(ioc->debug_level & MPT_DEBUG_MSG_FRAME))
201 		return;
202 	n = 24;
203 	for (i=0; i<n; i++) {
204 		if (i && ((i%8)==0))
205 			printk("\n");
206 		printk("%08x ", le32_to_cpu(mfp[i]));
207 	}
208 	printk("\n");
209 }
210 
211 static inline void
DBG_DUMP_REPLY_FRAME(MPT_ADAPTER * ioc,u32 * mfp)212 DBG_DUMP_REPLY_FRAME(MPT_ADAPTER *ioc, u32 *mfp)
213 {
214 	int  i, n;
215 
216 	if (!(ioc->debug_level & MPT_DEBUG_MSG_FRAME))
217 		return;
218 	n = (le32_to_cpu(mfp[0]) & 0x00FF0000) >> 16;
219 	printk(KERN_INFO " ");
220 	for (i=0; i<n; i++)
221 		printk(" %08x", le32_to_cpu(mfp[i]));
222 	printk("\n");
223 }
224 
225 static inline void
DBG_DUMP_REQUEST_FRAME_HDR(MPT_ADAPTER * ioc,u32 * mfp)226 DBG_DUMP_REQUEST_FRAME_HDR(MPT_ADAPTER *ioc, u32 *mfp)
227 {
228 	int  i, n;
229 
230 	if (!(ioc->debug_level & MPT_DEBUG_MSG_FRAME))
231 		return;
232 	n = 3;
233 	printk(KERN_INFO " ");
234 	for (i=0; i<n; i++)
235 		printk(" %08x", le32_to_cpu(mfp[i]));
236 	printk("\n");
237 }
238 
239 static inline void
DBG_DUMP_TM_REQUEST_FRAME(MPT_ADAPTER * ioc,u32 * mfp)240 DBG_DUMP_TM_REQUEST_FRAME(MPT_ADAPTER *ioc, u32 *mfp)
241 {
242 	int  i, n;
243 
244 	if (!(ioc->debug_level & MPT_DEBUG_TM))
245 		return;
246 	n = 13;
247 	printk(KERN_DEBUG "TM_REQUEST:\n");
248 	for (i=0; i<n; i++) {
249 		if (i && ((i%8)==0))
250 			printk("\n");
251 		printk("%08x ", le32_to_cpu(mfp[i]));
252 	}
253 	printk("\n");
254 }
255 
256 static inline void
DBG_DUMP_TM_REPLY_FRAME(MPT_ADAPTER * ioc,u32 * mfp)257 DBG_DUMP_TM_REPLY_FRAME(MPT_ADAPTER *ioc, u32 *mfp)
258 {
259 	int  i, n;
260 
261 	if (!(ioc->debug_level & MPT_DEBUG_TM))
262 		return;
263 	n = (le32_to_cpu(mfp[0]) & 0x00FF0000) >> 16;
264 	printk(KERN_DEBUG "TM_REPLY MessageLength=%d:\n", n);
265 	for (i=0; i<n; i++) {
266 		if (i && ((i%8)==0))
267 			printk("\n");
268 		printk(" %08x", le32_to_cpu(mfp[i]));
269 	}
270 	printk("\n");
271 }
272 
273 #define dmfprintk(IOC, CMD)			\
274 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_MSG_FRAME)
275 
276 # else /* ifdef MPT_DEBUG_MF */
277 
278 #define DBG_DUMP_FW_DOWNLOAD(IOC, mfp, numfrags)
279 #define DBG_DUMP_PUT_MSG_FRAME(IOC, mfp)
280 #define DBG_DUMP_FW_REQUEST_FRAME(IOC, mfp)
281 #define DBG_DUMP_REQUEST_FRAME(IOC, mfp)
282 #define DBG_DUMP_REPLY_FRAME(IOC, mfp)
283 #define DBG_DUMP_REQUEST_FRAME_HDR(IOC, mfp)
284 #define DBG_DUMP_TM_REQUEST_FRAME(IOC, mfp)
285 #define DBG_DUMP_TM_REPLY_FRAME(IOC, mfp)
286 
287 #define dmfprintk(IOC, CMD)			\
288 	MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_MSG_FRAME)
289 
290 #endif /* defined(MPT_DEBUG_VERBOSE) && defined(CONFIG_FUSION_LOGGING) */
291 
292 #endif /* ifndef MPTDEBUG_H_INCLUDED */
293