debug.h 5.7 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. void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
  23. void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
  24. void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
  25. #include <linux/random.h>
  26. #define ubi_assert(expr) do { \
  27. if (unlikely(!(expr))) { \
  28. pr_crit("UBI assert failed in %s at %u (pid %d)\n", \
  29. __func__, __LINE__, current->pid); \
  30. dump_stack(); \
  31. } \
  32. } while (0)
  33. #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
  34. print_hex_dump(l, ps, pt, r, g, b, len, a)
  35. #define ubi_dbg_msg(type, fmt, ...) \
  36. pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
  37. ##__VA_ARGS__)
  38. /* General debugging messages */
  39. #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
  40. /* Messages from the eraseblock association sub-system */
  41. #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
  42. /* Messages from the wear-leveling sub-system */
  43. #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
  44. /* Messages from the input/output sub-system */
  45. #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
  46. /* Initialization and build messages */
  47. #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
  48. void ubi_dump_vol_info(const struct ubi_volume *vol);
  49. void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
  50. void ubi_dump_av(const struct ubi_ainf_volume *av);
  51. void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
  52. void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
  53. int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
  54. int len);
  55. int ubi_debugging_init_dev(struct ubi_device *ubi);
  56. void ubi_debugging_exit_dev(struct ubi_device *ubi);
  57. int ubi_debugfs_init(void);
  58. void ubi_debugfs_exit(void);
  59. int ubi_debugfs_init_dev(struct ubi_device *ubi);
  60. void ubi_debugfs_exit_dev(struct ubi_device *ubi);
  61. /*
  62. * The UBI debugfs directory name pattern and maximum name length (3 for "ubi"
  63. * + 2 for the number plus 1 for the trailing zero byte.
  64. */
  65. #define UBI_DFS_DIR_NAME "ubi%d"
  66. #define UBI_DFS_DIR_LEN (3 + 2 + 1)
  67. /**
  68. * struct ubi_debug_info - debugging information for an UBI device.
  69. *
  70. * @chk_gen: if UBI general extra checks are enabled
  71. * @chk_io: if UBI I/O extra checks are enabled
  72. * @disable_bgt: disable the background task for testing purposes
  73. * @emulate_bitflips: emulate bit-flips for testing purposes
  74. * @emulate_io_failures: emulate write/erase failures for testing purposes
  75. * @dfs_dir_name: name of debugfs directory containing files of this UBI device
  76. * @dfs_dir: direntry object of the UBI device debugfs directory
  77. * @dfs_chk_gen: debugfs knob to enable UBI general extra checks
  78. * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
  79. * @dfs_disable_bgt: debugfs knob to disable the background task
  80. * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
  81. * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
  82. */
  83. struct ubi_debug_info {
  84. unsigned int chk_gen:1;
  85. unsigned int chk_io:1;
  86. unsigned int disable_bgt:1;
  87. unsigned int emulate_bitflips:1;
  88. unsigned int emulate_io_failures:1;
  89. char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
  90. struct dentry *dfs_dir;
  91. struct dentry *dfs_chk_gen;
  92. struct dentry *dfs_chk_io;
  93. struct dentry *dfs_disable_bgt;
  94. struct dentry *dfs_emulate_bitflips;
  95. struct dentry *dfs_emulate_io_failures;
  96. };
  97. /**
  98. * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
  99. * @ubi: UBI device description object
  100. *
  101. * Returns non-zero if the UBI background thread is disabled for testing
  102. * purposes.
  103. */
  104. static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
  105. {
  106. return ubi->dbg->disable_bgt;
  107. }
  108. /**
  109. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
  110. * @ubi: UBI device description object
  111. *
  112. * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
  113. */
  114. static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
  115. {
  116. if (ubi->dbg->emulate_bitflips)
  117. return !(random32() % 200);
  118. return 0;
  119. }
  120. /**
  121. * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
  122. * @ubi: UBI device description object
  123. *
  124. * Returns non-zero if a write failure should be emulated, otherwise returns
  125. * zero.
  126. */
  127. static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
  128. {
  129. if (ubi->dbg->emulate_io_failures)
  130. return !(random32() % 500);
  131. return 0;
  132. }
  133. /**
  134. * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
  135. * @ubi: UBI device description object
  136. *
  137. * Returns non-zero if an erase failure should be emulated, otherwise returns
  138. * zero.
  139. */
  140. static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
  141. {
  142. if (ubi->dbg->emulate_io_failures)
  143. return !(random32() % 400);
  144. return 0;
  145. }
  146. #endif /* !__UBI_DEBUG_H__ */