| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (c) International Business Machines Corp., 2006 | 
|  | 3 | * | 
|  | 4 | * This program is free software; you can redistribute it and/or modify | 
|  | 5 | * it under the terms of the GNU General Public License as published by | 
|  | 6 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 7 | * (at your option) any later version. | 
|  | 8 | * | 
|  | 9 | * This program is distributed in the hope that it will be useful, | 
|  | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | 
|  | 12 | * the GNU General Public License for more details. | 
|  | 13 | * | 
|  | 14 | * You should have received a copy of the GNU General Public License | 
|  | 15 | * along with this program; if not, write to the Free Software | 
|  | 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
|  | 17 | * | 
|  | 18 | * Author: Artem Bityutskiy (Битюцкий Артём) | 
|  | 19 | */ | 
|  | 20 |  | 
|  | 21 | #ifndef __UBI_SCAN_H__ | 
|  | 22 | #define __UBI_SCAN_H__ | 
|  | 23 |  | 
|  | 24 | /* The erase counter value for this physical eraseblock is unknown */ | 
|  | 25 | #define UBI_SCAN_UNKNOWN_EC (-1) | 
|  | 26 |  | 
|  | 27 | /** | 
|  | 28 | * struct ubi_scan_leb - scanning information about a physical eraseblock. | 
|  | 29 | * @ec: erase counter (%UBI_SCAN_UNKNOWN_EC if it is unknown) | 
|  | 30 | * @pnum: physical eraseblock number | 
|  | 31 | * @lnum: logical eraseblock number | 
|  | 32 | * @scrub: if this physical eraseblock needs scrubbing | 
|  | 33 | * @sqnum: sequence number | 
|  | 34 | * @u: unions RB-tree or @list links | 
|  | 35 | * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects | 
|  | 36 | * @u.list: link in one of the eraseblock lists | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 37 | * | 
|  | 38 | * One object of this type is allocated for each physical eraseblock during | 
|  | 39 | * scanning. | 
|  | 40 | */ | 
|  | 41 | struct ubi_scan_leb { | 
|  | 42 | int ec; | 
|  | 43 | int pnum; | 
|  | 44 | int lnum; | 
|  | 45 | int scrub; | 
|  | 46 | unsigned long long sqnum; | 
|  | 47 | union { | 
|  | 48 | struct rb_node rb; | 
|  | 49 | struct list_head list; | 
|  | 50 | } u; | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 51 | }; | 
|  | 52 |  | 
|  | 53 | /** | 
|  | 54 | * struct ubi_scan_volume - scanning information about a volume. | 
|  | 55 | * @vol_id: volume ID | 
|  | 56 | * @highest_lnum: highest logical eraseblock number in this volume | 
|  | 57 | * @leb_count: number of logical eraseblocks in this volume | 
|  | 58 | * @vol_type: volume type | 
|  | 59 | * @used_ebs: number of used logical eraseblocks in this volume (only for | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 60 | *            static volumes) | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 61 | * @last_data_size: amount of data in the last logical eraseblock of this | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 62 | *                  volume (always equivalent to the usable logical eraseblock | 
|  | 63 | *                  size in case of dynamic volumes) | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 64 | * @data_pad: how many bytes at the end of logical eraseblocks of this volume | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 65 | *            are not used (due to volume alignment) | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 66 | * @compat: compatibility flags of this volume | 
|  | 67 | * @rb: link in the volume RB-tree | 
|  | 68 | * @root: root of the RB-tree containing all the eraseblock belonging to this | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 69 | *        volume (&struct ubi_scan_leb objects) | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 70 | * | 
|  | 71 | * One object of this type is allocated for each volume during scanning. | 
|  | 72 | */ | 
|  | 73 | struct ubi_scan_volume { | 
|  | 74 | int vol_id; | 
|  | 75 | int highest_lnum; | 
|  | 76 | int leb_count; | 
|  | 77 | int vol_type; | 
|  | 78 | int used_ebs; | 
|  | 79 | int last_data_size; | 
|  | 80 | int data_pad; | 
|  | 81 | int compat; | 
|  | 82 | struct rb_node rb; | 
|  | 83 | struct rb_root root; | 
|  | 84 | }; | 
|  | 85 |  | 
|  | 86 | /** | 
|  | 87 | * struct ubi_scan_info - UBI scanning information. | 
|  | 88 | * @volumes: root of the volume RB-tree | 
|  | 89 | * @corr: list of corrupted physical eraseblocks | 
|  | 90 | * @free: list of free physical eraseblocks | 
|  | 91 | * @erase: list of physical eraseblocks which have to be erased | 
|  | 92 | * @alien: list of physical eraseblocks which should not be used by UBI (e.g., | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 93 | *         those belonging to "preserve"-compatible internal volumes) | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 94 | * @bad_peb_count: count of bad physical eraseblocks | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 95 | * @vols_found: number of volumes found during scanning | 
|  | 96 | * @highest_vol_id: highest volume ID | 
|  | 97 | * @alien_peb_count: count of physical eraseblocks in the @alien list | 
|  | 98 | * @is_empty: flag indicating whether the MTD device is empty or not | 
|  | 99 | * @min_ec: lowest erase counter value | 
|  | 100 | * @max_ec: highest erase counter value | 
|  | 101 | * @max_sqnum: highest sequence number value | 
|  | 102 | * @mean_ec: mean erase counter value | 
|  | 103 | * @ec_sum: a temporary variable used when calculating @mean_ec | 
|  | 104 | * @ec_count: a temporary variable used when calculating @mean_ec | 
| Artem Bityutskiy | 4a40685 | 2009-07-19 14:33:14 +0300 | [diff] [blame] | 105 | * @corr_count: count of corrupted PEBs | 
| Artem Bityutskiy | fe96efc | 2009-06-30 16:11:59 +0300 | [diff] [blame] | 106 | * @image_seq_set: indicates @ubi->image_seq is known | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 107 | * | 
|  | 108 | * This data structure contains the result of scanning and may be used by other | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 109 | * UBI sub-systems to build final UBI data structures, further error-recovery | 
|  | 110 | * and so on. | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 111 | */ | 
|  | 112 | struct ubi_scan_info { | 
|  | 113 | struct rb_root volumes; | 
|  | 114 | struct list_head corr; | 
|  | 115 | struct list_head free; | 
|  | 116 | struct list_head erase; | 
|  | 117 | struct list_head alien; | 
|  | 118 | int bad_peb_count; | 
|  | 119 | int vols_found; | 
|  | 120 | int highest_vol_id; | 
|  | 121 | int alien_peb_count; | 
|  | 122 | int is_empty; | 
|  | 123 | int min_ec; | 
|  | 124 | int max_ec; | 
|  | 125 | unsigned long long max_sqnum; | 
|  | 126 | int mean_ec; | 
| Artem Bityutskiy | 4bc1dca | 2008-04-19 20:44:31 +0300 | [diff] [blame] | 127 | uint64_t ec_sum; | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 128 | int ec_count; | 
| Artem Bityutskiy | 4a40685 | 2009-07-19 14:33:14 +0300 | [diff] [blame] | 129 | int corr_count; | 
| Artem Bityutskiy | fe96efc | 2009-06-30 16:11:59 +0300 | [diff] [blame] | 130 | int image_seq_set; | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 131 | }; | 
|  | 132 |  | 
|  | 133 | struct ubi_device; | 
|  | 134 | struct ubi_vid_hdr; | 
|  | 135 |  | 
|  | 136 | /* | 
| Artem Bityutskiy | 85c6e6e | 2008-07-16 10:25:56 +0300 | [diff] [blame] | 137 | * ubi_scan_move_to_list - move a PEB from the volume tree to a list. | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 138 | * | 
|  | 139 | * @sv: volume scanning information | 
|  | 140 | * @seb: scanning eraseblock infprmation | 
|  | 141 | * @list: the list to move to | 
|  | 142 | */ | 
|  | 143 | static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv, | 
|  | 144 | struct ubi_scan_leb *seb, | 
|  | 145 | struct list_head *list) | 
|  | 146 | { | 
|  | 147 | rb_erase(&seb->u.rb, &sv->root); | 
|  | 148 | list_add_tail(&seb->u.list, list); | 
|  | 149 | } | 
|  | 150 |  | 
| Artem Bityutskiy | e88d6e10 | 2007-08-29 14:51:52 +0300 | [diff] [blame] | 151 | int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 152 | int pnum, int ec, const struct ubi_vid_hdr *vid_hdr, | 
|  | 153 | int bitflips); | 
|  | 154 | struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si, | 
|  | 155 | int vol_id); | 
|  | 156 | struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv, | 
|  | 157 | int lnum); | 
|  | 158 | void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv); | 
| Artem Bityutskiy | e88d6e10 | 2007-08-29 14:51:52 +0300 | [diff] [blame] | 159 | struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 160 | struct ubi_scan_info *si); | 
| Artem Bityutskiy | e88d6e10 | 2007-08-29 14:51:52 +0300 | [diff] [blame] | 161 | int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, | 
|  | 162 | int pnum, int ec); | 
| Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 163 | struct ubi_scan_info *ubi_scan(struct ubi_device *ubi); | 
|  | 164 | void ubi_scan_destroy_si(struct ubi_scan_info *si); | 
|  | 165 |  | 
|  | 166 | #endif /* !__UBI_SCAN_H__ */ |