blob: db21bc2d66df5a53cf4a33c2135c0e014fa04ab6 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -07002 * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * 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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019#ifndef _A_DEBUG_H_
20#define _A_DEBUG_H_
21
22#ifdef __cplusplus
23extern "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
56void 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
118typedef 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
125typedef 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
Srinivas Girigowda6147c582016-10-18 12:26:15 -0700141#ifdef WLAN_DEBUG
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800142
143/* for source files that will instantiate the debug variables */
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -0700144#define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s, name, moddesc, initmask, count, descriptions) \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800145 ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -0700146 {NULL, (name), (moddesc), 0, (initmask), (count), (descriptions)}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147
148#ifdef ATH_MODULE_NAME
149extern ATH_DEBUG_MODULE_DBG_INFO
150GET_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
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -0700154#define ATH_DEBUG_SET_DEBUG_MASK(s, lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155
156#define ATH_DEBUG_DECLARE_EXTERN(s) \
157 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s)
158
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -0700159#define AR_DEBUG_PRINTBUF(buffer, length, desc) debug_dump_bytes(buffer, length, desc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160
161#define AR_DEBUG_ASSERT A_ASSERT
162
163void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
164void 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 */
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -0700175#define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s, name, moddesc, initmask, count, descriptions)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176#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)
Srinivas Girigowdaea4d8062017-10-14 12:40:48 -0700180#define ATH_DEBUG_SET_DEBUG_MASK(s, lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800181#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