blob: 9c8ce51636b1aa4e711dfa6689ff3f1c09c088f5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kyungmin Parkc880c532008-11-19 16:25:44 +01002/*
3 * Copyright (c) International Business Machines Corp., 2006
4 *
Kyungmin Parkc880c532008-11-19 16:25:44 +01005 * Author: Artem Bityutskiy (Битюцкий Артём)
6 */
7
8#ifndef __UBI_DEBUG_H__
9#define __UBI_DEBUG_H__
10
Heiko Schocherf5895d12014-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);
Kyungmin Parkc880c532008-11-19 16:25:44 +010014
Heiko Schocherf5895d12014-06-24 10:10:04 +020015#ifndef __UBOOT__
16#include <linux/random.h>
Kyungmin Parkc880c532008-11-19 16:25:44 +010017#endif
18
Alexey Brodkin2d2fa492018-06-05 17:17:57 +030019#include <hexdump.h>
20
Eran Matityahua59fb302019-02-13 20:55:43 +020021#ifndef __UBOOT__
Heiko Schocherf5895d12014-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 Matityahua59fb302019-02-13 20:55:43 +020029#else
Pali Rohár38ed4e72022-07-10 13:38:07 +020030#include <log.h>
31#define ubi_assert(expr) assert(expr)
Eran Matityahua59fb302019-02-13 20:55:43 +020032#endif
Kyungmin Parkc880c532008-11-19 16:25:44 +010033
Alexey Brodkin2d2fa492018-06-05 17:17:57 +030034#define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
35 print_hex_dump(ps, pt, r, g, b, len, a)
Kyungmin Parkc880c532008-11-19 16:25:44 +010036
Heiko Schocherf5895d12014-06-24 10:10:04 +020037#define ubi_dbg_msg(type, fmt, ...) \
38 pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
39 ##__VA_ARGS__)
Kyungmin Parkc880c532008-11-19 16:25:44 +010040
Heiko Schocherf5895d12014-06-24 10:10:04 +020041/* General debugging messages */
42#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
43/* Messages from the eraseblock association sub-system */
44#define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
45/* Messages from the wear-leveling sub-system */
46#define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
47/* Messages from the input/output sub-system */
48#define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
49/* Initialization and build messages */
50#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
Kyungmin Parkc880c532008-11-19 16:25:44 +010051
Heiko Schocherf5895d12014-06-24 10:10:04 +020052void ubi_dump_vol_info(const struct ubi_volume *vol);
53void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
54void ubi_dump_av(const struct ubi_ainf_volume *av);
55void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
56void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
57int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
58 int len);
59int ubi_debugfs_init(void);
60void ubi_debugfs_exit(void);
61int ubi_debugfs_init_dev(struct ubi_device *ubi);
62void ubi_debugfs_exit_dev(struct ubi_device *ubi);
Kyungmin Parkc880c532008-11-19 16:25:44 +010063
Heiko Schocherf5895d12014-06-24 10:10:04 +020064/**
65 * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
66 * @ubi: UBI device description object
67 *
68 * Returns non-zero if the UBI background thread is disabled for testing
69 * purposes.
70 */
71static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
72{
73 return ubi->dbg.disable_bgt;
74}
Kyungmin Parkc880c532008-11-19 16:25:44 +010075
Kyungmin Parkc880c532008-11-19 16:25:44 +010076/**
77 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
Heiko Schocherf5895d12014-06-24 10:10:04 +020078 * @ubi: UBI device description object
Kyungmin Parkc880c532008-11-19 16:25:44 +010079 *
80 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
81 */
Heiko Schocherf5895d12014-06-24 10:10:04 +020082static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
Kyungmin Parkc880c532008-11-19 16:25:44 +010083{
Heiko Schocherf5895d12014-06-24 10:10:04 +020084 if (ubi->dbg.emulate_bitflips)
85 return !(prandom_u32() % 200);
86 return 0;
Kyungmin Parkc880c532008-11-19 16:25:44 +010087}
Kyungmin Parkc880c532008-11-19 16:25:44 +010088
Kyungmin Parkc880c532008-11-19 16:25:44 +010089/**
90 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
Heiko Schocherf5895d12014-06-24 10:10:04 +020091 * @ubi: UBI device description object
Kyungmin Parkc880c532008-11-19 16:25:44 +010092 *
93 * Returns non-zero if a write failure should be emulated, otherwise returns
94 * zero.
95 */
Heiko Schocherf5895d12014-06-24 10:10:04 +020096static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
Kyungmin Parkc880c532008-11-19 16:25:44 +010097{
Heiko Schocherf5895d12014-06-24 10:10:04 +020098 if (ubi->dbg.emulate_io_failures)
99 return !(prandom_u32() % 500);
100 return 0;
Kyungmin Parkc880c532008-11-19 16:25:44 +0100101}
Kyungmin Parkc880c532008-11-19 16:25:44 +0100102
Kyungmin Parkc880c532008-11-19 16:25:44 +0100103/**
104 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
Heiko Schocherf5895d12014-06-24 10:10:04 +0200105 * @ubi: UBI device description object
Kyungmin Parkc880c532008-11-19 16:25:44 +0100106 *
107 * Returns non-zero if an erase failure should be emulated, otherwise returns
108 * zero.
109 */
Heiko Schocherf5895d12014-06-24 10:10:04 +0200110static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
Kyungmin Parkc880c532008-11-19 16:25:44 +0100111{
Heiko Schocherf5895d12014-06-24 10:10:04 +0200112 if (ubi->dbg.emulate_io_failures)
113 return !(prandom_u32() % 400);
114 return 0;
Kyungmin Parkc880c532008-11-19 16:25:44 +0100115}
Kyungmin Parkc880c532008-11-19 16:25:44 +0100116
Heiko Schocherf5895d12014-06-24 10:10:04 +0200117static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
118{
119 return ubi->dbg.chk_io;
120}
121
122static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
123{
124 return ubi->dbg.chk_gen;
125}
Heiko Schocher94b66de2015-10-22 06:19:21 +0200126
127static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
128{
129 return ubi->dbg.chk_fastmap;
130}
131
132static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
133{
134 ubi->dbg.chk_fastmap = 1;
135}
136
137int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
Kyungmin Parkc880c532008-11-19 16:25:44 +0100138#endif /* !__UBI_DEBUG_H__ */