1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) International Business Machines Corp., 2006
5 * Author: Artem Bityutskiy (Битюцкий Артём)
8 #ifndef __UBI_DEBUG_H__
9 #define __UBI_DEBUG_H__
11 void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
12 void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
13 void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
16 #include <linux/random.h>
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); \
31 #define ubi_assert(expr) assert(expr)
34 #define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
35 print_hex_dump(ps, pt, r, g, b, len, a)
37 #define ubi_dbg_msg(type, fmt, ...) \
38 pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
41 /* General debugging messages */
42 #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
43 /* Messages from the eraseblock association sub-system */
44 #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
45 /* Messages from the wear-leveling sub-system */
46 #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
47 /* Messages from the input/output sub-system */
48 #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
49 /* Initialization and build messages */
50 #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
52 void ubi_dump_vol_info(const struct ubi_volume *vol);
53 void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
54 void ubi_dump_av(const struct ubi_ainf_volume *av);
55 void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
56 void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
57 int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
59 int ubi_debugfs_init(void);
60 void ubi_debugfs_exit(void);
61 int ubi_debugfs_init_dev(struct ubi_device *ubi);
62 void ubi_debugfs_exit_dev(struct ubi_device *ubi);
65 * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
66 * @ubi: UBI device description object
68 * Returns non-zero if the UBI background thread is disabled for testing
71 static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
73 return ubi->dbg.disable_bgt;
77 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
78 * @ubi: UBI device description object
80 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
82 static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
84 if (ubi->dbg.emulate_bitflips)
85 return !(prandom_u32() % 200);
90 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
91 * @ubi: UBI device description object
93 * Returns non-zero if a write failure should be emulated, otherwise returns
96 static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
98 if (ubi->dbg.emulate_io_failures)
99 return !(prandom_u32() % 500);
104 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
105 * @ubi: UBI device description object
107 * Returns non-zero if an erase failure should be emulated, otherwise returns
110 static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
112 if (ubi->dbg.emulate_io_failures)
113 return !(prandom_u32() % 400);
117 static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
119 return ubi->dbg.chk_io;
122 static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
124 return ubi->dbg.chk_gen;
127 static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
129 return ubi->dbg.chk_fastmap;
132 static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
134 ubi->dbg.chk_fastmap = 1;
137 int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
138 #endif /* !__UBI_DEBUG_H__ */