#define pr_fmt(fmt) …
#include <linux/init.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/vmalloc.h>
#include <linux/math64.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/rawnand.h>
#include <linux/mtd/partitions.h>
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/random.h>
#include <linux/sched.h>
#include <linux/sched/mm.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/seq_file.h>
#include <linux/debugfs.h>
#if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \
!defined(CONFIG_NANDSIM_SECOND_ID_BYTE) || \
!defined(CONFIG_NANDSIM_THIRD_ID_BYTE) || \
!defined(CONFIG_NANDSIM_FOURTH_ID_BYTE)
#define CONFIG_NANDSIM_FIRST_ID_BYTE …
#define CONFIG_NANDSIM_SECOND_ID_BYTE …
#define CONFIG_NANDSIM_THIRD_ID_BYTE …
#define CONFIG_NANDSIM_FOURTH_ID_BYTE …
#endif
#ifndef CONFIG_NANDSIM_ACCESS_DELAY
#define CONFIG_NANDSIM_ACCESS_DELAY …
#endif
#ifndef CONFIG_NANDSIM_PROGRAMM_DELAY
#define CONFIG_NANDSIM_PROGRAMM_DELAY …
#endif
#ifndef CONFIG_NANDSIM_ERASE_DELAY
#define CONFIG_NANDSIM_ERASE_DELAY …
#endif
#ifndef CONFIG_NANDSIM_OUTPUT_CYCLE
#define CONFIG_NANDSIM_OUTPUT_CYCLE …
#endif
#ifndef CONFIG_NANDSIM_INPUT_CYCLE
#define CONFIG_NANDSIM_INPUT_CYCLE …
#endif
#ifndef CONFIG_NANDSIM_BUS_WIDTH
#define CONFIG_NANDSIM_BUS_WIDTH …
#endif
#ifndef CONFIG_NANDSIM_DO_DELAYS
#define CONFIG_NANDSIM_DO_DELAYS …
#endif
#ifndef CONFIG_NANDSIM_LOG
#define CONFIG_NANDSIM_LOG …
#endif
#ifndef CONFIG_NANDSIM_DBG
#define CONFIG_NANDSIM_DBG …
#endif
#ifndef CONFIG_NANDSIM_MAX_PARTS
#define CONFIG_NANDSIM_MAX_PARTS …
#endif
static uint access_delay = …;
static uint programm_delay = …;
static uint erase_delay = …;
static uint output_cycle = …;
static uint input_cycle = …;
static uint bus_width = …;
static uint do_delays = …;
static uint log = …;
static uint dbg = …;
static unsigned long parts[CONFIG_NANDSIM_MAX_PARTS];
static unsigned int parts_num;
static char *badblocks = …;
static char *weakblocks = …;
static char *weakpages = …;
static unsigned int bitflips = …;
static char *gravepages = …;
static unsigned int overridesize = …;
static char *cache_file = …;
static unsigned int bbt;
static unsigned int bch;
static u_char id_bytes[8] = …;
module_param_array(…);
module_param_named(first_id_byte, id_bytes[0], byte, 0400);
module_param_named(second_id_byte, id_bytes[1], byte, 0400);
module_param_named(third_id_byte, id_bytes[2], byte, 0400);
module_param_named(fourth_id_byte, id_bytes[3], byte, 0400);
module_param(access_delay, uint, 0400);
module_param(programm_delay, uint, 0400);
module_param(erase_delay, uint, 0400);
module_param(output_cycle, uint, 0400);
module_param(input_cycle, uint, 0400);
module_param(bus_width, uint, 0400);
module_param(do_delays, uint, 0400);
module_param(log, uint, 0400);
module_param(dbg, uint, 0400);
module_param_array(…);
module_param(badblocks, charp, 0400);
module_param(weakblocks, charp, 0400);
module_param(weakpages, charp, 0400);
module_param(bitflips, uint, 0400);
module_param(gravepages, charp, 0400);
module_param(overridesize, uint, 0400);
module_param(cache_file, charp, 0400);
module_param(bbt, uint, 0400);
module_param(bch, uint, 0400);
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
#define NS_LARGEST_PAGE_SIZE …
#define NS_LOG(args...) …
#define NS_DBG(args...) …
#define NS_WARN(args...) …
#define NS_ERR(args...) …
#define NS_INFO(args...) …
#define NS_UDELAY(us) …
#define NS_MDELAY(us) …
#define NS_IS_INITIALIZED(ns) …
#define NS_STATUS_OK(ns) …
#define NS_STATUS_FAILED(ns) …
#define NS_RAW_OFFSET(ns) …
#define NS_RAW_OFFSET_OOB(ns) …
#define NS_PAGE_BYTE_SHIFT(ns) …
#define STATE_CMD_READ0 …
#define STATE_CMD_READ1 …
#define STATE_CMD_READSTART …
#define STATE_CMD_PAGEPROG …
#define STATE_CMD_READOOB …
#define STATE_CMD_ERASE1 …
#define STATE_CMD_STATUS …
#define STATE_CMD_SEQIN …
#define STATE_CMD_READID …
#define STATE_CMD_ERASE2 …
#define STATE_CMD_RESET …
#define STATE_CMD_RNDOUT …
#define STATE_CMD_RNDOUTSTART …
#define STATE_CMD_MASK …
#define STATE_ADDR_PAGE …
#define STATE_ADDR_SEC …
#define STATE_ADDR_COLUMN …
#define STATE_ADDR_ZERO …
#define STATE_ADDR_MASK …
#define STATE_DATAIN …
#define STATE_DATAIN_MASK …
#define STATE_DATAOUT …
#define STATE_DATAOUT_ID …
#define STATE_DATAOUT_STATUS …
#define STATE_DATAOUT_MASK …
#define STATE_READY …
#define STATE_UNKNOWN …
#define ACTION_CPY …
#define ACTION_PRGPAGE …
#define ACTION_SECERASE …
#define ACTION_ZEROOFF …
#define ACTION_HALFOFF …
#define ACTION_OOBOFF …
#define ACTION_MASK …
#define NS_OPER_NUM …
#define NS_OPER_STATES …
#define OPT_ANY …
#define OPT_PAGE512 …
#define OPT_PAGE2048 …
#define OPT_PAGE512_8BIT …
#define OPT_PAGE4096 …
#define OPT_LARGEPAGE …
#define OPT_SMALLPAGE …
#define NS_STATE(x) …
#define NS_MAX_PREVSTATES …
#define NS_MAX_HELD_PAGES …
ns_mem;
struct nandsim { … };
static struct nandsim_operations { … } ops[NS_OPER_NUM] = …;
struct weak_block { … };
static LIST_HEAD(weak_blocks);
struct weak_page { … };
static LIST_HEAD(weak_pages);
struct grave_page { … };
static LIST_HEAD(grave_pages);
static unsigned long *erase_block_wear = …;
static unsigned int wear_eb_count = …;
static unsigned long total_wear = …;
static struct mtd_info *nsmtd;
static int ns_show(struct seq_file *m, void *private)
{ … }
DEFINE_SHOW_ATTRIBUTE(…);
static int ns_debugfs_create(struct nandsim *ns)
{ … }
static void ns_debugfs_remove(struct nandsim *ns)
{ … }
static int __init ns_alloc_device(struct nandsim *ns)
{ … }
static void ns_free_device(struct nandsim *ns)
{ … }
static char __init *ns_get_partition_name(int i)
{ … }
static int __init ns_init(struct mtd_info *mtd)
{ … }
static void ns_free(struct nandsim *ns)
{ … }
static int ns_parse_badblocks(struct nandsim *ns, struct mtd_info *mtd)
{ … }
static int ns_parse_weakblocks(void)
{ … }
static int ns_erase_error(unsigned int erase_block_no)
{ … }
static int ns_parse_weakpages(void)
{ … }
static int ns_write_error(unsigned int page_no)
{ … }
static int ns_parse_gravepages(void)
{ … }
static int ns_read_error(unsigned int page_no)
{ … }
static int ns_setup_wear_reporting(struct mtd_info *mtd)
{ … }
static void ns_update_wear(unsigned int erase_block_no)
{ … }
static char *ns_get_state_name(uint32_t state)
{ … }
static int ns_check_command(int cmd)
{ … }
static uint32_t ns_get_state_by_command(unsigned command)
{ … }
static inline void ns_accept_addr_byte(struct nandsim *ns, u_char bt)
{ … }
static inline void ns_switch_to_ready_state(struct nandsim *ns, u_char status)
{ … }
static int ns_find_operation(struct nandsim *ns, uint32_t flag)
{ … }
static void ns_put_pages(struct nandsim *ns)
{ … }
static int ns_get_pages(struct nandsim *ns, struct file *file, size_t count,
loff_t pos)
{ … }
static ssize_t ns_read_file(struct nandsim *ns, struct file *file, void *buf,
size_t count, loff_t pos)
{ … }
static ssize_t ns_write_file(struct nandsim *ns, struct file *file, void *buf,
size_t count, loff_t pos)
{ … }
static inline union ns_mem *NS_GET_PAGE(struct nandsim *ns)
{ … }
static inline u_char *NS_PAGE_BYTE_OFF(struct nandsim *ns)
{ … }
static int ns_do_read_error(struct nandsim *ns, int num)
{ … }
static void ns_do_bit_flips(struct nandsim *ns, int num)
{ … }
static void ns_read_page(struct nandsim *ns, int num)
{ … }
static void ns_erase_sector(struct nandsim *ns)
{ … }
static int ns_prog_page(struct nandsim *ns, int num)
{ … }
static int ns_do_state_action(struct nandsim *ns, uint32_t action)
{ … }
static void ns_switch_state(struct nandsim *ns)
{ … }
static u_char ns_nand_read_byte(struct nand_chip *chip)
{ … }
static void ns_nand_write_byte(struct nand_chip *chip, u_char byte)
{ … }
static void ns_nand_write_buf(struct nand_chip *chip, const u_char *buf,
int len)
{ … }
static void ns_nand_read_buf(struct nand_chip *chip, u_char *buf, int len)
{ … }
static int ns_exec_op(struct nand_chip *chip, const struct nand_operation *op,
bool check_only)
{ … }
static int ns_attach_chip(struct nand_chip *chip)
{ … }
static const struct nand_controller_ops ns_controller_ops = …;
static int __init ns_init_module(void)
{ … }
module_init(…) …;
static void __exit ns_cleanup_module(void)
{ … }
module_exit(ns_cleanup_module);
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;