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 #define ubi_assert(expr) do { \ 23 if (unlikely(!(expr))) { \ 24 pr_crit("UBI assert failed in %s at %u (pid %d)\n", \ 25 __func__, __LINE__, current->pid); \ 26 dump_stack(); \ 27 } \ 28 } while (0) 29 30 #define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \ 31 print_hex_dump(ps, pt, r, g, b, len, a) 32 33 #define ubi_dbg_msg(type, fmt, ...) \ 34 pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \ 35 ##__VA_ARGS__) 36 37 /* General debugging messages */ 38 #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) 39 /* Messages from the eraseblock association sub-system */ 40 #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__) 41 /* Messages from the wear-leveling sub-system */ 42 #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__) 43 /* Messages from the input/output sub-system */ 44 #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__) 45 /* Initialization and build messages */ 46 #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) 47 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_debugfs_init(void); 56 void ubi_debugfs_exit(void); 57 int ubi_debugfs_init_dev(struct ubi_device *ubi); 58 void ubi_debugfs_exit_dev(struct ubi_device *ubi); 59 60 /** 61 * ubi_dbg_is_bgt_disabled - if the background thread is disabled. 62 * @ubi: UBI device description object 63 * 64 * Returns non-zero if the UBI background thread is disabled for testing 65 * purposes. 66 */ 67 static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) 68 { 69 return ubi->dbg.disable_bgt; 70 } 71 72 /** 73 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. 74 * @ubi: UBI device description object 75 * 76 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. 77 */ 78 static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) 79 { 80 if (ubi->dbg.emulate_bitflips) 81 return !(prandom_u32() % 200); 82 return 0; 83 } 84 85 /** 86 * ubi_dbg_is_write_failure - if it is time to emulate a write failure. 87 * @ubi: UBI device description object 88 * 89 * Returns non-zero if a write failure should be emulated, otherwise returns 90 * zero. 91 */ 92 static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) 93 { 94 if (ubi->dbg.emulate_io_failures) 95 return !(prandom_u32() % 500); 96 return 0; 97 } 98 99 /** 100 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. 101 * @ubi: UBI device description object 102 * 103 * Returns non-zero if an erase failure should be emulated, otherwise returns 104 * zero. 105 */ 106 static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) 107 { 108 if (ubi->dbg.emulate_io_failures) 109 return !(prandom_u32() % 400); 110 return 0; 111 } 112 113 static inline int ubi_dbg_chk_io(const struct ubi_device *ubi) 114 { 115 return ubi->dbg.chk_io; 116 } 117 118 static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi) 119 { 120 return ubi->dbg.chk_gen; 121 } 122 123 static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi) 124 { 125 return ubi->dbg.chk_fastmap; 126 } 127 128 static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi) 129 { 130 ubi->dbg.chk_fastmap = 1; 131 } 132 133 int ubi_dbg_power_cut(struct ubi_device *ubi, int caller); 134 #endif /* !__UBI_DEBUG_H__ */ 135