1230557Sjimharris/*-
2230557Sjimharris * BSD LICENSE
3230557Sjimharris *
4230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
5230557Sjimharris * All rights reserved.
6230557Sjimharris *
7230557Sjimharris * Redistribution and use in source and binary forms, with or without
8230557Sjimharris * modification, are permitted provided that the following conditions
9230557Sjimharris * are met:
10230557Sjimharris *
11230557Sjimharris *   * Redistributions of source code must retain the above copyright
12230557Sjimharris *     notice, this list of conditions and the following disclaimer.
13230557Sjimharris *   * Redistributions in binary form must reproduce the above copyright
14230557Sjimharris *     notice, this list of conditions and the following disclaimer in
15230557Sjimharris *     the documentation and/or other materials provided with the
16230557Sjimharris *     distribution.
17230557Sjimharris *
18230557Sjimharris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19230557Sjimharris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20230557Sjimharris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21230557Sjimharris * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22230557Sjimharris * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23230557Sjimharris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24230557Sjimharris * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25230557Sjimharris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26230557Sjimharris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27230557Sjimharris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28230557Sjimharris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29230557Sjimharris */
30230557Sjimharris
31230557Sjimharris#include <sys/cdefs.h>
32230557Sjimharris__FBSDID("$FreeBSD$");
33230557Sjimharris
34230557Sjimharris#include <dev/isci/isci.h>
35230557Sjimharris
36230557Sjimharris#include <dev/isci/scil/scif_user_callback.h>
37230557Sjimharris#include <dev/isci/scil/scic_user_callback.h>
38230557Sjimharris#include <dev/isci/scil/sci_logger.h>
39230557Sjimharris
40230557Sjimharris#include <machine/stdarg.h>
41230557Sjimharris#include <sys/time.h>
42230557Sjimharris
43230557Sjimharris#define ERROR_LEVEL	0
44230557Sjimharris#define WARNING_LEVEL	1
45230557Sjimharris#define TRACE_LEVEL	2
46230557Sjimharris#define INFO_LEVEL	3
47230557Sjimharris
48230557Sjimharrisvoid
49230557Sjimharrisisci_log_message(uint32_t verbosity, char *log_message_prefix,
50230557Sjimharris    char *log_message, ...)
51230557Sjimharris{
52230557Sjimharris	va_list argp;
53230557Sjimharris	char buffer[512];
54230557Sjimharris	struct timeval tv;
55230557Sjimharris
56230557Sjimharris	if (verbosity > g_isci_debug_level)
57230557Sjimharris		return;
58230557Sjimharris
59230557Sjimharris	va_start (argp, log_message);
60230557Sjimharris	vsnprintf(buffer, sizeof(buffer)-1, log_message, argp);
61230557Sjimharris	va_end(argp);
62230557Sjimharris	microtime(&tv);
63230557Sjimharris
64230557Sjimharris	printf("isci: %d:%06d %s %s", (int)tv.tv_sec, (int)tv.tv_usec,
65230557Sjimharris	    log_message_prefix, buffer);
66230557Sjimharris}
67230557Sjimharris
68230557Sjimharris
69230557Sjimharris#ifdef SCI_LOGGING
70230557Sjimharris#define SCI_ENABLE_LOGGING_ERROR	1
71230557Sjimharris#define SCI_ENABLE_LOGGING_WARNING	1
72230557Sjimharris#define SCI_ENABLE_LOGGING_INFO		1
73230557Sjimharris#define SCI_ENABLE_LOGGING_TRACE	1
74230557Sjimharris#define SCI_ENABLE_LOGGING_STATES	1
75230557Sjimharris
76230557Sjimharris#define ISCI_LOG_MESSAGE(			\
77230557Sjimharris	logger_object,				\
78230557Sjimharris	log_object_mask,			\
79230557Sjimharris	log_message,				\
80230557Sjimharris	verbosity,				\
81230557Sjimharris	log_message_prefix			\
82230557Sjimharris)						\
83230557Sjimharris{						\
84230557Sjimharris	va_list argp;				\
85230557Sjimharris	char buffer[512];			\
86230557Sjimharris						\
87230557Sjimharris	if (!sci_logger_is_enabled(logger_object, log_object_mask, verbosity)) \
88230557Sjimharris		return;				\
89230557Sjimharris						\
90230557Sjimharris	va_start (argp, log_message);		\
91230557Sjimharris	vsnprintf(buffer, sizeof(buffer)-1, log_message, argp); \
92230557Sjimharris	va_end(argp);				\
93230557Sjimharris						\
94230557Sjimharris	/* prepend the "object:verbosity_level:" */ \
95230557Sjimharris	isci_log_message(verbosity, log_message_prefix, buffer); \
96230557Sjimharris}
97230557Sjimharris#endif /* SCI_LOGGING */
98230557Sjimharris
99230557Sjimharris
100230557Sjimharris#ifdef SCI_ENABLE_LOGGING_ERROR
101230557Sjimharris/**
102230557Sjimharris * @brief In this method the user is expected to log the supplied
103230557Sjimharris *        error information.  The user must be capable of handling variable
104230557Sjimharris *        length argument lists and should consider prepending the fact
105230557Sjimharris *        that this is an error from the framework.
106230557Sjimharris *
107230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
108230557Sjimharris *             associated with this message.
109230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
110230557Sjimharris *             for which this message is being generated.
111230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
112230557Sjimharris *
113230557Sjimharris * @return none
114230557Sjimharris */
115230557Sjimharrisvoid scif_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,
116230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
117230557Sjimharris{
118230557Sjimharris
119230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
120230557Sjimharris	    SCI_LOG_VERBOSITY_ERROR, "FRAMEWORK: ERROR: ");
121230557Sjimharris}
122230557Sjimharris#endif
123230557Sjimharris
124230557Sjimharris#ifdef SCI_ENABLE_LOGGING_WARNING
125230557Sjimharris/**
126230557Sjimharris * @brief In this method the user is expected to log the supplied warning
127230557Sjimharris *        information.  The user must be capable of handling variable
128230557Sjimharris *        length argument lists and should consider prepending the fact
129230557Sjimharris *        that this is a warning from the framework.
130230557Sjimharris *
131230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
132230557Sjimharris *             associated with this message.
133230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
134230557Sjimharris *             for which this message is being generated.
135230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
136230557Sjimharris *
137230557Sjimharris * @return none
138230557Sjimharris */
139230557Sjimharrisvoid
140230557Sjimharrisscif_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,
141230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
142230557Sjimharris{
143230557Sjimharris
144230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
145230557Sjimharris	    SCI_LOG_VERBOSITY_WARNING, "FRAMEWORK: WARNING: ");
146230557Sjimharris}
147230557Sjimharris#endif
148230557Sjimharris
149230557Sjimharris#ifdef SCI_ENABLE_LOGGING_INFO
150230557Sjimharris/**
151230557Sjimharris * @brief In this method the user is expected to log the supplied debug
152230557Sjimharris *        information.  The user must be capable of handling variable
153230557Sjimharris *        length argument lists and should consider prepending the fact
154230557Sjimharris *        that this is a debug message from the framework.
155230557Sjimharris *
156230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
157230557Sjimharris *             associated with this message.
158230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
159230557Sjimharris *             for which this message is being generated.
160230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
161230557Sjimharris *
162230557Sjimharris * @return none
163230557Sjimharris */
164230557Sjimharrisvoid
165230557Sjimharrisscif_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,
166230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
167230557Sjimharris{
168230557Sjimharris
169230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
170230557Sjimharris	    SCI_LOG_VERBOSITY_INFO, "FRAMEWORK: INFO: ");
171230557Sjimharris}
172230557Sjimharris#endif
173230557Sjimharris
174230557Sjimharris#ifdef SCI_ENABLE_LOGGING_TRACE
175230557Sjimharris/**
176230557Sjimharris * @brief In this method the user is expected to log the supplied function
177230557Sjimharris *        trace information.  The user must be capable of handling variable
178230557Sjimharris *        length argument lists and should consider prepending the fact
179230557Sjimharris *        that this is a function trace (i.e. entry/exit) message from the
180230557Sjimharris *        framework.
181230557Sjimharris *
182230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
183230557Sjimharris *             associated with this message.
184230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
185230557Sjimharris *             for which this message is being generated.
186230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
187230557Sjimharris *
188230557Sjimharris * @return none
189230557Sjimharris */
190230557Sjimharrisvoid
191230557Sjimharrisscif_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,
192230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
193230557Sjimharris{
194230557Sjimharris
195230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
196230557Sjimharris	    SCI_LOG_VERBOSITY_TRACE, "FRAMEWORK: TRACE: ");
197230557Sjimharris}
198230557Sjimharris#endif
199230557Sjimharris
200230557Sjimharris#ifdef SCI_ENABLE_LOGGING_STATES
201230557Sjimharris/**
202230557Sjimharris * @brief In this method the user is expected to log the supplied function
203230557Sjimharris *        state transition information.  The user must be capable of handling
204230557Sjimharris *        variable length argument lists and should consider prepending the
205230557Sjimharris *        fact that this is a function trace (i.e. entry/exit) message from
206230557Sjimharris *        the framework.
207230557Sjimharris *
208230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
209230557Sjimharris *             associated with this message.
210230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
211230557Sjimharris *             for which this message is being generated.
212230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
213230557Sjimharris *
214230557Sjimharris * @return none
215230557Sjimharris */
216230557Sjimharrisvoid
217230557Sjimharrisscif_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,
218230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
219230557Sjimharris{
220230557Sjimharris
221230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
222230557Sjimharris	    SCI_LOG_VERBOSITY_STATES, "FRAMEWORK: STATE TRANSITION: ");
223230557Sjimharris}
224230557Sjimharris#endif
225230557Sjimharris
226230557Sjimharris#ifdef SCI_ENABLE_LOGGING_ERROR
227230557Sjimharris/**
228230557Sjimharris * @brief In this method the user is expected to log the supplied
229230557Sjimharris *        error information.  The user must be capable of handling variable
230230557Sjimharris *        length argument lists and should consider prepending the fact
231230557Sjimharris *        that this is an error from the core.
232230557Sjimharris *
233230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
234230557Sjimharris *             associated with this message.
235230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
236230557Sjimharris *             for which this message is being generated.
237230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
238230557Sjimharris *
239230557Sjimharris * @return none
240230557Sjimharris */
241230557Sjimharrisvoid
242230557Sjimharrisscic_cb_logger_log_error(SCI_LOGGER_HANDLE_T logger_object,
243230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
244230557Sjimharris{
245230557Sjimharris
246230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
247230557Sjimharris	    SCI_LOG_VERBOSITY_ERROR, "CORE: ERROR: ");
248230557Sjimharris}
249230557Sjimharris#endif
250230557Sjimharris
251230557Sjimharris#ifdef SCI_ENABLE_LOGGING_WARNING
252230557Sjimharris/**
253230557Sjimharris * @brief In this method the user is expected to log the supplied warning
254230557Sjimharris *        information.  The user must be capable of handling variable
255230557Sjimharris *        length argument lists and should consider prepending the fact
256230557Sjimharris *        that this is a warning from the core.
257230557Sjimharris *
258230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
259230557Sjimharris *             associated with this message.
260230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
261230557Sjimharris *             for which this message is being generated.
262230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
263230557Sjimharris *
264230557Sjimharris * @return none
265230557Sjimharris */
266230557Sjimharrisvoid
267230557Sjimharrisscic_cb_logger_log_warning(SCI_LOGGER_HANDLE_T logger_object,
268230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
269230557Sjimharris{
270230557Sjimharris
271230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
272230557Sjimharris	    SCI_LOG_VERBOSITY_WARNING, "CORE: WARNING: ");
273230557Sjimharris}
274230557Sjimharris#endif
275230557Sjimharris
276230557Sjimharris#ifdef SCI_ENABLE_LOGGING_INFO
277230557Sjimharris/**
278230557Sjimharris * @brief In this method the user is expected to log the supplied debug
279230557Sjimharris *        information.  The user must be capable of handling variable
280230557Sjimharris *        length argument lists and should consider prepending the fact
281230557Sjimharris *        that this is a debug message from the core.
282230557Sjimharris *
283230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
284230557Sjimharris *             associated with this message.
285230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
286230557Sjimharris *             for which this message is being generated.
287230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
288230557Sjimharris *
289230557Sjimharris * @return none
290230557Sjimharris */
291230557Sjimharrisvoid
292230557Sjimharrisscic_cb_logger_log_info(SCI_LOGGER_HANDLE_T logger_object,
293230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
294230557Sjimharris{
295230557Sjimharris
296230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
297230557Sjimharris	    SCI_LOG_VERBOSITY_INFO, "CORE: INFO: ");
298230557Sjimharris}
299230557Sjimharris#endif
300230557Sjimharris
301230557Sjimharris#ifdef SCI_ENABLE_LOGGING_TRACE
302230557Sjimharris/**
303230557Sjimharris * @brief In this method the user is expected to log the supplied function
304230557Sjimharris *        trace information.  The user must be capable of handling variable
305230557Sjimharris *        length argument lists and should consider prepending the fact
306230557Sjimharris *        that this is a function trace (i.e. entry/exit) message from the
307230557Sjimharris *        core.
308230557Sjimharris *
309230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
310230557Sjimharris *             associated with this message.
311230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
312230557Sjimharris *             for which this message is being generated.
313230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
314230557Sjimharris *
315230557Sjimharris * @return none
316230557Sjimharris */
317230557Sjimharrisvoid
318230557Sjimharrisscic_cb_logger_log_trace(SCI_LOGGER_HANDLE_T logger_object,
319230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
320230557Sjimharris{
321230557Sjimharris
322230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
323230557Sjimharris	    SCI_LOG_VERBOSITY_TRACE, "CORE: TRACE: ");
324230557Sjimharris}
325230557Sjimharris#endif
326230557Sjimharris
327230557Sjimharris#ifdef SCI_ENABLE_LOGGING_STATES
328230557Sjimharris/**
329230557Sjimharris * @brief In this method the user is expected to log the supplied function
330230557Sjimharris *        state transition information.  The user must be capable of handling
331230557Sjimharris *        variable length argument lists and should consider prepending the
332230557Sjimharris *        fact that this is a function trace (i.e. entry/exit) message from
333230557Sjimharris *        the core.
334230557Sjimharris *
335230557Sjimharris * @param[in]  logger_object This parameter specifies the logger object
336230557Sjimharris *             associated with this message.
337230557Sjimharris * @param[in]  log_object_mask This parameter specifies the log objects
338230557Sjimharris *             for which this message is being generated.
339230557Sjimharris * @param[in]  log_message This parameter specifies the message to be logged.
340230557Sjimharris *
341230557Sjimharris * @return none
342230557Sjimharris */
343230557Sjimharrisvoid
344230557Sjimharrisscic_cb_logger_log_states(SCI_LOGGER_HANDLE_T logger_object,
345230557Sjimharris    uint32_t log_object_mask, char *log_message, ...)
346230557Sjimharris{
347230557Sjimharris
348230557Sjimharris	ISCI_LOG_MESSAGE(logger_object, log_object_mask, log_message,
349230557Sjimharris	    SCI_LOG_VERBOSITY_STATES, "CORE: STATE TRANSITION: ");
350230557Sjimharris}
351230557Sjimharris#endif
352