debug.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 dbg_do_msg(typ, fmt, ...) do { \
  36. if (ubi_msg_flags & typ) \
  37. dbg_msg(fmt, ##__VA_ARGS__); \
  38. } while (0)
  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_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
  48. void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
  49. void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
  50. void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
  51. void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
  52. void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
  53. void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
  54. void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
  55. extern unsigned int ubi_msg_flags;
  56. /*
  57. * Debugging message type flags (must match msg_type_names in debug.c).
  58. *
  59. * UBI_MSG_GEN: general messages
  60. * UBI_MSG_EBA: journal messages
  61. * UBI_MSG_WL: mount messages
  62. * UBI_MSG_IO: commit messages
  63. * UBI_MSG_BLD: LEB find messages
  64. */
  65. enum {
  66. UBI_MSG_GEN = 0x1,
  67. UBI_MSG_EBA = 0x2,
  68. UBI_MSG_WL = 0x4,
  69. UBI_MSG_IO = 0x8,
  70. UBI_MSG_BLD = 0x10,
  71. };
  72. #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
  73. print_hex_dump(l, ps, pt, r, g, b, len, a)
  74. /* General debugging messages */
  75. #define dbg_gen(fmt, ...) dbg_do_msg(UBI_MSG_GEN, fmt, ##__VA_ARGS__)
  76. /* Messages from the eraseblock association sub-system */
  77. #define dbg_eba(fmt, ...) dbg_do_msg(UBI_MSG_EBA, fmt, ##__VA_ARGS__)
  78. /* Messages from the wear-leveling sub-system */
  79. #define dbg_wl(fmt, ...) dbg_do_msg(UBI_MSG_WL, fmt, ##__VA_ARGS__)
  80. /* Messages from the input/output sub-system */
  81. #define dbg_io(fmt, ...) dbg_do_msg(UBI_MSG_IO, fmt, ##__VA_ARGS__)
  82. /* Initialization and build messages */
  83. #define dbg_bld(fmt, ...) dbg_do_msg(UBI_MSG_BLD, fmt, ##__VA_ARGS__)
  84. extern unsigned int ubi_chk_flags;
  85. /*
  86. * Debugging check flags.
  87. *
  88. * UBI_CHK_GEN: general checks
  89. * UBI_CHK_IO: check writes and erases
  90. */
  91. enum {
  92. UBI_CHK_GEN = 0x1,
  93. UBI_CHK_IO = 0x2,
  94. };
  95. int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
  96. int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
  97. int offset, int len);
  98. extern unsigned int ubi_tst_flags;
  99. /*
  100. * Special testing flags.
  101. *
  102. * UBIFS_TST_DISABLE_BGT: disable the background thread
  103. * UBI_TST_EMULATE_BITFLIPS: emulate bit-flips
  104. * UBI_TST_EMULATE_WRITE_FAILURES: emulate write failures
  105. * UBI_TST_EMULATE_ERASE_FAILURES: emulate erase failures
  106. */
  107. enum {
  108. UBI_TST_DISABLE_BGT = 0x1,
  109. UBI_TST_EMULATE_BITFLIPS = 0x2,
  110. UBI_TST_EMULATE_WRITE_FAILURES = 0x4,
  111. UBI_TST_EMULATE_ERASE_FAILURES = 0x8,
  112. };
  113. /**
  114. * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
  115. *
  116. * Returns non-zero if the UBI background thread is disabled for testing
  117. * purposes.
  118. */
  119. static inline int ubi_dbg_is_bgt_disabled(void)
  120. {
  121. return ubi_tst_flags & UBI_TST_DISABLE_BGT;
  122. }
  123. /**
  124. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
  125. *
  126. * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
  127. */
  128. static inline int ubi_dbg_is_bitflip(void)
  129. {
  130. if (ubi_tst_flags & UBI_TST_EMULATE_BITFLIPS)
  131. return !(random32() % 200);
  132. return 0;
  133. }
  134. /**
  135. * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
  136. *
  137. * Returns non-zero if a write failure should be emulated, otherwise returns
  138. * zero.
  139. */
  140. static inline int ubi_dbg_is_write_failure(void)
  141. {
  142. if (ubi_tst_flags & UBI_TST_EMULATE_WRITE_FAILURES)
  143. return !(random32() % 500);
  144. return 0;
  145. }
  146. /**
  147. * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
  148. *
  149. * Returns non-zero if an erase failure should be emulated, otherwise returns
  150. * zero.
  151. */
  152. static inline int ubi_dbg_is_erase_failure(void)
  153. {
  154. if (ubi_tst_flags & UBI_TST_EMULATE_ERASE_FAILURES)
  155. return !(random32() % 400);
  156. return 0;
  157. }
  158. #else
  159. #define ubi_assert(expr) ({})
  160. #define dbg_err(fmt, ...) ({})
  161. #define dbg_msg(fmt, ...) ({})
  162. #define dbg_gen(fmt, ...) ({})
  163. #define dbg_eba(fmt, ...) ({})
  164. #define dbg_wl(fmt, ...) ({})
  165. #define dbg_io(fmt, ...) ({})
  166. #define dbg_bld(fmt, ...) ({})
  167. #define ubi_dbg_dump_stack() ({})
  168. #define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
  169. #define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
  170. #define ubi_dbg_dump_vol_info(vol) ({})
  171. #define ubi_dbg_dump_vtbl_record(r, idx) ({})
  172. #define ubi_dbg_dump_sv(sv) ({})
  173. #define ubi_dbg_dump_seb(seb, type) ({})
  174. #define ubi_dbg_dump_mkvol_req(req) ({})
  175. #define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({})
  176. #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) ({})
  177. #define ubi_dbg_is_bgt_disabled() 0
  178. #define ubi_dbg_is_bitflip() 0
  179. #define ubi_dbg_is_write_failure() 0
  180. #define ubi_dbg_is_erase_failure() 0
  181. #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
  182. #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
  183. #endif /* !CONFIG_MTD_UBI_DEBUG */
  184. #endif /* !__UBI_DEBUG_H__ */