a_debug.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #ifndef _A_DEBUG_H_
  27. #define _A_DEBUG_H_
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif /* __cplusplus */
  31. #include <a_types.h>
  32. #include "osapi_linux.h"
  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. #define ATH_DEBUG_MASK_DEFAULTS (ATH_DEBUG_ERR | ATH_DEBUG_WARN)
  43. #define ATH_DEBUG_ANY 0xFFFF
  44. /* other aliases used throughout */
  45. #define ATH_DEBUG_ERROR ATH_DEBUG_ERR
  46. #define ATH_LOG_ERR ATH_DEBUG_ERR
  47. #define ATH_LOG_INF ATH_DEBUG_INFO
  48. #define ATH_LOG_TRC ATH_DEBUG_TRC
  49. #define ATH_DEBUG_TRACE ATH_DEBUG_TRC
  50. #define ATH_DEBUG_INIT ATH_DEBUG_INFO
  51. /* bits 8..31 are module-specific masks */
  52. #define ATH_DEBUG_MODULE_MASK_SHIFT 8
  53. /* macro to make a module-specific masks */
  54. #define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))
  55. void debug_dump_bytes(A_UCHAR *buffer, A_UINT16 length,
  56. char *pDescription);
  57. /* Debug support on a per-module basis
  58. *
  59. * Usage:
  60. *
  61. * Each module can utilize it's own debug mask variable. A set of commonly used
  62. * masks are provided (ERRORS, WARNINGS, TRACE etc..). It is up to each module
  63. * to define module-specific masks using the macros above.
  64. *
  65. * Each module defines a single debug mask variable debug_XXX where the "name" of the module is
  66. * common to all C-files within that module. This requires every C-file that includes a_debug.h
  67. * to define the module name in that file.
  68. *
  69. * Example:
  70. *
  71. * #define ATH_MODULE_NAME htc
  72. * #include "a_debug.h"
  73. *
  74. * This will define a debug mask structure called debug_htc and all debug macros will reference this
  75. * variable.
  76. *
  77. * A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro:
  78. *
  79. * #define ATH_DEBUG_MY_MASK1 ATH_DEBUG_MAKE_MODULE_MASK(0)
  80. * #define ATH_DEBUG_MY_MASK2 ATH_DEBUG_MAKE_MODULE_MASK(1)
  81. *
  82. * The instantiation of the debug structure should be made by the module. When a module is
  83. * instantiated, the module can set a description string, a default mask and an array of description
  84. * entries containing information on each module-defined debug mask.
  85. * NOTE: The instantiation is statically allocated, only one instance can exist per module.
  86. *
  87. * Example:
  88. *
  89. *
  90. * #define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0)
  91. *
  92. * #ifdef DEBUG
  93. * static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = {
  94. * { ATH_DEBUG_BMI , "BMI Tracing"}, <== description of the module specific mask
  95. * };
  96. *
  97. * ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi,
  98. * "bmi" <== module name
  99. * "Boot Manager Interface", <== description of module
  100. * ATH_DEBUG_MASK_DEFAULTS, <== defaults
  101. * ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc),
  102. * bmi_debug_desc);
  103. *
  104. * #endif
  105. *
  106. * A module can optionally register it's debug module information in order for other tools to change the
  107. * bit mask at runtime. A module can call A_REGISTER_MODULE_DEBUG_INFO() in it's module
  108. * init code. This macro can be called multiple times without consequence. The debug info maintains
  109. * state to indicate whether the information was previously registered.
  110. *
  111. * */
  112. #define ATH_DEBUG_MAX_MASK_DESC_LENGTH 32
  113. #define ATH_DEBUG_MAX_MOD_DESC_LENGTH 64
  114. typedef struct {
  115. A_UINT32 Mask;
  116. A_CHAR Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH];
  117. } ATH_DEBUG_MASK_DESCRIPTION;
  118. #define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0)
  119. typedef struct _ATH_DEBUG_MODULE_DBG_INFO {
  120. struct _ATH_DEBUG_MODULE_DBG_INFO *pNext;
  121. A_CHAR ModuleName[16];
  122. A_CHAR ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH];
  123. A_UINT32 Flags;
  124. A_UINT32 CurrentMask;
  125. int MaxDescriptions;
  126. ATH_DEBUG_MASK_DESCRIPTION *pMaskDescriptions; /* pointer to array of descriptions */
  127. } ATH_DEBUG_MODULE_DBG_INFO;
  128. #define ATH_DEBUG_DESCRIPTION_COUNT(d) (int)((sizeof((d))) / (sizeof(ATH_DEBUG_MASK_DESCRIPTION)))
  129. #define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s)
  130. #define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask
  131. #define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s
  132. #ifdef WLAN_DEBUG
  133. /* for source files that will instantiate the debug variables */
  134. #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) \
  135. ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \
  136. {NULL,(name),(moddesc),0,(initmask),count,(descriptions)}
  137. #ifdef ATH_MODULE_NAME
  138. extern ATH_DEBUG_MODULE_DBG_INFO
  139. GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME);
  140. #define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl))
  141. #endif /* ATH_MODULE_NAME */
  142. #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl)
  143. #define ATH_DEBUG_DECLARE_EXTERN(s) \
  144. extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s)
  145. #define AR_DEBUG_PRINTBUF(buffer, length, desc) debug_dump_bytes(buffer,length,desc)
  146. #define AR_DEBUG_ASSERT A_ASSERT
  147. void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
  148. void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
  149. #ifdef A_SIMOS_DEVHOST
  150. #define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
  151. #define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
  152. #else
  153. #define A_DUMP_MODULE_DEBUG_INFO(s)
  154. #define A_REGISTER_MODULE_DEBUG_INFO(s)
  155. #endif
  156. #else /* !DEBUG */
  157. /* NON DEBUG */
  158. #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions)
  159. #define AR_DEBUG_LVL_CHECK(lvl) 0
  160. #define AR_DEBUG_PRINTBUF(buffer, length, desc)
  161. #define AR_DEBUG_ASSERT(test)
  162. #define ATH_DEBUG_DECLARE_EXTERN(s)
  163. #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl)
  164. #define A_DUMP_MODULE_DEBUG_INFO(s)
  165. #define A_REGISTER_MODULE_DEBUG_INFO(s)
  166. #endif
  167. #if defined(__linux__) && !defined(LINUX_EMULATION)
  168. #include "debug_linux.h"
  169. #endif
  170. #ifdef __cplusplus
  171. }
  172. #endif /* __cplusplus */
  173. #endif