a_debug.h 7.1 KB

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