blob: 2c2faaf1b4dcc069f40139cb1efded2ab76df05d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kyungmin Park961df832008-11-19 16:25:44 +01002/*
3 * Copyright (c) International Business Machines Corp., 2006
4 *
Kyungmin Park961df832008-11-19 16:25:44 +01005 * Author: Artem Bityutskiy (Битюцкий Артём)
6 */
7
8#ifndef __UBI_DEBUG_H__
9#define __UBI_DEBUG_H__
10
Heiko Schocherff94bc42014-06-24 10:10:04 +020011void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
12void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
13void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
14
Heiko Schocherff94bc42014-06-24 10:10:04 +020015#ifndef __UBOOT__
Kyungmin Park961df832008-11-19 16:25:44 +010016#include <linux/random.h>
17#endif
18
Alexey Brodkinf8c987f2018-06-05 17:17:57 +030019#include <hexdump.h>
20
Eran Matityahu66e78fc2019-02-13 20:55:43 +020021#ifndef __UBOOT__
Heiko Schocherff94bc42014-06-24 10:10:04 +020022#define ubi_assert(expr) do { \
23 if (unlikely(!(expr))) { \
24 pr_crit("UBI assert failed in %s at %u (pid %d)\n", \
25 __func__, __LINE__, current->pid); \
26 dump_stack(); \
27 } \
28} while (0)
Eran Matityahu66e78fc2019-02-13 20:55:43 +020029#else
30#define ubi_assert(expr) do { \
31 if (unlikely(!(expr))) { \
Eran Matityahu734b0802019-02-13 20:56:17 +020032 pr_debug("UBI assert failed in %s at %u\n", \
Eran Matityahu66e78fc2019-02-13 20:55:43 +020033 __func__, __LINE__); \
34 dump_stack(); \
35 } \
36} while (0)
37#endif
Kyungmin Park961df832008-11-19 16:25:44 +010038
Alexey Brodkinf8c987f2018-06-05 17:17:57 +030039#define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
40 print_hex_dump(ps, pt, r, g, b, len, a)
Kyungmin Park961df832008-11-19 16:25:44 +010041
Heiko Schocherff94bc42014-06-24 10:10:04 +020042#define ubi_dbg_msg(type, fmt, ...) \
43 pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
44 ##__VA_ARGS__)
Kyungmin Park961df832008-11-19 16:25:44 +010045
Heiko Schocherff94bc42014-06-24 10:10:04 +020046/* General debugging messages */
47#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
48/* Messages from the eraseblock association sub-system */
49#define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
50/* Messages from the wear-leveling sub-system */
51#define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
52/* Messages from the input/output sub-system */
53#define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
Kyungmin Park961df832008-11-19 16:25:44 +010054/* Initialization and build messages */
Heiko Schocherff94bc42014-06-24 10:10:04 +020055#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
Kyungmin Park961df832008-11-19 16:25:44 +010056
Heiko Schocherff94bc42014-06-24 10:10:04 +020057void ubi_dump_vol_info(const struct ubi_volume *vol);
58void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
59void ubi_dump_av(const struct ubi_ainf_volume *av);
60void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
61void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
62int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
63 int len);
64int ubi_debugfs_init(void);
65void ubi_debugfs_exit(void);
66int ubi_debugfs_init_dev(struct ubi_device *ubi);
67void ubi_debugfs_exit_dev(struct ubi_device *ubi);
68
69/**
70 * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
71 * @ubi: UBI device description object
72 *
73 * Returns non-zero if the UBI background thread is disabled for testing
74 * purposes.
75 */
76static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
77{
78 return ubi->dbg.disable_bgt;
79}
80
Kyungmin Park961df832008-11-19 16:25:44 +010081/**
82 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
Heiko Schocherff94bc42014-06-24 10:10:04 +020083 * @ubi: UBI device description object
Kyungmin Park961df832008-11-19 16:25:44 +010084 *
85 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
86 */
Heiko Schocherff94bc42014-06-24 10:10:04 +020087static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
Kyungmin Park961df832008-11-19 16:25:44 +010088{
Heiko Schocherff94bc42014-06-24 10:10:04 +020089 if (ubi->dbg.emulate_bitflips)
90 return !(prandom_u32() % 200);
91 return 0;
Kyungmin Park961df832008-11-19 16:25:44 +010092}
Kyungmin Park961df832008-11-19 16:25:44 +010093
Kyungmin Park961df832008-11-19 16:25:44 +010094/**
95 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
Heiko Schocherff94bc42014-06-24 10:10:04 +020096 * @ubi: UBI device description object
Kyungmin Park961df832008-11-19 16:25:44 +010097 *
98 * Returns non-zero if a write failure should be emulated, otherwise returns
99 * zero.
100 */
Heiko Schocherff94bc42014-06-24 10:10:04 +0200101static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
Kyungmin Park961df832008-11-19 16:25:44 +0100102{
Heiko Schocherff94bc42014-06-24 10:10:04 +0200103 if (ubi->dbg.emulate_io_failures)
104 return !(prandom_u32() % 500);
105 return 0;
Kyungmin Park961df832008-11-19 16:25:44 +0100106}
Kyungmin Park961df832008-11-19 16:25:44 +0100107
Kyungmin Park961df832008-11-19 16:25:44 +0100108/**
109 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
Heiko Schocherff94bc42014-06-24 10:10:04 +0200110 * @ubi: UBI device description object
Kyungmin Park961df832008-11-19 16:25:44 +0100111 *
112 * Returns non-zero if an erase failure should be emulated, otherwise returns
113 * zero.
114 */
Heiko Schocherff94bc42014-06-24 10:10:04 +0200115static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
Kyungmin Park961df832008-11-19 16:25:44 +0100116{
Heiko Schocherff94bc42014-06-24 10:10:04 +0200117 if (ubi->dbg.emulate_io_failures)
118 return !(prandom_u32() % 400);
119 return 0;
Kyungmin Park961df832008-11-19 16:25:44 +0100120}
Kyungmin Park961df832008-11-19 16:25:44 +0100121
Heiko Schocherff94bc42014-06-24 10:10:04 +0200122static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
123{
124 return ubi->dbg.chk_io;
125}
126
127static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
128{
129 return ubi->dbg.chk_gen;
130}
Heiko Schocher0195a7b2015-10-22 06:19:21 +0200131
132static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
133{
134 return ubi->dbg.chk_fastmap;
135}
136
137static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
138{
139 ubi->dbg.chk_fastmap = 1;
140}
141
142int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
Kyungmin Park961df832008-11-19 16:25:44 +0100143#endif /* !__UBI_DEBUG_H__ */