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 { \ |
| 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 | } \ |
| 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 | |
| 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 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 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); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 58 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame^] | 59 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG |
| 60 | /* General debugging messages */ |
| 61 | #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 62 | #else |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame^] | 63 | #define dbg_gen(fmt, ...) ({}) |
| 64 | #endif |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 65 | |
| 66 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA |
Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 67 | /* Messages from the eraseblock association sub-system */ |
Artem Bityutskiy | d19bafd | 2007-12-18 12:57:52 +0200 | [diff] [blame] | 68 | #define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 69 | #else |
| 70 | #define dbg_eba(fmt, ...) ({}) |
| 71 | #endif |
| 72 | |
| 73 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL |
Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 74 | /* Messages from the wear-leveling sub-system */ |
Artem Bityutskiy | d19bafd | 2007-12-18 12:57:52 +0200 | [diff] [blame] | 75 | #define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 76 | #else |
| 77 | #define dbg_wl(fmt, ...) ({}) |
| 78 | #endif |
| 79 | |
| 80 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO |
Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 81 | /* Messages from the input/output sub-system */ |
Artem Bityutskiy | d19bafd | 2007-12-18 12:57:52 +0200 | [diff] [blame] | 82 | #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 83 | #else |
| 84 | #define dbg_io(fmt, ...) ({}) |
| 85 | #endif |
| 86 | |
| 87 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD |
| 88 | /* Initialization and build messages */ |
Artem Bityutskiy | d19bafd | 2007-12-18 12:57:52 +0200 | [diff] [blame] | 89 | #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
Artem Bityutskiy | a4f0fcd | 2008-02-12 13:26:31 +0200 | [diff] [blame] | 90 | #define UBI_IO_DEBUG 1 |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 91 | #else |
| 92 | #define dbg_bld(fmt, ...) ({}) |
Artem Bityutskiy | a4f0fcd | 2008-02-12 13:26:31 +0200 | [diff] [blame] | 93 | #define UBI_IO_DEBUG 0 |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 94 | #endif |
| 95 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame^] | 96 | #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT |
| 97 | #define DBG_DISABLE_BGT 1 |
| 98 | #else |
| 99 | #define DBG_DISABLE_BGT 0 |
| 100 | #endif |
| 101 | |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 102 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS |
| 103 | /** |
| 104 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. |
| 105 | * |
| 106 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. |
| 107 | */ |
| 108 | static inline int ubi_dbg_is_bitflip(void) |
| 109 | { |
| 110 | return !(random32() % 200); |
| 111 | } |
| 112 | #else |
| 113 | #define ubi_dbg_is_bitflip() 0 |
| 114 | #endif |
| 115 | |
| 116 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES |
| 117 | /** |
| 118 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. |
| 119 | * |
| 120 | * Returns non-zero if a write failure should be emulated, otherwise returns |
| 121 | * zero. |
| 122 | */ |
| 123 | static inline int ubi_dbg_is_write_failure(void) |
| 124 | { |
| 125 | return !(random32() % 500); |
| 126 | } |
| 127 | #else |
| 128 | #define ubi_dbg_is_write_failure() 0 |
| 129 | #endif |
| 130 | |
| 131 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES |
| 132 | /** |
| 133 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. |
| 134 | * |
| 135 | * Returns non-zero if an erase failure should be emulated, otherwise returns |
| 136 | * zero. |
| 137 | */ |
| 138 | static inline int ubi_dbg_is_erase_failure(void) |
| 139 | { |
| 140 | return !(random32() % 400); |
| 141 | } |
| 142 | #else |
| 143 | #define ubi_dbg_is_erase_failure() 0 |
| 144 | #endif |
| 145 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame^] | 146 | #else |
| 147 | |
| 148 | #define ubi_assert(expr) ({}) |
| 149 | #define dbg_err(fmt, ...) ({}) |
| 150 | #define dbg_msg(fmt, ...) ({}) |
| 151 | #define dbg_gen(fmt, ...) ({}) |
| 152 | #define dbg_eba(fmt, ...) ({}) |
| 153 | #define dbg_wl(fmt, ...) ({}) |
| 154 | #define dbg_io(fmt, ...) ({}) |
| 155 | #define dbg_bld(fmt, ...) ({}) |
| 156 | #define ubi_dbg_dump_stack() ({}) |
| 157 | #define ubi_dbg_dump_ec_hdr(ec_hdr) ({}) |
| 158 | #define ubi_dbg_dump_vid_hdr(vid_hdr) ({}) |
| 159 | #define ubi_dbg_dump_vol_info(vol) ({}) |
| 160 | #define ubi_dbg_dump_vtbl_record(r, idx) ({}) |
| 161 | #define ubi_dbg_dump_sv(sv) ({}) |
| 162 | #define ubi_dbg_dump_seb(seb, type) ({}) |
| 163 | #define ubi_dbg_dump_mkvol_req(req) ({}) |
| 164 | |
| 165 | #define UBI_IO_DEBUG 0 |
| 166 | #define DBG_DISABLE_BGT 0 |
| 167 | #define ubi_dbg_is_bitflip() 0 |
| 168 | #define ubi_dbg_is_write_failure() 0 |
| 169 | #define ubi_dbg_is_erase_failure() 0 |
| 170 | |
| 171 | #endif /* !CONFIG_MTD_UBI_DEBUG */ |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 172 | #endif /* !__UBI_DEBUG_H__ */ |