blob: bee6fa1e5147649f1e35b6660ddd524f3f887cd4 [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
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020041#define dbg_do_msg(typ, fmt, ...) do { \
42 if (ubi_msg_flags & typ) \
43 dbg_msg(fmt, ##__VA_ARGS__); \
44} while (0)
45
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040046#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 Bityutskiy867996b2009-07-24 15:31:33 +030063void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040064
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020065extern unsigned int ubi_msg_flags;
66
67/*
68 * Debugging message type flags (must match msg_type_names in debug.c).
69 *
70 * UBI_MSG_GEN: general messages
71 * UBI_MSG_EBA: journal messages
72 * UBI_MSG_WL: mount messages
73 * UBI_MSG_IO: commit messages
74 * UBI_MSG_BLD: LEB find messages
75 */
76enum {
77 UBI_MSG_GEN = 0x1,
78 UBI_MSG_EBA = 0x2,
79 UBI_MSG_WL = 0x4,
80 UBI_MSG_IO = 0x8,
81 UBI_MSG_BLD = 0x10,
82};
83
Artem Bityutskiy31532492010-09-03 22:27:46 +030084#define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \
85 print_hex_dump(l, ps, pt, r, g, b, len, a)
86
Artem Bityutskiyc8566352008-07-16 17:40:22 +030087/* General debugging messages */
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020088#define dbg_gen(fmt, ...) dbg_do_msg(UBI_MSG_GEN, fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040089
Artem Bityutskiy85c6e6e2008-07-16 10:25:56 +030090/* Messages from the eraseblock association sub-system */
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020091#define dbg_eba(fmt, ...) dbg_do_msg(UBI_MSG_EBA, fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040092
Artem Bityutskiy85c6e6e2008-07-16 10:25:56 +030093/* Messages from the wear-leveling sub-system */
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020094#define dbg_wl(fmt, ...) dbg_do_msg(UBI_MSG_WL, fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040095
Artem Bityutskiy85c6e6e2008-07-16 10:25:56 +030096/* Messages from the input/output sub-system */
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020097#define dbg_io(fmt, ...) dbg_do_msg(UBI_MSG_IO, fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040098
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040099/* Initialization and build messages */
Artem Bityutskiyb342efd2011-03-11 14:33:23 +0200100#define dbg_bld(fmt, ...) dbg_do_msg(UBI_MSG_BLD, fmt, ##__VA_ARGS__)
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400101
Artem Bityutskiy40a71a82009-06-28 19:16:55 +0300102#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
103int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
Artem Bityutskiy6e9065d2010-01-25 17:09:30 +0200104int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
105 int offset, int len);
Artem Bityutskiy40a71a82009-06-28 19:16:55 +0300106#else
107#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
Artem Bityutskiy6e9065d2010-01-25 17:09:30 +0200108#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
Artem Bityutskiy40a71a82009-06-28 19:16:55 +0300109#endif
110
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300111#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
112#define DBG_DISABLE_BGT 1
113#else
114#define DBG_DISABLE_BGT 0
115#endif
116
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400117#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 */
123static 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 */
138static 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 */
153static 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
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300161#else
162
163#define ubi_assert(expr) ({})
164#define dbg_err(fmt, ...) ({})
165#define dbg_msg(fmt, ...) ({})
166#define dbg_gen(fmt, ...) ({})
167#define dbg_eba(fmt, ...) ({})
168#define dbg_wl(fmt, ...) ({})
169#define dbg_io(fmt, ...) ({})
170#define dbg_bld(fmt, ...) ({})
171#define ubi_dbg_dump_stack() ({})
172#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
173#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
174#define ubi_dbg_dump_vol_info(vol) ({})
175#define ubi_dbg_dump_vtbl_record(r, idx) ({})
176#define ubi_dbg_dump_sv(sv) ({})
177#define ubi_dbg_dump_seb(seb, type) ({})
178#define ubi_dbg_dump_mkvol_req(req) ({})
Artem Bityutskiy867996b2009-07-24 15:31:33 +0300179#define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({})
Artem Bityutskiy31532492010-09-03 22:27:46 +0300180#define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) ({})
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300181
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300182#define DBG_DISABLE_BGT 0
183#define ubi_dbg_is_bitflip() 0
184#define ubi_dbg_is_write_failure() 0
185#define ubi_dbg_is_erase_failure() 0
Artem Bityutskiy13987882009-06-29 15:58:36 +0300186#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
Artem Bityutskiy6e9065d2010-01-25 17:09:30 +0200187#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300188
189#endif /* !CONFIG_MTD_UBI_DEBUG */
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400190#endif /* !__UBI_DEBUG_H__ */