blob: 17a1071297267b7a45e565f71f8bbedb7ab31df6 [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
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040027#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040028
Artem Bityutskiyc8566352008-07-16 17:40:22 +030029#define ubi_assert(expr) do { \
Artem Bityutskiyf2863c52008-12-28 12:20:51 +020030 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 } \
Artem Bityutskiyc8566352008-07-16 17:40:22 +030035} while (0)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040036
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020037#define dbg_msg(fmt, ...) \
38 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
Harvey Harrisoncb53b3b2008-04-18 13:44:19 -070039 current->pid, __func__, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040040
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
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040051void 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);
Artem Bityutskiy867996b2009-07-24 15:31:33 +030058void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040059
Artem Bityutskiyc8566352008-07-16 17:40:22 +030060#ifdef CONFIG_MTD_UBI_DEBUG_MSG
61/* General debugging messages */
62#define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040063#else
Artem Bityutskiyc8566352008-07-16 17:40:22 +030064#define dbg_gen(fmt, ...) ({})
65#endif
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040066
67#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
Artem Bityutskiy85c6e6e2008-07-16 10:25:56 +030068/* Messages from the eraseblock association sub-system */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020069#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040070#else
71#define dbg_eba(fmt, ...) ({})
72#endif
73
74#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
Artem Bityutskiy85c6e6e2008-07-16 10:25:56 +030075/* Messages from the wear-leveling sub-system */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020076#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040077#else
78#define dbg_wl(fmt, ...) ({})
79#endif
80
81#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
Artem Bityutskiy85c6e6e2008-07-16 10:25:56 +030082/* Messages from the input/output sub-system */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020083#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040084#else
85#define dbg_io(fmt, ...) ({})
86#endif
87
88#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
89/* Initialization and build messages */
Artem Bityutskiyd19bafd2007-12-18 12:57:52 +020090#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
Artem Bityutskiya4f0fcd2008-02-12 13:26:31 +020091#define UBI_IO_DEBUG 1
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040092#else
93#define dbg_bld(fmt, ...) ({})
Artem Bityutskiya4f0fcd2008-02-12 13:26:31 +020094#define UBI_IO_DEBUG 0
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040095#endif
96
Artem Bityutskiy40a71a82009-06-28 19:16:55 +030097#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
98int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
Artem Bityutskiy6e9065d2010-01-25 17:09:30 +020099int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
100 int offset, int len);
Artem Bityutskiy40a71a82009-06-28 19:16:55 +0300101#else
102#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
Artem Bityutskiy6e9065d2010-01-25 17:09:30 +0200103#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
Artem Bityutskiy40a71a82009-06-28 19:16:55 +0300104#endif
105
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300106#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
107#define DBG_DISABLE_BGT 1
108#else
109#define DBG_DISABLE_BGT 0
110#endif
111
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400112#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
113/**
114 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
115 *
116 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
117 */
118static inline int ubi_dbg_is_bitflip(void)
119{
120 return !(random32() % 200);
121}
122#else
123#define ubi_dbg_is_bitflip() 0
124#endif
125
126#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
127/**
128 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
129 *
130 * Returns non-zero if a write failure should be emulated, otherwise returns
131 * zero.
132 */
133static inline int ubi_dbg_is_write_failure(void)
134{
135 return !(random32() % 500);
136}
137#else
138#define ubi_dbg_is_write_failure() 0
139#endif
140
141#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
142/**
143 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
144 *
145 * Returns non-zero if an erase failure should be emulated, otherwise returns
146 * zero.
147 */
148static inline int ubi_dbg_is_erase_failure(void)
149{
150 return !(random32() % 400);
151}
152#else
153#define ubi_dbg_is_erase_failure() 0
154#endif
155
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300156#else
157
158#define ubi_assert(expr) ({})
159#define dbg_err(fmt, ...) ({})
160#define dbg_msg(fmt, ...) ({})
161#define dbg_gen(fmt, ...) ({})
162#define dbg_eba(fmt, ...) ({})
163#define dbg_wl(fmt, ...) ({})
164#define dbg_io(fmt, ...) ({})
165#define dbg_bld(fmt, ...) ({})
166#define ubi_dbg_dump_stack() ({})
167#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
168#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
169#define ubi_dbg_dump_vol_info(vol) ({})
170#define ubi_dbg_dump_vtbl_record(r, idx) ({})
171#define ubi_dbg_dump_sv(sv) ({})
172#define ubi_dbg_dump_seb(seb, type) ({})
173#define ubi_dbg_dump_mkvol_req(req) ({})
Artem Bityutskiy867996b2009-07-24 15:31:33 +0300174#define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({})
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300175
176#define UBI_IO_DEBUG 0
177#define DBG_DISABLE_BGT 0
178#define ubi_dbg_is_bitflip() 0
179#define ubi_dbg_is_write_failure() 0
180#define ubi_dbg_is_erase_failure() 0
Artem Bityutskiy13987882009-06-29 15:58:36 +0300181#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
Artem Bityutskiy6e9065d2010-01-25 17:09:30 +0200182#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300183
184#endif /* !CONFIG_MTD_UBI_DEBUG */
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400185#endif /* !__UBI_DEBUG_H__ */