summaryrefslogtreecommitdiff
path: root/uapi/linux/a_debug.h
blob: 62931060cf08b9843ebff3c0dc7459e45a02c70c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * Copyright (c) 2013-2015 The Linux Foundation. All rights reserved.
 *
 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
 *
 *
 * Permission to use, copy, modify, and/or distribute this software for
 * any purpose with or without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all
 * copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * This file was originally distributed by Qualcomm Atheros, Inc.
 * under proprietary terms before Copyright ownership was assigned
 * to the Linux Foundation.
 */

#ifndef _A_DEBUG_H_
#define _A_DEBUG_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include <a_types.h>
#include "osapi_linux.h"

/* standard debug print masks bits 0..7 */
#define ATH_DEBUG_ERR   (1 << 0)        /* errors */
#define ATH_DEBUG_WARN  (1 << 1)        /* warnings */
#define ATH_DEBUG_INFO  (1 << 2)        /* informational (module startup info) */
#define ATH_DEBUG_TRC   (1 << 3)        /* generic function call tracing */
#define ATH_DEBUG_RSVD1 (1 << 4)
#define ATH_DEBUG_RSVD2 (1 << 5)
#define ATH_DEBUG_RSVD3 (1 << 6)
#define ATH_DEBUG_RSVD4 (1 << 7)

#define ATH_DEBUG_MASK_DEFAULTS  (ATH_DEBUG_ERR | ATH_DEBUG_WARN)
#define ATH_DEBUG_ANY  0xFFFF

/* other aliases used throughout */
#define ATH_DEBUG_ERROR   ATH_DEBUG_ERR
#define ATH_LOG_ERR       ATH_DEBUG_ERR
#define ATH_LOG_INF       ATH_DEBUG_INFO
#define ATH_LOG_TRC       ATH_DEBUG_TRC
#define ATH_DEBUG_TRACE   ATH_DEBUG_TRC
#define ATH_DEBUG_INIT    ATH_DEBUG_INFO

/* bits 8..31 are module-specific masks */
#define ATH_DEBUG_MODULE_MASK_SHIFT   8

/* macro to make a module-specific masks */
#define ATH_DEBUG_MAKE_MODULE_MASK(index)  (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))

void debug_dump_bytes(A_UCHAR *buffer, A_UINT16 length,
		      char *pDescription);

/* Debug support on a per-module basis
 *
 * Usage:
 *
 *   Each module can utilize it's own debug mask variable.  A set of commonly used
 *   masks are provided (ERRORS, WARNINGS, TRACE etc..).  It is up to each module
 *   to define module-specific masks using the macros above.
 *
 *   Each module defines a single debug mask variable debug_XXX where the "name" of the module is
 *   common to all C-files within that module.  This requires every C-file that includes a_debug.h
 *   to define the module name in that file.
 *
 *   Example:
 *
 *   #define ATH_MODULE_NAME htc
 *   #include "a_debug.h"
 *
 *   This will define a debug mask structure called debug_htc and all debug macros will reference this
 *   variable.
 *
 *   A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro:
 *
 *      #define ATH_DEBUG_MY_MASK1  ATH_DEBUG_MAKE_MODULE_MASK(0)
 *      #define ATH_DEBUG_MY_MASK2  ATH_DEBUG_MAKE_MODULE_MASK(1)
 *
 *   The instantiation of the debug structure should be made by the module.  When a module is
 *   instantiated, the module can set a description string, a default mask and an array of description
 *   entries containing information on each module-defined debug mask.
 *   NOTE: The instantiation is statically allocated, only one instance can exist per module.
 *
 *   Example:
 *
 *
 *   #define ATH_DEBUG_BMI  ATH_DEBUG_MAKE_MODULE_MASK(0)
 *
 *   #ifdef DEBUG
 *   static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = {
 *       { ATH_DEBUG_BMI , "BMI Tracing"},   <== description of the module specific mask
 *   };
 *
 *   ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi,
 *                                    "bmi"  <== module name
 *                                    "Boot Manager Interface",  <== description of module
 *                                    ATH_DEBUG_MASK_DEFAULTS,          <== defaults
 *                                    ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc),
 *                                    bmi_debug_desc);
 *
 *   #endif
 *
 *  A module can optionally register it's debug module information in order for other tools to change the
 *  bit mask at runtime.  A module can call  A_REGISTER_MODULE_DEBUG_INFO() in it's module
 *  init code.  This macro can be called multiple times without consequence.  The debug info maintains
 *  state to indicate whether the information was previously registered.
 *
 * */

#define ATH_DEBUG_MAX_MASK_DESC_LENGTH   32
#define ATH_DEBUG_MAX_MOD_DESC_LENGTH    64

typedef struct {
	A_UINT32 Mask;
	A_CHAR Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH];
} ATH_DEBUG_MASK_DESCRIPTION;

#define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0)

typedef struct _ATH_DEBUG_MODULE_DBG_INFO {
	struct _ATH_DEBUG_MODULE_DBG_INFO *pNext;
	A_CHAR ModuleName[16];
	A_CHAR ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH];
	A_UINT32 Flags;
	A_UINT32 CurrentMask;
	int MaxDescriptions;
	ATH_DEBUG_MASK_DESCRIPTION *pMaskDescriptions;          /* pointer to array of descriptions */
} ATH_DEBUG_MODULE_DBG_INFO;

#define ATH_DEBUG_DESCRIPTION_COUNT(d)  (int)((sizeof((d))) / (sizeof(ATH_DEBUG_MASK_DESCRIPTION)))

#define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s)
#define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask
#define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s

#ifdef DEBUG

/* for source files that will instantiate the debug variables */
#define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) \
	ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \
	{NULL,(name),(moddesc),0,(initmask),count,(descriptions)}

#ifdef ATH_MODULE_NAME
extern ATH_DEBUG_MODULE_DBG_INFO
GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME);
#define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl))
#endif /* ATH_MODULE_NAME */

#define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl)

#define ATH_DEBUG_DECLARE_EXTERN(s) \
	extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s)

#define AR_DEBUG_PRINTBUF(buffer, length, desc) debug_dump_bytes(buffer,length,desc)

#define AR_DEBUG_ASSERT A_ASSERT

void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
#ifdef A_SIMOS_DEVHOST
#define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
#define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
#else
#define A_DUMP_MODULE_DEBUG_INFO(s)
#define A_REGISTER_MODULE_DEBUG_INFO(s)
#endif

#else                           /* !DEBUG */
/* NON DEBUG */
#define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions)
#define AR_DEBUG_LVL_CHECK(lvl) 0
#define AR_DEBUG_PRINTBUF(buffer, length, desc)
#define AR_DEBUG_ASSERT(test)
#define ATH_DEBUG_DECLARE_EXTERN(s)
#define ATH_DEBUG_SET_DEBUG_MASK(s,lvl)
#define A_DUMP_MODULE_DEBUG_INFO(s)
#define A_REGISTER_MODULE_DEBUG_INFO(s)

#endif

#if defined(__linux__) && !defined(LINUX_EMULATION)
#include "debug_linux.h"
#endif

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif