1 //------------------------------------------------------------------------------
2 // <copyright file="a_debug.h" company="Atheros">
3 // Copyright (c) 2004-2010 Atheros Corporation. All rights reserved.
6 // Permission to use, copy, modify, and/or distribute this software for any
7 // purpose with or without fee is hereby granted, provided that the above
8 // copyright notice and this permission notice appear in all copies.
10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 //------------------------------------------------------------------------------
20 //==============================================================================
21 // Author(s): ="Atheros"
22 //==============================================================================
28 #endif /* __cplusplus */
32 /* standard debug print masks bits 0..7 */
33 #define ATH_DEBUG_ERR (1 << 0) /* errors */
34 #define ATH_DEBUG_WARN (1 << 1) /* warnings */
35 #define ATH_DEBUG_INFO (1 << 2) /* informational (module startup info) */
36 #define ATH_DEBUG_TRC (1 << 3) /* generic function call tracing */
37 #define ATH_DEBUG_RSVD1 (1 << 4)
38 #define ATH_DEBUG_RSVD2 (1 << 5)
39 #define ATH_DEBUG_RSVD3 (1 << 6)
40 #define ATH_DEBUG_RSVD4 (1 << 7)
42 #define ATH_DEBUG_MASK_DEFAULTS (ATH_DEBUG_ERR | ATH_DEBUG_WARN)
43 #define ATH_DEBUG_ANY 0xFFFF
45 /* other aliases used throughout */
46 #define ATH_DEBUG_ERROR ATH_DEBUG_ERR
47 #define ATH_LOG_ERR ATH_DEBUG_ERR
48 #define ATH_LOG_INF ATH_DEBUG_INFO
49 #define ATH_LOG_TRC ATH_DEBUG_TRC
50 #define ATH_DEBUG_TRACE ATH_DEBUG_TRC
51 #define ATH_DEBUG_INIT ATH_DEBUG_INFO
53 /* bits 8..31 are module-specific masks */
54 #define ATH_DEBUG_MODULE_MASK_SHIFT 8
56 /* macro to make a module-specific masks */
57 #define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))
59 void DebugDumpBytes(u8 *buffer, u16 length, char *pDescription);
61 /* Debug support on a per-module basis
65 * Each module can utilize it's own debug mask variable. A set of commonly used
66 * masks are provided (ERRORS, WARNINGS, TRACE etc..). It is up to each module
67 * to define module-specific masks using the macros above.
69 * Each module defines a single debug mask variable debug_XXX where the "name" of the module is
70 * common to all C-files within that module. This requires every C-file that includes a_debug.h
71 * to define the module name in that file.
75 * #define ATH_MODULE_NAME htc
76 * #include "a_debug.h"
78 * This will define a debug mask structure called debug_htc and all debug macros will reference this
81 * A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro:
83 * #define ATH_DEBUG_MY_MASK1 ATH_DEBUG_MAKE_MODULE_MASK(0)
84 * #define ATH_DEBUG_MY_MASK2 ATH_DEBUG_MAKE_MODULE_MASK(1)
86 * The instantiation of the debug structure should be made by the module. When a module is
87 * instantiated, the module can set a description string, a default mask and an array of description
88 * entries containing information on each module-defined debug mask.
89 * NOTE: The instantiation is statically allocated, only one instance can exist per module.
94 * #define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0)
97 * static struct ath_debug_mask_description bmi_debug_desc[] = {
98 * { ATH_DEBUG_BMI , "BMI Tracing"}, <== description of the module specific mask
101 * ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi,
102 * "bmi" <== module name
103 * "Boot Manager Interface", <== description of module
104 * ATH_DEBUG_MASK_DEFAULTS, <== defaults
105 * ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc),
110 * A module can optionally register it's debug module information in order for other tools to change the
111 * bit mask at runtime. A module can call A_REGISTER_MODULE_DEBUG_INFO() in it's module
112 * init code. This macro can be called multiple times without consequence. The debug info maintains
113 * state to indicate whether the information was previously registered.
117 #define ATH_DEBUG_MAX_MASK_DESC_LENGTH 32
118 #define ATH_DEBUG_MAX_MOD_DESC_LENGTH 64
120 struct ath_debug_mask_description {
122 char Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH];
125 #define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0)
127 typedef struct _ATH_DEBUG_MODULE_DBG_INFO{
128 struct _ATH_DEBUG_MODULE_DBG_INFO *pNext;
130 char ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH];
134 struct ath_debug_mask_description *pMaskDescriptions; /* pointer to array of descriptions */
135 } ATH_DEBUG_MODULE_DBG_INFO;
137 #define ATH_DEBUG_DESCRIPTION_COUNT(d) (int)((sizeof((d))) / (sizeof(struct ath_debug_mask_description)))
139 #define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s)
140 #define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask
141 #define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s
143 #ifdef ATH_DEBUG_MODULE
145 /* for source files that will instantiate the debug variables */
146 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) \
147 ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \
148 {NULL,(name),(moddesc),0,(initmask),count,(descriptions)}
150 #ifdef ATH_MODULE_NAME
151 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME);
152 #define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl))
153 #endif /* ATH_MODULE_NAME */
155 #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl)
157 #define ATH_DEBUG_DECLARE_EXTERN(s) \
158 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s)
160 #define AR_DEBUG_PRINTBUF(buffer, length, desc) DebugDumpBytes(buffer,length,desc)
163 #define AR_DEBUG_ASSERT A_ASSERT
165 void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
166 void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
167 #define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
168 #define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
170 #else /* !ATH_DEBUG_MODULE */
171 /* NON ATH_DEBUG_MODULE */
172 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions)
173 #define AR_DEBUG_LVL_CHECK(lvl) 0
174 #define AR_DEBUG_PRINTBUF(buffer, length, desc)
175 #define AR_DEBUG_ASSERT(test)
176 #define ATH_DEBUG_DECLARE_EXTERN(s)
177 #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl)
178 #define A_DUMP_MODULE_DEBUG_INFO(s)
179 #define A_REGISTER_MODULE_DEBUG_INFO(s)
183 int a_get_module_mask(char *module_name, u32 *pMask);
184 int a_set_module_mask(char *module_name, u32 Mask);
185 void a_dump_module_debug_info_by_name(char *module_name);
186 void a_module_debug_support_init(void);
187 void a_module_debug_support_cleanup(void);
189 #include "../os/linux/include/debug_linux.h"
193 #endif /* __cplusplus */