cam_debug.h revision 39212
139212Sgibbs/*
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 *
2839212Sgibbs *      $Id$
2939212Sgibbs */
3039212Sgibbs#ifndef	_CAM_CAM_DEBUG_H
3139212Sgibbs#define _CAM_CAM_DEBUG_H 1
3239212Sgibbs
3339212Sgibbs#if defined(CAMDEBUG) && defined(KERNEL)
3439212Sgibbs#include <machine/clock.h>
3539212Sgibbs#endif /* CAMDEBUG && KERNEL */
3639212Sgibbs
3739212Sgibbs/*
3839212Sgibbs * Debugging flags.
3939212Sgibbs */
4039212Sgibbstypedef enum {
4139212Sgibbs	CAM_DEBUG_NONE		= 0x00, /* no debugging */
4239212Sgibbs	CAM_DEBUG_INFO		= 0x01,	/* scsi commands, errors, data */
4339212Sgibbs	CAM_DEBUG_TRACE		= 0x02,	/* routine flow tracking */
4439212Sgibbs	CAM_DEBUG_SUBTRACE	= 0x04,	/* internal to routine flows */
4539212Sgibbs} cam_debug_flags;
4639212Sgibbs
4739212Sgibbs#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;
5339212Sgibbs
5439212Sgibbs/* Debugging macros. */
5539212Sgibbs#define	CAM_DEBUG(path, flag, printfargs)		\
5639212Sgibbs	if ((cam_dflags & (flag))			\
5739212Sgibbs	 && (cam_dpath != NULL)				\
5839212Sgibbs	 && (xpt_path_comp(path, cam_dpath) >= 0)) {	\
5939212Sgibbs		xpt_print_path(path);			\
6039212Sgibbs 		printf printfargs;			\
6139212Sgibbs		DELAY(100000);				\
6239212Sgibbs	}
6339212Sgibbs#define	CAM_DEBUG_PRINT(flag, printfargs)		\
6439212Sgibbs	if (cam_dflags & (flag)) {			\
6539212Sgibbs		printf("cam_debug: ");			\
6639212Sgibbs 		printf printfargs;			\
6739212Sgibbs		DELAY(100000);				\
6839212Sgibbs	}
6939212Sgibbs
7039212Sgibbs#else /* !CAMDEBUG || !KERNEL */
7139212Sgibbs
7239212Sgibbs#define	CAM_DEBUG(A, B, C)
7339212Sgibbs#define	CAM_DEBUG_PRINT(A, B)
7439212Sgibbs
7539212Sgibbs#endif /* CAMDEBUG && KERNEL */
7639212Sgibbs
7739212Sgibbs#endif /* _CAM_CAM_DEBUG_H */
78