Lines Matching +full:- +full:av
1 // SPDX-License-Identifier: GPL-2.0-only
13 * init_seen - allocate memory for used for debugging.
23 ret = kcalloc(BITS_TO_LONGS(ubi->peb_count), sizeof(unsigned long), in init_seen()
26 return ERR_PTR(-ENOMEM); in init_seen()
32 * free_seen - free the seen logic integer array.
33 * @seen: integer array of @ubi->peb_count size
41 * set_seen - mark a PEB as seen.
44 * @seen: integer array of @ubi->peb_count size
55 * self_check_seen - check whether all PEB have been seen by fastmap.
57 * @seen: integer array of @ubi->peb_count size
66 for (pnum = 0; pnum < ubi->peb_count; pnum++) { in self_check_seen()
67 if (!test_bit(pnum, seen) && ubi->lookuptbl[pnum]) { in self_check_seen()
68 ubi_err(ubi, "self-check failed for PEB %d, fastmap didn't see it", pnum); in self_check_seen()
69 ret = -EINVAL; in self_check_seen()
77 * ubi_calc_fm_size - calculates the fastmap size in bytes for an UBI device.
88 (ubi->peb_count * sizeof(struct ubi_fm_ec)) + in ubi_calc_fm_size()
90 (ubi->peb_count * sizeof(__be32))) + in ubi_calc_fm_size()
92 return roundup(size, ubi->leb_size); in ubi_calc_fm_size()
97 * new_fm_vhdr - allocate a new volume header for fastmap usage.
114 vh->vol_type = UBI_VID_DYNAMIC; in new_fm_vbuf()
115 vh->vol_id = cpu_to_be32(vol_id); in new_fm_vbuf()
120 vh->compat = UBI_COMPAT_DELETE; in new_fm_vbuf()
127 * add_aeb - create and add a attach erase block to a given list.
143 return -ENOMEM; in add_aeb()
145 aeb->lnum = -1; in add_aeb()
146 aeb->scrub = scrub; in add_aeb()
147 aeb->copy_flag = aeb->sqnum = 0; in add_aeb()
149 ai->ec_sum += aeb->ec; in add_aeb()
150 ai->ec_count++; in add_aeb()
152 if (ai->max_ec < aeb->ec) in add_aeb()
153 ai->max_ec = aeb->ec; in add_aeb()
155 if (ai->min_ec > aeb->ec) in add_aeb()
156 ai->min_ec = aeb->ec; in add_aeb()
158 list_add_tail(&aeb->u.list, list); in add_aeb()
164 * add_vol - create and add a new volume to ubi_attach_info.
179 struct ubi_ainf_volume *av; in add_vol() local
181 av = ubi_add_av(ai, vol_id); in add_vol()
182 if (IS_ERR(av)) in add_vol()
183 return av; in add_vol()
185 av->data_pad = data_pad; in add_vol()
186 av->last_data_size = last_eb_bytes; in add_vol()
187 av->compat = 0; in add_vol()
188 av->vol_type = vol_type; in add_vol()
189 if (av->vol_type == UBI_STATIC_VOLUME) in add_vol()
190 av->used_ebs = used_ebs; in add_vol()
193 return av; in add_vol()
197 * assign_aeb_to_av - assigns a SEB to a given ainf_volume and removes it
201 * @av: target scan volume
205 struct ubi_ainf_volume *av) in assign_aeb_to_av() argument
208 struct rb_node **p = &av->root.rb_node, *parent = NULL; in assign_aeb_to_av()
214 if (aeb->lnum != tmp_aeb->lnum) { in assign_aeb_to_av()
215 if (aeb->lnum < tmp_aeb->lnum) in assign_aeb_to_av()
216 p = &(*p)->rb_left; in assign_aeb_to_av()
218 p = &(*p)->rb_right; in assign_aeb_to_av()
225 list_del(&aeb->u.list); in assign_aeb_to_av()
226 av->leb_count++; in assign_aeb_to_av()
228 rb_link_node(&aeb->u.rb, parent, p); in assign_aeb_to_av()
229 rb_insert_color(&aeb->u.rb, &av->root); in assign_aeb_to_av()
233 * update_vol - inserts or updates a LEB which was found a pool.
236 * @av: the volume this LEB belongs to
243 struct ubi_ainf_volume *av, struct ubi_vid_hdr *new_vh, in update_vol() argument
246 struct rb_node **p = &av->root.rb_node, *parent = NULL; in update_vol()
254 if (be32_to_cpu(new_vh->lnum) != aeb->lnum) { in update_vol()
255 if (be32_to_cpu(new_vh->lnum) < aeb->lnum) in update_vol()
256 p = &(*p)->rb_left; in update_vol()
258 p = &(*p)->rb_right; in update_vol()
267 if (aeb->pnum == new_aeb->pnum) { in update_vol()
268 ubi_assert(aeb->lnum == new_aeb->lnum); in update_vol()
274 cmp_res = ubi_compare_lebs(ubi, aeb, new_aeb->pnum, new_vh); in update_vol()
280 victim = ubi_alloc_aeb(ai, aeb->pnum, aeb->ec); in update_vol()
282 return -ENOMEM; in update_vol()
284 list_add_tail(&victim->u.list, &ai->erase); in update_vol()
286 if (av->highest_lnum == be32_to_cpu(new_vh->lnum)) in update_vol()
287 av->last_data_size = in update_vol()
288 be32_to_cpu(new_vh->data_size); in update_vol()
291 av->vol_id, aeb->lnum, new_aeb->pnum); in update_vol()
293 aeb->ec = new_aeb->ec; in update_vol()
294 aeb->pnum = new_aeb->pnum; in update_vol()
295 aeb->copy_flag = new_vh->copy_flag; in update_vol()
296 aeb->scrub = new_aeb->scrub; in update_vol()
297 aeb->sqnum = new_aeb->sqnum; in update_vol()
303 av->vol_id, aeb->lnum, new_aeb->pnum); in update_vol()
304 list_add_tail(&new_aeb->u.list, &ai->erase); in update_vol()
311 if (av->highest_lnum <= be32_to_cpu(new_vh->lnum)) { in update_vol()
312 av->highest_lnum = be32_to_cpu(new_vh->lnum); in update_vol()
313 av->last_data_size = be32_to_cpu(new_vh->data_size); in update_vol()
316 if (av->vol_type == UBI_STATIC_VOLUME) in update_vol()
317 av->used_ebs = be32_to_cpu(new_vh->used_ebs); in update_vol()
319 av->leb_count++; in update_vol()
321 rb_link_node(&new_aeb->u.rb, parent, p); in update_vol()
322 rb_insert_color(&new_aeb->u.rb, &av->root); in update_vol()
328 * process_pool_aeb - we found a non-empty PEB in a pool.
340 int vol_id = be32_to_cpu(new_vh->vol_id); in process_pool_aeb()
341 struct ubi_ainf_volume *av; in process_pool_aeb() local
350 av = ubi_find_av(ai, vol_id); in process_pool_aeb()
351 if (!av) { in process_pool_aeb()
357 ubi_assert(vol_id == av->vol_id); in process_pool_aeb()
359 return update_vol(ubi, ai, av, new_vh, new_aeb); in process_pool_aeb()
363 * unmap_peb - unmap a PEB.
372 struct ubi_ainf_volume *av; in unmap_peb() local
376 ubi_rb_for_each_entry(node, av, &ai->volumes, rb) { in unmap_peb()
377 ubi_rb_for_each_entry(node2, aeb, &av->root, u.rb) { in unmap_peb()
378 if (aeb->pnum == pnum) { in unmap_peb()
379 rb_erase(&aeb->u.rb, &av->root); in unmap_peb()
380 av->leb_count--; in unmap_peb()
389 * scan_pool - scans a pool for changed (no longer empty PEBs).
395 * @free: list of PEBs which are most likely free (and go into @ai->free)
410 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in scan_pool()
412 return -ENOMEM; in scan_pool()
417 return -ENOMEM; in scan_pool()
453 image_seq = be32_to_cpu(ech->image_seq); in scan_pool()
455 if (image_seq && (image_seq != ubi->image_seq)) { in scan_pool()
457 be32_to_cpu(ech->image_seq), ubi->image_seq); in scan_pool()
464 unsigned long long ec = be64_to_cpu(ech->ec); in scan_pool()
481 new_aeb = ubi_alloc_aeb(ai, pnum, be64_to_cpu(ech->ec)); in scan_pool()
483 ret = -ENOMEM; in scan_pool()
487 new_aeb->lnum = be32_to_cpu(vh->lnum); in scan_pool()
488 new_aeb->sqnum = be64_to_cpu(vh->sqnum); in scan_pool()
489 new_aeb->copy_flag = vh->copy_flag; in scan_pool()
490 new_aeb->scrub = scrub; in scan_pool()
492 if (*max_sqnum < new_aeb->sqnum) in scan_pool()
493 *max_sqnum = new_aeb->sqnum; in scan_pool()
516 * count_fastmap_pebs - Counts the PEBs found by fastmap.
522 struct ubi_ainf_volume *av; in count_fastmap_pebs() local
526 list_for_each_entry(aeb, &ai->erase, u.list) in count_fastmap_pebs()
529 list_for_each_entry(aeb, &ai->free, u.list) in count_fastmap_pebs()
532 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) in count_fastmap_pebs()
533 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) in count_fastmap_pebs()
540 * ubi_attach_fastmap - creates ubi_attach_info from a fastmap.
553 struct ubi_ainf_volume *av; in ubi_attach_fastmap() local
562 size_t fm_pos = 0, fm_size = ubi->fm_size; in ubi_attach_fastmap()
564 void *fm_raw = ubi->fm_buf; in ubi_attach_fastmap()
568 ai->min_ec = UBI_MAX_ERASECOUNTER; in ubi_attach_fastmap()
571 ai->max_sqnum = fmsb->sqnum; in ubi_attach_fastmap()
581 if (be32_to_cpu(fmhdr->magic) != UBI_FM_HDR_MAGIC) { in ubi_attach_fastmap()
583 be32_to_cpu(fmhdr->magic), UBI_FM_HDR_MAGIC); in ubi_attach_fastmap()
591 if (be32_to_cpu(fmpl->magic) != UBI_FM_POOL_MAGIC) { in ubi_attach_fastmap()
593 be32_to_cpu(fmpl->magic), UBI_FM_POOL_MAGIC); in ubi_attach_fastmap()
601 if (be32_to_cpu(fmpl_wl->magic) != UBI_FM_POOL_MAGIC) { in ubi_attach_fastmap()
603 be32_to_cpu(fmpl_wl->magic), UBI_FM_POOL_MAGIC); in ubi_attach_fastmap()
607 pool_size = be16_to_cpu(fmpl->size); in ubi_attach_fastmap()
608 wl_pool_size = be16_to_cpu(fmpl_wl->size); in ubi_attach_fastmap()
609 fm->max_pool_size = be16_to_cpu(fmpl->max_size); in ubi_attach_fastmap()
610 fm->max_wl_pool_size = be16_to_cpu(fmpl_wl->max_size); in ubi_attach_fastmap()
623 if (fm->max_pool_size > UBI_FM_MAX_POOL_SIZE || in ubi_attach_fastmap()
624 fm->max_pool_size < 0) { in ubi_attach_fastmap()
625 ubi_err(ubi, "bad maximal pool size: %i", fm->max_pool_size); in ubi_attach_fastmap()
629 if (fm->max_wl_pool_size > UBI_FM_MAX_POOL_SIZE || in ubi_attach_fastmap()
630 fm->max_wl_pool_size < 0) { in ubi_attach_fastmap()
632 fm->max_wl_pool_size); in ubi_attach_fastmap()
637 for (i = 0; i < be32_to_cpu(fmhdr->free_peb_count); i++) { in ubi_attach_fastmap()
643 ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), in ubi_attach_fastmap()
644 be32_to_cpu(fmec->ec), 0); in ubi_attach_fastmap()
650 for (i = 0; i < be32_to_cpu(fmhdr->used_peb_count); i++) { in ubi_attach_fastmap()
656 ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum), in ubi_attach_fastmap()
657 be32_to_cpu(fmec->ec), 0); in ubi_attach_fastmap()
663 for (i = 0; i < be32_to_cpu(fmhdr->scrub_peb_count); i++) { in ubi_attach_fastmap()
669 ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum), in ubi_attach_fastmap()
670 be32_to_cpu(fmec->ec), 1); in ubi_attach_fastmap()
676 for (i = 0; i < be32_to_cpu(fmhdr->erase_peb_count); i++) { in ubi_attach_fastmap()
682 ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), in ubi_attach_fastmap()
683 be32_to_cpu(fmec->ec), 1); in ubi_attach_fastmap()
688 ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); in ubi_attach_fastmap()
689 ai->bad_peb_count = be32_to_cpu(fmhdr->bad_peb_count); in ubi_attach_fastmap()
692 for (i = 0; i < be32_to_cpu(fmhdr->vol_count); i++) { in ubi_attach_fastmap()
698 if (be32_to_cpu(fmvhdr->magic) != UBI_FM_VHDR_MAGIC) { in ubi_attach_fastmap()
700 be32_to_cpu(fmvhdr->magic), UBI_FM_VHDR_MAGIC); in ubi_attach_fastmap()
704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id), in ubi_attach_fastmap()
705 be32_to_cpu(fmvhdr->used_ebs), in ubi_attach_fastmap()
706 be32_to_cpu(fmvhdr->data_pad), in ubi_attach_fastmap()
707 fmvhdr->vol_type, in ubi_attach_fastmap()
708 be32_to_cpu(fmvhdr->last_eb_bytes)); in ubi_attach_fastmap()
710 if (IS_ERR(av)) { in ubi_attach_fastmap()
711 if (PTR_ERR(av) == -EEXIST) in ubi_attach_fastmap()
713 fmvhdr->vol_id); in ubi_attach_fastmap()
718 ai->vols_found++; in ubi_attach_fastmap()
719 if (ai->highest_vol_id < be32_to_cpu(fmvhdr->vol_id)) in ubi_attach_fastmap()
720 ai->highest_vol_id = be32_to_cpu(fmvhdr->vol_id); in ubi_attach_fastmap()
724 fm_pos += (sizeof(__be32) * be32_to_cpu(fm_eba->reserved_pebs)); in ubi_attach_fastmap()
728 if (be32_to_cpu(fm_eba->magic) != UBI_FM_EBA_MAGIC) { in ubi_attach_fastmap()
730 be32_to_cpu(fm_eba->magic), UBI_FM_EBA_MAGIC); in ubi_attach_fastmap()
734 for (j = 0; j < be32_to_cpu(fm_eba->reserved_pebs); j++) { in ubi_attach_fastmap()
735 int pnum = be32_to_cpu(fm_eba->pnum[j]); in ubi_attach_fastmap()
742 if (tmp_aeb->pnum == pnum) { in ubi_attach_fastmap()
753 aeb->lnum = j; in ubi_attach_fastmap()
755 if (av->highest_lnum <= aeb->lnum) in ubi_attach_fastmap()
756 av->highest_lnum = aeb->lnum; in ubi_attach_fastmap()
758 assign_aeb_to_av(ai, aeb, av); in ubi_attach_fastmap()
761 aeb->pnum, aeb->lnum, av->vol_id); in ubi_attach_fastmap()
765 ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &free); in ubi_attach_fastmap()
769 ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &free); in ubi_attach_fastmap()
773 if (max_sqnum > ai->max_sqnum) in ubi_attach_fastmap()
774 ai->max_sqnum = max_sqnum; in ubi_attach_fastmap()
777 list_move_tail(&tmp_aeb->u.list, &ai->free); in ubi_attach_fastmap()
780 list_move_tail(&tmp_aeb->u.list, &ai->erase); in ubi_attach_fastmap()
790 if (WARN_ON(count_fastmap_pebs(ai) != ubi->peb_count - in ubi_attach_fastmap()
791 ai->bad_peb_count - fm->used_blocks)) in ubi_attach_fastmap()
800 list_del(&tmp_aeb->u.list); in ubi_attach_fastmap()
804 list_del(&tmp_aeb->u.list); in ubi_attach_fastmap()
812 * find_fm_anchor - find the most recent Fastmap superblock (anchor)
817 int ret = -1; in find_fm_anchor()
821 list_for_each_entry(aeb, &ai->fastmap, u.list) { in find_fm_anchor()
822 if (aeb->vol_id == UBI_FM_SB_VOLUME_ID && aeb->sqnum > max_sqnum) { in find_fm_anchor()
823 max_sqnum = aeb->sqnum; in find_fm_anchor()
824 ret = aeb->pnum; in find_fm_anchor()
836 new = ubi_alloc_aeb(ai, old->pnum, old->ec); in clone_aeb()
840 new->vol_id = old->vol_id; in clone_aeb()
841 new->sqnum = old->sqnum; in clone_aeb()
842 new->lnum = old->lnum; in clone_aeb()
843 new->scrub = old->scrub; in clone_aeb()
844 new->copy_flag = old->copy_flag; in clone_aeb()
850 * ubi_scan_fastmap - scan the fastmap.
879 list_for_each_entry(aeb, &scan_ai->fastmap, u.list) { in ubi_scan_fastmap()
884 return -ENOMEM; in ubi_scan_fastmap()
886 list_add(&new->u.list, &ai->fastmap); in ubi_scan_fastmap()
889 down_write(&ubi->fm_protect); in ubi_scan_fastmap()
890 memset(ubi->fm_buf, 0, ubi->fm_size); in ubi_scan_fastmap()
894 ret = -ENOMEM; in ubi_scan_fastmap()
900 ret = -ENOMEM; in ubi_scan_fastmap()
909 fm->to_be_tortured[0] = 1; in ubi_scan_fastmap()
911 if (be32_to_cpu(fmsb->magic) != UBI_FM_SB_MAGIC) { in ubi_scan_fastmap()
913 be32_to_cpu(fmsb->magic), UBI_FM_SB_MAGIC); in ubi_scan_fastmap()
918 if (fmsb->version != UBI_FM_FMT_VERSION) { in ubi_scan_fastmap()
920 fmsb->version, UBI_FM_FMT_VERSION); in ubi_scan_fastmap()
925 used_blocks = be32_to_cpu(fmsb->used_blocks); in ubi_scan_fastmap()
933 fm_size = ubi->leb_size * used_blocks; in ubi_scan_fastmap()
934 if (fm_size != ubi->fm_size) { in ubi_scan_fastmap()
936 fm_size, ubi->fm_size); in ubi_scan_fastmap()
941 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in ubi_scan_fastmap()
943 ret = -ENOMEM; in ubi_scan_fastmap()
949 ret = -ENOMEM; in ubi_scan_fastmap()
958 pnum = be32_to_cpu(fmsb->block_loc[i]); in ubi_scan_fastmap()
980 fm->to_be_tortured[i] = 1; in ubi_scan_fastmap()
982 image_seq = be32_to_cpu(ech->image_seq); in ubi_scan_fastmap()
983 if (!ubi->image_seq) in ubi_scan_fastmap()
984 ubi->image_seq = image_seq; in ubi_scan_fastmap()
990 if (image_seq && (image_seq != ubi->image_seq)) { in ubi_scan_fastmap()
992 be32_to_cpu(ech->image_seq), ubi->image_seq); in ubi_scan_fastmap()
1005 if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) { in ubi_scan_fastmap()
1007 be32_to_cpu(vh->vol_id), in ubi_scan_fastmap()
1013 if (be32_to_cpu(vh->vol_id) != UBI_FM_DATA_VOLUME_ID) { in ubi_scan_fastmap()
1015 be32_to_cpu(vh->vol_id), in ubi_scan_fastmap()
1022 if (sqnum < be64_to_cpu(vh->sqnum)) in ubi_scan_fastmap()
1023 sqnum = be64_to_cpu(vh->sqnum); in ubi_scan_fastmap()
1025 ret = ubi_io_read_data(ubi, ubi->fm_buf + (ubi->leb_size * i), in ubi_scan_fastmap()
1026 pnum, 0, ubi->leb_size); in ubi_scan_fastmap()
1037 fmsb2 = (struct ubi_fm_sb *)(ubi->fm_buf); in ubi_scan_fastmap()
1038 tmp_crc = be32_to_cpu(fmsb2->data_crc); in ubi_scan_fastmap()
1039 fmsb2->data_crc = 0; in ubi_scan_fastmap()
1040 crc = crc32(UBI_CRC32_INIT, ubi->fm_buf, fm_size); in ubi_scan_fastmap()
1049 fmsb2->sqnum = sqnum; in ubi_scan_fastmap()
1051 fm->used_blocks = used_blocks; in ubi_scan_fastmap()
1065 while (i--) in ubi_scan_fastmap()
1066 kmem_cache_free(ubi_wl_entry_slab, fm->e[i]); in ubi_scan_fastmap()
1068 ret = -ENOMEM; in ubi_scan_fastmap()
1072 e->pnum = be32_to_cpu(fmsb2->block_loc[i]); in ubi_scan_fastmap()
1073 e->ec = be32_to_cpu(fmsb2->block_ec[i]); in ubi_scan_fastmap()
1074 fm->e[i] = e; in ubi_scan_fastmap()
1077 ubi->fm = fm; in ubi_scan_fastmap()
1078 ubi->fm_pool.max_size = ubi->fm->max_pool_size; in ubi_scan_fastmap()
1079 ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size; in ubi_scan_fastmap()
1081 ubi_msg(ubi, "fastmap pool size: %d", ubi->fm_pool.max_size); in ubi_scan_fastmap()
1083 ubi->fm_wl_pool.max_size); in ubi_scan_fastmap()
1084 ubi->fm_disabled = 0; in ubi_scan_fastmap()
1085 ubi->fast_attach = 1; in ubi_scan_fastmap()
1090 up_write(&ubi->fm_protect); in ubi_scan_fastmap()
1106 struct ubi_device *ubi = vol->ubi; in ubi_fastmap_init_checkmap()
1108 if (!ubi->fast_attach) in ubi_fastmap_init_checkmap()
1111 vol->checkmap = kcalloc(BITS_TO_LONGS(leb_count), sizeof(unsigned long), in ubi_fastmap_init_checkmap()
1113 if (!vol->checkmap) in ubi_fastmap_init_checkmap()
1114 return -ENOMEM; in ubi_fastmap_init_checkmap()
1121 kfree(vol->checkmap); in ubi_fastmap_destroy_checkmap()
1125 * ubi_write_fastmap - writes a fastmap.
1152 fm_raw = ubi->fm_buf; in ubi_write_fastmap()
1153 memset(ubi->fm_buf, 0, ubi->fm_size); in ubi_write_fastmap()
1157 ret = -ENOMEM; in ubi_write_fastmap()
1163 ret = -ENOMEM; in ubi_write_fastmap()
1176 spin_lock(&ubi->volumes_lock); in ubi_write_fastmap()
1177 spin_lock(&ubi->wl_lock); in ubi_write_fastmap()
1181 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1185 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1187 fmsb->magic = cpu_to_be32(UBI_FM_SB_MAGIC); in ubi_write_fastmap()
1188 fmsb->version = UBI_FM_FMT_VERSION; in ubi_write_fastmap()
1189 fmsb->used_blocks = cpu_to_be32(new_fm->used_blocks); in ubi_write_fastmap()
1191 fmsb->sqnum = 0; in ubi_write_fastmap()
1193 fmh->magic = cpu_to_be32(UBI_FM_HDR_MAGIC); in ubi_write_fastmap()
1202 fmpl->magic = cpu_to_be32(UBI_FM_POOL_MAGIC); in ubi_write_fastmap()
1203 fmpl->size = cpu_to_be16(ubi->fm_pool.size); in ubi_write_fastmap()
1204 fmpl->max_size = cpu_to_be16(ubi->fm_pool.max_size); in ubi_write_fastmap()
1206 for (i = 0; i < ubi->fm_pool.size; i++) { in ubi_write_fastmap()
1207 fmpl->pebs[i] = cpu_to_be32(ubi->fm_pool.pebs[i]); in ubi_write_fastmap()
1208 set_seen(ubi, ubi->fm_pool.pebs[i], seen_pebs); in ubi_write_fastmap()
1213 fmpl_wl->magic = cpu_to_be32(UBI_FM_POOL_MAGIC); in ubi_write_fastmap()
1214 fmpl_wl->size = cpu_to_be16(ubi->fm_wl_pool.size); in ubi_write_fastmap()
1215 fmpl_wl->max_size = cpu_to_be16(ubi->fm_wl_pool.max_size); in ubi_write_fastmap()
1217 for (i = 0; i < ubi->fm_wl_pool.size; i++) { in ubi_write_fastmap()
1218 fmpl_wl->pebs[i] = cpu_to_be32(ubi->fm_wl_pool.pebs[i]); in ubi_write_fastmap()
1219 set_seen(ubi, ubi->fm_wl_pool.pebs[i], seen_pebs); in ubi_write_fastmap()
1225 fec->pnum = cpu_to_be32(wl_e->pnum); in ubi_write_fastmap()
1226 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1227 fec->ec = cpu_to_be32(wl_e->ec); in ubi_write_fastmap()
1231 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1233 fmh->free_peb_count = cpu_to_be32(free_peb_count); in ubi_write_fastmap()
1238 fec->pnum = cpu_to_be32(wl_e->pnum); in ubi_write_fastmap()
1239 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1240 fec->ec = cpu_to_be32(wl_e->ec); in ubi_write_fastmap()
1244 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1250 fec->pnum = cpu_to_be32(wl_e->pnum); in ubi_write_fastmap()
1251 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1252 fec->ec = cpu_to_be32(wl_e->ec); in ubi_write_fastmap()
1256 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1258 fmh->used_peb_count = cpu_to_be32(used_peb_count); in ubi_write_fastmap()
1263 fec->pnum = cpu_to_be32(wl_e->pnum); in ubi_write_fastmap()
1264 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1265 fec->ec = cpu_to_be32(wl_e->ec); in ubi_write_fastmap()
1269 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1271 fmh->scrub_peb_count = cpu_to_be32(scrub_peb_count); in ubi_write_fastmap()
1274 list_for_each_entry(ubi_wrk, &ubi->works, list) { in ubi_write_fastmap()
1276 wl_e = ubi_wrk->e; in ubi_write_fastmap()
1281 fec->pnum = cpu_to_be32(wl_e->pnum); in ubi_write_fastmap()
1282 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1283 fec->ec = cpu_to_be32(wl_e->ec); in ubi_write_fastmap()
1287 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1290 fmh->erase_peb_count = cpu_to_be32(erase_peb_count); in ubi_write_fastmap()
1293 vol = ubi->volumes[i]; in ubi_write_fastmap()
1302 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1304 fvh->magic = cpu_to_be32(UBI_FM_VHDR_MAGIC); in ubi_write_fastmap()
1305 fvh->vol_id = cpu_to_be32(vol->vol_id); in ubi_write_fastmap()
1306 fvh->vol_type = vol->vol_type; in ubi_write_fastmap()
1307 fvh->used_ebs = cpu_to_be32(vol->used_ebs); in ubi_write_fastmap()
1308 fvh->data_pad = cpu_to_be32(vol->data_pad); in ubi_write_fastmap()
1309 fvh->last_eb_bytes = cpu_to_be32(vol->last_eb_bytes); in ubi_write_fastmap()
1311 ubi_assert(vol->vol_type == UBI_DYNAMIC_VOLUME || in ubi_write_fastmap()
1312 vol->vol_type == UBI_STATIC_VOLUME); in ubi_write_fastmap()
1315 fm_pos += sizeof(*feba) + (sizeof(__be32) * vol->reserved_pebs); in ubi_write_fastmap()
1316 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1318 for (j = 0; j < vol->reserved_pebs; j++) { in ubi_write_fastmap()
1322 feba->pnum[j] = cpu_to_be32(ldesc.pnum); in ubi_write_fastmap()
1325 feba->reserved_pebs = cpu_to_be32(j); in ubi_write_fastmap()
1326 feba->magic = cpu_to_be32(UBI_FM_EBA_MAGIC); in ubi_write_fastmap()
1328 fmh->vol_count = cpu_to_be32(vol_count); in ubi_write_fastmap()
1329 fmh->bad_peb_count = cpu_to_be32(ubi->bad_peb_count); in ubi_write_fastmap()
1331 avhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_write_fastmap()
1332 avhdr->lnum = 0; in ubi_write_fastmap()
1334 spin_unlock(&ubi->wl_lock); in ubi_write_fastmap()
1335 spin_unlock(&ubi->volumes_lock); in ubi_write_fastmap()
1337 dbg_bld("writing fastmap SB to PEB %i", new_fm->e[0]->pnum); in ubi_write_fastmap()
1338 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avbuf); in ubi_write_fastmap()
1344 for (i = 0; i < new_fm->used_blocks; i++) { in ubi_write_fastmap()
1345 fmsb->block_loc[i] = cpu_to_be32(new_fm->e[i]->pnum); in ubi_write_fastmap()
1346 set_seen(ubi, new_fm->e[i]->pnum, seen_pebs); in ubi_write_fastmap()
1347 fmsb->block_ec[i] = cpu_to_be32(new_fm->e[i]->ec); in ubi_write_fastmap()
1350 fmsb->data_crc = 0; in ubi_write_fastmap()
1351 fmsb->data_crc = cpu_to_be32(crc32(UBI_CRC32_INIT, fm_raw, in ubi_write_fastmap()
1352 ubi->fm_size)); in ubi_write_fastmap()
1354 for (i = 1; i < new_fm->used_blocks; i++) { in ubi_write_fastmap()
1355 dvhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_write_fastmap()
1356 dvhdr->lnum = cpu_to_be32(i); in ubi_write_fastmap()
1358 new_fm->e[i]->pnum, be64_to_cpu(dvhdr->sqnum)); in ubi_write_fastmap()
1359 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvbuf); in ubi_write_fastmap()
1362 new_fm->e[i]->pnum); in ubi_write_fastmap()
1367 for (i = 0; i < new_fm->used_blocks; i++) { in ubi_write_fastmap()
1368 ret = ubi_io_write_data(ubi, fm_raw + (i * ubi->leb_size), in ubi_write_fastmap()
1369 new_fm->e[i]->pnum, 0, ubi->leb_size); in ubi_write_fastmap()
1372 new_fm->e[i]->pnum); in ubi_write_fastmap()
1378 ubi->fm = new_fm; in ubi_write_fastmap()
1395 * erase_block - Manually erase a PEB.
1407 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in erase_block()
1409 return -ENOMEM; in erase_block()
1415 ret = -EINVAL; in erase_block()
1423 ec = be64_to_cpu(ec_hdr->ec); in erase_block()
1426 ret = -EINVAL; in erase_block()
1430 ec_hdr->ec = cpu_to_be64(ec); in erase_block()
1442 * invalidate_fastmap - destroys a fastmap.
1461 if (!ubi->fm) in invalidate_fastmap()
1464 ubi->fm = NULL; in invalidate_fastmap()
1466 ret = -ENOMEM; in invalidate_fastmap()
1477 ret = -ENOSPC; in invalidate_fastmap()
1486 vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in invalidate_fastmap()
1487 ret = ubi_io_write_vid_hdr(ubi, e->pnum, vb); in invalidate_fastmap()
1493 fm->used_blocks = 1; in invalidate_fastmap()
1494 fm->e[0] = e; in invalidate_fastmap()
1496 ubi->fm = fm; in invalidate_fastmap()
1508 * return_fm_pebs - returns all PEBs used by a fastmap back to the
1509 * WL sub-system.
1521 for (i = 0; i < fm->used_blocks; i++) { in return_fm_pebs()
1522 if (fm->e[i]) { in return_fm_pebs()
1523 ubi_wl_put_fm_peb(ubi, fm->e[i], i, in return_fm_pebs()
1524 fm->to_be_tortured[i]); in return_fm_pebs()
1525 fm->e[i] = NULL; in return_fm_pebs()
1531 * ubi_update_fastmap - will be called by UBI if a volume changes or
1543 down_write(&ubi->fm_protect); in ubi_update_fastmap()
1544 down_write(&ubi->work_sem); in ubi_update_fastmap()
1545 down_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1549 if (ubi->ro_mode || ubi->fm_disabled) { in ubi_update_fastmap()
1550 up_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1551 up_write(&ubi->work_sem); in ubi_update_fastmap()
1552 up_write(&ubi->fm_protect); in ubi_update_fastmap()
1558 up_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1559 up_write(&ubi->work_sem); in ubi_update_fastmap()
1560 up_write(&ubi->fm_protect); in ubi_update_fastmap()
1561 return -ENOMEM; in ubi_update_fastmap()
1564 new_fm->used_blocks = ubi->fm_size / ubi->leb_size; in ubi_update_fastmap()
1565 old_fm = ubi->fm; in ubi_update_fastmap()
1566 ubi->fm = NULL; in ubi_update_fastmap()
1568 if (new_fm->used_blocks > UBI_FM_MAX_BLOCKS) { in ubi_update_fastmap()
1570 ret = -ENOSPC; in ubi_update_fastmap()
1574 for (i = 1; i < new_fm->used_blocks; i++) { in ubi_update_fastmap()
1575 spin_lock(&ubi->wl_lock); in ubi_update_fastmap()
1577 spin_unlock(&ubi->wl_lock); in ubi_update_fastmap()
1580 if (old_fm && old_fm->e[i]) { in ubi_update_fastmap()
1581 ret = erase_block(ubi, old_fm->e[i]->pnum); in ubi_update_fastmap()
1586 ubi_wl_put_fm_peb(ubi, new_fm->e[j], in ubi_update_fastmap()
1588 new_fm->e[j] = NULL; in ubi_update_fastmap()
1592 new_fm->e[i] = old_fm->e[i]; in ubi_update_fastmap()
1593 old_fm->e[i] = NULL; in ubi_update_fastmap()
1598 ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0); in ubi_update_fastmap()
1599 new_fm->e[j] = NULL; in ubi_update_fastmap()
1602 ret = -ENOSPC; in ubi_update_fastmap()
1606 new_fm->e[i] = tmp_e; in ubi_update_fastmap()
1608 if (old_fm && old_fm->e[i]) { in ubi_update_fastmap()
1609 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, in ubi_update_fastmap()
1610 old_fm->to_be_tortured[i]); in ubi_update_fastmap()
1611 old_fm->e[i] = NULL; in ubi_update_fastmap()
1617 if (old_fm && new_fm->used_blocks < old_fm->used_blocks) { in ubi_update_fastmap()
1618 for (i = new_fm->used_blocks; i < old_fm->used_blocks; i++) { in ubi_update_fastmap()
1619 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, in ubi_update_fastmap()
1620 old_fm->to_be_tortured[i]); in ubi_update_fastmap()
1621 old_fm->e[i] = NULL; in ubi_update_fastmap()
1625 spin_lock(&ubi->wl_lock); in ubi_update_fastmap()
1626 tmp_e = ubi->fm_anchor; in ubi_update_fastmap()
1627 ubi->fm_anchor = NULL; in ubi_update_fastmap()
1628 spin_unlock(&ubi->wl_lock); in ubi_update_fastmap()
1633 ret = erase_block(ubi, old_fm->e[0]->pnum); in ubi_update_fastmap()
1637 for (i = 1; i < new_fm->used_blocks; i++) { in ubi_update_fastmap()
1638 ubi_wl_put_fm_peb(ubi, new_fm->e[i], in ubi_update_fastmap()
1640 new_fm->e[i] = NULL; in ubi_update_fastmap()
1644 new_fm->e[0] = old_fm->e[0]; in ubi_update_fastmap()
1645 new_fm->e[0]->ec = ret; in ubi_update_fastmap()
1646 old_fm->e[0] = NULL; in ubi_update_fastmap()
1649 ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0, in ubi_update_fastmap()
1650 old_fm->to_be_tortured[0]); in ubi_update_fastmap()
1651 new_fm->e[0] = tmp_e; in ubi_update_fastmap()
1652 old_fm->e[0] = NULL; in ubi_update_fastmap()
1658 for (i = 1; i < new_fm->used_blocks; i++) { in ubi_update_fastmap()
1659 ubi_wl_put_fm_peb(ubi, new_fm->e[i], i, 0); in ubi_update_fastmap()
1660 new_fm->e[i] = NULL; in ubi_update_fastmap()
1663 ret = -ENOSPC; in ubi_update_fastmap()
1666 new_fm->e[0] = tmp_e; in ubi_update_fastmap()
1675 up_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1676 up_write(&ubi->work_sem); in ubi_update_fastmap()
1677 up_write(&ubi->fm_protect); in ubi_update_fastmap()