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