blob: 467722eb618b20a384320e4bee15be409f2f5e77 [file] [log] [blame]
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +04001/*
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
47struct ubi_ec_hdr;
48struct ubi_vid_hdr;
49struct ubi_volume;
50struct ubi_vtbl_record;
51struct ubi_scan_volume;
52struct ubi_scan_leb;
53struct ubi_mkvol_req;
54
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040055void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
56void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
57void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
58void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
59void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
60void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
61void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040062
63#else
64
65#define dbg_msg(fmt, ...) ({})
66#define ubi_dbg_dump_stack() ({})
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040067#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
68#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
69#define ubi_dbg_dump_vol_info(vol) ({})
70#define ubi_dbg_dump_vtbl_record(r, idx) ({})
71#define ubi_dbg_dump_sv(sv) ({})
72#define ubi_dbg_dump_seb(seb, type) ({})
73#define ubi_dbg_dump_mkvol_req(req) ({})
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040074
75#endif /* CONFIG_MTD_UBI_DEBUG_MSG */
76
77#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
78/* Messages from the eraseblock association unit */
79#define dbg_eba(fmt, ...) \
80 printk(KERN_DEBUG "UBI DBG eba: %s: " fmt "\n", __FUNCTION__, \
81 ##__VA_ARGS__)
82#else
83#define dbg_eba(fmt, ...) ({})
84#endif
85
86#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
87/* Messages from the wear-leveling unit */
88#define dbg_wl(fmt, ...) \
89 printk(KERN_DEBUG "UBI DBG wl: %s: " fmt "\n", __FUNCTION__, \
90 ##__VA_ARGS__)
91#else
92#define dbg_wl(fmt, ...) ({})
93#endif
94
95#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
96/* Messages from the input/output unit */
97#define dbg_io(fmt, ...) \
98 printk(KERN_DEBUG "UBI DBG io: %s: " fmt "\n", __FUNCTION__, \
99 ##__VA_ARGS__)
100#else
101#define dbg_io(fmt, ...) ({})
102#endif
103
104#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
105/* Initialization and build messages */
106#define dbg_bld(fmt, ...) \
107 printk(KERN_DEBUG "UBI DBG bld: %s: " fmt "\n", __FUNCTION__, \
108 ##__VA_ARGS__)
109#else
110#define dbg_bld(fmt, ...) ({})
111#endif
112
113#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
114/**
115 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
116 *
117 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
118 */
119static inline int ubi_dbg_is_bitflip(void)
120{
121 return !(random32() % 200);
122}
123#else
124#define ubi_dbg_is_bitflip() 0
125#endif
126
127#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
128/**
129 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
130 *
131 * Returns non-zero if a write failure should be emulated, otherwise returns
132 * zero.
133 */
134static inline int ubi_dbg_is_write_failure(void)
135{
136 return !(random32() % 500);
137}
138#else
139#define ubi_dbg_is_write_failure() 0
140#endif
141
142#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
143/**
144 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
145 *
146 * Returns non-zero if an erase failure should be emulated, otherwise returns
147 * zero.
148 */
149static inline int ubi_dbg_is_erase_failure(void)
150{
151 return !(random32() % 400);
152}
153#else
154#define ubi_dbg_is_erase_failure() 0
155#endif
156
157#endif /* !__UBI_DEBUG_H__ */