^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) International Business Machines Corp., 2006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) Nokia Corporation, 2006, 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Artem Bityutskiy (Битюцкий Артём)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef __UBI_UBI_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define __UBI_UBI_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/cdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/mtd/ubi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "ubi-media.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Maximum number of supported UBI devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define UBI_MAX_DEVICES 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* UBI name used for character devices, sysfs, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define UBI_NAME_STR "ubi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct ubi_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* Normal UBI messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __printf(2, 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* UBI warning messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) __printf(2, 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* UBI error messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __printf(2, 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void ubi_err(const struct ubi_device *ubi, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* Background thread name pattern */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * This marker in the EBA table means that the LEB is um-mapped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * NOTE! It has to have the same value as %UBI_ALL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define UBI_LEB_UNMAPPED -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * In case of errors, UBI tries to repeat the operation several times before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * returning error. The below constant defines how many times UBI re-tries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define UBI_IO_RETRIES 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * Length of the protection queue. The length is effectively equivalent to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * number of (global) erase cycles PEBs are protected from the wear-leveling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * worker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define UBI_PROT_QUEUE_LEN 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* The volume ID/LEB number/erase counter is unknown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define UBI_UNKNOWN -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * The UBI debugfs directory name pattern and maximum name length (3 for "ubi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * + 2 for the number plus 1 for the trailing zero byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define UBI_DFS_DIR_NAME "ubi%d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define UBI_DFS_DIR_LEN (3 + 2 + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Error codes returned by the I/O sub-system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * UBI_IO_FF: the read region of flash contains only 0xFFs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * integrity error reported by the MTD driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * (uncorrectable ECC error in case of NAND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * UBI_IO_BAD_HDR_EBADMSG: the same as %UBI_IO_BAD_HDR, but also there was a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * data integrity error reported by the MTD driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * (uncorrectable ECC error in case of NAND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * UBI_IO_BITFLIPS: bit-flips were detected and corrected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Note, it is probably better to have bit-flip and ebadmsg as flags which can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * be or'ed with other error code. But this is a big change because there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * may callers, so it does not worth the risk of introducing a bug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) UBI_IO_FF = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) UBI_IO_FF_BITFLIPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) UBI_IO_BAD_HDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) UBI_IO_BAD_HDR_EBADMSG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) UBI_IO_BITFLIPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Return codes of the 'ubi_eba_copy_leb()' function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * MOVE_CANCEL_RACE: canceled because the volume is being deleted, the source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * PEB was put meanwhile, or there is I/O on the source PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * MOVE_SOURCE_RD_ERR: canceled because there was a read error from the source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * MOVE_TARGET_RD_ERR: canceled because there was a read error from the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * MOVE_TARGET_WR_ERR: canceled because there was a write error to the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * MOVE_TARGET_BITFLIPS: canceled because a bit-flip was detected in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * target PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * MOVE_RETRY: retry scrubbing the PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MOVE_CANCEL_RACE = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MOVE_SOURCE_RD_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) MOVE_TARGET_RD_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MOVE_TARGET_WR_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MOVE_TARGET_BITFLIPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) MOVE_RETRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Return codes of the fastmap sub-system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * UBI_NO_FASTMAP: No fastmap super block was found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * UBI_BAD_FASTMAP: A fastmap was found but it's unusable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) UBI_NO_FASTMAP = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) UBI_BAD_FASTMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * Flags for emulate_power_cut in ubi_debug_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * POWER_CUT_EC_WRITE: Emulate a power cut when writing an EC header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * POWER_CUT_VID_WRITE: Emulate a power cut when writing a VID header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) POWER_CUT_EC_WRITE = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) POWER_CUT_VID_WRITE = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * struct ubi_vid_io_buf - VID buffer used to read/write VID info to/from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * flash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * @hdr: a pointer to the VID header stored in buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @buffer: underlying buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct ubi_vid_io_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct ubi_vid_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * struct ubi_wl_entry - wear-leveling entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @u.rb: link in the corresponding (free/used) RB-tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * @u.list: link in the protection queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * @ec: erase counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @pnum: physical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * This data structure is used in the WL sub-system. Each physical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * has a corresponding &struct wl_entry object which may be kept in different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * RB-trees. See WL sub-system for details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct ubi_wl_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct rb_node rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) } u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int pnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * struct ubi_ltree_entry - an entry in the lock tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * @rb: links RB-tree nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @vol_id: volume ID of the locked logical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @lnum: locked logical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @users: how many tasks are using this logical eraseblock or wait for it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * @mutex: read/write mutex to implement read/write access serialization to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * the (@vol_id, @lnum) logical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * This data structure is used in the EBA sub-system to implement per-LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * locking. When a logical eraseblock is being locked - corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * &struct ubi_ltree_entry object is inserted to the lock tree (@ubi->ltree).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * See EBA sub-system for details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct ubi_ltree_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct rb_node rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int users;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct rw_semaphore mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * struct ubi_rename_entry - volume re-name description data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * @new_name_len: new volume name length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * @new_name: new volume name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * @remove: if not zero, this volume should be removed, not re-named
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * @desc: descriptor of the volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * @list: links re-name entries into a list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * This data structure is utilized in the multiple volume re-name code. Namely,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * UBI first creates a list of &struct ubi_rename_entry objects from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * &struct ubi_rnvol_req request object, and then utilizes this list to do all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * the job.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct ubi_rename_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int new_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) char new_name[UBI_VOL_NAME_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct ubi_volume_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct ubi_volume_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * struct ubi_fastmap_layout - in-memory fastmap data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * @e: PEBs used by the current fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * @to_be_tortured: if non-zero tortured this PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @used_blocks: number of used PEBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * @max_pool_size: maximal size of the user pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * @max_wl_pool_size: maximal size of the pool used by the WL sub-system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct ubi_fastmap_layout {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct ubi_wl_entry *e[UBI_FM_MAX_BLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) int to_be_tortured[UBI_FM_MAX_BLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int used_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int max_pool_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int max_wl_pool_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * struct ubi_fm_pool - in-memory fastmap pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * @pebs: PEBs in this pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * @used: number of used PEBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * @size: total number of PEBs in this pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * @max_size: maximal size of the pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * A pool gets filled with up to max_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * If all PEBs within the pool are used a new fastmap will be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * to the flash and the pool gets refilled with empty PEBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct ubi_fm_pool {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int pebs[UBI_FM_MAX_POOL_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * struct ubi_eba_leb_desc - EBA logical eraseblock descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * @lnum: the logical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * @pnum: the physical eraseblock where the LEB can be found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * This structure is here to hide EBA's internal from other part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * UBI implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * One can query the position of a LEB by calling ubi_eba_get_ldesc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct ubi_eba_leb_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int pnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * struct ubi_volume - UBI volume description data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @dev: device object to make use of the the Linux device model
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * @cdev: character device object to create character device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * @ubi: reference to the UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * @vol_id: volume ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * @ref_count: volume reference count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * @readers: number of users holding this volume in read-only mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * @writers: number of users holding this volume in read-write mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * @exclusive: whether somebody holds this volume in exclusive mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * @metaonly: whether somebody is altering only meta data of this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * @reserved_pebs: how many physical eraseblocks are reserved for this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * @usable_leb_size: logical eraseblock size without padding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * @used_ebs: how many logical eraseblocks in this volume contain data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * @last_eb_bytes: how many bytes are stored in the last logical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * @used_bytes: how many bytes of data this volume contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * @alignment: volume alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * @data_pad: how many bytes are not used at the end of physical eraseblocks to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * satisfy the requested alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * @name_len: volume name length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * @name: volume name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * @upd_ebs: how many eraseblocks are expected to be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * @ch_lnum: LEB number which is being changing by the atomic LEB change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * @upd_bytes: how many bytes are expected to be received for volume update or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * atomic LEB change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * @upd_received: how many bytes were already received for volume update or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * atomic LEB change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * @upd_buf: update buffer which is used to collect update data or data for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * atomic LEB change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * @eba_tbl: EBA table of this volume (LEB->PEB mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * @skip_check: %1 if CRC check of this static volume should be skipped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * Directly reflects the presence of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * %UBI_VTBL_SKIP_CRC_CHECK_FLG flag in the vtbl entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * @checked: %1 if this static volume was checked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * @corrupted: %1 if the volume is corrupted (static volumes only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * @upd_marker: %1 if the update marker is set for this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * @updating: %1 if the volume is being updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * @changing_leb: %1 if the atomic LEB change ioctl command is in progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * @direct_writes: %1 if direct writes are enabled for this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * @checkmap: bitmap to remember which PEB->LEB mappings got checked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * protected by UBI LEB lock tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * The @corrupted field indicates that the volume's contents is corrupted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * Since UBI protects only static volumes, this field is not relevant to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * dynamic volumes - it is user's responsibility to assure their data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * integrity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * The @upd_marker flag indicates that this volume is either being updated at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * the moment or is damaged because of an unclean reboot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct ubi_volume {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct cdev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct ubi_device *ubi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int ref_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) int readers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int writers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int metaonly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int reserved_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int vol_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int usable_leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int used_ebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int last_eb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) long long used_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int data_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) int name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) char name[UBI_VOL_NAME_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int upd_ebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int ch_lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) long long upd_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) long long upd_received;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void *upd_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct ubi_eba_table *eba_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) unsigned int skip_check:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) unsigned int checked:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) unsigned int corrupted:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) unsigned int upd_marker:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) unsigned int updating:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) unsigned int changing_leb:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned int direct_writes:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) #ifdef CONFIG_MTD_UBI_FASTMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) unsigned long *checkmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * @vol: reference to the corresponding volume description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, %UBI_EXCLUSIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * or %UBI_METAONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct ubi_volume_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct ubi_volume *vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct ubi_wl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * struct ubi_debug_info - debugging information for an UBI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * @chk_gen: if UBI general extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * @chk_io: if UBI I/O extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * @chk_fastmap: if UBI fastmap extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * @disable_bgt: disable the background task for testing purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) * @emulate_bitflips: emulate bit-flips for testing purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * @emulate_io_failures: emulate write/erase failures for testing purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * @emulate_power_cut: emulate power cut for testing purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * @power_cut_counter: count down for writes left until emulated power cut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * @power_cut_min: minimum number of writes before emulating a power cut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * @power_cut_max: maximum number of writes until emulating a power cut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * @dfs_dir_name: name of debugfs directory containing files of this UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * @dfs_dir: direntry object of the UBI device debugfs directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * @dfs_chk_gen: debugfs knob to enable UBI general extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * @dfs_chk_fastmap: debugfs knob to enable UBI fastmap extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * @dfs_disable_bgt: debugfs knob to disable the background task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * @dfs_emulate_power_cut: debugfs knob to emulate power cuts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * @dfs_power_cut_min: debugfs knob for minimum writes before power cut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * @dfs_power_cut_max: debugfs knob for maximum writes until power cut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct ubi_debug_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) unsigned int chk_gen:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unsigned int chk_io:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) unsigned int chk_fastmap:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) unsigned int disable_bgt:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) unsigned int emulate_bitflips:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) unsigned int emulate_io_failures:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) unsigned int emulate_power_cut:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) unsigned int power_cut_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) unsigned int power_cut_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) unsigned int power_cut_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct dentry *dfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct dentry *dfs_chk_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct dentry *dfs_chk_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct dentry *dfs_chk_fastmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct dentry *dfs_disable_bgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct dentry *dfs_emulate_bitflips;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct dentry *dfs_emulate_io_failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct dentry *dfs_emulate_power_cut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct dentry *dfs_power_cut_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct dentry *dfs_power_cut_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * struct ubi_device - UBI device description structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * @dev: UBI device object to use the the Linux device model
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * @cdev: character device object to create character device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * @ubi_num: UBI device number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * @ubi_name: UBI device name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * @vol_count: number of volumes in this UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * @volumes: volumes of this UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * @volumes_lock: protects @volumes, @rsvd_pebs, @avail_pebs, beb_rsvd_pebs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * @beb_rsvd_level, @bad_peb_count, @good_peb_count, @vol_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * @vol->readers, @vol->writers, @vol->exclusive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * @vol->metaonly, @vol->ref_count, @vol->mapping and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * @vol->eba_tbl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * @ref_count: count of references on the UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * @image_seq: image sequence number recorded on EC headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * @rsvd_pebs: count of reserved physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * @avail_pebs: count of available physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * @beb_rsvd_pebs: how many physical eraseblocks are reserved for bad PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * @beb_rsvd_level: normal level of PEBs reserved for bad PEB handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * @autoresize_vol_id: ID of the volume which has to be auto-resized at the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * of UBI initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * @vtbl_slots: how many slots are available in the volume table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * @vtbl_size: size of the volume table in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * @vtbl: in-RAM volume table copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * @device_mutex: protects on-flash volume table and serializes volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * creation, deletion, update, re-size, re-name and set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * @max_ec: current highest erase counter value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * @mean_ec: current mean erase counter value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * @global_sqnum: global sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * @ltree_lock: protects the lock tree and @global_sqnum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) * @ltree: the lock tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * @alc_mutex: serializes "atomic LEB change" operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * @fm_disabled: non-zero if fastmap is disabled (default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * @fm: in-memory data structure of the currently used fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * @fm_pool: in-memory data structure of the fastmap pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * @fm_wl_pool: in-memory data structure of the fastmap pool used by the WL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * sub-system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * @fm_protect: serializes ubi_update_fastmap(), protects @fm_buf and makes sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * that critical sections cannot be interrupted by ubi_update_fastmap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * @fm_buf: vmalloc()'d buffer which holds the raw fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * @fm_size: fastmap size in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * @fm_eba_sem: allows ubi_update_fastmap() to block EBA table changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * @fm_work: fastmap work queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * @fm_work_scheduled: non-zero if fastmap work was scheduled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * @fast_attach: non-zero if UBI was attached by fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * @fm_anchor: The new anchor PEB used during fastmap update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * @fm_next_anchor: An anchor PEB candidate for the next time fastmap is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * @fm_do_produce_anchor: If true produce an anchor PEB in wl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * @used: RB-tree of used physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * @erroneous: RB-tree of erroneous used physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * @free: RB-tree of free physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * @free_count: Contains the number of elements in @free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * @scrub: RB-tree of physical eraseblocks which need scrubbing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * @pq: protection queue (contain physical eraseblocks which are temporarily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * protected from the wear-leveling worker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * @pq_head: protection queue head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * @wl_lock: protects the @used, @free, @pq, @pq_head, @lookuptbl, @move_from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * @move_to, @move_to_put @erase_pending, @wl_scheduled, @works,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * @erroneous, @erroneous_peb_count, @fm_work_scheduled, @fm_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * and @fm_wl_pool fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * @move_mutex: serializes eraseblock moves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * @work_sem: used to wait for all the scheduled works to finish and prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * new works from being submitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * @wl_scheduled: non-zero if the wear-leveling was scheduled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * @lookuptbl: a table to quickly find a &struct ubi_wl_entry object for any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * physical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * @move_from: physical eraseblock from where the data is being moved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * @move_to: physical eraseblock where the data is being moved to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * @move_to_put: if the "to" PEB was put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * @works: list of pending works
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * @works_count: count of pending works
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * @bgt_thread: background thread description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * @thread_enabled: if the background thread is enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * @bgt_name: background thread name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * @flash_size: underlying MTD device size (in bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * @peb_count: count of physical eraseblocks on the MTD device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * @peb_size: physical eraseblock size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * @bad_peb_limit: top limit of expected bad physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * @bad_peb_count: count of bad physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * @good_peb_count: count of good physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * @corr_peb_count: count of corrupted physical eraseblocks (preserved and not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * used by UBI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * @erroneous_peb_count: count of erroneous physical eraseblocks in @erroneous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * @max_erroneous: maximum allowed amount of erroneous physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * @min_io_size: minimal input/output unit size of the underlying MTD device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * @hdrs_min_io_size: minimal I/O unit size used for VID and EC headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * @ro_mode: if the UBI device is in read-only mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * @leb_size: logical eraseblock size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * @leb_start: starting offset of logical eraseblocks within physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * @ec_hdr_alsize: size of the EC header aligned to @hdrs_min_io_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * @vid_hdr_alsize: size of the VID header aligned to @hdrs_min_io_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * @vid_hdr_offset: starting offset of the volume identifier header (might be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * unaligned)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * @vid_hdr_aloffset: starting offset of the VID header aligned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * @hdrs_min_io_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * @bad_allowed: whether the MTD device admits bad physical eraseblocks or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * @nor_flash: non-zero if working on top of NOR flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * @max_write_size: maximum amount of bytes the underlying flash can write at a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * time (MTD write buffer size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * @mtd: MTD device descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * @peb_buf: a buffer of PEB size used for different purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * @buf_mutex: protects @peb_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * @ckvol_mutex: serializes static volume checking when opening
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * @dbg: debugging information for this UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct ubi_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct cdev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) int ubi_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) char ubi_name[sizeof(UBI_NAME_STR)+5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int vol_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) struct ubi_volume *volumes[UBI_MAX_VOLUMES+UBI_INT_VOL_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) spinlock_t volumes_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) int ref_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) int image_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int rsvd_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) int avail_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) int beb_rsvd_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) int beb_rsvd_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int bad_peb_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) int autoresize_vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) int vtbl_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) int vtbl_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) struct ubi_vtbl_record *vtbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct mutex device_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) int max_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /* Note, mean_ec is not updated run-time - should be fixed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) int mean_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* EBA sub-system's stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) unsigned long long global_sqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) spinlock_t ltree_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct rb_root ltree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct mutex alc_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) /* Fastmap stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) int fm_disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct ubi_fastmap_layout *fm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct ubi_fm_pool fm_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct ubi_fm_pool fm_wl_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct rw_semaphore fm_eba_sem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct rw_semaphore fm_protect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) void *fm_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) size_t fm_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct work_struct fm_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) int fm_work_scheduled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) int fast_attach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct ubi_wl_entry *fm_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct ubi_wl_entry *fm_next_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int fm_do_produce_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* Wear-leveling sub-system's stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct rb_root used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct rb_root erroneous;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct rb_root free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) int free_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) struct rb_root scrub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct list_head pq[UBI_PROT_QUEUE_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) int pq_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) spinlock_t wl_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct mutex move_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct rw_semaphore work_sem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) int wl_scheduled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct ubi_wl_entry **lookuptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct ubi_wl_entry *move_from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) struct ubi_wl_entry *move_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) int move_to_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct list_head works;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) int works_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) struct task_struct *bgt_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) int thread_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) char bgt_name[sizeof(UBI_BGT_NAME_PATTERN)+2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* I/O sub-system's stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) long long flash_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) int peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) int peb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int bad_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) int good_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int corr_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) int erroneous_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) int max_erroneous;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) int min_io_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) int hdrs_min_io_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) int ro_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) int leb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) int leb_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) int ec_hdr_alsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) int vid_hdr_alsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) int vid_hdr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) int vid_hdr_aloffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) int vid_hdr_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) unsigned int bad_allowed:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) unsigned int nor_flash:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int max_write_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct mtd_info *mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) void *peb_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct mutex buf_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct mutex ckvol_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct ubi_debug_info dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * struct ubi_ainf_peb - attach information about a physical eraseblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * @ec: erase counter (%UBI_UNKNOWN if it is unknown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * @pnum: physical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * @vol_id: ID of the volume this LEB belongs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * @lnum: logical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * @scrub: if this physical eraseblock needs scrubbing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * @copy_flag: this LEB is a copy (@copy_flag is set in VID header of this LEB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * @sqnum: sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * @u: unions RB-tree or @list links
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * @u.rb: link in the per-volume RB-tree of &struct ubi_ainf_peb objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * @u.list: link in one of the eraseblock lists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * One object of this type is allocated for each physical eraseblock when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) * attaching an MTD device. Note, if this PEB does not belong to any LEB /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * volume, the @vol_id and @lnum fields are initialized to %UBI_UNKNOWN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) struct ubi_ainf_peb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) int pnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) int vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) int lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) unsigned int scrub:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) unsigned int copy_flag:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) unsigned long long sqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) struct rb_node rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) } u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * struct ubi_ainf_volume - attaching information about a volume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * @vol_id: volume ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * @highest_lnum: highest logical eraseblock number in this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * @leb_count: number of logical eraseblocks in this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * @vol_type: volume type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * @used_ebs: number of used logical eraseblocks in this volume (only for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * static volumes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * @last_data_size: amount of data in the last logical eraseblock of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * volume (always equivalent to the usable logical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * size in case of dynamic volumes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * @data_pad: how many bytes at the end of logical eraseblocks of this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * are not used (due to volume alignment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * @compat: compatibility flags of this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * @rb: link in the volume RB-tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * @root: root of the RB-tree containing all the eraseblock belonging to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * volume (&struct ubi_ainf_peb objects)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * One object of this type is allocated for each volume when attaching an MTD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct ubi_ainf_volume {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) int vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) int highest_lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) int leb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) int vol_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) int used_ebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) int last_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) int data_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) int compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct rb_node rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct rb_root root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * struct ubi_attach_info - MTD device attaching information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * @volumes: root of the volume RB-tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * @corr: list of corrupted physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * @free: list of free physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * @erase: list of physical eraseblocks which have to be erased
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * those belonging to "preserve"-compatible internal volumes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * @fastmap: list of physical eraseblocks which relate to fastmap (e.g.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * eraseblocks of the current and not yet erased old fastmap blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) * @corr_peb_count: count of PEBs in the @corr list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) * @empty_peb_count: count of PEBs which are presumably empty (contain only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * 0xFF bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) * @alien_peb_count: count of PEBs in the @alien list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * @bad_peb_count: count of bad physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * as bad yet, but which look like bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * @vols_found: number of volumes found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * @highest_vol_id: highest volume ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * @is_empty: flag indicating whether the MTD device is empty or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * @force_full_scan: flag indicating whether we need to do a full scan and drop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) all existing Fastmap data structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * @min_ec: lowest erase counter value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) * @max_ec: highest erase counter value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) * @max_sqnum: highest sequence number value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * @mean_ec: mean erase counter value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) * @ec_sum: a temporary variable used when calculating @mean_ec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) * @ec_count: a temporary variable used when calculating @mean_ec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * @ech: temporary EC header. Only available during scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * @vidh: temporary VID buffer. Only available during scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * This data structure contains the result of attaching an MTD device and may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * be used by other UBI sub-systems to build final UBI data structures, further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * error-recovery and so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) struct ubi_attach_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) struct rb_root volumes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct list_head corr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct list_head free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct list_head erase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct list_head alien;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct list_head fastmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) int corr_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) int empty_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) int alien_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int bad_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) int maybe_bad_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) int vols_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) int highest_vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) int is_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) int force_full_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) int min_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) int max_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) unsigned long long max_sqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) int mean_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) uint64_t ec_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) int ec_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) struct kmem_cache *aeb_slab_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct ubi_ec_hdr *ech;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct ubi_vid_io_buf *vidb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * struct ubi_work - UBI work description data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * @list: a link in the list of pending works
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * @func: worker function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * @e: physical eraseblock to erase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * @vol_id: the volume ID on which this erasure is being performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * @lnum: the logical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * @torture: if the physical eraseblock has to be tortured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * The @func pointer points to the worker function. If the @shutdown argument is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * not zero, the worker has to free the resources and exit immediately as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * WL sub-system is shutting down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * The worker has to return zero in case of success and a negative error code in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct ubi_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) int (*func)(struct ubi_device *ubi, struct ubi_work *wrk, int shutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) /* The below fields are only relevant to erasure works */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct ubi_wl_entry *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) int vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) int lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) int torture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) extern struct kmem_cache *ubi_wl_entry_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) extern const struct file_operations ubi_ctrl_cdev_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) extern const struct file_operations ubi_cdev_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) extern const struct file_operations ubi_vol_cdev_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) extern struct class ubi_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) extern struct mutex ubi_devices_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) extern struct blocking_notifier_head ubi_notifiers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /* attach.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) struct ubi_ainf_peb *ubi_alloc_aeb(struct ubi_attach_info *ai, int pnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) int ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) void ubi_free_aeb(struct ubi_attach_info *ai, struct ubi_ainf_peb *aeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) int ec, const struct ubi_vid_hdr *vid_hdr, int bitflips);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) struct ubi_ainf_volume *ubi_add_av(struct ubi_attach_info *ai, int vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) int vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct ubi_attach_info *ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) int ubi_attach(struct ubi_device *ubi, int force_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) void ubi_destroy_ai(struct ubi_attach_info *ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /* vtbl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct ubi_vtbl_record *vtbl_rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) struct list_head *rename_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* vmt.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) /* upd.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) long long bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) const void __user *buf, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) const struct ubi_leb_change_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) const void __user *buf, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) /* misc.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) int ubi_check_volume(struct ubi_device *ubi, int vol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) void ubi_update_reserved(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) void ubi_calculate_reserved(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) int ubi_check_pattern(const void *buf, uint8_t patt, int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) static inline bool ubi_leb_valid(struct ubi_volume *vol, int lnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) return lnum >= 0 && lnum < vol->reserved_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) /* eba.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) struct ubi_eba_table *ubi_eba_create_table(struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) int nentries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) void ubi_eba_destroy_table(struct ubi_eba_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) void ubi_eba_copy_table(struct ubi_volume *vol, struct ubi_eba_table *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) int nentries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) void ubi_eba_replace_table(struct ubi_volume *vol, struct ubi_eba_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) void ubi_eba_get_ldesc(struct ubi_volume *vol, int lnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) struct ubi_eba_leb_desc *ldesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) bool ubi_eba_is_mapped(struct ubi_volume *vol, int lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) int lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) void *buf, int offset, int len, int check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct ubi_sgl *sgl, int lnum, int offset, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) int check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) const void *buf, int offset, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) int lnum, const void *buf, int len, int used_ebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) int lnum, const void *buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct ubi_vid_io_buf *vidb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) unsigned long long ubi_next_sqnum(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct ubi_attach_info *ai_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /* wl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) int ubi_wl_get_peb(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) int pnum, int torture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) void ubi_wl_close(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) int ubi_thread(void *u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *used_e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) int lnum, int torture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) int ubi_is_erase_work(struct ubi_work *wrk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) void ubi_refill_pools(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) int ubi_ensure_anchor_pebs(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) int ubi_bitflip_check(struct ubi_device *ubi, int pnum, int force_scrub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) /* io.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) int ubi_io_is_bad(const struct ubi_device *ubi, int pnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct ubi_ec_hdr *ec_hdr, int verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) struct ubi_ec_hdr *ec_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct ubi_vid_io_buf *vidb, int verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) struct ubi_vid_io_buf *vidb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) /* build.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) int vid_hdr_offset, int max_beb_per1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) int ubi_detach_mtd_dev(int ubi_num, int anyway);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) struct ubi_device *ubi_get_device(int ubi_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) void ubi_put_device(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) struct ubi_device *ubi_get_by_major(int major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) int ubi_major2num(int major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) int ntype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) int ubi_notify_all(struct ubi_device *ubi, int ntype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct notifier_block *nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) int ubi_enumerate_volumes(struct notifier_block *nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) void ubi_free_all_volumes(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) void ubi_free_internal_volumes(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) /* kapi.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) struct ubi_volume_info *vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) /* scan.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) int pnum, const struct ubi_vid_hdr *vid_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) /* fastmap.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) #ifdef CONFIG_MTD_UBI_FASTMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) size_t ubi_calc_fm_size(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) int ubi_update_fastmap(struct ubi_device *ubi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) struct ubi_attach_info *scan_ai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) static inline int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) static inline void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) /* block.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) #ifdef CONFIG_MTD_UBI_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) int ubiblock_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) void ubiblock_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) int ubiblock_create(struct ubi_volume_info *vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) int ubiblock_remove(struct ubi_volume_info *vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) static inline int ubiblock_init(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) static inline void ubiblock_exit(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) static inline int ubiblock_create(struct ubi_volume_info *vi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) static inline int ubiblock_remove(struct ubi_volume_info *vi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) * ubi_for_each_free_peb - walk the UBI free RB tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) * @e: a pointer to a ubi_wl_entry to use as cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * @pos: a pointer to RB-tree entry type to use as a loop counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) #define ubi_for_each_free_peb(ubi, e, tmp_rb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->free, u.rb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) * ubi_for_each_used_peb - walk the UBI used RB tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) * @e: a pointer to a ubi_wl_entry to use as cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) * @pos: a pointer to RB-tree entry type to use as a loop counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) #define ubi_for_each_used_peb(ubi, e, tmp_rb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->used, u.rb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) * ubi_for_each_scub_peb - walk the UBI scub RB tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) * @e: a pointer to a ubi_wl_entry to use as cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) * @pos: a pointer to RB-tree entry type to use as a loop counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) #define ubi_for_each_scrub_peb(ubi, e, tmp_rb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) ubi_rb_for_each_entry((tmp_rb), (e), &(ubi)->scrub, u.rb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * ubi_for_each_protected_peb - walk the UBI protection queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * @i: a integer used as counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * @e: a pointer to a ubi_wl_entry to use as cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) #define ubi_for_each_protected_peb(ubi, i, e) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) for ((i) = 0; (i) < UBI_PROT_QUEUE_LEN; (i)++) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) list_for_each_entry((e), &(ubi->pq[(i)]), u.list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) * ubi_rb_for_each_entry - walk an RB-tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * @rb: a pointer to type 'struct rb_node' to use as a loop counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * @pos: a pointer to RB-tree entry type to use as a loop counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) * @root: RB-tree's root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * @member: the name of the 'struct rb_node' within the RB-tree entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) #define ubi_rb_for_each_entry(rb, pos, root, member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) for (rb = rb_first(root), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) pos = (rb ? container_of(rb, typeof(*pos), member) : NULL); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) rb; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) rb = rb_next(rb), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) pos = (rb ? container_of(rb, typeof(*pos), member) : NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) * ubi_move_aeb_to_list - move a PEB from the volume tree to a list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * @av: volume attaching information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * @aeb: attaching eraseblock information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) * @list: the list to move to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) static inline void ubi_move_aeb_to_list(struct ubi_ainf_volume *av,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) struct ubi_ainf_peb *aeb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) struct list_head *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) rb_erase(&aeb->u.rb, &av->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) list_add_tail(&aeb->u.list, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) * ubi_init_vid_buf - Initialize a VID buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) * @ubi: the UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) * @vidb: the VID buffer to initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) * @buf: the underlying buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) static inline void ubi_init_vid_buf(const struct ubi_device *ubi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct ubi_vid_io_buf *vidb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) memset(buf, 0, ubi->vid_hdr_alsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) vidb->buffer = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) vidb->hdr = buf + ubi->vid_hdr_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) * ubi_init_vid_buf - Allocate a VID buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * @ubi: the UBI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) * @gfp_flags: GFP flags to use for the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) static inline struct ubi_vid_io_buf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) ubi_alloc_vid_buf(const struct ubi_device *ubi, gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct ubi_vid_io_buf *vidb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) vidb = kzalloc(sizeof(*vidb), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (!vidb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) buf = kmalloc(ubi->vid_hdr_alsize, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) kfree(vidb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) ubi_init_vid_buf(ubi, vidb, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) return vidb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * ubi_free_vid_buf - Free a VID buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * @vidb: the VID buffer to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) static inline void ubi_free_vid_buf(struct ubi_vid_io_buf *vidb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (!vidb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) kfree(vidb->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) kfree(vidb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) * ubi_get_vid_hdr - Get the VID header attached to a VID buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) * @vidb: VID buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static inline struct ubi_vid_hdr *ubi_get_vid_hdr(struct ubi_vid_io_buf *vidb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return vidb->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) * This function is equivalent to 'ubi_io_read()', but @offset is relative to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * the beginning of the logical eraseblock, not to the beginning of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) * physical eraseblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) static inline int ubi_io_read_data(const struct ubi_device *ubi, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) int pnum, int offset, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) ubi_assert(offset >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) return ubi_io_read(ubi, buf, pnum, offset + ubi->leb_start, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * This function is equivalent to 'ubi_io_write()', but @offset is relative to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * the beginning of the logical eraseblock, not to the beginning of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) * physical eraseblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) static inline int ubi_io_write_data(struct ubi_device *ubi, const void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) int pnum, int offset, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) ubi_assert(offset >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) return ubi_io_write(ubi, buf, pnum, offset + ubi->leb_start, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) * ubi_ro_mode - switch to read-only mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static inline void ubi_ro_mode(struct ubi_device *ubi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (!ubi->ro_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) ubi->ro_mode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) ubi_warn(ubi, "switch to read-only mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) * vol_id2idx - get table index by volume ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) * @vol_id: volume ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static inline int vol_id2idx(const struct ubi_device *ubi, int vol_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (vol_id >= UBI_INTERNAL_VOL_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) return vol_id - UBI_INTERNAL_VOL_START + ubi->vtbl_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) * idx2vol_id - get volume ID by table index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) * @idx: table index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static inline int idx2vol_id(const struct ubi_device *ubi, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (idx >= ubi->vtbl_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return idx - ubi->vtbl_slots + UBI_INTERNAL_VOL_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) * ubi_is_fm_vol - check whether a volume ID is a Fastmap volume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * @vol_id: volume ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static inline bool ubi_is_fm_vol(int vol_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) switch (vol_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) case UBI_FM_SB_VOLUME_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) case UBI_FM_DATA_VOLUME_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) * ubi_find_fm_block - check whether a PEB is part of the current Fastmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) * @ubi: UBI device description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) * @pnum: physical eraseblock to look for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) * This function returns a wear leveling object if @pnum relates to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) * fastmap, @NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) static inline struct ubi_wl_entry *ubi_find_fm_block(const struct ubi_device *ubi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) int pnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if (ubi->fm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) for (i = 0; i < ubi->fm->used_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) if (ubi->fm->e[i]->pnum == pnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) return ubi->fm->e[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) #endif /* !__UBI_UBI_H__ */