blob: 8ea99d8c9e1f0459862b77bbd54918e3b68bf88a [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 */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020042#define dbg_msg(fmt, ...) \
43 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
Harvey Harrisoncb53b3b2008-04-18 13:44:19 -070044 current->pid, __func__, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040045
46#define ubi_dbg_dump_stack() dump_stack()
47
48struct ubi_ec_hdr;
49struct ubi_vid_hdr;
50struct ubi_volume;
51struct ubi_vtbl_record;
52struct ubi_scan_volume;
53struct ubi_scan_leb;
54struct ubi_mkvol_req;
55
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040056void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
57void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
58void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
59void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
60void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
61void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
62void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040063
64#else
65
66#define dbg_msg(fmt, ...) ({})
67#define ubi_dbg_dump_stack() ({})
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040068#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
69#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
70#define ubi_dbg_dump_vol_info(vol) ({})
71#define ubi_dbg_dump_vtbl_record(r, idx) ({})
72#define ubi_dbg_dump_sv(sv) ({})
73#define ubi_dbg_dump_seb(seb, type) ({})
74#define ubi_dbg_dump_mkvol_req(req) ({})
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040075
76#endif /* CONFIG_MTD_UBI_DEBUG_MSG */
77
78#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
79/* Messages from the eraseblock association unit */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020080#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040081#else
82#define dbg_eba(fmt, ...) ({})
83#endif
84
85#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
86/* Messages from the wear-leveling unit */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020087#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040088#else
89#define dbg_wl(fmt, ...) ({})
90#endif
91
92#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
93/* Messages from the input/output unit */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020094#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040095#else
96#define dbg_io(fmt, ...) ({})
97#endif
98
99#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
100/* Initialization and build messages */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +0200101#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem Bityutskiya4f0fcd2008-02-12 13:26:31 +0200102#define UBI_IO_DEBUG 1
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400103#else
104#define dbg_bld(fmt, ...) ({})
Artem Bityutskiya4f0fcd2008-02-12 13:26:31 +0200105#define UBI_IO_DEBUG 0
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400106#endif
107
108#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
109/**
110 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
111 *
112 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
113 */
114static inline int ubi_dbg_is_bitflip(void)
115{
116 return !(random32() % 200);
117}
118#else
119#define ubi_dbg_is_bitflip() 0
120#endif
121
122#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
123/**
124 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
125 *
126 * Returns non-zero if a write failure should be emulated, otherwise returns
127 * zero.
128 */
129static inline int ubi_dbg_is_write_failure(void)
130{
131 return !(random32() % 500);
132}
133#else
134#define ubi_dbg_is_write_failure() 0
135#endif
136
137#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
138/**
139 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
140 *
141 * Returns non-zero if an erase failure should be emulated, otherwise returns
142 * zero.
143 */
144static inline int ubi_dbg_is_erase_failure(void)
145{
146 return !(random32() % 400);
147}
148#else
149#define ubi_dbg_is_erase_failure() 0
150#endif
151
152#endif /* !__UBI_DEBUG_H__ */