debug.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */
  3. #ifndef _CNSS_DEBUG_H
  4. #define _CNSS_DEBUG_H
  5. #include <linux/printk.h>
  6. #if IS_ENABLED(CONFIG_IPC_LOGGING)
  7. #include <linux/ipc_logging.h>
  8. #include <asm/current.h>
  9. extern void *cnss_ipc_log_context;
  10. extern void *cnss_ipc_log_long_context;
  11. #ifdef CONFIG_CNSS2_DEBUG
  12. #define CNSS_IPC_LOG_PAGES 100
  13. #else
  14. #define CNSS_IPC_LOG_PAGES 50
  15. #endif
  16. #define cnss_debug_log_print(_x...) \
  17. cnss_debug_ipc_log_print(cnss_ipc_log_context, _x)
  18. #define cnss_debug_log_long_print(_x...) \
  19. cnss_debug_ipc_log_print(cnss_ipc_log_long_context, _x)
  20. #else
  21. #define cnss_debug_log_print(_x...) \
  22. cnss_debug_ipc_log_print((void *)NULL, _x)
  23. #define cnss_debug_log_long_print(_x...) \
  24. cnss_debug_ipc_log_print((void *)NULL, _x)
  25. #endif
  26. #define proc_name (in_irq() ? "irq" : \
  27. (in_softirq() ? "soft_irq" : current->comm))
  28. #define cnss_pr_err(_fmt, ...) \
  29. cnss_debug_log_print(proc_name, __func__, \
  30. KERN_ERR, _fmt, ##__VA_ARGS__)
  31. #define cnss_pr_warn(_fmt, ...) \
  32. cnss_debug_log_print(proc_name, __func__, \
  33. KERN_WARNING, _fmt, ##__VA_ARGS__)
  34. #define cnss_pr_info(_fmt, ...) \
  35. cnss_debug_log_print(proc_name, __func__, \
  36. KERN_INFO, _fmt, ##__VA_ARGS__)
  37. #define cnss_pr_dbg(_fmt, ...) \
  38. cnss_debug_log_print(proc_name, __func__, \
  39. KERN_DEBUG, _fmt, ##__VA_ARGS__)
  40. #define cnss_pr_vdbg(_fmt, ...) \
  41. cnss_debug_log_long_print(proc_name, __func__, \
  42. KERN_DEBUG, _fmt, ##__VA_ARGS__)
  43. #define cnss_pr_buf(_fmt, ...) \
  44. cnss_debug_log_long_print(proc_name, __func__, \
  45. NULL, _fmt, ##__VA_ARGS__)
  46. #ifdef CONFIG_CNSS2_DEBUG
  47. #define CNSS_ASSERT(_condition) do { \
  48. if (!(_condition)) { \
  49. cnss_pr_err("ASSERT at line %d\n", \
  50. __LINE__); \
  51. BUG(); \
  52. } \
  53. } while (0)
  54. #else
  55. #define CNSS_ASSERT(_condition) do { \
  56. if (!(_condition)) { \
  57. cnss_pr_err("ASSERT at line %d\n", \
  58. __LINE__); \
  59. WARN_ON(1); \
  60. } \
  61. } while (0)
  62. #endif
  63. #define cnss_fatal_err(_fmt, ...) \
  64. cnss_pr_err("fatal: " _fmt, ##__VA_ARGS__)
  65. int cnss_debug_init(void);
  66. void cnss_debug_deinit(void);
  67. int cnss_debugfs_create(struct cnss_plat_data *plat_priv);
  68. void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv);
  69. void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
  70. const char *log_level, char *fmt, ...);
  71. #endif /* _CNSS_DEBUG_H */