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