aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAdrian Chadd <adrian@FreeBSD.org>2016-05-16 23:40:32 +0000
committerAdrian Chadd <adrian@FreeBSD.org>2016-05-16 23:40:32 +0000
commitfb403678c2d93baa95731c739128a29afb757779 (patch)
treed32792372e5c129d7b6238443ea1ca2114131d19 /sys
parent9d8ae244a39ce1f32774ddfe9cb61dd58d84a814 (diff)
downloadsrc-fb403678c2d93baa95731c739128a29afb757779.tar.gz
src-fb403678c2d93baa95731c739128a29afb757779.zip
[bhnd] Add logging macros to BHND.
There are 5 logging levels: * ERROR * WARN * INFO * DEBUG * TRACE There are 2 logging context: * with * without device DEBUG and TRACE records are printed only if bootverbose. Logging records are printed with source code line information if acceptable logging level is DEBUG or TRACE. Submitted by: Michael Zhilin <mizhka@gmail.com> Differential Revision: https://reviews.freebsd.org/D6247
Notes
Notes: svn path=/head/; revision=299990
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/NOTES3
-rw-r--r--sys/conf/options3
-rw-r--r--sys/dev/bhnd/bhnd.h1
-rw-r--r--sys/dev/bhnd/bhnd_debug.h192
4 files changed, 199 insertions, 0 deletions
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
index 45732dac2673..cdcae45ba685 100644
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -3061,3 +3061,6 @@ options EM_MULTIQUEUE # Activate multiqueue features/disable MSI-X
# zlib I/O stream support
# This enables support for compressed core dumps.
options GZIO
+
+# BHND(4) drivers
+options BHND_LOGLEVEL # Logging threshold level \ No newline at end of file
diff --git a/sys/conf/options b/sys/conf/options
index 87d056569989..6e6b9de3ff83 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -979,3 +979,6 @@ RANDOM_ENABLE_UMA opt_global.h
# Intel em(4) driver
EM_MULTIQUEUE opt_em.h
+
+# BHND(4) driver
+BHND_LOGLEVEL opt_global.h
diff --git a/sys/dev/bhnd/bhnd.h b/sys/dev/bhnd/bhnd.h
index 6abdf2f156c4..9011d89e9fab 100644
--- a/sys/dev/bhnd/bhnd.h
+++ b/sys/dev/bhnd/bhnd.h
@@ -39,6 +39,7 @@
#include "bhnd_ids.h"
#include "bhnd_types.h"
+#include "bhnd_debug.h"
#include "bhnd_bus_if.h"
extern devclass_t bhnd_devclass;
diff --git a/sys/dev/bhnd/bhnd_debug.h b/sys/dev/bhnd/bhnd_debug.h
new file mode 100644
index 000000000000..dfe0bd2623dd
--- /dev/null
+++ b/sys/dev/bhnd/bhnd_debug.h
@@ -0,0 +1,192 @@
+/*-
+ * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+/* $FreeBSD$ */
+
+/*
+ * This file provides set of macros for logging:
+ * - BHND_<LEVEL> and
+ * - BHND_<LEVEL>_DEV
+ * where LEVEL = {ERROR,WARN,INFO,DEBUG}
+ *
+ * BHND_<LEVEL> macros is proxies to printf call and accept same parameters,
+ * for instance:
+ * BHND_INFO("register %d has value %d", reg, val);
+ *
+ * BHND_<LEVEL>_DEV macros is proxies to device_printf call and accept
+ * same parameters, for instance:
+ * BHND_INFO_DEV(dev, "register %d has value %d", reg, val);
+ *
+ * All macros contains newline char at the end of each call
+ *
+ * ERROR, WARN, INFO messages are printed only if:
+ * - log message level is lower than BHND_LOGGING (logging threshold)
+ *
+ * DEBUG, TRACE messages are printed only if:
+ * - bootverbose and
+ * - log message level is lower than BHND_LOGGING (logging threshold)
+ *
+ * In addition, for debugging purpose log message contains information about
+ * file name and line number if BHND_LOGGING is more than BHND_INFO_LEVEL
+ *
+ * NOTE: macros starting with underscore (_) are private and should be not used
+ *
+ * To override logging (for instance, force tracing), you can use:
+ * - "options BHND_LOGLEVEL=BHND_TRACE_LEVEL" in kernel configuration
+ * - "#define BHND_LOGGING BHND_TRACE_LEVEL" in source code file
+ *
+ * NOTE: kernel config option doesn't override log level defined on file level,
+ * so try to avoid "#define BHND_LOGGING"
+ */
+
+#ifndef _BHND_BHND_DEBUG_H_
+#define _BHND_BHND_DEBUG_H_
+
+#include <sys/systm.h>
+
+#include "opt_global.h"
+
+#define BHND_ERROR_LEVEL 0x00
+#define BHND_ERROR_MSG "ERROR"
+#define BHND_WARN_LEVEL 0x10
+#define BHND_WARN_MSG "!WARN"
+#define BHND_INFO_LEVEL 0x20
+#define BHND_INFO_MSG " info"
+#define BHND_DEBUG_LEVEL 0x30
+#define BHND_DEBUG_MSG "debug"
+#define BHND_TRACE_LEVEL 0x40
+#define BHND_TRACE_MSG "trace"
+
+#if !(defined(BHND_LOGGING))
+#if !(defined(BHND_LOGLEVEL))
+/* By default logging will print only INFO+ message*/
+#define BHND_LOGGING BHND_INFO_LEVEL
+#else /* defined(BHND_LOGLEVEL) */
+/* Kernel configuration specifies logging level */
+#define BHND_LOGGING BHND_LOGLEVEL
+#endif /* !(defined(BHND_LOGLEVEL)) */
+#endif /* !(defined(BHND_LOGGING)) */
+
+#if BHND_LOGGING > BHND_INFO_LEVEL
+#define _BHND_PRINT(fn, level, fmt, ...) \
+ do { \
+ if (level##LEVEL < BHND_DEBUG_LEVEL || bootverbose) \
+ fn "[BHND " level##MSG "] %s:%d => " fmt "\n", \
+ __func__, __LINE__, ## __VA_ARGS__); \
+ } while(0);
+#else /* BHND_LOGGING <= BHND_INFO_LEVEL */
+#define _BHND_PRINT(fn, level, fmt, ...) \
+ do { \
+ if (level##LEVEL < BHND_DEBUG_LEVEL || bootverbose) \
+ fn "bhnd: " fmt "\n", ## __VA_ARGS__); \
+ } while(0);
+#endif /* BHND_LOGGING > BHND_INFO_LEVEL */
+
+
+#define _BHND_RAWPRINTFN printf(
+#define _BHND_DEVPRINTFN(dev) device_printf(dev,
+
+#define _BHND_LOGPRINT(level, fmt, ...) \
+ _BHND_PRINT(_BHND_RAWPRINTFN, level, fmt, ## __VA_ARGS__)
+#define _BHND_DEVPRINT(dev, level, fmt, ...) \
+ _BHND_PRINT(_BHND_DEVPRINTFN(dev), level, fmt, ## __VA_ARGS__)
+
+#define BHND_ERROR(fmt, ...) \
+ _BHND_LOGPRINT(BHND_ERROR_, fmt, ## __VA_ARGS__);
+#define BHND_ERROR_DEV(dev, fmt, ...) \
+ _BHND_DEVPRINT(dev, BHND_ERROR_, fmt, ## __VA_ARGS__)
+
+#if BHND_LOGGING >= BHND_WARN_LEVEL
+#define BHND_WARN(fmt, ...) \
+ _BHND_LOGPRINT(BHND_WARN_, fmt, ## __VA_ARGS__)
+#define BHND_WARN_DEV(dev, fmt, ...) \
+ _BHND_DEVPRINT(dev, BHND_WARN_, fmt, ## __VA_ARGS__)
+
+#if BHND_LOGGING >= BHND_INFO_LEVEL
+#define BHND_INFO(fmt, ...) \
+ _BHND_LOGPRINT(BHND_INFO_, fmt, ## __VA_ARGS__)
+#define BHND_INFO_DEV(dev, fmt, ...) \
+ _BHND_DEVPRINT(dev, BHND_INFO_, fmt, ## __VA_ARGS__)
+
+#if BHND_LOGGING >= BHND_DEBUG_LEVEL
+#define BHND_DEBUG(fmt, ...) \
+ _BHND_LOGPRINT(BHND_DEBUG_, fmt, ## __VA_ARGS__)
+#define BHND_DEBUG_DEV(dev, fmt, ...) \
+ _BHND_DEVPRINT(dev, BHND_DEBUG_, fmt, ## __VA_ARGS__)
+
+#if BHND_LOGGING >= BHND_TRACE_LEVEL
+#define BHND_TRACE(fmt, ...) \
+ _BHND_LOGPRINT(BHND_TRACE_, fmt, ## __VA_ARGS__)
+#define BHND_TRACE_DEV(dev, fmt, ...) \
+ _BHND_DEVPRINT(dev, BHND_TRACE_, fmt, ## __VA_ARGS__)
+
+#endif /* BHND_LOGGING >= BHND_TRACE_LEVEL */
+#endif /* BHND_LOGGING >= BHND_DEBUG_LEVEL */
+#endif /* BHND_LOGGING >= BHND_INFO_LEVEL */
+#endif /* BHND_LOGGING >= BHND_WARN_LEVEL */
+
+/*
+ * Empty defines without device context
+ */
+#if !(defined(BHND_WARN))
+#define BHND_WARN(fmt, ...);
+#endif
+
+#if !(defined(BHND_INFO))
+#define BHND_INFO(fmt, ...);
+#endif
+
+#if !(defined(BHND_DEBUG))
+#define BHND_DEBUG(fmt, ...);
+#endif
+
+#if !(defined(BHND_TRACE))
+#define BHND_TRACE(fmt, ...);
+#endif
+
+/*
+ * Empty defines with device context
+ */
+#if !(defined(BHND_WARN_DEV))
+#define BHND_WARN_DEV(dev, fmt, ...);
+#endif
+
+#if !(defined(BHND_INFO_DEV))
+#define BHND_INFO_DEV(dev, fmt, ...);
+#endif
+
+#if !(defined(BHND_DEBUG_DEV))
+#define BHND_DEBUG_DEV(dev, fmt, ...);
+#endif
+
+#if !(defined(BHND_TRACE_DEV))
+#define BHND_TRACE_DEV(dev, fmt, ...);
+#endif
+
+#endif /* _BHND_BHND_DEBUG_H_ */