debug.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
  25. #define ubi_assert(expr) do { \
  26. if (unlikely(!(expr))) { \
  27. printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \
  28. __func__, __LINE__, current->pid); \
  29. ubi_dbg_dump_stack(); \
  30. } \
  31. } while (0)
  32. #define dbg_msg(fmt, ...) \
  33. printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
  34. current->pid, __func__, ##__VA_ARGS__)
  35. #define ubi_dbg_dump_stack() dump_stack()
  36. struct ubi_ec_hdr;
  37. struct ubi_vid_hdr;
  38. struct ubi_volume;
  39. struct ubi_vtbl_record;
  40. struct ubi_scan_volume;
  41. struct ubi_scan_leb;
  42. struct ubi_mkvol_req;
  43. void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
  44. void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
  45. void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
  46. void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
  47. void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
  48. void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
  49. void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
  50. void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
  51. #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
  52. print_hex_dump(l, ps, pt, r, g, b, len, a)
  53. #ifdef CONFIG_MTD_UBI_DEBUG_MSG
  54. /* General debugging messages */
  55. #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
  56. #else
  57. #define dbg_gen(fmt, ...) ({})
  58. #endif
  59. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
  60. /* Messages from the eraseblock association sub-system */
  61. #define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
  62. #else
  63. #define dbg_eba(fmt, ...) ({})
  64. #endif
  65. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
  66. /* Messages from the wear-leveling sub-system */
  67. #define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
  68. #else
  69. #define dbg_wl(fmt, ...) ({})
  70. #endif
  71. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
  72. /* Messages from the input/output sub-system */
  73. #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
  74. #else
  75. #define dbg_io(fmt, ...) ({})
  76. #endif
  77. #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
  78. /* Initialization and build messages */
  79. #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
  80. #define UBI_IO_DEBUG 1
  81. #else
  82. #define dbg_bld(fmt, ...) ({})
  83. #define UBI_IO_DEBUG 0
  84. #endif
  85. #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
  86. int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
  87. int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
  88. int offset, int len);
  89. #else
  90. #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
  91. #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
  92. #endif
  93. #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
  94. #define DBG_DISABLE_BGT 1
  95. #else
  96. #define DBG_DISABLE_BGT 0
  97. #endif
  98. #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
  99. /**
  100. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
  101. *
  102. * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
  103. */
  104. static inline int ubi_dbg_is_bitflip(void)
  105. {
  106. return !(random32() % 200);
  107. }
  108. #else
  109. #define ubi_dbg_is_bitflip() 0
  110. #endif
  111. #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
  112. /**
  113. * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
  114. *
  115. * Returns non-zero if a write failure should be emulated, otherwise returns
  116. * zero.
  117. */
  118. static inline int ubi_dbg_is_write_failure(void)
  119. {
  120. return !(random32() % 500);
  121. }
  122. #else
  123. #define ubi_dbg_is_write_failure() 0
  124. #endif
  125. #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
  126. /**
  127. * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
  128. *
  129. * Returns non-zero if an erase failure should be emulated, otherwise returns
  130. * zero.
  131. */
  132. static inline int ubi_dbg_is_erase_failure(void)
  133. {
  134. return !(random32() % 400);
  135. }
  136. #else
  137. #define ubi_dbg_is_erase_failure() 0
  138. #endif
  139. #else
  140. #define ubi_assert(expr) ({})
  141. #define dbg_err(fmt, ...) ({})
  142. #define dbg_msg(fmt, ...) ({})
  143. #define dbg_gen(fmt, ...) ({})
  144. #define dbg_eba(fmt, ...) ({})
  145. #define dbg_wl(fmt, ...) ({})
  146. #define dbg_io(fmt, ...) ({})
  147. #define dbg_bld(fmt, ...) ({})
  148. #define ubi_dbg_dump_stack() ({})
  149. #define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
  150. #define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
  151. #define ubi_dbg_dump_vol_info(vol) ({})
  152. #define ubi_dbg_dump_vtbl_record(r, idx) ({})
  153. #define ubi_dbg_dump_sv(sv) ({})
  154. #define ubi_dbg_dump_seb(seb, type) ({})
  155. #define ubi_dbg_dump_mkvol_req(req) ({})
  156. #define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({})
  157. #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) ({})
  158. #define UBI_IO_DEBUG 0
  159. #define DBG_DISABLE_BGT 0
  160. #define ubi_dbg_is_bitflip() 0
  161. #define ubi_dbg_is_write_failure() 0
  162. #define ubi_dbg_is_erase_failure() 0
  163. #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
  164. #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
  165. #endif /* !CONFIG_MTD_UBI_DEBUG */
  166. #endif /* !__UBI_DEBUG_H__ */