blob: 222b2b8ae969504ea400226f759a8ceea15ed51a [file] [log] [blame]
Kyungmin Parkc880c532008-11-19 16:25:44 +01001/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kyungmin Parkc880c532008-11-19 16:25:44 +01005 *
6 * Author: Artem Bityutskiy (Битюцкий Артём)
7 */
8
9#ifndef __UBI_DEBUG_H__
10#define __UBI_DEBUG_H__
11
12#ifdef CONFIG_MTD_UBI_DEBUG
13#ifdef UBI_LINUX
14#include <linux/random.h>
15#endif
16
17#define ubi_assert(expr) BUG_ON(!(expr))
18#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
19#else
20#define ubi_assert(expr) ({})
21#define dbg_err(fmt, ...) ({})
22#endif
23
24#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
25#define DBG_DISABLE_BGT 1
26#else
27#define DBG_DISABLE_BGT 0
28#endif
29
30#ifdef CONFIG_MTD_UBI_DEBUG_MSG
31/* Generic debugging message */
32#define dbg_msg(fmt, ...) \
33 printk(KERN_DEBUG "UBI DBG: %s: " fmt "\n", \
34 __FUNCTION__, ##__VA_ARGS__)
35
36#define ubi_dbg_dump_stack() dump_stack()
37
38struct ubi_ec_hdr;
39struct ubi_vid_hdr;
40struct ubi_volume;
41struct ubi_vtbl_record;
42struct ubi_scan_volume;
43struct ubi_scan_leb;
44struct ubi_mkvol_req;
45
46void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
47void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
48void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
49void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
50void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
51void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
52void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
53
54#else
55
56#define dbg_msg(fmt, ...) ({})
57#define ubi_dbg_dump_stack() ({})
58#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
59#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
60#define ubi_dbg_dump_vol_info(vol) ({})
61#define ubi_dbg_dump_vtbl_record(r, idx) ({})
62#define ubi_dbg_dump_sv(sv) ({})
63#define ubi_dbg_dump_seb(seb, type) ({})
64#define ubi_dbg_dump_mkvol_req(req) ({})
65
66#endif /* CONFIG_MTD_UBI_DEBUG_MSG */
67
68#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
69/* Messages from the eraseblock association unit */
70#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
71#else
72#define dbg_eba(fmt, ...) ({})
73#endif
74
75#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
76/* Messages from the wear-leveling unit */
77#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
78#else
79#define dbg_wl(fmt, ...) ({})
80#endif
81
82#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
83/* Messages from the input/output unit */
84#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
85#else
86#define dbg_io(fmt, ...) ({})
87#endif
88
89#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
90/* Initialization and build messages */
91#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
92#else
93#define dbg_bld(fmt, ...) ({})
94#endif
95
96#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
97/**
98 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
99 *
100 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
101 */
102static inline int ubi_dbg_is_bitflip(void)
103{
104 return !(random32() % 200);
105}
106#else
107#define ubi_dbg_is_bitflip() 0
108#endif
109
110#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
111/**
112 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
113 *
114 * Returns non-zero if a write failure should be emulated, otherwise returns
115 * zero.
116 */
117static inline int ubi_dbg_is_write_failure(void)
118{
119 return !(random32() % 500);
120}
121#else
122#define ubi_dbg_is_write_failure() 0
123#endif
124
125#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
126/**
127 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
128 *
129 * Returns non-zero if an erase failure should be emulated, otherwise returns
130 * zero.
131 */
132static inline int ubi_dbg_is_erase_failure(void)
133{
134 return !(random32() % 400);
135}
136#else
137#define ubi_dbg_is_erase_failure() 0
138#endif
139
140#endif /* !__UBI_DEBUG_H__ */