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