xref: /freebsd/sys/dev/isci/isci_logger.c (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * BSD LICENSE
5  *
6  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  *   * Redistributions of source code must retain the above copyright
14  *     notice, this list of conditions and the following disclaimer.
15  *   * Redistributions in binary form must reproduce the above copyright
16  *     notice, this list of conditions and the following disclaimer in
17  *     the documentation and/or other materials provided with the
18  *     distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35 
36 #include <dev/isci/isci.h>
37 
38 #include <dev/isci/scil/scif_user_callback.h>
39 #include <dev/isci/scil/scic_user_callback.h>
40 #include <dev/isci/scil/sci_logger.h>
41 
42 #include <machine/stdarg.h>
43 #include <sys/time.h>
44 
45 #define ERROR_LEVEL	0
46 #define WARNING_LEVEL	1
47 #define TRACE_LEVEL	2
48 #define INFO_LEVEL	3
49 
50 void
51 isci_log_message(uint32_t verbosity, char *log_message_prefix,
52     char *log_message, ...)
53 {
54 	va_list argp;
55 	char buffer[512];
56 	struct timeval tv;
57 
58 	if (verbosity > g_isci_debug_level)
59 		return;
60 
61 	va_start (argp, log_message);
62 	vsnprintf(buffer, sizeof(buffer)-1, log_message, argp);
63 	va_end(argp);
64 	microtime(&tv);
65 
66 	printf("isci: %d:%06d %s %s", (int)tv.tv_sec, (int)tv.tv_usec,
67 	    log_message_prefix, buffer);
68 }
69 
70 
71 #ifdef SCI_LOGGING
72 #define SCI_ENABLE_LOGGING_ERROR	1
73 #define SCI_ENABLE_LOGGING_WARNING	1
74 #define SCI_ENABLE_LOGGING_INFO		1
75 #define SCI_ENABLE_LOGGING_TRACE	1
76 #define SCI_ENABLE_LOGGING_STATES	1
77 
78 #define ISCI_LOG_MESSAGE(			\
79 	logger_object,				\
80 	log_object_mask,			\
81 	log_message,				\
82 	verbosity,				\
83 	log_message_prefix			\
84 )						\
85 {						\
86 	va_list argp;				\
87 	char buffer[512];			\
88 						\
89 	if (!sci_logger_is_enabled(logger_object, log_object_mask, verbosity)) \
90 		return;				\
91 						\
92 	va_start (argp, log_message);		\
93 	vsnprintf(buffer, sizeof(buffer)-1, log_message, argp); \
94 	va_end(argp);				\
95 						\
96 	/* prepend the "object:verbosity_level:" */ \
97 	isci_log_message(verbosity, log_message_prefix, buffer); \
98 }
99 #endif /* SCI_LOGGING */
100 
101 
102 #ifdef SCI_ENABLE_LOGGING_ERROR
103 /**
104  * @brief In this method the user is expected to log the supplied
105  *        error information.  The user must be capable of handling variable
106  *        length argument lists and should consider prepending the fact
107  *        that this is an error from the framework.
108  *
109  * @param[in]  logger_object This parameter specifies the logger object
110  *             associated with this message.
111  * @param[in]  log_object_mask This parameter specifies the log objects
112  *             for which this message is being generated.
113  * @param[in]  log_message This parameter specifies the message to be logged.
114  *
115  * @return none
116  */
117 void scif_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,
118     uint32_t log_object_mask, char *log_message, ...)
119 {
120 
121 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
122 	    SCI_LOG_VERBOSITY_ERROR, "FRAMEWORK: ERROR: ");
123 }
124 #endif
125 
126 #ifdef SCI_ENABLE_LOGGING_WARNING
127 /**
128  * @brief In this method the user is expected to log the supplied warning
129  *        information.  The user must be capable of handling variable
130  *        length argument lists and should consider prepending the fact
131  *        that this is a warning from the framework.
132  *
133  * @param[in]  logger_object This parameter specifies the logger object
134  *             associated with this message.
135  * @param[in]  log_object_mask This parameter specifies the log objects
136  *             for which this message is being generated.
137  * @param[in]  log_message This parameter specifies the message to be logged.
138  *
139  * @return none
140  */
141 void
142 scif_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,
143     uint32_t log_object_mask, char *log_message, ...)
144 {
145 
146 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
147 	    SCI_LOG_VERBOSITY_WARNING, "FRAMEWORK: WARNING: ");
148 }
149 #endif
150 
151 #ifdef SCI_ENABLE_LOGGING_INFO
152 /**
153  * @brief In this method the user is expected to log the supplied debug
154  *        information.  The user must be capable of handling variable
155  *        length argument lists and should consider prepending the fact
156  *        that this is a debug message from the framework.
157  *
158  * @param[in]  logger_object This parameter specifies the logger object
159  *             associated with this message.
160  * @param[in]  log_object_mask This parameter specifies the log objects
161  *             for which this message is being generated.
162  * @param[in]  log_message This parameter specifies the message to be logged.
163  *
164  * @return none
165  */
166 void
167 scif_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,
168     uint32_t log_object_mask, char *log_message, ...)
169 {
170 
171 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
172 	    SCI_LOG_VERBOSITY_INFO, "FRAMEWORK: INFO: ");
173 }
174 #endif
175 
176 #ifdef SCI_ENABLE_LOGGING_TRACE
177 /**
178  * @brief In this method the user is expected to log the supplied function
179  *        trace information.  The user must be capable of handling variable
180  *        length argument lists and should consider prepending the fact
181  *        that this is a function trace (i.e. entry/exit) message from the
182  *        framework.
183  *
184  * @param[in]  logger_object This parameter specifies the logger object
185  *             associated with this message.
186  * @param[in]  log_object_mask This parameter specifies the log objects
187  *             for which this message is being generated.
188  * @param[in]  log_message This parameter specifies the message to be logged.
189  *
190  * @return none
191  */
192 void
193 scif_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,
194     uint32_t log_object_mask, char *log_message, ...)
195 {
196 
197 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
198 	    SCI_LOG_VERBOSITY_TRACE, "FRAMEWORK: TRACE: ");
199 }
200 #endif
201 
202 #ifdef SCI_ENABLE_LOGGING_STATES
203 /**
204  * @brief In this method the user is expected to log the supplied function
205  *        state transition information.  The user must be capable of handling
206  *        variable length argument lists and should consider prepending the
207  *        fact that this is a function trace (i.e. entry/exit) message from
208  *        the framework.
209  *
210  * @param[in]  logger_object This parameter specifies the logger object
211  *             associated with this message.
212  * @param[in]  log_object_mask This parameter specifies the log objects
213  *             for which this message is being generated.
214  * @param[in]  log_message This parameter specifies the message to be logged.
215  *
216  * @return none
217  */
218 void
219 scif_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,
220     uint32_t log_object_mask, char *log_message, ...)
221 {
222 
223 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
224 	    SCI_LOG_VERBOSITY_STATES, "FRAMEWORK: STATE TRANSITION: ");
225 }
226 #endif
227 
228 #ifdef SCI_ENABLE_LOGGING_ERROR
229 /**
230  * @brief In this method the user is expected to log the supplied
231  *        error information.  The user must be capable of handling variable
232  *        length argument lists and should consider prepending the fact
233  *        that this is an error from the core.
234  *
235  * @param[in]  logger_object This parameter specifies the logger object
236  *             associated with this message.
237  * @param[in]  log_object_mask This parameter specifies the log objects
238  *             for which this message is being generated.
239  * @param[in]  log_message This parameter specifies the message to be logged.
240  *
241  * @return none
242  */
243 void
244 scic_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,
245     uint32_t log_object_mask, char *log_message, ...)
246 {
247 
248 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
249 	    SCI_LOG_VERBOSITY_ERROR, "CORE: ERROR: ");
250 }
251 #endif
252 
253 #ifdef SCI_ENABLE_LOGGING_WARNING
254 /**
255  * @brief In this method the user is expected to log the supplied warning
256  *        information.  The user must be capable of handling variable
257  *        length argument lists and should consider prepending the fact
258  *        that this is a warning from the core.
259  *
260  * @param[in]  logger_object This parameter specifies the logger object
261  *             associated with this message.
262  * @param[in]  log_object_mask This parameter specifies the log objects
263  *             for which this message is being generated.
264  * @param[in]  log_message This parameter specifies the message to be logged.
265  *
266  * @return none
267  */
268 void
269 scic_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,
270     uint32_t log_object_mask, char *log_message, ...)
271 {
272 
273 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
274 	    SCI_LOG_VERBOSITY_WARNING, "CORE: WARNING: ");
275 }
276 #endif
277 
278 #ifdef SCI_ENABLE_LOGGING_INFO
279 /**
280  * @brief In this method the user is expected to log the supplied debug
281  *        information.  The user must be capable of handling variable
282  *        length argument lists and should consider prepending the fact
283  *        that this is a debug message from the core.
284  *
285  * @param[in]  logger_object This parameter specifies the logger object
286  *             associated with this message.
287  * @param[in]  log_object_mask This parameter specifies the log objects
288  *             for which this message is being generated.
289  * @param[in]  log_message This parameter specifies the message to be logged.
290  *
291  * @return none
292  */
293 void
294 scic_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,
295     uint32_t log_object_mask, char *log_message, ...)
296 {
297 
298 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
299 	    SCI_LOG_VERBOSITY_INFO, "CORE: INFO: ");
300 }
301 #endif
302 
303 #ifdef SCI_ENABLE_LOGGING_TRACE
304 /**
305  * @brief In this method the user is expected to log the supplied function
306  *        trace information.  The user must be capable of handling variable
307  *        length argument lists and should consider prepending the fact
308  *        that this is a function trace (i.e. entry/exit) message from the
309  *        core.
310  *
311  * @param[in]  logger_object This parameter specifies the logger object
312  *             associated with this message.
313  * @param[in]  log_object_mask This parameter specifies the log objects
314  *             for which this message is being generated.
315  * @param[in]  log_message This parameter specifies the message to be logged.
316  *
317  * @return none
318  */
319 void
320 scic_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,
321     uint32_t log_object_mask, char *log_message, ...)
322 {
323 
324 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
325 	    SCI_LOG_VERBOSITY_TRACE, "CORE: TRACE: ");
326 }
327 #endif
328 
329 #ifdef SCI_ENABLE_LOGGING_STATES
330 /**
331  * @brief In this method the user is expected to log the supplied function
332  *        state transition information.  The user must be capable of handling
333  *        variable length argument lists and should consider prepending the
334  *        fact that this is a function trace (i.e. entry/exit) message from
335  *        the core.
336  *
337  * @param[in]  logger_object This parameter specifies the logger object
338  *             associated with this message.
339  * @param[in]  log_object_mask This parameter specifies the log objects
340  *             for which this message is being generated.
341  * @param[in]  log_message This parameter specifies the message to be logged.
342  *
343  * @return none
344  */
345 void
346 scic_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,
347     uint32_t log_object_mask, char *log_message, ...)
348 {
349 
350 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
351 	    SCI_LOG_VERBOSITY_STATES, "CORE: STATE TRANSITION: ");
352 }
353 #endif
354