Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / staging / ath6kl / include / a_debug.h
1 //------------------------------------------------------------------------------
2 // <copyright file="a_debug.h" company="Atheros">
3 //    Copyright (c) 2004-2010 Atheros Corporation.  All rights reserved.
4 // 
5 //
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.
9 //
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.
17 //
18 //
19 //------------------------------------------------------------------------------
20 //==============================================================================
21 // Author(s): ="Atheros"
22 //==============================================================================
23 #ifndef _A_DEBUG_H_
24 #define _A_DEBUG_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30 #include <a_types.h>
31 #include <a_osapi.h>
32
33     /* standard debug print masks bits 0..7 */
34 #define ATH_DEBUG_ERR   (1 << 0)   /* errors */
35 #define ATH_DEBUG_WARN  (1 << 1)   /* warnings */
36 #define ATH_DEBUG_INFO  (1 << 2)   /* informational (module startup info) */
37 #define ATH_DEBUG_TRC   (1 << 3)   /* generic function call tracing */
38 #define ATH_DEBUG_RSVD1 (1 << 4)
39 #define ATH_DEBUG_RSVD2 (1 << 5)
40 #define ATH_DEBUG_RSVD3 (1 << 6)
41 #define ATH_DEBUG_RSVD4 (1 << 7)
42
43 #define ATH_DEBUG_MASK_DEFAULTS  (ATH_DEBUG_ERR | ATH_DEBUG_WARN)
44 #define ATH_DEBUG_ANY  0xFFFF
45
46     /* other aliases used throughout */
47 #define ATH_DEBUG_ERROR   ATH_DEBUG_ERR
48 #define ATH_LOG_ERR       ATH_DEBUG_ERR
49 #define ATH_LOG_INF       ATH_DEBUG_INFO
50 #define ATH_LOG_TRC       ATH_DEBUG_TRC
51 #define ATH_DEBUG_TRACE   ATH_DEBUG_TRC
52 #define ATH_DEBUG_INIT    ATH_DEBUG_INFO
53
54     /* bits 8..31 are module-specific masks */
55 #define ATH_DEBUG_MODULE_MASK_SHIFT   8
56
57     /* macro to make a module-specific masks */
58 #define ATH_DEBUG_MAKE_MODULE_MASK(index)  (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))
59
60 void DebugDumpBytes(A_UCHAR *buffer, A_UINT16 length, char *pDescription);
61
62 /* Debug support on a per-module basis
63  *
64  * Usage:
65  *
66  *   Each module can utilize it's own debug mask variable.  A set of commonly used
67  *   masks are provided (ERRORS, WARNINGS, TRACE etc..).  It is up to each module
68  *   to define module-specific masks using the macros above.
69  *
70  *   Each module defines a single debug mask variable debug_XXX where the "name" of the module is
71  *   common to all C-files within that module.  This requires every C-file that includes a_debug.h
72  *   to define the module name in that file.
73  *
74  *   Example:
75  *
76  *   #define ATH_MODULE_NAME htc
77  *   #include "a_debug.h"
78  *
79  *   This will define a debug mask structure called debug_htc and all debug macros will reference this
80  *   variable.
81  *
82  *   A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro:
83  *
84  *      #define ATH_DEBUG_MY_MASK1  ATH_DEBUG_MAKE_MODULE_MASK(0)
85  *      #define ATH_DEBUG_MY_MASK2  ATH_DEBUG_MAKE_MODULE_MASK(1)
86  *
87  *   The instantiation of the debug structure should be made by the module.  When a module is
88  *   instantiated, the module can set a description string, a default mask and an array of description
89  *   entries containing information on each module-defined debug mask.
90  *   NOTE: The instantiation is statically allocated, only one instance can exist per module.
91  *
92  *   Example:
93  *
94  *
95  *   #define ATH_DEBUG_BMI  ATH_DEBUG_MAKE_MODULE_MASK(0)
96  *
97  *   #ifdef DEBUG
98  *   static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = {
99  *       { ATH_DEBUG_BMI , "BMI Tracing"},   <== description of the module specific mask
100  *   };
101  *
102  *   ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi,
103  *                                    "bmi"  <== module name
104  *                                    "Boot Manager Interface",  <== description of module
105  *                                    ATH_DEBUG_MASK_DEFAULTS,          <== defaults
106  *                                    ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc),
107  *                                    bmi_debug_desc);
108  *
109  *   #endif
110  *
111  *  A module can optionally register it's debug module information in order for other tools to change the
112  *  bit mask at runtime.  A module can call  A_REGISTER_MODULE_DEBUG_INFO() in it's module
113  *  init code.  This macro can be called multiple times without consequence.  The debug info maintains
114  *  state to indicate whether the information was previously registered.
115  *
116  * */
117
118 #define ATH_DEBUG_MAX_MASK_DESC_LENGTH   32
119 #define ATH_DEBUG_MAX_MOD_DESC_LENGTH    64
120
121 typedef struct {
122     A_UINT32 Mask;
123     A_CHAR   Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH];
124 } ATH_DEBUG_MASK_DESCRIPTION;
125
126 #define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0)
127
128 typedef struct  _ATH_DEBUG_MODULE_DBG_INFO{
129     struct _ATH_DEBUG_MODULE_DBG_INFO *pNext;
130     A_CHAR                      ModuleName[16];
131     A_CHAR                      ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH];
132     A_UINT32                    Flags;
133     A_UINT32                    CurrentMask;
134     int                         MaxDescriptions;
135     ATH_DEBUG_MASK_DESCRIPTION  *pMaskDescriptions; /* pointer to array of descriptions */
136 } ATH_DEBUG_MODULE_DBG_INFO;
137
138 #define ATH_DEBUG_DESCRIPTION_COUNT(d)  (int)((sizeof((d))) / (sizeof(ATH_DEBUG_MASK_DESCRIPTION)))
139
140 #define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s)
141 #define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask
142 #define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s
143
144 #ifdef ATH_DEBUG_MODULE
145
146     /* for source files that will instantiate the debug variables */
147 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) \
148 ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \
149             {NULL,(name),(moddesc),0,(initmask),count,(descriptions)}
150
151 #ifdef ATH_MODULE_NAME
152 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME);
153 #define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl))
154 #endif /* ATH_MODULE_NAME */
155
156 #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl)
157
158 #define ATH_DEBUG_DECLARE_EXTERN(s) \
159     extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s)
160
161 #define AR_DEBUG_PRINTBUF(buffer, length, desc) DebugDumpBytes(buffer,length,desc)
162
163
164 #define AR_DEBUG_ASSERT A_ASSERT
165
166 void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
167 void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
168 #define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
169 #define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
170
171 #else /* !ATH_DEBUG_MODULE */
172     /* NON ATH_DEBUG_MODULE */
173 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions)
174 #define AR_DEBUG_LVL_CHECK(lvl) 0
175 #define AR_DEBUG_PRINTBUF(buffer, length, desc)
176 #define AR_DEBUG_ASSERT(test)
177 #define ATH_DEBUG_DECLARE_EXTERN(s)
178 #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl)
179 #define A_DUMP_MODULE_DEBUG_INFO(s)
180 #define A_REGISTER_MODULE_DEBUG_INFO(s)
181
182 #endif
183
184 A_STATUS a_get_module_mask(A_CHAR *module_name, A_UINT32 *pMask);
185 A_STATUS a_set_module_mask(A_CHAR *module_name, A_UINT32 Mask);
186 void a_dump_module_debug_info_by_name(A_CHAR *module_name);
187 void a_module_debug_support_init(void);
188 void a_module_debug_support_cleanup(void);
189
190 #ifdef UNDER_NWIFI
191 #include "../os/windows/include/debug.h"
192 #endif
193
194 #ifdef ATHR_CE_LEGACY
195 #include "../os/windows/include/debug.h"
196 #endif
197
198 #if defined(__linux__) && !defined(LINUX_EMULATION)
199 #include "../os/linux/include/debug_linux.h"
200 #endif
201
202 #ifdef REXOS
203 #include "../os/rexos/include/common/debug_rexos.h"
204 #endif
205
206 #if defined ART_WIN
207 #include "../os/win_art/include/debug_win.h"
208 #endif
209
210 #ifdef WIN_NWF
211 #include <debug_win.h>
212 #endif
213
214 #ifdef THREADX
215 #define ATH_DEBUG_MAKE_MODULE_MASK(index)  (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))
216 #include "../os/threadx/include/common/debug_threadx.h"
217 #endif  
218
219
220 #ifdef __cplusplus
221 }
222 #endif /* __cplusplus */
223
224 #endif