xref: /freebsd/sys/dev/isci/isci_logger.c (revision 685dc743)
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 #include <dev/isci/isci.h>
35 
36 #include <dev/isci/scil/scif_user_callback.h>
37 #include <dev/isci/scil/scic_user_callback.h>
38 #include <dev/isci/scil/sci_logger.h>
39 
40 #include <machine/stdarg.h>
41 #include <sys/time.h>
42 
43 #define ERROR_LEVEL	0
44 #define WARNING_LEVEL	1
45 #define TRACE_LEVEL	2
46 #define INFO_LEVEL	3
47 
48 void
isci_log_message(uint32_t verbosity,char * log_message_prefix,char * log_message,...)49 isci_log_message(uint32_t verbosity, char *log_message_prefix,
50     char *log_message, ...)
51 {
52 	va_list argp;
53 	char buffer[512];
54 	struct timeval tv;
55 
56 	if (verbosity > g_isci_debug_level)
57 		return;
58 
59 	va_start (argp, log_message);
60 	vsnprintf(buffer, sizeof(buffer)-1, log_message, argp);
61 	va_end(argp);
62 	microtime(&tv);
63 
64 	printf("isci: %d:%06d %s %s", (int)tv.tv_sec, (int)tv.tv_usec,
65 	    log_message_prefix, buffer);
66 }
67 
68 
69 #ifdef SCI_LOGGING
70 #define SCI_ENABLE_LOGGING_ERROR	1
71 #define SCI_ENABLE_LOGGING_WARNING	1
72 #define SCI_ENABLE_LOGGING_INFO		1
73 #define SCI_ENABLE_LOGGING_TRACE	1
74 #define SCI_ENABLE_LOGGING_STATES	1
75 
76 #define ISCI_LOG_MESSAGE(			\
77 	logger_object,				\
78 	log_object_mask,			\
79 	log_message,				\
80 	verbosity,				\
81 	log_message_prefix			\
82 )						\
83 {						\
84 	va_list argp;				\
85 	char buffer[512];			\
86 						\
87 	if (!sci_logger_is_enabled(logger_object, log_object_mask, verbosity)) \
88 		return;				\
89 						\
90 	va_start (argp, log_message);		\
91 	vsnprintf(buffer, sizeof(buffer)-1, log_message, argp); \
92 	va_end(argp);				\
93 						\
94 	/* prepend the "object:verbosity_level:" */ \
95 	isci_log_message(verbosity, log_message_prefix, buffer); \
96 }
97 #endif /* SCI_LOGGING */
98 
99 
100 #ifdef SCI_ENABLE_LOGGING_ERROR
101 /**
102  * @brief In this method the user is expected to log the supplied
103  *        error information.  The user must be capable of handling variable
104  *        length argument lists and should consider prepending the fact
105  *        that this is an error from the framework.
106  *
107  * @param[in]  logger_object This parameter specifies the logger object
108  *             associated with this message.
109  * @param[in]  log_object_mask This parameter specifies the log objects
110  *             for which this message is being generated.
111  * @param[in]  log_message This parameter specifies the message to be logged.
112  *
113  * @return none
114  */
scif_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)115 void scif_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,
116     uint32_t log_object_mask, char *log_message, ...)
117 {
118 
119 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
120 	    SCI_LOG_VERBOSITY_ERROR, "FRAMEWORK: ERROR: ");
121 }
122 #endif
123 
124 #ifdef SCI_ENABLE_LOGGING_WARNING
125 /**
126  * @brief In this method the user is expected to log the supplied warning
127  *        information.  The user must be capable of handling variable
128  *        length argument lists and should consider prepending the fact
129  *        that this is a warning from the framework.
130  *
131  * @param[in]  logger_object This parameter specifies the logger object
132  *             associated with this message.
133  * @param[in]  log_object_mask This parameter specifies the log objects
134  *             for which this message is being generated.
135  * @param[in]  log_message This parameter specifies the message to be logged.
136  *
137  * @return none
138  */
139 void
scif_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)140 scif_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,
141     uint32_t log_object_mask, char *log_message, ...)
142 {
143 
144 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
145 	    SCI_LOG_VERBOSITY_WARNING, "FRAMEWORK: WARNING: ");
146 }
147 #endif
148 
149 #ifdef SCI_ENABLE_LOGGING_INFO
150 /**
151  * @brief In this method the user is expected to log the supplied debug
152  *        information.  The user must be capable of handling variable
153  *        length argument lists and should consider prepending the fact
154  *        that this is a debug message from the framework.
155  *
156  * @param[in]  logger_object This parameter specifies the logger object
157  *             associated with this message.
158  * @param[in]  log_object_mask This parameter specifies the log objects
159  *             for which this message is being generated.
160  * @param[in]  log_message This parameter specifies the message to be logged.
161  *
162  * @return none
163  */
164 void
scif_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)165 scif_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,
166     uint32_t log_object_mask, char *log_message, ...)
167 {
168 
169 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
170 	    SCI_LOG_VERBOSITY_INFO, "FRAMEWORK: INFO: ");
171 }
172 #endif
173 
174 #ifdef SCI_ENABLE_LOGGING_TRACE
175 /**
176  * @brief In this method the user is expected to log the supplied function
177  *        trace information.  The user must be capable of handling variable
178  *        length argument lists and should consider prepending the fact
179  *        that this is a function trace (i.e. entry/exit) message from the
180  *        framework.
181  *
182  * @param[in]  logger_object This parameter specifies the logger object
183  *             associated with this message.
184  * @param[in]  log_object_mask This parameter specifies the log objects
185  *             for which this message is being generated.
186  * @param[in]  log_message This parameter specifies the message to be logged.
187  *
188  * @return none
189  */
190 void
scif_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)191 scif_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,
192     uint32_t log_object_mask, char *log_message, ...)
193 {
194 
195 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
196 	    SCI_LOG_VERBOSITY_TRACE, "FRAMEWORK: TRACE: ");
197 }
198 #endif
199 
200 #ifdef SCI_ENABLE_LOGGING_STATES
201 /**
202  * @brief In this method the user is expected to log the supplied function
203  *        state transition information.  The user must be capable of handling
204  *        variable length argument lists and should consider prepending the
205  *        fact that this is a function trace (i.e. entry/exit) message from
206  *        the framework.
207  *
208  * @param[in]  logger_object This parameter specifies the logger object
209  *             associated with this message.
210  * @param[in]  log_object_mask This parameter specifies the log objects
211  *             for which this message is being generated.
212  * @param[in]  log_message This parameter specifies the message to be logged.
213  *
214  * @return none
215  */
216 void
scif_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)217 scif_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,
218     uint32_t log_object_mask, char *log_message, ...)
219 {
220 
221 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
222 	    SCI_LOG_VERBOSITY_STATES, "FRAMEWORK: STATE TRANSITION: ");
223 }
224 #endif
225 
226 #ifdef SCI_ENABLE_LOGGING_ERROR
227 /**
228  * @brief In this method the user is expected to log the supplied
229  *        error information.  The user must be capable of handling variable
230  *        length argument lists and should consider prepending the fact
231  *        that this is an error from the core.
232  *
233  * @param[in]  logger_object This parameter specifies the logger object
234  *             associated with this message.
235  * @param[in]  log_object_mask This parameter specifies the log objects
236  *             for which this message is being generated.
237  * @param[in]  log_message This parameter specifies the message to be logged.
238  *
239  * @return none
240  */
241 void
scic_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)242 scic_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,
243     uint32_t log_object_mask, char *log_message, ...)
244 {
245 
246 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
247 	    SCI_LOG_VERBOSITY_ERROR, "CORE: ERROR: ");
248 }
249 #endif
250 
251 #ifdef SCI_ENABLE_LOGGING_WARNING
252 /**
253  * @brief In this method the user is expected to log the supplied warning
254  *        information.  The user must be capable of handling variable
255  *        length argument lists and should consider prepending the fact
256  *        that this is a warning from the core.
257  *
258  * @param[in]  logger_object This parameter specifies the logger object
259  *             associated with this message.
260  * @param[in]  log_object_mask This parameter specifies the log objects
261  *             for which this message is being generated.
262  * @param[in]  log_message This parameter specifies the message to be logged.
263  *
264  * @return none
265  */
266 void
scic_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)267 scic_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,
268     uint32_t log_object_mask, char *log_message, ...)
269 {
270 
271 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
272 	    SCI_LOG_VERBOSITY_WARNING, "CORE: WARNING: ");
273 }
274 #endif
275 
276 #ifdef SCI_ENABLE_LOGGING_INFO
277 /**
278  * @brief In this method the user is expected to log the supplied debug
279  *        information.  The user must be capable of handling variable
280  *        length argument lists and should consider prepending the fact
281  *        that this is a debug message from the core.
282  *
283  * @param[in]  logger_object This parameter specifies the logger object
284  *             associated with this message.
285  * @param[in]  log_object_mask This parameter specifies the log objects
286  *             for which this message is being generated.
287  * @param[in]  log_message This parameter specifies the message to be logged.
288  *
289  * @return none
290  */
291 void
scic_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)292 scic_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,
293     uint32_t log_object_mask, char *log_message, ...)
294 {
295 
296 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
297 	    SCI_LOG_VERBOSITY_INFO, "CORE: INFO: ");
298 }
299 #endif
300 
301 #ifdef SCI_ENABLE_LOGGING_TRACE
302 /**
303  * @brief In this method the user is expected to log the supplied function
304  *        trace information.  The user must be capable of handling variable
305  *        length argument lists and should consider prepending the fact
306  *        that this is a function trace (i.e. entry/exit) message from the
307  *        core.
308  *
309  * @param[in]  logger_object This parameter specifies the logger object
310  *             associated with this message.
311  * @param[in]  log_object_mask This parameter specifies the log objects
312  *             for which this message is being generated.
313  * @param[in]  log_message This parameter specifies the message to be logged.
314  *
315  * @return none
316  */
317 void
scic_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)318 scic_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,
319     uint32_t log_object_mask, char *log_message, ...)
320 {
321 
322 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
323 	    SCI_LOG_VERBOSITY_TRACE, "CORE: TRACE: ");
324 }
325 #endif
326 
327 #ifdef SCI_ENABLE_LOGGING_STATES
328 /**
329  * @brief In this method the user is expected to log the supplied function
330  *        state transition information.  The user must be capable of handling
331  *        variable length argument lists and should consider prepending the
332  *        fact that this is a function trace (i.e. entry/exit) message from
333  *        the core.
334  *
335  * @param[in]  logger_object This parameter specifies the logger object
336  *             associated with this message.
337  * @param[in]  log_object_mask This parameter specifies the log objects
338  *             for which this message is being generated.
339  * @param[in]  log_message This parameter specifies the message to be logged.
340  *
341  * @return none
342  */
343 void
scic_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,uint32_t log_object_mask,char * log_message,...)344 scic_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,
345     uint32_t log_object_mask, char *log_message, ...)
346 {
347 
348 	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
349 	    SCI_LOG_VERBOSITY_STATES, "CORE: STATE TRANSITION: ");
350 }
351 #endif
352