cam_debug.h revision 208911
1139743Simp/*-
239212Sgibbs * Macros for tracing/loging information in the CAM layer
339212Sgibbs *
439212Sgibbs * Copyright (c) 1997 Justin T. Gibbs.
539212Sgibbs * All rights reserved.
639212Sgibbs *
739212Sgibbs * Redistribution and use in source and binary forms, with or without
839212Sgibbs * modification, are permitted provided that the following conditions
939212Sgibbs * are met:
1039212Sgibbs * 1. Redistributions of source code must retain the above copyright
1139212Sgibbs *    notice, this list of conditions, and the following disclaimer,
1239212Sgibbs *    without modification, immediately at the beginning of the file.
1339212Sgibbs * 2. The name of the author may not be used to endorse or promote products
1439212Sgibbs *    derived from this software without specific prior written permission.
1539212Sgibbs *
1639212Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1739212Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1839212Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1939212Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2039212Sgibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2139212Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2239212Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2339212Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2439212Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2539212Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2639212Sgibbs * SUCH DAMAGE.
2739212Sgibbs *
2850477Speter * $FreeBSD: head/sys/cam/cam_debug.h 208911 2010-06-08 16:17:25Z mjacob $
2939212Sgibbs */
3039212Sgibbs#ifndef	_CAM_CAM_DEBUG_H
3139212Sgibbs#define _CAM_CAM_DEBUG_H 1
3239212Sgibbs
3339212Sgibbs/*
3439212Sgibbs * Debugging flags.
3539212Sgibbs */
3639212Sgibbstypedef enum {
3739212Sgibbs	CAM_DEBUG_NONE		= 0x00, /* no debugging */
3839212Sgibbs	CAM_DEBUG_INFO		= 0x01,	/* scsi commands, errors, data */
3939212Sgibbs	CAM_DEBUG_TRACE		= 0x02,	/* routine flow tracking */
4039212Sgibbs	CAM_DEBUG_SUBTRACE	= 0x04,	/* internal to routine flows */
4141546Smjacob	CAM_DEBUG_CDB		= 0x08, /* print out SCSI CDBs only */
4249926Sgibbs	CAM_DEBUG_XPT		= 0x10,	/* print out xpt scheduling */
43208911Smjacob	CAM_DEBUG_PERIPH	= 0x20, /* print out peripheral calls */
44208911Smjacob	CAM_DEBUG_PROBE		= 0x40  /* print out probe actions */
4539212Sgibbs} cam_debug_flags;
4639212Sgibbs
4755206Speter#if defined(CAMDEBUG) && defined(_KERNEL)
4839212Sgibbs
4939212Sgibbs/* Path we want to debug */
5039212Sgibbsextern struct cam_path *cam_dpath;
5139212Sgibbs/* Current debug levels set */
5239212Sgibbsextern u_int32_t cam_dflags;
5374840Sken/* Printf delay value (to prevent scrolling) */
5449926Sgibbsextern u_int32_t cam_debug_delay;
5539212Sgibbs
5639212Sgibbs/* Debugging macros. */
5741546Smjacob#define	CAM_DEBUGGED(path, flag)			\
5841546Smjacob	((cam_dflags & (flag))				\
5941546Smjacob	 && (cam_dpath != NULL)				\
6049926Sgibbs	 && (xpt_path_comp(cam_dpath, path) >= 0)	\
6149926Sgibbs	 && (xpt_path_comp(cam_dpath, path) < 2))
62208911Smjacob
6339212Sgibbs#define	CAM_DEBUG(path, flag, printfargs)		\
6439212Sgibbs	if ((cam_dflags & (flag))			\
6539212Sgibbs	 && (cam_dpath != NULL)				\
6649926Sgibbs	 && (xpt_path_comp(cam_dpath, path) >= 0)	\
6749926Sgibbs	 && (xpt_path_comp(cam_dpath, path) < 2)) {	\
6839212Sgibbs		xpt_print_path(path);			\
6939212Sgibbs 		printf printfargs;			\
7049926Sgibbs		if (cam_debug_delay != 0)		\
7149926Sgibbs			DELAY(cam_debug_delay);		\
7239212Sgibbs	}
73208911Smjacob
7439212Sgibbs#define	CAM_DEBUG_PRINT(flag, printfargs)		\
7539212Sgibbs	if (cam_dflags & (flag)) {			\
7639212Sgibbs		printf("cam_debug: ");			\
7739212Sgibbs 		printf printfargs;			\
7849926Sgibbs		if (cam_debug_delay != 0)		\
7949926Sgibbs			DELAY(cam_debug_delay);		\
8039212Sgibbs	}
8139212Sgibbs
82208911Smjacob#define	CAM_DEBUG_PATH_PRINT(flag, path, printfargs)	\
83208911Smjacob	if (cam_dflags & (flag)) {			\
84208911Smjacob		xpt_print(path, "cam_debug: ");		\
85208911Smjacob 		printf printfargs;			\
86208911Smjacob		if (cam_debug_delay != 0)		\
87208911Smjacob			DELAY(cam_debug_delay);		\
88208911Smjacob	}
89208911Smjacob
9055206Speter#else /* !CAMDEBUG || !_KERNEL */
9139212Sgibbs
9241546Smjacob#define	CAM_DEBUGGED(A, B)	0
9339212Sgibbs#define	CAM_DEBUG(A, B, C)
9439212Sgibbs#define	CAM_DEBUG_PRINT(A, B)
95208911Smjacob#define	CAM_DEBUG_PATH_PRINT(A, B, C)
9639212Sgibbs
9755206Speter#endif /* CAMDEBUG && _KERNEL */
9839212Sgibbs
9939212Sgibbs#endif /* _CAM_CAM_DEBUG_H */
100