]>
Commit | Line | Data |
---|---|---|
801c135c AB |
1 | /* |
2 | * Copyright (c) International Business Machines Corp., 2006 | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
12 | * the GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | * | |
18 | * Author: Artem Bityutskiy (Битюцкий Артём) | |
19 | */ | |
20 | ||
21 | #ifndef __UBI_DEBUG_H__ | |
22 | #define __UBI_DEBUG_H__ | |
23 | ||
24 | #ifdef CONFIG_MTD_UBI_DEBUG | |
25 | #include <linux/random.h> | |
26 | ||
801c135c | 27 | #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) |
801c135c | 28 | |
c8566350 | 29 | #define ubi_assert(expr) do { \ |
f2863c54 AB |
30 | if (unlikely(!(expr))) { \ |
31 | printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \ | |
32 | __func__, __LINE__, current->pid); \ | |
33 | ubi_dbg_dump_stack(); \ | |
34 | } \ | |
c8566350 | 35 | } while (0) |
801c135c | 36 | |
d19bafd9 AB |
37 | #define dbg_msg(fmt, ...) \ |
38 | printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ | |
cb53b3b9 | 39 | current->pid, __func__, ##__VA_ARGS__) |
801c135c AB |
40 | |
41 | #define ubi_dbg_dump_stack() dump_stack() | |
42 | ||
43 | struct ubi_ec_hdr; | |
44 | struct ubi_vid_hdr; | |
45 | struct ubi_volume; | |
46 | struct ubi_vtbl_record; | |
47 | struct ubi_scan_volume; | |
48 | struct ubi_scan_leb; | |
49 | struct ubi_mkvol_req; | |
50 | ||
801c135c AB |
51 | void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); |
52 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); | |
53 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol); | |
54 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); | |
55 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); | |
56 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); | |
57 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); | |
867996b1 | 58 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
801c135c | 59 | |
c8566350 AB |
60 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG |
61 | /* General debugging messages */ | |
62 | #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
801c135c | 63 | #else |
c8566350 AB |
64 | #define dbg_gen(fmt, ...) ({}) |
65 | #endif | |
801c135c AB |
66 | |
67 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA | |
85c6e6e2 | 68 | /* Messages from the eraseblock association sub-system */ |
d19bafd9 | 69 | #define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
801c135c AB |
70 | #else |
71 | #define dbg_eba(fmt, ...) ({}) | |
72 | #endif | |
73 | ||
74 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL | |
85c6e6e2 | 75 | /* Messages from the wear-leveling sub-system */ |
d19bafd9 | 76 | #define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
801c135c AB |
77 | #else |
78 | #define dbg_wl(fmt, ...) ({}) | |
79 | #endif | |
80 | ||
81 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO | |
85c6e6e2 | 82 | /* Messages from the input/output sub-system */ |
d19bafd9 | 83 | #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
801c135c AB |
84 | #else |
85 | #define dbg_io(fmt, ...) ({}) | |
86 | #endif | |
87 | ||
88 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD | |
89 | /* Initialization and build messages */ | |
d19bafd9 | 90 | #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
a4f0fcdf | 91 | #define UBI_IO_DEBUG 1 |
801c135c AB |
92 | #else |
93 | #define dbg_bld(fmt, ...) ({}) | |
a4f0fcdf | 94 | #define UBI_IO_DEBUG 0 |
801c135c AB |
95 | #endif |
96 | ||
40a71a87 AB |
97 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
98 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); | |
99 | #else | |
100 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 | |
101 | #endif | |
102 | ||
c8566350 AB |
103 | #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT |
104 | #define DBG_DISABLE_BGT 1 | |
105 | #else | |
106 | #define DBG_DISABLE_BGT 0 | |
107 | #endif | |
108 | ||
801c135c AB |
109 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS |
110 | /** | |
111 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. | |
112 | * | |
113 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. | |
114 | */ | |
115 | static inline int ubi_dbg_is_bitflip(void) | |
116 | { | |
117 | return !(random32() % 200); | |
118 | } | |
119 | #else | |
120 | #define ubi_dbg_is_bitflip() 0 | |
121 | #endif | |
122 | ||
123 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES | |
124 | /** | |
125 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. | |
126 | * | |
127 | * Returns non-zero if a write failure should be emulated, otherwise returns | |
128 | * zero. | |
129 | */ | |
130 | static inline int ubi_dbg_is_write_failure(void) | |
131 | { | |
132 | return !(random32() % 500); | |
133 | } | |
134 | #else | |
135 | #define ubi_dbg_is_write_failure() 0 | |
136 | #endif | |
137 | ||
138 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES | |
139 | /** | |
140 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. | |
141 | * | |
142 | * Returns non-zero if an erase failure should be emulated, otherwise returns | |
143 | * zero. | |
144 | */ | |
145 | static inline int ubi_dbg_is_erase_failure(void) | |
146 | { | |
147 | return !(random32() % 400); | |
148 | } | |
149 | #else | |
150 | #define ubi_dbg_is_erase_failure() 0 | |
151 | #endif | |
152 | ||
c8566350 AB |
153 | #else |
154 | ||
155 | #define ubi_assert(expr) ({}) | |
156 | #define dbg_err(fmt, ...) ({}) | |
157 | #define dbg_msg(fmt, ...) ({}) | |
158 | #define dbg_gen(fmt, ...) ({}) | |
159 | #define dbg_eba(fmt, ...) ({}) | |
160 | #define dbg_wl(fmt, ...) ({}) | |
161 | #define dbg_io(fmt, ...) ({}) | |
162 | #define dbg_bld(fmt, ...) ({}) | |
163 | #define ubi_dbg_dump_stack() ({}) | |
164 | #define ubi_dbg_dump_ec_hdr(ec_hdr) ({}) | |
165 | #define ubi_dbg_dump_vid_hdr(vid_hdr) ({}) | |
166 | #define ubi_dbg_dump_vol_info(vol) ({}) | |
167 | #define ubi_dbg_dump_vtbl_record(r, idx) ({}) | |
168 | #define ubi_dbg_dump_sv(sv) ({}) | |
169 | #define ubi_dbg_dump_seb(seb, type) ({}) | |
170 | #define ubi_dbg_dump_mkvol_req(req) ({}) | |
867996b1 | 171 | #define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({}) |
c8566350 AB |
172 | |
173 | #define UBI_IO_DEBUG 0 | |
174 | #define DBG_DISABLE_BGT 0 | |
175 | #define ubi_dbg_is_bitflip() 0 | |
176 | #define ubi_dbg_is_write_failure() 0 | |
177 | #define ubi_dbg_is_erase_failure() 0 | |
1398788f | 178 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 |
c8566350 AB |
179 | |
180 | #endif /* !CONFIG_MTD_UBI_DEBUG */ | |
801c135c | 181 | #endif /* !__UBI_DEBUG_H__ */ |