log.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver
  3. * drivers/misc/iwmc3200top/log.h
  4. *
  5. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. *
  21. *
  22. * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com>
  23. * -
  24. *
  25. */
  26. #ifndef __LOG_H__
  27. #define __LOG_H__
  28. /* log severity:
  29. * The log levels here match FW log levels
  30. * so values need to stay as is */
  31. #define LOG_SEV_CRITICAL 0
  32. #define LOG_SEV_ERROR 1
  33. #define LOG_SEV_WARNING 2
  34. #define LOG_SEV_INFO 3
  35. #define LOG_SEV_INFOEX 4
  36. /* Log levels not defined for FW */
  37. #define LOG_SEV_TRACE 5
  38. #define LOG_SEV_DUMP 6
  39. #define LOG_SEV_FW_FILTER_ALL \
  40. (BIT(LOG_SEV_CRITICAL) | \
  41. BIT(LOG_SEV_ERROR) | \
  42. BIT(LOG_SEV_WARNING) | \
  43. BIT(LOG_SEV_INFO) | \
  44. BIT(LOG_SEV_INFOEX))
  45. #define LOG_SEV_FILTER_ALL \
  46. (BIT(LOG_SEV_CRITICAL) | \
  47. BIT(LOG_SEV_ERROR) | \
  48. BIT(LOG_SEV_WARNING) | \
  49. BIT(LOG_SEV_INFO) | \
  50. BIT(LOG_SEV_INFOEX) | \
  51. BIT(LOG_SEV_TRACE) | \
  52. BIT(LOG_SEV_DUMP))
  53. /* log source */
  54. #define LOG_SRC_INIT 0
  55. #define LOG_SRC_DEBUGFS 1
  56. #define LOG_SRC_FW_DOWNLOAD 2
  57. #define LOG_SRC_FW_MSG 3
  58. #define LOG_SRC_TST 4
  59. #define LOG_SRC_IRQ 5
  60. #define LOG_SRC_MAX 6
  61. #define LOG_SRC_ALL 0xFF
  62. /**
  63. * Default intitialization runtime log level
  64. */
  65. #ifndef LOG_SEV_FILTER_RUNTIME
  66. #define LOG_SEV_FILTER_RUNTIME \
  67. (BIT(LOG_SEV_CRITICAL) | \
  68. BIT(LOG_SEV_ERROR) | \
  69. BIT(LOG_SEV_WARNING))
  70. #endif
  71. #ifndef FW_LOG_SEV_FILTER_RUNTIME
  72. #define FW_LOG_SEV_FILTER_RUNTIME LOG_SEV_FILTER_ALL
  73. #endif
  74. #ifdef CONFIG_IWMC3200TOP_DEBUG
  75. /**
  76. * Log macros
  77. */
  78. #define priv2dev(priv) (&(priv->func)->dev)
  79. #define LOG_CRITICAL(priv, src, fmt, args...) \
  80. do { \
  81. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_CRITICAL)) \
  82. dev_crit(priv2dev(priv), "%s %d: " fmt, \
  83. __func__, __LINE__, ##args); \
  84. } while (0)
  85. #define LOG_ERROR(priv, src, fmt, args...) \
  86. do { \
  87. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_ERROR)) \
  88. dev_err(priv2dev(priv), "%s %d: " fmt, \
  89. __func__, __LINE__, ##args); \
  90. } while (0)
  91. #define LOG_WARNING(priv, src, fmt, args...) \
  92. do { \
  93. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_WARNING)) \
  94. dev_warn(priv2dev(priv), "%s %d: " fmt, \
  95. __func__, __LINE__, ##args); \
  96. } while (0)
  97. #define LOG_INFO(priv, src, fmt, args...) \
  98. do { \
  99. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFO)) \
  100. dev_info(priv2dev(priv), "%s %d: " fmt, \
  101. __func__, __LINE__, ##args); \
  102. } while (0)
  103. #define LOG_TRACE(priv, src, fmt, args...) \
  104. do { \
  105. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_TRACE)) \
  106. dev_dbg(priv2dev(priv), "%s %d: " fmt, \
  107. __func__, __LINE__, ##args); \
  108. } while (0)
  109. #define LOG_HEXDUMP(src, ptr, len) \
  110. do { \
  111. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_DUMP)) \
  112. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, \
  113. 16, 1, ptr, len, false); \
  114. } while (0)
  115. void iwmct_log_top_message(struct iwmct_priv *priv, u8 *buf, int len);
  116. extern u8 iwmct_logdefs[];
  117. int iwmct_log_set_filter(u8 src, u8 logmask);
  118. int iwmct_log_set_fw_filter(u8 src, u8 logmask);
  119. ssize_t show_iwmct_log_level(struct device *d,
  120. struct device_attribute *attr, char *buf);
  121. ssize_t store_iwmct_log_level(struct device *d,
  122. struct device_attribute *attr,
  123. const char *buf, size_t count);
  124. ssize_t show_iwmct_log_level_fw(struct device *d,
  125. struct device_attribute *attr, char *buf);
  126. ssize_t store_iwmct_log_level_fw(struct device *d,
  127. struct device_attribute *attr,
  128. const char *buf, size_t count);
  129. #else
  130. #define LOG_CRITICAL(priv, src, fmt, args...)
  131. #define LOG_ERROR(priv, src, fmt, args...)
  132. #define LOG_WARNING(priv, src, fmt, args...)
  133. #define LOG_INFO(priv, src, fmt, args...)
  134. #define LOG_TRACE(priv, src, fmt, args...)
  135. #define LOG_HEXDUMP(src, ptr, len)
  136. static inline void iwmct_log_top_message(struct iwmct_priv *priv,
  137. u8 *buf, int len) {}
  138. static inline int iwmct_log_set_filter(u8 src, u8 logmask) { return 0; }
  139. static inline int iwmct_log_set_fw_filter(u8 src, u8 logmask) { return 0; }
  140. #endif /* CONFIG_IWMC3200TOP_DEBUG */
  141. int log_get_filter_str(char *buf, int size);
  142. int log_get_fw_filter_str(char *buf, int size);
  143. #endif /* __LOG_H__ */