blob: 2e13ebb2fb75551886978092aac4b648bcb29a7c [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>
Simon Glassbdd5f812023-09-14 18:21:46 -060020#include <linux/printk.h>
Alexey Brodkin2d2fa492018-06-05 17:17:57 +030021
Eran Matityahua59fb302019-02-13 20:55:43 +020022#ifndef __UBOOT__
Heiko Schocherf5895d12014-06-24 10:10:04 +020023#define ubi_assert(expr) do { \
24 if (unlikely(!(expr))) { \
25 pr_crit("UBI assert failed in %s at %u (pid %d)\n", \
26 __func__, __LINE__, current->pid); \
27 dump_stack(); \
28 } \
29} while (0)
Eran Matityahua59fb302019-02-13 20:55:43 +020030#else
Pali Rohár38ed4e72022-07-10 13:38:07 +020031#include <log.h>
32#define ubi_assert(expr) assert(expr)
Eran Matityahua59fb302019-02-13 20:55:43 +020033#endif
Kyungmin Parkc880c532008-11-19 16:25:44 +010034
Alexey Brodkin2d2fa492018-06-05 17:17:57 +030035#define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
36 print_hex_dump(ps, pt, r, g, b, len, a)
Kyungmin Parkc880c532008-11-19 16:25:44 +010037
Heiko Schocherf5895d12014-06-24 10:10:04 +020038#define ubi_dbg_msg(type, fmt, ...) \
39 pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
40 ##__VA_ARGS__)
Kyungmin Parkc880c532008-11-19 16:25:44 +010041
Heiko Schocherf5895d12014-06-24 10:10:04 +020042/* General debugging messages */
43#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
44/* Messages from the eraseblock association sub-system */
45#define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
46/* Messages from the wear-leveling sub-system */
47#define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
48/* Messages from the input/output sub-system */
49#define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
50/* Initialization and build messages */
51#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
Kyungmin Parkc880c532008-11-19 16:25:44 +010052
Heiko Schocherf5895d12014-06-24 10:10:04 +020053void ubi_dump_vol_info(const struct ubi_volume *vol);
54void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
55void ubi_dump_av(const struct ubi_ainf_volume *av);
56void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
57void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
58int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
59 int len);
60int ubi_debugfs_init(void);
61void ubi_debugfs_exit(void);
62int ubi_debugfs_init_dev(struct ubi_device *ubi);
63void ubi_debugfs_exit_dev(struct ubi_device *ubi);
Kyungmin Parkc880c532008-11-19 16:25:44 +010064
Heiko Schocherf5895d12014-06-24 10:10:04 +020065/**
66 * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
67 * @ubi: UBI device description object
68 *
69 * Returns non-zero if the UBI background thread is disabled for testing
70 * purposes.
71 */
72static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
73{
74 return ubi->dbg.disable_bgt;
75}
Kyungmin Parkc880c532008-11-19 16:25:44 +010076
Kyungmin Parkc880c532008-11-19 16:25:44 +010077/**
78 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
Heiko Schocherf5895d12014-06-24 10:10:04 +020079 * @ubi: UBI device description object
Kyungmin Parkc880c532008-11-19 16:25:44 +010080 *
81 * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
82 */
Heiko Schocherf5895d12014-06-24 10:10:04 +020083static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
Kyungmin Parkc880c532008-11-19 16:25:44 +010084{
Heiko Schocherf5895d12014-06-24 10:10:04 +020085 if (ubi->dbg.emulate_bitflips)
86 return !(prandom_u32() % 200);
87 return 0;
Kyungmin Parkc880c532008-11-19 16:25:44 +010088}
Kyungmin Parkc880c532008-11-19 16:25:44 +010089
Kyungmin Parkc880c532008-11-19 16:25:44 +010090/**
91 * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
Heiko Schocherf5895d12014-06-24 10:10:04 +020092 * @ubi: UBI device description object
Kyungmin Parkc880c532008-11-19 16:25:44 +010093 *
94 * Returns non-zero if a write failure should be emulated, otherwise returns
95 * zero.
96 */
Heiko Schocherf5895d12014-06-24 10:10:04 +020097static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
Kyungmin Parkc880c532008-11-19 16:25:44 +010098{
Heiko Schocherf5895d12014-06-24 10:10:04 +020099 if (ubi->dbg.emulate_io_failures)
100 return !(prandom_u32() % 500);
101 return 0;
Kyungmin Parkc880c532008-11-19 16:25:44 +0100102}
Kyungmin Parkc880c532008-11-19 16:25:44 +0100103
Kyungmin Parkc880c532008-11-19 16:25:44 +0100104/**
105 * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
Heiko Schocherf5895d12014-06-24 10:10:04 +0200106 * @ubi: UBI device description object
Kyungmin Parkc880c532008-11-19 16:25:44 +0100107 *
108 * Returns non-zero if an erase failure should be emulated, otherwise returns
109 * zero.
110 */
Heiko Schocherf5895d12014-06-24 10:10:04 +0200111static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
Kyungmin Parkc880c532008-11-19 16:25:44 +0100112{
Heiko Schocherf5895d12014-06-24 10:10:04 +0200113 if (ubi->dbg.emulate_io_failures)
114 return !(prandom_u32() % 400);
115 return 0;
Kyungmin Parkc880c532008-11-19 16:25:44 +0100116}
Kyungmin Parkc880c532008-11-19 16:25:44 +0100117
Heiko Schocherf5895d12014-06-24 10:10:04 +0200118static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
119{
120 return ubi->dbg.chk_io;
121}
122
123static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
124{
125 return ubi->dbg.chk_gen;
126}
Heiko Schocher94b66de2015-10-22 06:19:21 +0200127
128static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
129{
130 return ubi->dbg.chk_fastmap;
131}
132
133static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
134{
135 ubi->dbg.chk_fastmap = 1;
136}
137
138int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
Kyungmin Parkc880c532008-11-19 16:25:44 +0100139#endif /* !__UBI_DEBUG_H__ */