xref: /freebsd/sys/cam/cam_debug.h (revision bec9534d1d180ff06c240db7bbd809764a6a8f6f)
1898b0535SWarner Losh /*-
28b8a9b1dSJustin T. Gibbs  * Macros for tracing/loging information in the CAM layer
38b8a9b1dSJustin T. Gibbs  *
4*bec9534dSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5*bec9534dSPedro F. Giffuni  *
68b8a9b1dSJustin T. Gibbs  * Copyright (c) 1997 Justin T. Gibbs.
78b8a9b1dSJustin T. Gibbs  * All rights reserved.
88b8a9b1dSJustin T. Gibbs  *
98b8a9b1dSJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
108b8a9b1dSJustin T. Gibbs  * modification, are permitted provided that the following conditions
118b8a9b1dSJustin T. Gibbs  * are met:
128b8a9b1dSJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
138b8a9b1dSJustin T. Gibbs  *    notice, this list of conditions, and the following disclaimer,
148b8a9b1dSJustin T. Gibbs  *    without modification, immediately at the beginning of the file.
158b8a9b1dSJustin T. Gibbs  * 2. The name of the author may not be used to endorse or promote products
168b8a9b1dSJustin T. Gibbs  *    derived from this software without specific prior written permission.
178b8a9b1dSJustin T. Gibbs  *
188b8a9b1dSJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
198b8a9b1dSJustin T. Gibbs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208b8a9b1dSJustin T. Gibbs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
218b8a9b1dSJustin T. Gibbs  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
228b8a9b1dSJustin T. Gibbs  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
238b8a9b1dSJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248b8a9b1dSJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
258b8a9b1dSJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
268b8a9b1dSJustin T. Gibbs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
278b8a9b1dSJustin T. Gibbs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288b8a9b1dSJustin T. Gibbs  * SUCH DAMAGE.
298b8a9b1dSJustin T. Gibbs  *
30c3aac50fSPeter Wemm  * $FreeBSD$
318b8a9b1dSJustin T. Gibbs  */
328b8a9b1dSJustin T. Gibbs #ifndef	_CAM_CAM_DEBUG_H
338b8a9b1dSJustin T. Gibbs #define _CAM_CAM_DEBUG_H 1
348b8a9b1dSJustin T. Gibbs 
358b8a9b1dSJustin T. Gibbs /*
368b8a9b1dSJustin T. Gibbs  * Debugging flags.
378b8a9b1dSJustin T. Gibbs  */
388b8a9b1dSJustin T. Gibbs typedef enum {
398b8a9b1dSJustin T. Gibbs 	CAM_DEBUG_NONE		= 0x00, /* no debugging */
408b8a9b1dSJustin T. Gibbs 	CAM_DEBUG_INFO		= 0x01,	/* scsi commands, errors, data */
418b8a9b1dSJustin T. Gibbs 	CAM_DEBUG_TRACE		= 0x02,	/* routine flow tracking */
428b8a9b1dSJustin T. Gibbs 	CAM_DEBUG_SUBTRACE	= 0x04,	/* internal to routine flows */
43c7f682dbSMatt Jacob 	CAM_DEBUG_CDB		= 0x08, /* print out SCSI CDBs only */
44b8b98bc3SJustin T. Gibbs 	CAM_DEBUG_XPT		= 0x10,	/* print out xpt scheduling */
4582b361b1SMatt Jacob 	CAM_DEBUG_PERIPH	= 0x20, /* print out peripheral calls */
4682b361b1SMatt Jacob 	CAM_DEBUG_PROBE		= 0x40  /* print out probe actions */
478b8a9b1dSJustin T. Gibbs } cam_debug_flags;
488b8a9b1dSJustin T. Gibbs 
49f0f25b9cSAlexander Motin #if defined(_KERNEL)
50f0f25b9cSAlexander Motin 
51f0f25b9cSAlexander Motin #ifndef CAM_DEBUG_FLAGS
52f0f25b9cSAlexander Motin #define CAM_DEBUG_FLAGS		CAM_DEBUG_NONE
53f0f25b9cSAlexander Motin #endif
54f0f25b9cSAlexander Motin 
55f0f25b9cSAlexander Motin #ifndef CAM_DEBUG_COMPILE
56f0f25b9cSAlexander Motin #ifdef CAMDEBUG
57f0f25b9cSAlexander Motin #define CAM_DEBUG_COMPILE	(-1)
58f0f25b9cSAlexander Motin #else
59f0f25b9cSAlexander Motin #define CAM_DEBUG_COMPILE	(CAM_DEBUG_INFO | CAM_DEBUG_CDB | \
60f0f25b9cSAlexander Motin 				 CAM_DEBUG_PERIPH | CAM_DEBUG_PROBE | \
61f0f25b9cSAlexander Motin 				 CAM_DEBUG_FLAGS)
62f0f25b9cSAlexander Motin #endif
63f0f25b9cSAlexander Motin #endif
64f0f25b9cSAlexander Motin 
65f0f25b9cSAlexander Motin #ifndef CAM_DEBUG_BUS
66431d3a5bSAlexander Motin #define CAM_DEBUG_BUS		CAM_BUS_WILDCARD
67f0f25b9cSAlexander Motin #endif
68f0f25b9cSAlexander Motin #ifndef CAM_DEBUG_TARGET
69431d3a5bSAlexander Motin #define CAM_DEBUG_TARGET	CAM_TARGET_WILDCARD
70f0f25b9cSAlexander Motin #endif
71f0f25b9cSAlexander Motin #ifndef CAM_DEBUG_LUN
72431d3a5bSAlexander Motin #define CAM_DEBUG_LUN		CAM_LUN_WILDCARD
73f0f25b9cSAlexander Motin #endif
74f0f25b9cSAlexander Motin 
75f0f25b9cSAlexander Motin #ifndef CAM_DEBUG_DELAY
76f0f25b9cSAlexander Motin #define CAM_DEBUG_DELAY		0
77f0f25b9cSAlexander Motin #endif
788b8a9b1dSJustin T. Gibbs 
798b8a9b1dSJustin T. Gibbs /* Path we want to debug */
808b8a9b1dSJustin T. Gibbs extern struct cam_path *cam_dpath;
818b8a9b1dSJustin T. Gibbs /* Current debug levels set */
828b8a9b1dSJustin T. Gibbs extern u_int32_t cam_dflags;
833393f8daSKenneth D. Merry /* Printf delay value (to prevent scrolling) */
84b8b98bc3SJustin T. Gibbs extern u_int32_t cam_debug_delay;
858b8a9b1dSJustin T. Gibbs 
868b8a9b1dSJustin T. Gibbs /* Debugging macros. */
87c7f682dbSMatt Jacob #define	CAM_DEBUGGED(path, flag)			\
88f0f25b9cSAlexander Motin 	(((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)	\
89c7f682dbSMatt Jacob 	 && (cam_dpath != NULL)				\
90b8b98bc3SJustin T. Gibbs 	 && (xpt_path_comp(cam_dpath, path) >= 0)	\
91b8b98bc3SJustin T. Gibbs 	 && (xpt_path_comp(cam_dpath, path) < 2))
9282b361b1SMatt Jacob 
938b8a9b1dSJustin T. Gibbs #define	CAM_DEBUG(path, flag, printfargs)		\
94f0f25b9cSAlexander Motin 	if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)	\
958b8a9b1dSJustin T. Gibbs 	 && (cam_dpath != NULL)				\
96b8b98bc3SJustin T. Gibbs 	 && (xpt_path_comp(cam_dpath, path) >= 0)	\
97b8b98bc3SJustin T. Gibbs 	 && (xpt_path_comp(cam_dpath, path) < 2)) {	\
988b8a9b1dSJustin T. Gibbs 		xpt_print_path(path);			\
998b8a9b1dSJustin T. Gibbs 		printf printfargs;			\
100b8b98bc3SJustin T. Gibbs 		if (cam_debug_delay != 0)		\
101b8b98bc3SJustin T. Gibbs 			DELAY(cam_debug_delay);		\
1028b8a9b1dSJustin T. Gibbs 	}
10382b361b1SMatt Jacob 
1040d4f3c31SAlexander Motin #define	CAM_DEBUG_DEV(dev, flag, printfargs)		\
1050d4f3c31SAlexander Motin 	if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)	\
1060d4f3c31SAlexander Motin 	 && (cam_dpath != NULL)				\
1070d4f3c31SAlexander Motin 	 && (xpt_path_comp_dev(cam_dpath, dev) >= 0)	\
1080d4f3c31SAlexander Motin 	 && (xpt_path_comp_dev(cam_dpath, dev) < 2)) {	\
1090d4f3c31SAlexander Motin 		xpt_print_device(dev);			\
1100d4f3c31SAlexander Motin 		printf printfargs;			\
1110d4f3c31SAlexander Motin 		if (cam_debug_delay != 0)		\
1120d4f3c31SAlexander Motin 			DELAY(cam_debug_delay);		\
1130d4f3c31SAlexander Motin 	}
1140d4f3c31SAlexander Motin 
1158b8a9b1dSJustin T. Gibbs #define	CAM_DEBUG_PRINT(flag, printfargs)		\
116f0f25b9cSAlexander Motin 	if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) {	\
1178b8a9b1dSJustin T. Gibbs 		printf("cam_debug: ");			\
1188b8a9b1dSJustin T. Gibbs 		printf printfargs;			\
119b8b98bc3SJustin T. Gibbs 		if (cam_debug_delay != 0)		\
120b8b98bc3SJustin T. Gibbs 			DELAY(cam_debug_delay);		\
1218b8a9b1dSJustin T. Gibbs 	}
1228b8a9b1dSJustin T. Gibbs 
12382b361b1SMatt Jacob #define	CAM_DEBUG_PATH_PRINT(flag, path, printfargs)	\
124f0f25b9cSAlexander Motin 	if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) {	\
12582b361b1SMatt Jacob 		xpt_print(path, "cam_debug: ");		\
12682b361b1SMatt Jacob 		printf printfargs;			\
12782b361b1SMatt Jacob 		if (cam_debug_delay != 0)		\
12882b361b1SMatt Jacob 			DELAY(cam_debug_delay);		\
12982b361b1SMatt Jacob 	}
13082b361b1SMatt Jacob 
131f0f25b9cSAlexander Motin #else /* !_KERNEL */
1328b8a9b1dSJustin T. Gibbs 
133c7f682dbSMatt Jacob #define	CAM_DEBUGGED(A, B)	0
1348b8a9b1dSJustin T. Gibbs #define	CAM_DEBUG(A, B, C)
1358b8a9b1dSJustin T. Gibbs #define	CAM_DEBUG_PRINT(A, B)
13682b361b1SMatt Jacob #define	CAM_DEBUG_PATH_PRINT(A, B, C)
1378b8a9b1dSJustin T. Gibbs 
138f0f25b9cSAlexander Motin #endif /* _KERNEL */
1398b8a9b1dSJustin T. Gibbs 
1408b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_DEBUG_H */
141