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$ 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 47236712Smav#if defined(_KERNEL) 4839212Sgibbs 49236712Smav#ifndef CAM_DEBUG_FLAGS 50236712Smav#define CAM_DEBUG_FLAGS CAM_DEBUG_NONE 51236712Smav#endif 52236712Smav 53236712Smav#ifndef CAM_DEBUG_COMPILE 54236712Smav#ifdef CAMDEBUG 55236712Smav#define CAM_DEBUG_COMPILE (-1) 56236712Smav#else 57236712Smav#define CAM_DEBUG_COMPILE (CAM_DEBUG_INFO | CAM_DEBUG_CDB | \ 58236712Smav CAM_DEBUG_PERIPH | CAM_DEBUG_PROBE | \ 59236712Smav CAM_DEBUG_FLAGS) 60236712Smav#endif 61236712Smav#endif 62236712Smav 63236712Smav#ifndef CAM_DEBUG_BUS 64236712Smav#define CAM_DEBUG_BUS (-1) 65236712Smav#endif 66236712Smav#ifndef CAM_DEBUG_TARGET 67236712Smav#define CAM_DEBUG_TARGET (-1) 68236712Smav#endif 69236712Smav#ifndef CAM_DEBUG_LUN 70236712Smav#define CAM_DEBUG_LUN (-1) 71236712Smav#endif 72236712Smav 73236712Smav#ifndef CAM_DEBUG_DELAY 74236712Smav#define CAM_DEBUG_DELAY 0 75236712Smav#endif 76236712Smav 7739212Sgibbs/* Path we want to debug */ 7839212Sgibbsextern struct cam_path *cam_dpath; 7939212Sgibbs/* Current debug levels set */ 8039212Sgibbsextern u_int32_t cam_dflags; 8174840Sken/* Printf delay value (to prevent scrolling) */ 8249926Sgibbsextern u_int32_t cam_debug_delay; 83236712Smav 8439212Sgibbs/* Debugging macros. */ 8541546Smjacob#define CAM_DEBUGGED(path, flag) \ 86236712Smav (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ 8741546Smjacob && (cam_dpath != NULL) \ 8849926Sgibbs && (xpt_path_comp(cam_dpath, path) >= 0) \ 8949926Sgibbs && (xpt_path_comp(cam_dpath, path) < 2)) 90208911Smjacob 9139212Sgibbs#define CAM_DEBUG(path, flag, printfargs) \ 92236712Smav if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ 9339212Sgibbs && (cam_dpath != NULL) \ 9449926Sgibbs && (xpt_path_comp(cam_dpath, path) >= 0) \ 9549926Sgibbs && (xpt_path_comp(cam_dpath, path) < 2)) { \ 9639212Sgibbs xpt_print_path(path); \ 97236712Smav printf printfargs; \ 9849926Sgibbs if (cam_debug_delay != 0) \ 9949926Sgibbs DELAY(cam_debug_delay); \ 10039212Sgibbs } 101208911Smjacob 102255126Smav#define CAM_DEBUG_DEV(dev, flag, printfargs) \ 103255126Smav if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags) \ 104255126Smav && (cam_dpath != NULL) \ 105255126Smav && (xpt_path_comp_dev(cam_dpath, dev) >= 0) \ 106255126Smav && (xpt_path_comp_dev(cam_dpath, dev) < 2)) { \ 107255126Smav xpt_print_device(dev); \ 108255126Smav printf printfargs; \ 109255126Smav if (cam_debug_delay != 0) \ 110255126Smav DELAY(cam_debug_delay); \ 111255126Smav } 112255126Smav 11339212Sgibbs#define CAM_DEBUG_PRINT(flag, printfargs) \ 114236712Smav if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) { \ 11539212Sgibbs printf("cam_debug: "); \ 116236712Smav printf printfargs; \ 11749926Sgibbs if (cam_debug_delay != 0) \ 11849926Sgibbs DELAY(cam_debug_delay); \ 11939212Sgibbs } 12039212Sgibbs 121208911Smjacob#define CAM_DEBUG_PATH_PRINT(flag, path, printfargs) \ 122236712Smav if (((flag) & (CAM_DEBUG_COMPILE) & cam_dflags)) { \ 123208911Smjacob xpt_print(path, "cam_debug: "); \ 124236712Smav printf printfargs; \ 125208911Smjacob if (cam_debug_delay != 0) \ 126208911Smjacob DELAY(cam_debug_delay); \ 127208911Smjacob } 128208911Smjacob 129236712Smav#else /* !_KERNEL */ 13039212Sgibbs 13141546Smjacob#define CAM_DEBUGGED(A, B) 0 13239212Sgibbs#define CAM_DEBUG(A, B, C) 13339212Sgibbs#define CAM_DEBUG_PRINT(A, B) 134208911Smjacob#define CAM_DEBUG_PATH_PRINT(A, B, C) 13539212Sgibbs 136236712Smav#endif /* _KERNEL */ 13739212Sgibbs 13839212Sgibbs#endif /* _CAM_CAM_DEBUG_H */ 139