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 27 #define ubi_assert(expr) BUG_ON(!(expr)) 28 #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) 29 #else 30 #define ubi_assert(expr) ({}) 31 #define dbg_err(fmt, ...) ({}) 32 #endif 33 34 #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT 35 #define DBG_DISABLE_BGT 1 36 #else 37 #define DBG_DISABLE_BGT 0 38 #endif 39 40 #ifdef CONFIG_MTD_UBI_DEBUG_MSG 41 /* Generic debugging message */ 42 #define dbg_msg(fmt, ...) \ 43 printk(KERN_DEBUG "UBI DBG: %s: " fmt "\n", __FUNCTION__, ##__VA_ARGS__) 44 45 #define ubi_dbg_dump_stack() dump_stack() 46 47 struct ubi_ec_hdr; 48 struct ubi_vid_hdr; 49 struct ubi_volume; 50 struct ubi_vtbl_record; 51 struct ubi_scan_volume; 52 struct ubi_scan_leb; 53 struct ubi_mkvol_req; 54 55 void ubi_dbg_print(int type, const char *func, const char *fmt, ...); 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); 63 void ubi_dbg_hexdump(const void *buf, int size); 64 65 #else 66 67 #define dbg_msg(fmt, ...) ({}) 68 #define ubi_dbg_dump_stack() ({}) 69 #define ubi_dbg_print(func, fmt, ...) ({}) 70 #define ubi_dbg_dump_ec_hdr(ec_hdr) ({}) 71 #define ubi_dbg_dump_vid_hdr(vid_hdr) ({}) 72 #define ubi_dbg_dump_vol_info(vol) ({}) 73 #define ubi_dbg_dump_vtbl_record(r, idx) ({}) 74 #define ubi_dbg_dump_sv(sv) ({}) 75 #define ubi_dbg_dump_seb(seb, type) ({}) 76 #define ubi_dbg_dump_mkvol_req(req) ({}) 77 #define ubi_dbg_hexdump(buf, size) ({}) 78 79 #endif /* CONFIG_MTD_UBI_DEBUG_MSG */ 80 81 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA 82 /* Messages from the eraseblock association unit */ 83 #define dbg_eba(fmt, ...) \ 84 printk(KERN_DEBUG "UBI DBG eba: %s: " fmt "\n", __FUNCTION__, \ 85 ##__VA_ARGS__) 86 #else 87 #define dbg_eba(fmt, ...) ({}) 88 #endif 89 90 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL 91 /* Messages from the wear-leveling unit */ 92 #define dbg_wl(fmt, ...) \ 93 printk(KERN_DEBUG "UBI DBG wl: %s: " fmt "\n", __FUNCTION__, \ 94 ##__VA_ARGS__) 95 #else 96 #define dbg_wl(fmt, ...) ({}) 97 #endif 98 99 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO 100 /* Messages from the input/output unit */ 101 #define dbg_io(fmt, ...) \ 102 printk(KERN_DEBUG "UBI DBG io: %s: " fmt "\n", __FUNCTION__, \ 103 ##__VA_ARGS__) 104 #else 105 #define dbg_io(fmt, ...) ({}) 106 #endif 107 108 #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD 109 /* Initialization and build messages */ 110 #define dbg_bld(fmt, ...) \ 111 printk(KERN_DEBUG "UBI DBG bld: %s: " fmt "\n", __FUNCTION__, \ 112 ##__VA_ARGS__) 113 #else 114 #define dbg_bld(fmt, ...) ({}) 115 #endif 116 117 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS 118 /** 119 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. 120 * 121 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. 122 */ 123 static inline int ubi_dbg_is_bitflip(void) 124 { 125 return !(random32() % 200); 126 } 127 #else 128 #define ubi_dbg_is_bitflip() 0 129 #endif 130 131 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES 132 /** 133 * ubi_dbg_is_write_failure - if it is time to emulate a write failure. 134 * 135 * Returns non-zero if a write failure should be emulated, otherwise returns 136 * zero. 137 */ 138 static inline int ubi_dbg_is_write_failure(void) 139 { 140 return !(random32() % 500); 141 } 142 #else 143 #define ubi_dbg_is_write_failure() 0 144 #endif 145 146 #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES 147 /** 148 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. 149 * 150 * Returns non-zero if an erase failure should be emulated, otherwise returns 151 * zero. 152 */ 153 static inline int ubi_dbg_is_erase_failure(void) 154 { 155 return !(random32() % 400); 156 } 157 #else 158 #define ubi_dbg_is_erase_failure() 0 159 #endif 160 161 #endif /* !__UBI_DEBUG_H__ */ 162