aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/bhnd/bhnd_debug.h
blob: 312851175867696a1b110479caa5ee699ed6c136 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*-
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
 *
 * 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>

#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_ */