Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (c) International Business Machines Corp., 2006
0004  *
0005  * Author: Artem Bityutskiy (Битюцкий Артём)
0006  */
0007 
0008 #ifndef __UBI_DEBUG_H__
0009 #define __UBI_DEBUG_H__
0010 
0011 void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
0012 void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
0013 void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
0014 
0015 #include <linux/random.h>
0016 
0017 #define ubi_assert(expr)  do {                                               \
0018     if (unlikely(!(expr))) {                                             \
0019         pr_crit("UBI assert failed in %s at %u (pid %d)\n",          \
0020                __func__, __LINE__, current->pid);                    \
0021         dump_stack();                                                \
0022     }                                                                    \
0023 } while (0)
0024 
0025 #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a)                   \
0026         print_hex_dump(l, ps, pt, r, g, b, len, a)
0027 
0028 #define ubi_dbg_msg(type, fmt, ...) \
0029     pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid,       \
0030          ##__VA_ARGS__)
0031 
0032 /* General debugging messages */
0033 #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
0034 /* Messages from the eraseblock association sub-system */
0035 #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
0036 /* Messages from the wear-leveling sub-system */
0037 #define dbg_wl(fmt, ...)  ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
0038 /* Messages from the input/output sub-system */
0039 #define dbg_io(fmt, ...)  ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
0040 /* Initialization and build messages */
0041 #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
0042 
0043 void ubi_dump_vol_info(const struct ubi_volume *vol);
0044 void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
0045 void ubi_dump_av(const struct ubi_ainf_volume *av);
0046 void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
0047 void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
0048 int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
0049               int len);
0050 int ubi_debugfs_init(void);
0051 void ubi_debugfs_exit(void);
0052 int ubi_debugfs_init_dev(struct ubi_device *ubi);
0053 void ubi_debugfs_exit_dev(struct ubi_device *ubi);
0054 
0055 /**
0056  * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
0057  * @ubi: UBI device description object
0058  *
0059  * Returns non-zero if the UBI background thread is disabled for testing
0060  * purposes.
0061  */
0062 static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
0063 {
0064     return ubi->dbg.disable_bgt;
0065 }
0066 
0067 /**
0068  * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
0069  * @ubi: UBI device description object
0070  *
0071  * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
0072  */
0073 static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
0074 {
0075     if (ubi->dbg.emulate_bitflips)
0076         return !(prandom_u32() % 200);
0077     return 0;
0078 }
0079 
0080 /**
0081  * ubi_dbg_is_write_failure - if it is time to emulate a write failure.
0082  * @ubi: UBI device description object
0083  *
0084  * Returns non-zero if a write failure should be emulated, otherwise returns
0085  * zero.
0086  */
0087 static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
0088 {
0089     if (ubi->dbg.emulate_io_failures)
0090         return !(prandom_u32() % 500);
0091     return 0;
0092 }
0093 
0094 /**
0095  * ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
0096  * @ubi: UBI device description object
0097  *
0098  * Returns non-zero if an erase failure should be emulated, otherwise returns
0099  * zero.
0100  */
0101 static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
0102 {
0103     if (ubi->dbg.emulate_io_failures)
0104         return !(prandom_u32() % 400);
0105     return 0;
0106 }
0107 
0108 static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
0109 {
0110     return ubi->dbg.chk_io;
0111 }
0112 
0113 static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
0114 {
0115     return ubi->dbg.chk_gen;
0116 }
0117 
0118 static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
0119 {
0120     return ubi->dbg.chk_fastmap;
0121 }
0122 
0123 static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
0124 {
0125     ubi->dbg.chk_fastmap = 1;
0126 }
0127 
0128 int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
0129 #endif /* !__UBI_DEBUG_H__ */