debug.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) International Business Machines Corp., 2006
  4. *
  5. * Author: Artem Bityutskiy (Битюцкий Артём)
  6. */
  7. #ifndef __UBI_DEBUG_H__
  8. #define __UBI_DEBUG_H__
  9. void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
  10. void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
  11. void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
  12. #ifndef __UBOOT__
  13. #include <linux/random.h>
  14. #endif
  15. #include <hexdump.h>
  16. #ifndef __UBOOT__
  17. #define ubi_assert(expr) do { \
  18. if (unlikely(!(expr))) { \
  19. pr_crit("UBI assert failed in %s at %u (pid %d)\n", \
  20. __func__, __LINE__, current->pid); \
  21. dump_stack(); \
  22. } \
  23. } while (0)
  24. #else
  25. #include <log.h>
  26. #define ubi_assert(expr) assert(expr)
  27. #endif
  28. #define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
  29. print_hex_dump(ps, pt, r, g, b, len, a)
  30. #define ubi_dbg_msg(type, fmt, ...) \
  31. pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
  32. ##__VA_ARGS__)
  33. /* General debugging messages */
  34. #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
  35. /* Messages from the eraseblock association sub-system */
  36. #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
  37. /* Messages from the wear-leveling sub-system */
  38. #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
  39. /* Messages from the input/output sub-system */
  40. #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
  41. /* Initialization and build messages */
  42. #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
  43. void ubi_dump_vol_info(const struct ubi_volume *vol);
  44. void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
  45. void ubi_dump_av(const struct ubi_ainf_volume *av);
  46. void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
  47. void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
  48. int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
  49. int len);
  50. int ubi_debugfs_init(void);
  51. void ubi_debugfs_exit(void);
  52. int ubi_debugfs_init_dev(struct ubi_device *ubi);
  53. void ubi_debugfs_exit_dev(struct ubi_device *ubi);
  54. /**
  55. * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
  56. * @ubi: UBI device description object
  57. *
  58. * Returns non-zero if the UBI background thread is disabled for testing
  59. * purposes.
  60. */
  61. static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
  62. {
  63. return ubi->dbg.disable_bgt;
  64. }
  65. /**
  66. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
  67. * @ubi: UBI device description object
  68. *
  69. * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
  70. */
  71. static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
  72. {
  73. if (ubi->dbg.emulate_bitflips)
  74. return !(prandom_u32() % 200);
  75. return 0;
  76. }
  77. /**
  78. * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
  79. * @ubi: UBI device description object
  80. *
  81. * Returns non-zero if a write failure should be emulated, otherwise returns
  82. * zero.
  83. */
  84. static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
  85. {
  86. if (ubi->dbg.emulate_io_failures)
  87. return !(prandom_u32() % 500);
  88. return 0;
  89. }
  90. /**
  91. * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
  92. * @ubi: UBI device description object
  93. *
  94. * Returns non-zero if an erase failure should be emulated, otherwise returns
  95. * zero.
  96. */
  97. static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
  98. {
  99. if (ubi->dbg.emulate_io_failures)
  100. return !(prandom_u32() % 400);
  101. return 0;
  102. }
  103. static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
  104. {
  105. return ubi->dbg.chk_io;
  106. }
  107. static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
  108. {
  109. return ubi->dbg.chk_gen;
  110. }
  111. static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
  112. {
  113. return ubi->dbg.chk_fastmap;
  114. }
  115. static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
  116. {
  117. ubi->dbg.chk_fastmap = 1;
  118. }
  119. int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
  120. #endif /* !__UBI_DEBUG_H__ */