debug.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. struct ubi_ec_hdr;
  23. struct ubi_vid_hdr;
  24. struct ubi_volume;
  25. struct ubi_vtbl_record;
  26. struct ubi_scan_volume;
  27. struct ubi_scan_leb;
  28. struct ubi_mkvol_req;
  29. #ifdef CONFIG_MTD_UBI_DEBUG
  30. #include <linux/random.h>
  31. #define ubi_assert(expr) do { \
  32. if (unlikely(!(expr))) { \
  33. printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \
  34. __func__, __LINE__, current->pid); \
  35. ubi_dbg_dump_stack(); \
  36. } \
  37. } while (0)
  38. #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
  39. #define ubi_dbg_dump_stack() dump_stack()
  40. #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
  41. print_hex_dump(l, ps, pt, r, g, b, len, a)
  42. #define ubi_dbg_msg(type, fmt, ...) \
  43. pr_debug("UBI DBG " type ": " fmt "\n", ##__VA_ARGS__)
  44. /* Just a debugging messages not related to any specific UBI subsystem */
  45. #define dbg_msg(fmt, ...) ubi_dbg_msg("msg", fmt, ##__VA_ARGS__)
  46. /* General debugging messages */
  47. #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
  48. /* Messages from the eraseblock association sub-system */
  49. #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
  50. /* Messages from the wear-leveling sub-system */
  51. #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
  52. /* Messages from the input/output sub-system */
  53. #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
  54. /* Initialization and build messages */
  55. #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
  56. void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
  57. void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
  58. void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
  59. void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
  60. void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
  61. void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
  62. void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
  63. void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
  64. extern unsigned int ubi_chk_flags;
  65. /*
  66. * Debugging check flags.
  67. *
  68. * UBI_CHK_GEN: general checks
  69. * UBI_CHK_IO: check writes and erases
  70. */
  71. enum {
  72. UBI_CHK_GEN = 0x1,
  73. UBI_CHK_IO = 0x2,
  74. };
  75. int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
  76. int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
  77. int offset, int len);
  78. extern unsigned int ubi_tst_flags;
  79. /*
  80. * Special testing flags.
  81. *
  82. * UBIFS_TST_DISABLE_BGT: disable the background thread
  83. * UBI_TST_EMULATE_BITFLIPS: emulate bit-flips
  84. * UBI_TST_EMULATE_WRITE_FAILURES: emulate write failures
  85. * UBI_TST_EMULATE_ERASE_FAILURES: emulate erase failures
  86. */
  87. enum {
  88. UBI_TST_DISABLE_BGT = 0x1,
  89. UBI_TST_EMULATE_BITFLIPS = 0x2,
  90. UBI_TST_EMULATE_WRITE_FAILURES = 0x4,
  91. UBI_TST_EMULATE_ERASE_FAILURES = 0x8,
  92. };
  93. /**
  94. * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
  95. *
  96. * Returns non-zero if the UBI background thread is disabled for testing
  97. * purposes.
  98. */
  99. static inline int ubi_dbg_is_bgt_disabled(void)
  100. {
  101. return ubi_tst_flags & UBI_TST_DISABLE_BGT;
  102. }
  103. /**
  104. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
  105. *
  106. * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
  107. */
  108. static inline int ubi_dbg_is_bitflip(void)
  109. {
  110. if (ubi_tst_flags & UBI_TST_EMULATE_BITFLIPS)
  111. return !(random32() % 200);
  112. return 0;
  113. }
  114. /**
  115. * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
  116. *
  117. * Returns non-zero if a write failure should be emulated, otherwise returns
  118. * zero.
  119. */
  120. static inline int ubi_dbg_is_write_failure(void)
  121. {
  122. if (ubi_tst_flags & UBI_TST_EMULATE_WRITE_FAILURES)
  123. return !(random32() % 500);
  124. return 0;
  125. }
  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. if (ubi_tst_flags & UBI_TST_EMULATE_ERASE_FAILURES)
  135. return !(random32() % 400);
  136. return 0;
  137. }
  138. #else
  139. /* Use "if (0)" to make compiler check arguments even if debugging is off */
  140. #define ubi_assert(expr) do { \
  141. if (0) { \
  142. printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \
  143. __func__, __LINE__, current->pid); \
  144. } \
  145. } while (0)
  146. #define dbg_err(fmt, ...) do { \
  147. if (0) \
  148. ubi_err(fmt, ##__VA_ARGS__); \
  149. } while (0)
  150. #define ubi_dbg_msg(fmt, ...) do { \
  151. if (0) \
  152. pr_debug(fmt "\n", ##__VA_ARGS__); \
  153. } while (0)
  154. #define dbg_msg(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
  155. #define dbg_gen(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
  156. #define dbg_eba(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
  157. #define dbg_wl(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
  158. #define dbg_io(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
  159. #define dbg_bld(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
  160. static inline void ubi_dbg_dump_stack(void) { return; }
  161. static inline void
  162. ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) { return; }
  163. static inline void
  164. ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) { return; }
  165. static inline void
  166. ubi_dbg_dump_vol_info(const struct ubi_volume *vol) { return; }
  167. static inline void
  168. ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) { return; }
  169. static inline void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) { return; }
  170. static inline void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb,
  171. int type) { return; }
  172. static inline void
  173. ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) { return; }
  174. static inline void ubi_dbg_dump_flash(struct ubi_device *ubi,
  175. int pnum, int offset, int len) { return; }
  176. static inline void
  177. ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r,
  178. int g, const void *b, size_t len, bool a) { return; }
  179. static inline int ubi_dbg_is_bgt_disabled(void) { return 0; }
  180. static inline int ubi_dbg_is_bitflip(void) { return 0; }
  181. static inline int ubi_dbg_is_write_failure(void) { return 0; }
  182. static inline int ubi_dbg_is_erase_failure(void) { return 0; }
  183. static inline int ubi_dbg_check_all_ff(struct ubi_device *ubi,
  184. int pnum, int offset,
  185. int len) { return 0; }
  186. static inline int ubi_dbg_check_write(struct ubi_device *ubi,
  187. const void *buf, int pnum,
  188. int offset, int len) { return 0; }
  189. #endif /* !CONFIG_MTD_UBI_DEBUG */
  190. #endif /* !__UBI_DEBUG_H__ */