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