162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) International Business Machines Corp., 2006 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Author: Artem Bityutskiy (Битюцкий Артём) 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __UBI_DEBUG_H__ 962306a36Sopenharmony_ci#define __UBI_DEBUG_H__ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_civoid ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); 1262306a36Sopenharmony_civoid ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); 1362306a36Sopenharmony_civoid ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/random.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define ubi_assert(expr) do { \ 1862306a36Sopenharmony_ci if (unlikely(!(expr))) { \ 1962306a36Sopenharmony_ci pr_crit("UBI assert failed in %s at %u (pid %d)\n", \ 2062306a36Sopenharmony_ci __func__, __LINE__, current->pid); \ 2162306a36Sopenharmony_ci dump_stack(); \ 2262306a36Sopenharmony_ci } \ 2362306a36Sopenharmony_ci} while (0) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ 2662306a36Sopenharmony_ci print_hex_dump(l, ps, pt, r, g, b, len, a) 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#define ubi_dbg_msg(type, fmt, ...) \ 2962306a36Sopenharmony_ci pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \ 3062306a36Sopenharmony_ci ##__VA_ARGS__) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* General debugging messages */ 3362306a36Sopenharmony_ci#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) 3462306a36Sopenharmony_ci/* Messages from the eraseblock association sub-system */ 3562306a36Sopenharmony_ci#define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__) 3662306a36Sopenharmony_ci/* Messages from the wear-leveling sub-system */ 3762306a36Sopenharmony_ci#define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__) 3862306a36Sopenharmony_ci/* Messages from the input/output sub-system */ 3962306a36Sopenharmony_ci#define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__) 4062306a36Sopenharmony_ci/* Initialization and build messages */ 4162306a36Sopenharmony_ci#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_civoid ubi_dump_vol_info(const struct ubi_volume *vol); 4462306a36Sopenharmony_civoid ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); 4562306a36Sopenharmony_civoid ubi_dump_av(const struct ubi_ainf_volume *av); 4662306a36Sopenharmony_civoid ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type); 4762306a36Sopenharmony_civoid ubi_dump_mkvol_req(const struct ubi_mkvol_req *req); 4862306a36Sopenharmony_ciint ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, 4962306a36Sopenharmony_ci int len); 5062306a36Sopenharmony_ciint ubi_debugfs_init(void); 5162306a36Sopenharmony_civoid ubi_debugfs_exit(void); 5262306a36Sopenharmony_ciint ubi_debugfs_init_dev(struct ubi_device *ubi); 5362306a36Sopenharmony_civoid ubi_debugfs_exit_dev(struct ubi_device *ubi); 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/** 5662306a36Sopenharmony_ci * ubi_dbg_is_bgt_disabled - if the background thread is disabled. 5762306a36Sopenharmony_ci * @ubi: UBI device description object 5862306a36Sopenharmony_ci * 5962306a36Sopenharmony_ci * Returns non-zero if the UBI background thread is disabled for testing 6062306a36Sopenharmony_ci * purposes. 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_cistatic inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) 6362306a36Sopenharmony_ci{ 6462306a36Sopenharmony_ci return ubi->dbg.disable_bgt; 6562306a36Sopenharmony_ci} 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/** 6862306a36Sopenharmony_ci * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. 6962306a36Sopenharmony_ci * @ubi: UBI device description object 7062306a36Sopenharmony_ci * 7162306a36Sopenharmony_ci * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. 7262306a36Sopenharmony_ci */ 7362306a36Sopenharmony_cistatic inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) 7462306a36Sopenharmony_ci{ 7562306a36Sopenharmony_ci if (ubi->dbg.emulate_bitflips) 7662306a36Sopenharmony_ci return !get_random_u32_below(200); 7762306a36Sopenharmony_ci return 0; 7862306a36Sopenharmony_ci} 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/** 8162306a36Sopenharmony_ci * ubi_dbg_is_write_failure - if it is time to emulate a write failure. 8262306a36Sopenharmony_ci * @ubi: UBI device description object 8362306a36Sopenharmony_ci * 8462306a36Sopenharmony_ci * Returns non-zero if a write failure should be emulated, otherwise returns 8562306a36Sopenharmony_ci * zero. 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_cistatic inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) 8862306a36Sopenharmony_ci{ 8962306a36Sopenharmony_ci if (ubi->dbg.emulate_io_failures) 9062306a36Sopenharmony_ci return !get_random_u32_below(500); 9162306a36Sopenharmony_ci return 0; 9262306a36Sopenharmony_ci} 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/** 9562306a36Sopenharmony_ci * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. 9662306a36Sopenharmony_ci * @ubi: UBI device description object 9762306a36Sopenharmony_ci * 9862306a36Sopenharmony_ci * Returns non-zero if an erase failure should be emulated, otherwise returns 9962306a36Sopenharmony_ci * zero. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_cistatic inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) 10262306a36Sopenharmony_ci{ 10362306a36Sopenharmony_ci if (ubi->dbg.emulate_io_failures) 10462306a36Sopenharmony_ci return !get_random_u32_below(400); 10562306a36Sopenharmony_ci return 0; 10662306a36Sopenharmony_ci} 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_cistatic inline int ubi_dbg_chk_io(const struct ubi_device *ubi) 10962306a36Sopenharmony_ci{ 11062306a36Sopenharmony_ci return ubi->dbg.chk_io; 11162306a36Sopenharmony_ci} 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistatic inline int ubi_dbg_chk_gen(const struct ubi_device *ubi) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci return ubi->dbg.chk_gen; 11662306a36Sopenharmony_ci} 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistatic inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi) 11962306a36Sopenharmony_ci{ 12062306a36Sopenharmony_ci return ubi->dbg.chk_fastmap; 12162306a36Sopenharmony_ci} 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_cistatic inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi) 12462306a36Sopenharmony_ci{ 12562306a36Sopenharmony_ci ubi->dbg.chk_fastmap = 1; 12662306a36Sopenharmony_ci} 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciint ubi_dbg_power_cut(struct ubi_device *ubi, int caller); 12962306a36Sopenharmony_ci#endif /* !__UBI_DEBUG_H__ */ 130