Merge branch 'urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia-2.6
[deliverable/linux.git] / drivers / mtd / ubi / debug.h
CommitLineData
801c135c
AB
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
801c135c 27#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
801c135c 28
c8566350 29#define ubi_assert(expr) do { \
f2863c54
AB
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 } \
c8566350 35} while (0)
801c135c 36
d19bafd9
AB
37#define dbg_msg(fmt, ...) \
38 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
cb53b3b9 39 current->pid, __func__, ##__VA_ARGS__)
801c135c
AB
40
41#define ubi_dbg_dump_stack() dump_stack()
42
43struct ubi_ec_hdr;
44struct ubi_vid_hdr;
45struct ubi_volume;
46struct ubi_vtbl_record;
47struct ubi_scan_volume;
48struct ubi_scan_leb;
49struct ubi_mkvol_req;
50
801c135c
AB
51void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
52void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
53void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
54void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
55void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
56void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
57void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
867996b1 58void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
801c135c 59
31532494
AB
60#define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
61 print_hex_dump(l, ps, pt, r, g, b, len, a)
62
c8566350
AB
63#ifdef CONFIG_MTD_UBI_DEBUG_MSG
64/* General debugging messages */
65#define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
801c135c 66#else
c8566350
AB
67#define dbg_gen(fmt, ...) ({})
68#endif
801c135c
AB
69
70#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
85c6e6e2 71/* Messages from the eraseblock association sub-system */
d19bafd9 72#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
801c135c
AB
73#else
74#define dbg_eba(fmt, ...) ({})
75#endif
76
77#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
85c6e6e2 78/* Messages from the wear-leveling sub-system */
d19bafd9 79#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
801c135c
AB
80#else
81#define dbg_wl(fmt, ...) ({})
82#endif
83
84#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
85c6e6e2 85/* Messages from the input/output sub-system */
d19bafd9 86#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
801c135c
AB
87#else
88#define dbg_io(fmt, ...) ({})
89#endif
90
91#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
92/* Initialization and build messages */
d19bafd9 93#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
a4f0fcdf 94#define UBI_IO_DEBUG 1
801c135c
AB
95#else
96#define dbg_bld(fmt, ...) ({})
a4f0fcdf 97#define UBI_IO_DEBUG 0
801c135c
AB
98#endif
99
40a71a87
AB
100#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
101int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
6e9065d7
AB
102int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
103 int offset, int len);
40a71a87
AB
104#else
105#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
6e9065d7 106#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
40a71a87
AB
107#endif
108
c8566350
AB
109#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
110#define DBG_DISABLE_BGT 1
111#else
112#define DBG_DISABLE_BGT 0
113#endif
114
801c135c
AB
115#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
116/**
117 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
118 *
119 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
120 */
121static inline int ubi_dbg_is_bitflip(void)
122{
123 return !(random32() % 200);
124}
125#else
126#define ubi_dbg_is_bitflip() 0
127#endif
128
129#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
130/**
131 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
132 *
133 * Returns non-zero if a write failure should be emulated, otherwise returns
134 * zero.
135 */
136static inline int ubi_dbg_is_write_failure(void)
137{
138 return !(random32() % 500);
139}
140#else
141#define ubi_dbg_is_write_failure() 0
142#endif
143
144#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
145/**
146 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
147 *
148 * Returns non-zero if an erase failure should be emulated, otherwise returns
149 * zero.
150 */
151static inline int ubi_dbg_is_erase_failure(void)
152{
153 return !(random32() % 400);
154}
155#else
156#define ubi_dbg_is_erase_failure() 0
157#endif
158
c8566350
AB
159#else
160
161#define ubi_assert(expr) ({})
162#define dbg_err(fmt, ...) ({})
163#define dbg_msg(fmt, ...) ({})
164#define dbg_gen(fmt, ...) ({})
165#define dbg_eba(fmt, ...) ({})
166#define dbg_wl(fmt, ...) ({})
167#define dbg_io(fmt, ...) ({})
168#define dbg_bld(fmt, ...) ({})
169#define ubi_dbg_dump_stack() ({})
170#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
171#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
172#define ubi_dbg_dump_vol_info(vol) ({})
173#define ubi_dbg_dump_vtbl_record(r, idx) ({})
174#define ubi_dbg_dump_sv(sv) ({})
175#define ubi_dbg_dump_seb(seb, type) ({})
176#define ubi_dbg_dump_mkvol_req(req) ({})
867996b1 177#define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({})
31532494 178#define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) ({})
c8566350
AB
179
180#define UBI_IO_DEBUG 0
181#define DBG_DISABLE_BGT 0
182#define ubi_dbg_is_bitflip() 0
183#define ubi_dbg_is_write_failure() 0
184#define ubi_dbg_is_erase_failure() 0
1398788f 185#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
6e9065d7 186#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
c8566350
AB
187
188#endif /* !CONFIG_MTD_UBI_DEBUG */
801c135c 189#endif /* !__UBI_DEBUG_H__ */
This page took 0.441748 seconds and 5 git commands to generate.