Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) International Business Machines Corp., 2006 |
| 4 | * |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 5 | * Author: Artem Bityutskiy (Битюцкий Артём) |
| 6 | */ |
| 7 | |
| 8 | #ifndef __UBI_DEBUG_H__ |
| 9 | #define __UBI_DEBUG_H__ |
| 10 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 11 | void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
| 12 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); |
| 13 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 14 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 15 | #ifndef __UBOOT__ |
| 16 | #include <linux/random.h> |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 17 | #endif |
| 18 | |
Alexey Brodkin | 2d2fa49 | 2018-06-05 17:17:57 +0300 | [diff] [blame] | 19 | #include <hexdump.h> |
| 20 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 21 | #define ubi_assert(expr) do { \ |
| 22 | if (unlikely(!(expr))) { \ |
| 23 | pr_crit("UBI assert failed in %s at %u (pid %d)\n", \ |
| 24 | __func__, __LINE__, current->pid); \ |
| 25 | dump_stack(); \ |
| 26 | } \ |
| 27 | } while (0) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 28 | |
Alexey Brodkin | 2d2fa49 | 2018-06-05 17:17:57 +0300 | [diff] [blame] | 29 | #define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \ |
| 30 | print_hex_dump(ps, pt, r, g, b, len, a) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 31 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 32 | #define ubi_dbg_msg(type, fmt, ...) \ |
| 33 | pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \ |
| 34 | ##__VA_ARGS__) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 35 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 36 | /* General debugging messages */ |
| 37 | #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) |
| 38 | /* Messages from the eraseblock association sub-system */ |
| 39 | #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__) |
| 40 | /* Messages from the wear-leveling sub-system */ |
| 41 | #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__) |
| 42 | /* Messages from the input/output sub-system */ |
| 43 | #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__) |
| 44 | /* Initialization and build messages */ |
| 45 | #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 46 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 47 | void ubi_dump_vol_info(const struct ubi_volume *vol); |
| 48 | void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); |
| 49 | void ubi_dump_av(const struct ubi_ainf_volume *av); |
| 50 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type); |
| 51 | void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req); |
| 52 | int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, |
| 53 | int len); |
| 54 | int ubi_debugfs_init(void); |
| 55 | void ubi_debugfs_exit(void); |
| 56 | int ubi_debugfs_init_dev(struct ubi_device *ubi); |
| 57 | void ubi_debugfs_exit_dev(struct ubi_device *ubi); |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 58 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 59 | /** |
| 60 | * ubi_dbg_is_bgt_disabled - if the background thread is disabled. |
| 61 | * @ubi: UBI device description object |
| 62 | * |
| 63 | * Returns non-zero if the UBI background thread is disabled for testing |
| 64 | * purposes. |
| 65 | */ |
| 66 | static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) |
| 67 | { |
| 68 | return ubi->dbg.disable_bgt; |
| 69 | } |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 70 | |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 71 | /** |
| 72 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 73 | * @ubi: UBI device description object |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 74 | * |
| 75 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. |
| 76 | */ |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 77 | static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 78 | { |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 79 | if (ubi->dbg.emulate_bitflips) |
| 80 | return !(prandom_u32() % 200); |
| 81 | return 0; |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 82 | } |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 83 | |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 84 | /** |
| 85 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 86 | * @ubi: UBI device description object |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 87 | * |
| 88 | * Returns non-zero if a write failure should be emulated, otherwise returns |
| 89 | * zero. |
| 90 | */ |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 91 | static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 92 | { |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 93 | if (ubi->dbg.emulate_io_failures) |
| 94 | return !(prandom_u32() % 500); |
| 95 | return 0; |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 96 | } |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 97 | |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 98 | /** |
| 99 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 100 | * @ubi: UBI device description object |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 101 | * |
| 102 | * Returns non-zero if an erase failure should be emulated, otherwise returns |
| 103 | * zero. |
| 104 | */ |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 105 | static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 106 | { |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 107 | if (ubi->dbg.emulate_io_failures) |
| 108 | return !(prandom_u32() % 400); |
| 109 | return 0; |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 110 | } |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 111 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 112 | static inline int ubi_dbg_chk_io(const struct ubi_device *ubi) |
| 113 | { |
| 114 | return ubi->dbg.chk_io; |
| 115 | } |
| 116 | |
| 117 | static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi) |
| 118 | { |
| 119 | return ubi->dbg.chk_gen; |
| 120 | } |
Heiko Schocher | 94b66de | 2015-10-22 06:19:21 +0200 | [diff] [blame] | 121 | |
| 122 | static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi) |
| 123 | { |
| 124 | return ubi->dbg.chk_fastmap; |
| 125 | } |
| 126 | |
| 127 | static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi) |
| 128 | { |
| 129 | ubi->dbg.chk_fastmap = 1; |
| 130 | } |
| 131 | |
| 132 | int ubi_dbg_power_cut(struct ubi_device *ubi, int caller); |
Kyungmin Park | c880c53 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 133 | #endif /* !__UBI_DEBUG_H__ */ |