2 * Copyright (c) International Business Machines Corp., 2006
4 * SPDX-License-Identifier: GPL-2.0+
6 * Author: Artem Bityutskiy (Битюцкий Артём)
9 #ifndef __UBI_DEBUG_H__
10 #define __UBI_DEBUG_H__
12 #ifdef CONFIG_MTD_UBI_DEBUG
14 #include <linux/random.h>
17 #define ubi_assert(expr) BUG_ON(!(expr))
18 #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
20 #define ubi_assert(expr) ({})
21 #define dbg_err(fmt, ...) ({})
24 #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
25 #define DBG_DISABLE_BGT 1
27 #define DBG_DISABLE_BGT 0
30 #ifdef CONFIG_MTD_UBI_DEBUG_MSG
31 /* Generic debugging message */
32 #define dbg_msg(fmt, ...) \
33 printk(KERN_DEBUG "UBI DBG: %s: " fmt "\n", \
34 __FUNCTION__, ##__VA_ARGS__)
36 #define ubi_dbg_dump_stack() dump_stack()
41 struct ubi_vtbl_record;
42 struct ubi_scan_volume;
46 void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
47 void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
48 void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
49 void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
50 void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
51 void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
52 void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
56 #define dbg_msg(fmt, ...) ({})
57 #define ubi_dbg_dump_stack() ({})
58 #define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
59 #define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
60 #define ubi_dbg_dump_vol_info(vol) ({})
61 #define ubi_dbg_dump_vtbl_record(r, idx) ({})
62 #define ubi_dbg_dump_sv(sv) ({})
63 #define ubi_dbg_dump_seb(seb, type) ({})
64 #define ubi_dbg_dump_mkvol_req(req) ({})
66 #endif /* CONFIG_MTD_UBI_DEBUG_MSG */
68 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
69 /* Messages from the eraseblock association unit */
70 #define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
72 #define dbg_eba(fmt, ...) ({})
75 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
76 /* Messages from the wear-leveling unit */
77 #define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
79 #define dbg_wl(fmt, ...) ({})
82 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
83 /* Messages from the input/output unit */
84 #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
86 #define dbg_io(fmt, ...) ({})
89 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
90 /* Initialization and build messages */
91 #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
93 #define dbg_bld(fmt, ...) ({})
96 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
98 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
100 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
102 static inline int ubi_dbg_is_bitflip(void)
104 return !(random32() % 200);
107 #define ubi_dbg_is_bitflip() 0
110 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
112 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
114 * Returns non-zero if a write failure should be emulated, otherwise returns
117 static inline int ubi_dbg_is_write_failure(void)
119 return !(random32() % 500);
122 #define ubi_dbg_is_write_failure() 0
125 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
127 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
129 * Returns non-zero if an erase failure should be emulated, otherwise returns
132 static inline int ubi_dbg_is_erase_failure(void)
134 return !(random32() % 400);
137 #define ubi_dbg_is_erase_failure() 0
140 #endif /* !__UBI_DEBUG_H__ */