log.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #define LOG_SEV_FILTER_ALL \
  37. (BIT(LOG_SEV_CRITICAL) | \
  38. BIT(LOG_SEV_ERROR) | \
  39. BIT(LOG_SEV_WARNING) | \
  40. BIT(LOG_SEV_INFO) | \
  41. BIT(LOG_SEV_INFOEX))
  42. /* log source */
  43. #define LOG_SRC_INIT 0
  44. #define LOG_SRC_DEBUGFS 1
  45. #define LOG_SRC_FW_DOWNLOAD 2
  46. #define LOG_SRC_FW_MSG 3
  47. #define LOG_SRC_TST 4
  48. #define LOG_SRC_IRQ 5
  49. #define LOG_SRC_MAX 6
  50. #define LOG_SRC_ALL 0xFF
  51. /**
  52. * Default intitialization runtime log level
  53. */
  54. #ifndef LOG_SEV_FILTER_RUNTIME
  55. #define LOG_SEV_FILTER_RUNTIME \
  56. (BIT(LOG_SEV_CRITICAL) | \
  57. BIT(LOG_SEV_ERROR) | \
  58. BIT(LOG_SEV_WARNING))
  59. #endif
  60. #ifndef FW_LOG_SEV_FILTER_RUNTIME
  61. #define FW_LOG_SEV_FILTER_RUNTIME LOG_SEV_FILTER_ALL
  62. #endif
  63. #ifdef CONFIG_IWMC3200TOP_DEBUG
  64. /**
  65. * Log macros
  66. */
  67. #define priv2dev(priv) (&(priv->func)->dev)
  68. #define LOG_CRITICAL(priv, src, fmt, args...) \
  69. do { \
  70. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_CRITICAL)) \
  71. dev_crit(priv2dev(priv), "%s %d: " fmt, \
  72. __func__, __LINE__, ##args); \
  73. } while (0)
  74. #define LOG_ERROR(priv, src, fmt, args...) \
  75. do { \
  76. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_ERROR)) \
  77. dev_err(priv2dev(priv), "%s %d: " fmt, \
  78. __func__, __LINE__, ##args); \
  79. } while (0)
  80. #define LOG_WARNING(priv, src, fmt, args...) \
  81. do { \
  82. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_WARNING)) \
  83. dev_warn(priv2dev(priv), "%s %d: " fmt, \
  84. __func__, __LINE__, ##args); \
  85. } while (0)
  86. #define LOG_INFO(priv, src, fmt, args...) \
  87. do { \
  88. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFO)) \
  89. dev_info(priv2dev(priv), "%s %d: " fmt, \
  90. __func__, __LINE__, ##args); \
  91. } while (0)
  92. #define LOG_INFOEX(priv, src, fmt, args...) \
  93. do { \
  94. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFOEX)) \
  95. dev_dbg(priv2dev(priv), "%s %d: " fmt, \
  96. __func__, __LINE__, ##args); \
  97. } while (0)
  98. #define LOG_HEXDUMP(src, ptr, len) \
  99. do { \
  100. if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFOEX)) \
  101. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, \
  102. 16, 1, ptr, len, false); \
  103. } while (0)
  104. void iwmct_log_top_message(struct iwmct_priv *priv, u8 *buf, int len);
  105. extern u8 iwmct_logdefs[];
  106. int iwmct_log_set_filter(u8 src, u8 logmask);
  107. int iwmct_log_set_fw_filter(u8 src, u8 logmask);
  108. ssize_t show_iwmct_log_level(struct device *d,
  109. struct device_attribute *attr, char *buf);
  110. ssize_t store_iwmct_log_level(struct device *d,
  111. struct device_attribute *attr,
  112. const char *buf, size_t count);
  113. ssize_t show_iwmct_log_level_fw(struct device *d,
  114. struct device_attribute *attr, char *buf);
  115. ssize_t store_iwmct_log_level_fw(struct device *d,
  116. struct device_attribute *attr,
  117. const char *buf, size_t count);
  118. #else
  119. #define LOG_CRITICAL(priv, src, fmt, args...)
  120. #define LOG_ERROR(priv, src, fmt, args...)
  121. #define LOG_WARNING(priv, src, fmt, args...)
  122. #define LOG_INFO(priv, src, fmt, args...)
  123. #define LOG_INFOEX(priv, src, fmt, args...)
  124. #define LOG_HEXDUMP(src, ptr, len)
  125. static inline void iwmct_log_top_message(struct iwmct_priv *priv,
  126. u8 *buf, int len) {}
  127. static inline int iwmct_log_set_filter(u8 src, u8 logmask) { return 0; }
  128. static inline int iwmct_log_set_fw_filter(u8 src, u8 logmask) { return 0; }
  129. #endif /* CONFIG_IWMC3200TOP_DEBUG */
  130. int log_get_filter_str(char *buf, int size);
  131. int log_get_fw_filter_str(char *buf, int size);
  132. #endif /* __LOG_H__ */