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