/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2016 Michael Zhilin <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer,11* without modification.12* 2. Redistributions in binary form must reproduce at minimum a disclaimer13* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any14* redistribution must be conditioned upon including a substantially15* similar Disclaimer requirement for further binary redistribution.16*17* NO WARRANTY18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY21* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL22* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,23* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER26* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF28* THE POSSIBILITY OF SUCH DAMAGES.29*/303132/*33* This file provides set of macros for logging:34* - BHND_<LEVEL> and35* - BHND_<LEVEL>_DEV36* where LEVEL = {ERROR,WARN,INFO,DEBUG}37*38* BHND_<LEVEL> macros is proxies to printf call and accept same parameters,39* for instance:40* BHND_INFO("register %d has value %d", reg, val);41*42* BHND_<LEVEL>_DEV macros is proxies to device_printf call and accept43* same parameters, for instance:44* BHND_INFO_DEV(dev, "register %d has value %d", reg, val);45*46* All macros contains newline char at the end of each call47*48* ERROR, WARN, INFO messages are printed only if:49* - log message level is lower than BHND_LOGGING (logging threshold)50*51* DEBUG, TRACE messages are printed only if:52* - bootverbose and53* - log message level is lower than BHND_LOGGING (logging threshold)54*55* In addition, for debugging purpose log message contains information about56* file name and line number if BHND_LOGGING is more than BHND_INFO_LEVEL57*58* NOTE: macros starting with underscore (_) are private and should be not used59*60* To override logging (for instance, force tracing), you can use:61* - "options BHND_LOGLEVEL=BHND_TRACE_LEVEL" in kernel configuration62* - "#define BHND_LOGGING BHND_TRACE_LEVEL" in source code file63*64* NOTE: kernel config option doesn't override log level defined on file level,65* so try to avoid "#define BHND_LOGGING"66*/6768#ifndef _BHND_BHND_DEBUG_H_69#define _BHND_BHND_DEBUG_H_7071#include <sys/systm.h>7273#define BHND_ERROR_LEVEL 0x0074#define BHND_ERROR_MSG "ERROR"75#define BHND_WARN_LEVEL 0x1076#define BHND_WARN_MSG "!WARN"77#define BHND_INFO_LEVEL 0x2078#define BHND_INFO_MSG " info"79#define BHND_DEBUG_LEVEL 0x3080#define BHND_DEBUG_MSG "debug"81#define BHND_TRACE_LEVEL 0x4082#define BHND_TRACE_MSG "trace"8384#if !(defined(BHND_LOGGING))85#if !(defined(BHND_LOGLEVEL))86/* By default logging will print only INFO+ message*/87#define BHND_LOGGING BHND_INFO_LEVEL88#else /* defined(BHND_LOGLEVEL) */89/* Kernel configuration specifies logging level */90#define BHND_LOGGING BHND_LOGLEVEL91#endif /* !(defined(BHND_LOGLEVEL)) */92#endif /* !(defined(BHND_LOGGING)) */9394#if BHND_LOGGING > BHND_INFO_LEVEL95#define _BHND_PRINT(fn, level, fmt, ...) \96do { \97if (level##LEVEL < BHND_DEBUG_LEVEL || bootverbose) \98fn "[BHND " level##MSG "] %s:%d => " fmt "\n", \99__func__, __LINE__, ## __VA_ARGS__); \100} while(0);101#else /* BHND_LOGGING <= BHND_INFO_LEVEL */102#define _BHND_PRINT(fn, level, fmt, ...) \103do { \104if (level##LEVEL < BHND_DEBUG_LEVEL || bootverbose) \105fn "bhnd: " fmt "\n", ## __VA_ARGS__); \106} while(0);107#endif /* BHND_LOGGING > BHND_INFO_LEVEL */108109#define _BHND_RAWPRINTFN printf(110#define _BHND_DEVPRINTFN(dev) device_printf(dev,111112#define _BHND_LOGPRINT(level, fmt, ...) \113_BHND_PRINT(_BHND_RAWPRINTFN, level, fmt, ## __VA_ARGS__)114#define _BHND_DEVPRINT(dev, level, fmt, ...) \115_BHND_PRINT(_BHND_DEVPRINTFN(dev), level, fmt, ## __VA_ARGS__)116117#define BHND_ERROR(fmt, ...) \118_BHND_LOGPRINT(BHND_ERROR_, fmt, ## __VA_ARGS__);119#define BHND_ERROR_DEV(dev, fmt, ...) \120_BHND_DEVPRINT(dev, BHND_ERROR_, fmt, ## __VA_ARGS__)121122#if BHND_LOGGING >= BHND_WARN_LEVEL123#define BHND_WARN(fmt, ...) \124_BHND_LOGPRINT(BHND_WARN_, fmt, ## __VA_ARGS__)125#define BHND_WARN_DEV(dev, fmt, ...) \126_BHND_DEVPRINT(dev, BHND_WARN_, fmt, ## __VA_ARGS__)127128#if BHND_LOGGING >= BHND_INFO_LEVEL129#define BHND_INFO(fmt, ...) \130_BHND_LOGPRINT(BHND_INFO_, fmt, ## __VA_ARGS__)131#define BHND_INFO_DEV(dev, fmt, ...) \132_BHND_DEVPRINT(dev, BHND_INFO_, fmt, ## __VA_ARGS__)133134#if BHND_LOGGING >= BHND_DEBUG_LEVEL135#define BHND_DEBUG(fmt, ...) \136_BHND_LOGPRINT(BHND_DEBUG_, fmt, ## __VA_ARGS__)137#define BHND_DEBUG_DEV(dev, fmt, ...) \138_BHND_DEVPRINT(dev, BHND_DEBUG_, fmt, ## __VA_ARGS__)139140#if BHND_LOGGING >= BHND_TRACE_LEVEL141#define BHND_TRACE(fmt, ...) \142_BHND_LOGPRINT(BHND_TRACE_, fmt, ## __VA_ARGS__)143#define BHND_TRACE_DEV(dev, fmt, ...) \144_BHND_DEVPRINT(dev, BHND_TRACE_, fmt, ## __VA_ARGS__)145146#endif /* BHND_LOGGING >= BHND_TRACE_LEVEL */147#endif /* BHND_LOGGING >= BHND_DEBUG_LEVEL */148#endif /* BHND_LOGGING >= BHND_INFO_LEVEL */149#endif /* BHND_LOGGING >= BHND_WARN_LEVEL */150151/*152* Empty defines without device context153*/154#if !(defined(BHND_WARN))155#define BHND_WARN(fmt, ...);156#endif157158#if !(defined(BHND_INFO))159#define BHND_INFO(fmt, ...);160#endif161162#if !(defined(BHND_DEBUG))163#define BHND_DEBUG(fmt, ...);164#endif165166#if !(defined(BHND_TRACE))167#define BHND_TRACE(fmt, ...);168#endif169170/*171* Empty defines with device context172*/173#if !(defined(BHND_WARN_DEV))174#define BHND_WARN_DEV(dev, fmt, ...);175#endif176177#if !(defined(BHND_INFO_DEV))178#define BHND_INFO_DEV(dev, fmt, ...);179#endif180181#if !(defined(BHND_DEBUG_DEV))182#define BHND_DEBUG_DEV(dev, fmt, ...);183#endif184185#if !(defined(BHND_TRACE_DEV))186#define BHND_TRACE_DEV(dev, fmt, ...);187#endif188189#endif /* _BHND_BHND_DEBUG_H_ */190191192