1 /* 2 * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _A_DEBUG_H_ 20 #define _A_DEBUG_H_ 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif /* __cplusplus */ 25 26 #include <a_types.h> 27 #include "osapi_linux.h" 28 29 /* standard debug print masks bits 0..7 */ 30 #define ATH_DEBUG_ERR (1 << 0) /* errors */ 31 #define ATH_DEBUG_WARN (1 << 1) /* warnings */ 32 #define ATH_DEBUG_INFO (1 << 2) /* informational (module startup info) */ 33 #define ATH_DEBUG_TRC (1 << 3) /* generic function call tracing */ 34 #define ATH_DEBUG_RSVD1 (1 << 4) 35 #define ATH_DEBUG_RSVD2 (1 << 5) 36 #define ATH_DEBUG_RSVD3 (1 << 6) 37 #define ATH_DEBUG_RSVD4 (1 << 7) 38 39 #define ATH_DEBUG_MASK_DEFAULTS (ATH_DEBUG_ERR | ATH_DEBUG_WARN) 40 #define ATH_DEBUG_ANY 0xFFFF 41 42 /* other aliases used throughout */ 43 #define ATH_DEBUG_ERROR ATH_DEBUG_ERR 44 #define ATH_LOG_ERR ATH_DEBUG_ERR 45 #define ATH_LOG_INF ATH_DEBUG_INFO 46 #define ATH_LOG_TRC ATH_DEBUG_TRC 47 #define ATH_DEBUG_TRACE ATH_DEBUG_TRC 48 #define ATH_DEBUG_INIT ATH_DEBUG_INFO 49 50 /* bits 8..31 are module-specific masks */ 51 #define ATH_DEBUG_MODULE_MASK_SHIFT 8 52 53 /* macro to make a module-specific masks */ 54 #define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index))) 55 56 void debug_dump_bytes(A_UCHAR *buffer, A_UINT16 length, 57 char *pDescription); 58 59 /* Debug support on a per-module basis 60 * 61 * Usage: 62 * 63 * Each module can utilize it's own debug mask variable. A set of commonly used 64 * masks are provided (ERRORS, WARNINGS, TRACE etc..). It is up to each module 65 * to define module-specific masks using the macros above. 66 * 67 * Each module defines a single debug mask variable debug_XXX where the "name" of the module is 68 * common to all C-files within that module. This requires every C-file that includes a_debug.h 69 * to define the module name in that file. 70 * 71 * Example: 72 * 73 * #define ATH_MODULE_NAME htc 74 * #include "a_debug.h" 75 * 76 * This will define a debug mask structure called debug_htc and all debug macros will reference this 77 * variable. 78 * 79 * A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro: 80 * 81 * #define ATH_DEBUG_MY_MASK1 ATH_DEBUG_MAKE_MODULE_MASK(0) 82 * #define ATH_DEBUG_MY_MASK2 ATH_DEBUG_MAKE_MODULE_MASK(1) 83 * 84 * The instantiation of the debug structure should be made by the module. When a module is 85 * instantiated, the module can set a description string, a default mask and an array of description 86 * entries containing information on each module-defined debug mask. 87 * NOTE: The instantiation is statically allocated, only one instance can exist per module. 88 * 89 * Example: 90 * 91 * 92 * #define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0) 93 * 94 * #ifdef DEBUG 95 * static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = { 96 * { ATH_DEBUG_BMI , "BMI Tracing"}, <== description of the module specific mask 97 * }; 98 * 99 * ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi, 100 * "bmi" <== module name 101 * "Boot Manager Interface", <== description of module 102 * ATH_DEBUG_MASK_DEFAULTS, <== defaults 103 * ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc), 104 * bmi_debug_desc); 105 * 106 * #endif 107 * 108 * A module can optionally register it's debug module information in order for other tools to change the 109 * bit mask at runtime. A module can call A_REGISTER_MODULE_DEBUG_INFO() in it's module 110 * init code. This macro can be called multiple times without consequence. The debug info maintains 111 * state to indicate whether the information was previously registered. 112 * 113 * */ 114 115 #define ATH_DEBUG_MAX_MASK_DESC_LENGTH 32 116 #define ATH_DEBUG_MAX_MOD_DESC_LENGTH 64 117 118 typedef struct { 119 A_UINT32 Mask; 120 A_CHAR Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH]; 121 } ATH_DEBUG_MASK_DESCRIPTION; 122 123 #define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0) 124 125 typedef struct _ATH_DEBUG_MODULE_DBG_INFO { 126 struct _ATH_DEBUG_MODULE_DBG_INFO *pNext; 127 A_CHAR ModuleName[16]; 128 A_CHAR ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH]; 129 A_UINT32 Flags; 130 A_UINT32 CurrentMask; 131 int MaxDescriptions; 132 ATH_DEBUG_MASK_DESCRIPTION *pMaskDescriptions; /* pointer to array of descriptions */ 133 } ATH_DEBUG_MODULE_DBG_INFO; 134 135 #define ATH_DEBUG_DESCRIPTION_COUNT(d) (int)((sizeof((d))) / (sizeof(ATH_DEBUG_MASK_DESCRIPTION))) 136 137 #define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s) 138 #define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask 139 #define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s 140 141 #ifdef WLAN_DEBUG 142 143 /* for source files that will instantiate the debug variables */ 144 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s, name, moddesc, initmask, count, descriptions) \ 145 ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \ 146 {NULL, (name), (moddesc), 0, (initmask), (count), (descriptions)} 147 148 #ifdef ATH_MODULE_NAME 149 extern ATH_DEBUG_MODULE_DBG_INFO 150 GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME); 151 #define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl)) 152 #endif /* ATH_MODULE_NAME */ 153 154 #define ATH_DEBUG_SET_DEBUG_MASK(s, lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl) 155 156 #define ATH_DEBUG_DECLARE_EXTERN(s) \ 157 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) 158 159 #define AR_DEBUG_PRINTBUF(buffer, length, desc) debug_dump_bytes(buffer, length, desc) 160 161 #define AR_DEBUG_ASSERT A_ASSERT 162 163 void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo); 164 void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo); 165 #ifdef A_SIMOS_DEVHOST 166 #define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s))) 167 #define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s))) 168 #else 169 #define A_DUMP_MODULE_DEBUG_INFO(s) 170 #define A_REGISTER_MODULE_DEBUG_INFO(s) 171 #endif 172 173 #else /* !DEBUG */ 174 /* NON DEBUG */ 175 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s, name, moddesc, initmask, count, descriptions) 176 #define AR_DEBUG_LVL_CHECK(lvl) 0 177 #define AR_DEBUG_PRINTBUF(buffer, length, desc) 178 #define AR_DEBUG_ASSERT(test) 179 #define ATH_DEBUG_DECLARE_EXTERN(s) 180 #define ATH_DEBUG_SET_DEBUG_MASK(s, lvl) 181 #define A_DUMP_MODULE_DEBUG_INFO(s) 182 #define A_REGISTER_MODULE_DEBUG_INFO(s) 183 184 #endif 185 186 #if defined(__linux__) && !defined(LINUX_EMULATION) 187 #include "debug_linux.h" 188 #endif 189 190 #ifdef __cplusplus 191 } 192 #endif /* __cplusplus */ 193 #endif 194