Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 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 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 27 | #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 28 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 29 | #define ubi_assert(expr) do { \ |
Artem Bityutskiy | f2863c5 | 2008-12-28 12:20:51 +0200 | [diff] [blame] | 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 | } \ |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 35 | } while (0) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 36 | |
Artem Bityutskiy | d19bafd | 2007-12-18 12:57:52 +0200 | [diff] [blame] | 37 | #define dbg_msg(fmt, ...) \ |
| 38 | printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ |
Harvey Harrison | cb53b3b | 2008-04-18 13:44:19 -0700 | [diff] [blame] | 39 | current->pid, __func__, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 40 | |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 41 | #define dbg_do_msg(typ, fmt, ...) do { \ |
| 42 | if (ubi_msg_flags & typ) \ |
| 43 | dbg_msg(fmt, ##__VA_ARGS__); \ |
| 44 | } while (0) |
| 45 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 46 | #define ubi_dbg_dump_stack() dump_stack() |
| 47 | |
| 48 | struct ubi_ec_hdr; |
| 49 | struct ubi_vid_hdr; |
| 50 | struct ubi_volume; |
| 51 | struct ubi_vtbl_record; |
| 52 | struct ubi_scan_volume; |
| 53 | struct ubi_scan_leb; |
| 54 | struct ubi_mkvol_req; |
| 55 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 56 | void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); |
| 57 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); |
| 58 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol); |
| 59 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); |
| 60 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); |
| 61 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); |
| 62 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); |
Artem Bityutskiy | 867996b | 2009-07-24 15:31:33 +0300 | [diff] [blame] | 63 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 64 | |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 65 | extern unsigned int ubi_msg_flags; |
| 66 | |
| 67 | /* |
| 68 | * Debugging message type flags (must match msg_type_names in debug.c). |
| 69 | * |
| 70 | * UBI_MSG_GEN: general messages |
| 71 | * UBI_MSG_EBA: journal messages |
| 72 | * UBI_MSG_WL: mount messages |
| 73 | * UBI_MSG_IO: commit messages |
| 74 | * UBI_MSG_BLD: LEB find messages |
| 75 | */ |
| 76 | enum { |
| 77 | UBI_MSG_GEN = 0x1, |
| 78 | UBI_MSG_EBA = 0x2, |
| 79 | UBI_MSG_WL = 0x4, |
| 80 | UBI_MSG_IO = 0x8, |
| 81 | UBI_MSG_BLD = 0x10, |
| 82 | }; |
| 83 | |
Artem Bityutskiy | 3153249 | 2010-09-03 22:27:46 +0300 | [diff] [blame] | 84 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ |
| 85 | print_hex_dump(l, ps, pt, r, g, b, len, a) |
| 86 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 87 | /* General debugging messages */ |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 88 | #define dbg_gen(fmt, ...) dbg_do_msg(UBI_MSG_GEN, fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 89 | |
Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 90 | /* Messages from the eraseblock association sub-system */ |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 91 | #define dbg_eba(fmt, ...) dbg_do_msg(UBI_MSG_EBA, fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 92 | |
Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 93 | /* Messages from the wear-leveling sub-system */ |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 94 | #define dbg_wl(fmt, ...) dbg_do_msg(UBI_MSG_WL, fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 95 | |
Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 96 | /* Messages from the input/output sub-system */ |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 97 | #define dbg_io(fmt, ...) dbg_do_msg(UBI_MSG_IO, fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 98 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 99 | /* Initialization and build messages */ |
Artem Bityutskiy | b342efd | 2011-03-11 14:33:23 +0200 | [diff] [blame] | 100 | #define dbg_bld(fmt, ...) dbg_do_msg(UBI_MSG_BLD, fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 101 | |
Artem Bityutskiy | 92d124f | 2011-03-14 18:17:40 +0200 | [diff] [blame^] | 102 | extern unsigned int ubi_chk_flags; |
| 103 | |
| 104 | /* |
| 105 | * Debugging check flags. |
| 106 | * |
| 107 | * UBI_CHK_GEN: general checks |
| 108 | * UBI_CHK_IO: check writes and erases |
| 109 | */ |
| 110 | enum { |
| 111 | UBI_CHK_GEN = 0x1, |
| 112 | UBI_CHK_IO = 0x2, |
| 113 | }; |
| 114 | |
Artem Bityutskiy | 40a71a8 | 2009-06-28 19:16:55 +0300 | [diff] [blame] | 115 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); |
Artem Bityutskiy | 6e9065d | 2010-01-25 17:09:30 +0200 | [diff] [blame] | 116 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, |
| 117 | int offset, int len); |
Artem Bityutskiy | 40a71a8 | 2009-06-28 19:16:55 +0300 | [diff] [blame] | 118 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 119 | #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT |
| 120 | #define DBG_DISABLE_BGT 1 |
| 121 | #else |
| 122 | #define DBG_DISABLE_BGT 0 |
| 123 | #endif |
| 124 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 125 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS |
| 126 | /** |
| 127 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. |
| 128 | * |
| 129 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. |
| 130 | */ |
| 131 | static inline int ubi_dbg_is_bitflip(void) |
| 132 | { |
| 133 | return !(random32() % 200); |
| 134 | } |
| 135 | #else |
| 136 | #define ubi_dbg_is_bitflip() 0 |
| 137 | #endif |
| 138 | |
| 139 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES |
| 140 | /** |
| 141 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. |
| 142 | * |
| 143 | * Returns non-zero if a write failure should be emulated, otherwise returns |
| 144 | * zero. |
| 145 | */ |
| 146 | static inline int ubi_dbg_is_write_failure(void) |
| 147 | { |
| 148 | return !(random32() % 500); |
| 149 | } |
| 150 | #else |
| 151 | #define ubi_dbg_is_write_failure() 0 |
| 152 | #endif |
| 153 | |
| 154 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES |
| 155 | /** |
| 156 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. |
| 157 | * |
| 158 | * Returns non-zero if an erase failure should be emulated, otherwise returns |
| 159 | * zero. |
| 160 | */ |
| 161 | static inline int ubi_dbg_is_erase_failure(void) |
| 162 | { |
| 163 | return !(random32() % 400); |
| 164 | } |
| 165 | #else |
| 166 | #define ubi_dbg_is_erase_failure() 0 |
| 167 | #endif |
| 168 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 169 | #else |
| 170 | |
| 171 | #define ubi_assert(expr) ({}) |
| 172 | #define dbg_err(fmt, ...) ({}) |
| 173 | #define dbg_msg(fmt, ...) ({}) |
| 174 | #define dbg_gen(fmt, ...) ({}) |
| 175 | #define dbg_eba(fmt, ...) ({}) |
| 176 | #define dbg_wl(fmt, ...) ({}) |
| 177 | #define dbg_io(fmt, ...) ({}) |
| 178 | #define dbg_bld(fmt, ...) ({}) |
| 179 | #define ubi_dbg_dump_stack() ({}) |
| 180 | #define ubi_dbg_dump_ec_hdr(ec_hdr) ({}) |
| 181 | #define ubi_dbg_dump_vid_hdr(vid_hdr) ({}) |
| 182 | #define ubi_dbg_dump_vol_info(vol) ({}) |
| 183 | #define ubi_dbg_dump_vtbl_record(r, idx) ({}) |
| 184 | #define ubi_dbg_dump_sv(sv) ({}) |
| 185 | #define ubi_dbg_dump_seb(seb, type) ({}) |
| 186 | #define ubi_dbg_dump_mkvol_req(req) ({}) |
Artem Bityutskiy | 867996b | 2009-07-24 15:31:33 +0300 | [diff] [blame] | 187 | #define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({}) |
Artem Bityutskiy | 3153249 | 2010-09-03 22:27:46 +0300 | [diff] [blame] | 188 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) ({}) |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 189 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 190 | #define DBG_DISABLE_BGT 0 |
| 191 | #define ubi_dbg_is_bitflip() 0 |
| 192 | #define ubi_dbg_is_write_failure() 0 |
| 193 | #define ubi_dbg_is_erase_failure() 0 |
Artem Bityutskiy | 1398788 | 2009-06-29 15:58:36 +0300 | [diff] [blame] | 194 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 |
Artem Bityutskiy | 6e9065d | 2010-01-25 17:09:30 +0200 | [diff] [blame] | 195 | #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0 |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 196 | |
| 197 | #endif /* !CONFIG_MTD_UBI_DEBUG */ |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 198 | #endif /* !__UBI_DEBUG_H__ */ |