debug.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */
  3. /* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */
  4. #ifndef _CNSS_DEBUG_H
  5. #define _CNSS_DEBUG_H
  6. #include <linux/printk.h>
  7. enum log_level {
  8. EMERG_LOG = 0,
  9. ALERT_LOG = 1,
  10. CRIT_LOG = 2,
  11. ERR_LOG = 3,
  12. WARNING_LOG = 4,
  13. NOTICE_LOG = 5,
  14. INFO_LOG = 6,
  15. DEBUG_LOG = 7,
  16. DEBUG_HI_LOG = 8,
  17. MAX_LOG = 9,
  18. };
  19. extern enum log_level cnss_kernel_log_level;
  20. #if IS_ENABLED(CONFIG_IPC_LOGGING)
  21. #include <linux/ipc_logging.h>
  22. #include <asm/current.h>
  23. extern void *cnss_ipc_log_context;
  24. extern void *cnss_ipc_log_long_context;
  25. extern enum log_level cnss_ipc_log_level;
  26. #ifdef CONFIG_CNSS2_DEBUG
  27. #define CNSS_IPC_LOG_PAGES 100
  28. #else
  29. #define CNSS_IPC_LOG_PAGES 50
  30. #endif
  31. #define cnss_debug_log_print(_x...) \
  32. cnss_debug_ipc_log_print(cnss_ipc_log_context, _x)
  33. #define cnss_debug_log_long_print(_x...) \
  34. cnss_debug_ipc_log_print(cnss_ipc_log_long_context, _x)
  35. #else
  36. #define cnss_debug_log_print(_x...) \
  37. cnss_debug_ipc_log_print((void *)NULL, _x)
  38. #define cnss_debug_log_long_print(_x...) \
  39. cnss_debug_ipc_log_print((void *)NULL, _x)
  40. #endif
  41. #define proc_name (in_irq() ? "irq" : \
  42. (in_softirq() ? "soft_irq" : current->comm))
  43. #define cnss_pr_err(_fmt, ...) \
  44. cnss_debug_log_print(proc_name, __func__, \
  45. ERR_LOG, ERR_LOG, _fmt, ##__VA_ARGS__)
  46. #define cnss_pr_warn(_fmt, ...) \
  47. cnss_debug_log_print(proc_name, __func__, \
  48. WARNING_LOG, WARNING_LOG, _fmt, ##__VA_ARGS__)
  49. #define cnss_pr_info(_fmt, ...) \
  50. cnss_debug_log_print(proc_name, __func__, \
  51. INFO_LOG, INFO_LOG, _fmt, ##__VA_ARGS__)
  52. #define cnss_pr_dbg(_fmt, ...) \
  53. cnss_debug_log_print(proc_name, __func__, \
  54. DEBUG_LOG, DEBUG_LOG, _fmt, ##__VA_ARGS__)
  55. #define cnss_pr_vdbg(_fmt, ...) \
  56. cnss_debug_log_long_print(proc_name, __func__, \
  57. DEBUG_LOG, DEBUG_LOG, _fmt, ##__VA_ARGS__)
  58. #define cnss_pr_buf(_fmt, ...) \
  59. cnss_debug_log_long_print(proc_name, __func__, \
  60. DEBUG_HI_LOG, DEBUG_LOG, _fmt, ##__VA_ARGS__)
  61. #define cnss_pr_dbg_buf(_fmt, ...) \
  62. cnss_debug_log_long_print(proc_name, __func__, \
  63. DEBUG_HI_LOG, DEBUG_HI_LOG, _fmt, ##__VA_ARGS__)
  64. #ifdef CONFIG_CNSS2_DEBUG
  65. #define CNSS_ASSERT(_condition) do { \
  66. if (!(_condition)) { \
  67. cnss_pr_err("ASSERT at line %d\n", \
  68. __LINE__); \
  69. BUG(); \
  70. } \
  71. } while (0)
  72. #else
  73. #define CNSS_ASSERT(_condition) do { \
  74. if (!(_condition)) { \
  75. cnss_pr_err("ASSERT at line %d\n", \
  76. __LINE__); \
  77. WARN_ON(1); \
  78. } \
  79. } while (0)
  80. #endif
  81. #define cnss_fatal_err(_fmt, ...) \
  82. cnss_pr_err("fatal: " _fmt, ##__VA_ARGS__)
  83. int cnss_debug_init(void);
  84. void cnss_debug_deinit(void);
  85. int cnss_debugfs_create(struct cnss_plat_data *plat_priv);
  86. void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv);
  87. void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
  88. enum log_level kern_log_level,
  89. enum log_level ipc_log_level, char *fmt, ...);
  90. #endif /* _CNSS_DEBUG_H */