xref: /freebsd/sys/dev/isci/scil/sci_logger.h (revision f11c7f63056671247335df83a3fe80b94c6616ac)
1*f11c7f63SJim Harris /*-
2*f11c7f63SJim Harris  * This file is provided under a dual BSD/GPLv2 license.  When using or
3*f11c7f63SJim Harris  * redistributing this file, you may do so under either license.
4*f11c7f63SJim Harris  *
5*f11c7f63SJim Harris  * GPL LICENSE SUMMARY
6*f11c7f63SJim Harris  *
7*f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8*f11c7f63SJim Harris  *
9*f11c7f63SJim Harris  * This program is free software; you can redistribute it and/or modify
10*f11c7f63SJim Harris  * it under the terms of version 2 of the GNU General Public License as
11*f11c7f63SJim Harris  * published by the Free Software Foundation.
12*f11c7f63SJim Harris  *
13*f11c7f63SJim Harris  * This program is distributed in the hope that it will be useful, but
14*f11c7f63SJim Harris  * WITHOUT ANY WARRANTY; without even the implied warranty of
15*f11c7f63SJim Harris  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*f11c7f63SJim Harris  * General Public License for more details.
17*f11c7f63SJim Harris  *
18*f11c7f63SJim Harris  * You should have received a copy of the GNU General Public License
19*f11c7f63SJim Harris  * along with this program; if not, write to the Free Software
20*f11c7f63SJim Harris  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21*f11c7f63SJim Harris  * The full GNU General Public License is included in this distribution
22*f11c7f63SJim Harris  * in the file called LICENSE.GPL.
23*f11c7f63SJim Harris  *
24*f11c7f63SJim Harris  * BSD LICENSE
25*f11c7f63SJim Harris  *
26*f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27*f11c7f63SJim Harris  * All rights reserved.
28*f11c7f63SJim Harris  *
29*f11c7f63SJim Harris  * Redistribution and use in source and binary forms, with or without
30*f11c7f63SJim Harris  * modification, are permitted provided that the following conditions
31*f11c7f63SJim Harris  * are met:
32*f11c7f63SJim Harris  *
33*f11c7f63SJim Harris  *   * Redistributions of source code must retain the above copyright
34*f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer.
35*f11c7f63SJim Harris  *   * Redistributions in binary form must reproduce the above copyright
36*f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer in
37*f11c7f63SJim Harris  *     the documentation and/or other materials provided with the
38*f11c7f63SJim Harris  *     distribution.
39*f11c7f63SJim Harris  *
40*f11c7f63SJim Harris  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41*f11c7f63SJim Harris  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42*f11c7f63SJim Harris  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43*f11c7f63SJim Harris  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44*f11c7f63SJim Harris  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45*f11c7f63SJim Harris  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46*f11c7f63SJim Harris  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47*f11c7f63SJim Harris  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48*f11c7f63SJim Harris  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49*f11c7f63SJim Harris  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50*f11c7f63SJim Harris  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51*f11c7f63SJim Harris  *
52*f11c7f63SJim Harris  * $FreeBSD$
53*f11c7f63SJim Harris  */
54*f11c7f63SJim Harris #ifndef _SCI_LOGGER_H_
55*f11c7f63SJim Harris #define _SCI_LOGGER_H_
56*f11c7f63SJim Harris 
57*f11c7f63SJim Harris /**
58*f11c7f63SJim Harris  * @file
59*f11c7f63SJim Harris  *
60*f11c7f63SJim Harris  * @brief This file contains all of the interface methods that can be called
61*f11c7f63SJim Harris  *        by an SCI user on the logger object.  These methods should be
62*f11c7f63SJim Harris  *        utilized to control the amount of information being logged by the
63*f11c7f63SJim Harris  *        SCI implementation.
64*f11c7f63SJim Harris  */
65*f11c7f63SJim Harris 
66*f11c7f63SJim Harris #ifdef __cplusplus
67*f11c7f63SJim Harris extern "C" {
68*f11c7f63SJim Harris #endif // __cplusplus
69*f11c7f63SJim Harris 
70*f11c7f63SJim Harris #include <dev/isci/scil/sci_types.h>
71*f11c7f63SJim Harris 
72*f11c7f63SJim Harris 
73*f11c7f63SJim Harris /* The following is a list of verbosity levels that can be used to enable */
74*f11c7f63SJim Harris /* logging for specific log objects.                                      */
75*f11c7f63SJim Harris 
76*f11c7f63SJim Harris /** Enable/disable error level logging for the associated logger object(s). */
77*f11c7f63SJim Harris #define SCI_LOG_VERBOSITY_ERROR      0x00
78*f11c7f63SJim Harris 
79*f11c7f63SJim Harris /** Enable/disable warning level logging for the associated logger object(s). */
80*f11c7f63SJim Harris #define SCI_LOG_VERBOSITY_WARNING    0x01
81*f11c7f63SJim Harris 
82*f11c7f63SJim Harris /**
83*f11c7f63SJim Harris  * Enable/disable informative level logging for the associated logger object(s).
84*f11c7f63SJim Harris  */
85*f11c7f63SJim Harris #define SCI_LOG_VERBOSITY_INFO       0x02
86*f11c7f63SJim Harris 
87*f11c7f63SJim Harris /**
88*f11c7f63SJim Harris  * This constant is used to enable function trace (enter/exit) level
89*f11c7f63SJim Harris  * logging for the associated log object(s).
90*f11c7f63SJim Harris  */
91*f11c7f63SJim Harris #define SCI_LOG_VERBOSITY_TRACE      0x03
92*f11c7f63SJim Harris 
93*f11c7f63SJim Harris /**
94*f11c7f63SJim Harris  * This constant is used to enable state tracing information it will emit a
95*f11c7f63SJim Harris  * log message each time a state is entered for the associated log object(s).
96*f11c7f63SJim Harris  */
97*f11c7f63SJim Harris #define SCI_LOG_VERBOSITY_STATES     0x04
98*f11c7f63SJim Harris 
99*f11c7f63SJim Harris #ifdef SCI_LOGGING
100*f11c7f63SJim Harris 
101*f11c7f63SJim Harris /**
102*f11c7f63SJim Harris  * @brief This method will return the verbosity levels enabled for the object
103*f11c7f63SJim Harris  *        listed in the log_object parameter.
104*f11c7f63SJim Harris  * @note  Logging must be enabled at compile time in the driver, otherwise
105*f11c7f63SJim Harris  *        calling this method has no affect.
106*f11c7f63SJim Harris  *
107*f11c7f63SJim Harris  * @param[in]  logger This parameter specifies the logger for which to
108*f11c7f63SJim Harris  *             disable the supplied objects/verbosities.  For example,
109*f11c7f63SJim Harris  *             the framework and core components have different loggers.
110*f11c7f63SJim Harris  * @param[in]  log_object This parameter specifies the log object for which
111*f11c7f63SJim Harris  *             to retrieve the associated verbosity levels.
112*f11c7f63SJim Harris  *             @note This parameter is not a mask, but rather a discrete
113*f11c7f63SJim Harris  *             value.
114*f11c7f63SJim Harris  *
115*f11c7f63SJim Harris  * @return This method will return the verbosity levels enabled for the
116*f11c7f63SJim Harris  *         supplied log object.
117*f11c7f63SJim Harris  * @retval SCI_LOGGER_VERBOSITY_ERROR This value indicates that the error
118*f11c7f63SJim Harris  *         verbosity level was set for the supplied log_object.
119*f11c7f63SJim Harris  * @retval SCI_LOGGER_VERBOSITY_WARNING This value indicates that the warning
120*f11c7f63SJim Harris  *         verbosity level was set for the supplied log_object.
121*f11c7f63SJim Harris  * @retval SCI_LOGGER_VERBOSITY_INFO This value indicates that the
122*f11c7f63SJim Harris  *         informational verbosity level was set for the supplied log_object.
123*f11c7f63SJim Harris  * @retval SCI_LOGGER_VERBOSITY_TRACE This value indicates that the trace
124*f11c7f63SJim Harris  *         verbosity level was set for the supplied log_object.
125*f11c7f63SJim Harris  * @retval SCI_LOGGER_VERBOSITY_STATES This value indicates that the states
126*f11c7f63SJim Harris  *         transition verbosity level was set for the supplied log_object
127*f11c7f63SJim Harris  */
128*f11c7f63SJim Harris U8 sci_logger_get_verbosity_mask(
129*f11c7f63SJim Harris    SCI_LOGGER_HANDLE_T  logger,
130*f11c7f63SJim Harris    U32                  log_object
131*f11c7f63SJim Harris );
132*f11c7f63SJim Harris 
133*f11c7f63SJim Harris /**
134*f11c7f63SJim Harris  * @brief This method simply returns the log object mask.  This mask
135*f11c7f63SJim Harris  *        is essentially a list of log objects for which the specified
136*f11c7f63SJim Harris  *        level (verbosity) is enabled.
137*f11c7f63SJim Harris  * @note  Logging must be enabled at compile time in the driver, otherwise
138*f11c7f63SJim Harris  *        calling this method has no affect.
139*f11c7f63SJim Harris  * @note  Reserved bits in both the supplied masks shall be ignored.
140*f11c7f63SJim Harris  *
141*f11c7f63SJim Harris  * @param[in]  logger This parameter specifies the logger for which to
142*f11c7f63SJim Harris  *             disable the supplied objects/verbosities.  For example,
143*f11c7f63SJim Harris  *             the framework and core components have different loggers.
144*f11c7f63SJim Harris  * @param[in]  verbosity This parameter specifies the verbosity for which
145*f11c7f63SJim Harris  *             to retrieve the set of enabled log objects.  Valid values for
146*f11c7f63SJim Harris  *             this parameter are:
147*f11c7f63SJim Harris  *                -# SCI_LOGGER_VERBOSITY_ERROR
148*f11c7f63SJim Harris  *                -# SCI_LOGGER_VERBOSITY_WARNING
149*f11c7f63SJim Harris  *                -# SCI_LOGGER_VERBOSITY_INFO
150*f11c7f63SJim Harris  *                -# SCI_LOGGER_VERBOSITY_TRACE
151*f11c7f63SJim Harris  *                -# SCI_LOGGER_VERBOSITY_STATES
152*f11c7f63SJim Harris  *             @note This parameter is not a mask, but rather a discrete
153*f11c7f63SJim Harris  *             value.
154*f11c7f63SJim Harris  *
155*f11c7f63SJim Harris  * @return This method will return the log object mask indicating each of
156*f11c7f63SJim Harris  *         the log objects for which logging is enabled at the supplied level.
157*f11c7f63SJim Harris  */
158*f11c7f63SJim Harris U32 sci_logger_get_object_mask(
159*f11c7f63SJim Harris    SCI_LOGGER_HANDLE_T  logger,
160*f11c7f63SJim Harris    U8                   verbosity
161*f11c7f63SJim Harris );
162*f11c7f63SJim Harris 
163*f11c7f63SJim Harris /**
164*f11c7f63SJim Harris  * @brief This method will enable each of the supplied log objects in
165*f11c7f63SJim Harris  *        log_object_mask for each of the supplied verbosities in
166*f11c7f63SJim Harris  *        verbosity_mask.  To enable all logging, simply set all bits in
167*f11c7f63SJim Harris  *        both the log_object_mask and verbosity_mask.
168*f11c7f63SJim Harris  * @note  Logging must be enabled at compile time in the driver, otherwise
169*f11c7f63SJim Harris  *        calling this method has no affect.
170*f11c7f63SJim Harris  * @note  Reserved bits in both the supplied masks shall be ignored.
171*f11c7f63SJim Harris  *
172*f11c7f63SJim Harris  * @param[in]  logger This parameter specifies the logger for which to
173*f11c7f63SJim Harris  *             disable the supplied objects/verbosities.  For example,
174*f11c7f63SJim Harris  *             the framework and core components have different loggers.
175*f11c7f63SJim Harris  * @param[in]  log_object_mask This parameter specifies the log objects for
176*f11c7f63SJim Harris  *             which to enable logging.
177*f11c7f63SJim Harris  * @param[in]  verbosity_mask This parameter specifies the verbosity levels
178*f11c7f63SJim Harris  *             at which to enable each log_object.
179*f11c7f63SJim Harris  *
180*f11c7f63SJim Harris  * @return none
181*f11c7f63SJim Harris  */
182*f11c7f63SJim Harris void sci_logger_enable(
183*f11c7f63SJim Harris    SCI_LOGGER_HANDLE_T  logger,
184*f11c7f63SJim Harris    U32                  log_object_mask,
185*f11c7f63SJim Harris    U8                   verbosity_mask
186*f11c7f63SJim Harris );
187*f11c7f63SJim Harris 
188*f11c7f63SJim Harris /**
189*f11c7f63SJim Harris  * @brief This method will disable each of the supplied log objects in
190*f11c7f63SJim Harris  *        log_object_mask for each of the supplied verbosities in
191*f11c7f63SJim Harris  *        verbosity_mask.  To disable all logging, simply set all bits in
192*f11c7f63SJim Harris  *        both the log_object_mask and verbosity_mask.
193*f11c7f63SJim Harris  * @note  Logging must be enabled at compile time in the driver, otherwise
194*f11c7f63SJim Harris  *        calling this method has no affect.
195*f11c7f63SJim Harris  * @note  Reserved bits in both the supplied masks shall be ignored.
196*f11c7f63SJim Harris  *
197*f11c7f63SJim Harris  * @param[in]  logger This parameter specifies the logger for which to
198*f11c7f63SJim Harris  *             disable the supplied objects/verbosities.  For example,
199*f11c7f63SJim Harris  *             the framework and core components have different loggers.
200*f11c7f63SJim Harris  * @param[in]  log_object_mask This parameter specifies the log objects for
201*f11c7f63SJim Harris  *             which to disable logging.
202*f11c7f63SJim Harris  * @param[in]  verbosity_mask This parameter specifies the verbosity levels
203*f11c7f63SJim Harris  *             at which to disable each log_object.
204*f11c7f63SJim Harris  *
205*f11c7f63SJim Harris  * @return none
206*f11c7f63SJim Harris  */
207*f11c7f63SJim Harris void sci_logger_disable(
208*f11c7f63SJim Harris    SCI_LOGGER_HANDLE_T  logger,
209*f11c7f63SJim Harris    U32                  log_object_mask,
210*f11c7f63SJim Harris    U8                   verbosity_mask
211*f11c7f63SJim Harris );
212*f11c7f63SJim Harris 
213*f11c7f63SJim Harris 
214*f11c7f63SJim Harris /**
215*f11c7f63SJim Harris  * @brief this macro checks whether it is ok to log.
216*f11c7f63SJim Harris  *
217*f11c7f63SJim Harris  * @param[in]  logger This parameter specifies the logger for
218*f11c7f63SJim Harris  *             which to disable the supplied
219*f11c7f63SJim Harris  *             objects/verbosities.  For example, the framework
220*f11c7f63SJim Harris  *             and core components have different loggers.
221*f11c7f63SJim Harris  * @param[in]  log_object_mask This parameter specifies the log objects for
222*f11c7f63SJim Harris  *             which to disable logging.
223*f11c7f63SJim Harris  * @param[in]  verbosity_mask This parameter specifies the verbosity levels
224*f11c7f63SJim Harris  *             at which to disable each log_object.
225*f11c7f63SJim Harris  *
226*f11c7f63SJim Harris  * @return TRUE or FALSE
227*f11c7f63SJim Harris  */
228*f11c7f63SJim Harris BOOL sci_logger_is_enabled(
229*f11c7f63SJim Harris    SCI_LOGGER_HANDLE_T  logger,
230*f11c7f63SJim Harris    U32                  log_object_mask,
231*f11c7f63SJim Harris    U8                   verbosity_mask
232*f11c7f63SJim Harris );
233*f11c7f63SJim Harris 
234*f11c7f63SJim Harris 
235*f11c7f63SJim Harris #else // SCI_LOGGING
236*f11c7f63SJim Harris 
237*f11c7f63SJim Harris #define sci_logger_get_verbosity_mask(logger, log_object)
238*f11c7f63SJim Harris #define sci_logger_get_object_mask(logger, verbosity)
239*f11c7f63SJim Harris #define sci_logger_enable(logger, log_object_mask, verbosity_mask)
240*f11c7f63SJim Harris #define sci_logger_disable(logger, log_object_mask, verbosity_mask)
241*f11c7f63SJim Harris #define sci_logger_is_enabled(logger, log_object_mask, verbosity_level)
242*f11c7f63SJim Harris 
243*f11c7f63SJim Harris #endif // SCI_LOGGING
244*f11c7f63SJim Harris 
245*f11c7f63SJim Harris #ifdef __cplusplus
246*f11c7f63SJim Harris }
247*f11c7f63SJim Harris #endif // __cplusplus
248*f11c7f63SJim Harris 
249*f11c7f63SJim Harris #endif // _SCI_LOGGER_H_
250*f11c7f63SJim Harris 
251