debug.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Author: Artem Bityutskiy (Битюцкий Артём)
  19. */
  20. #ifndef __UBI_DEBUG_H__
  21. #define __UBI_DEBUG_H__
  22. #ifdef CONFIG_MTD_UBI_DEBUG
  23. #include <linux/random.h>
  24. #define ubi_assert(expr) BUG_ON(!(expr))
  25. #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
  26. #else
  27. #define ubi_assert(expr) ({})
  28. #define dbg_err(fmt, ...) ({})
  29. #endif
  30. #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
  31. #define DBG_DISABLE_BGT 1
  32. #else
  33. #define DBG_DISABLE_BGT 0
  34. #endif
  35. #ifdef CONFIG_MTD_UBI_DEBUG_MSG
  36. /* Generic debugging message */
  37. #define dbg_msg(fmt, ...) \
  38. printk(KERN_DEBUG "UBI DBG: %s: " fmt "\n", __FUNCTION__, ##__VA_ARGS__)
  39. #define ubi_dbg_dump_stack() dump_stack()
  40. struct ubi_ec_hdr;
  41. struct ubi_vid_hdr;
  42. struct ubi_volume;
  43. struct ubi_vtbl_record;
  44. struct ubi_scan_volume;
  45. struct ubi_scan_leb;
  46. struct ubi_mkvol_req;
  47. void ubi_dbg_print(int type, const char *func, const char *fmt, ...);
  48. void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
  49. void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
  50. void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
  51. void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
  52. void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
  53. void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
  54. void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
  55. void ubi_dbg_hexdump(const void *buf, int size);
  56. #else
  57. #define dbg_msg(fmt, ...) ({})
  58. #define ubi_dbg_dump_stack() ({})
  59. #define ubi_dbg_print(func, fmt, ...) ({})
  60. #define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
  61. #define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
  62. #define ubi_dbg_dump_vol_info(vol) ({})
  63. #define ubi_dbg_dump_vtbl_record(r, idx) ({})
  64. #define ubi_dbg_dump_sv(sv) ({})
  65. #define ubi_dbg_dump_seb(seb, type) ({})
  66. #define ubi_dbg_dump_mkvol_req(req) ({})
  67. #define ubi_dbg_hexdump(buf, size) ({})
  68. #endif /* CONFIG_MTD_UBI_DEBUG_MSG */
  69. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
  70. /* Messages from the eraseblock association unit */
  71. #define dbg_eba(fmt, ...) \
  72. printk(KERN_DEBUG "UBI DBG eba: %s: " fmt "\n", __FUNCTION__, \
  73. ##__VA_ARGS__)
  74. #else
  75. #define dbg_eba(fmt, ...) ({})
  76. #endif
  77. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
  78. /* Messages from the wear-leveling unit */
  79. #define dbg_wl(fmt, ...) \
  80. printk(KERN_DEBUG "UBI DBG wl: %s: " fmt "\n", __FUNCTION__, \
  81. ##__VA_ARGS__)
  82. #else
  83. #define dbg_wl(fmt, ...) ({})
  84. #endif
  85. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
  86. /* Messages from the input/output unit */
  87. #define dbg_io(fmt, ...) \
  88. printk(KERN_DEBUG "UBI DBG io: %s: " fmt "\n", __FUNCTION__, \
  89. ##__VA_ARGS__)
  90. #else
  91. #define dbg_io(fmt, ...) ({})
  92. #endif
  93. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
  94. /* Initialization and build messages */
  95. #define dbg_bld(fmt, ...) \
  96. printk(KERN_DEBUG "UBI DBG bld: %s: " fmt "\n", __FUNCTION__, \
  97. ##__VA_ARGS__)
  98. #else
  99. #define dbg_bld(fmt, ...) ({})
  100. #endif
  101. #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
  102. /**
  103. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
  104. *
  105. * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
  106. */
  107. static inline int ubi_dbg_is_bitflip(void)
  108. {
  109. return !(random32() % 200);
  110. }
  111. #else
  112. #define ubi_dbg_is_bitflip() 0
  113. #endif
  114. #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
  115. /**
  116. * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
  117. *
  118. * Returns non-zero if a write failure should be emulated, otherwise returns
  119. * zero.
  120. */
  121. static inline int ubi_dbg_is_write_failure(void)
  122. {
  123. return !(random32() % 500);
  124. }
  125. #else
  126. #define ubi_dbg_is_write_failure() 0
  127. #endif
  128. #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
  129. /**
  130. * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
  131. *
  132. * Returns non-zero if an erase failure should be emulated, otherwise returns
  133. * zero.
  134. */
  135. static inline int ubi_dbg_is_erase_failure(void)
  136. {
  137. return !(random32() % 400);
  138. }
  139. #else
  140. #define ubi_dbg_is_erase_failure() 0
  141. #endif
  142. #endif /* !__UBI_DEBUG_H__ */