]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/ubi/debug.h
pcm051: use ti_am335x_common.h config
[karo-tx-uboot.git] / drivers / mtd / ubi / debug.h
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 #ifdef CONFIG_MTD_UBI_DEBUG
13 #ifdef UBI_LINUX
14 #include <linux/random.h>
15 #endif
16
17 #define ubi_assert(expr)  BUG_ON(!(expr))
18 #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
19 #else
20 #define ubi_assert(expr)  ({})
21 #define dbg_err(fmt, ...) ({})
22 #endif
23
24 #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
25 #define DBG_DISABLE_BGT 1
26 #else
27 #define DBG_DISABLE_BGT 0
28 #endif
29
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__)
35
36 #define ubi_dbg_dump_stack() dump_stack()
37
38 struct ubi_ec_hdr;
39 struct ubi_vid_hdr;
40 struct ubi_volume;
41 struct ubi_vtbl_record;
42 struct ubi_scan_volume;
43 struct ubi_scan_leb;
44 struct ubi_mkvol_req;
45
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);
53
54 #else
55
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)      ({})
65
66 #endif /* CONFIG_MTD_UBI_DEBUG_MSG */
67
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__)
71 #else
72 #define dbg_eba(fmt, ...) ({})
73 #endif
74
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__)
78 #else
79 #define dbg_wl(fmt, ...) ({})
80 #endif
81
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__)
85 #else
86 #define dbg_io(fmt, ...) ({})
87 #endif
88
89 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
90 /* Initialization and build messages */
91 #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
92 #else
93 #define dbg_bld(fmt, ...) ({})
94 #endif
95
96 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
97 /**
98  * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
99  *
100  * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
101  */
102 static inline int ubi_dbg_is_bitflip(void)
103 {
104         return !(random32() % 200);
105 }
106 #else
107 #define ubi_dbg_is_bitflip() 0
108 #endif
109
110 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
111 /**
112  * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
113  *
114  * Returns non-zero if a write failure should be emulated, otherwise returns
115  * zero.
116  */
117 static inline int ubi_dbg_is_write_failure(void)
118 {
119         return !(random32() % 500);
120 }
121 #else
122 #define ubi_dbg_is_write_failure() 0
123 #endif
124
125 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
126 /**
127  * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
128  *
129  * Returns non-zero if an erase failure should be emulated, otherwise returns
130  * zero.
131  */
132 static inline int ubi_dbg_is_erase_failure(void)
133 {
134                 return !(random32() % 400);
135 }
136 #else
137 #define ubi_dbg_is_erase_failure() 0
138 #endif
139
140 #endif /* !__UBI_DEBUG_H__ */