• Home
  • Raw
  • Download

Lines Matching refs:ubi

71 unsigned long long ubi_next_sqnum(struct ubi_device *ubi)  in ubi_next_sqnum()  argument
75 spin_lock(&ubi->ltree_lock); in ubi_next_sqnum()
76 sqnum = ubi->global_sqnum++; in ubi_next_sqnum()
77 spin_unlock(&ubi->ltree_lock); in ubi_next_sqnum()
90 static int ubi_get_compat(const struct ubi_device *ubi, int vol_id) in ubi_get_compat() argument
211 static struct ubi_ltree_entry *ltree_lookup(struct ubi_device *ubi, int vol_id, in ltree_lookup() argument
216 p = ubi->ltree.rb_node; in ltree_lookup()
250 static struct ubi_ltree_entry *ltree_add_entry(struct ubi_device *ubi, in ltree_add_entry() argument
264 spin_lock(&ubi->ltree_lock); in ltree_add_entry()
265 le1 = ltree_lookup(ubi, vol_id, lnum); in ltree_add_entry()
283 p = &ubi->ltree.rb_node; in ltree_add_entry()
302 rb_insert_color(&le->rb, &ubi->ltree); in ltree_add_entry()
305 spin_unlock(&ubi->ltree_lock); in ltree_add_entry()
320 static int leb_read_lock(struct ubi_device *ubi, int vol_id, int lnum) in leb_read_lock() argument
324 le = ltree_add_entry(ubi, vol_id, lnum); in leb_read_lock()
337 static void leb_read_unlock(struct ubi_device *ubi, int vol_id, int lnum) in leb_read_unlock() argument
341 spin_lock(&ubi->ltree_lock); in leb_read_unlock()
342 le = ltree_lookup(ubi, vol_id, lnum); in leb_read_unlock()
347 rb_erase(&le->rb, &ubi->ltree); in leb_read_unlock()
350 spin_unlock(&ubi->ltree_lock); in leb_read_unlock()
362 static int leb_write_lock(struct ubi_device *ubi, int vol_id, int lnum) in leb_write_lock() argument
366 le = ltree_add_entry(ubi, vol_id, lnum); in leb_write_lock()
384 static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum) in leb_write_trylock() argument
388 le = ltree_add_entry(ubi, vol_id, lnum); in leb_write_trylock()
395 spin_lock(&ubi->ltree_lock); in leb_write_trylock()
399 rb_erase(&le->rb, &ubi->ltree); in leb_write_trylock()
402 spin_unlock(&ubi->ltree_lock); in leb_write_trylock()
413 static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum) in leb_write_unlock() argument
417 spin_lock(&ubi->ltree_lock); in leb_write_unlock()
418 le = ltree_lookup(ubi, vol_id, lnum); in leb_write_unlock()
423 rb_erase(&le->rb, &ubi->ltree); in leb_write_unlock()
426 spin_unlock(&ubi->ltree_lock); in leb_write_unlock()
451 int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, in ubi_eba_unmap_leb() argument
456 if (ubi->ro_mode) in ubi_eba_unmap_leb()
459 err = leb_write_lock(ubi, vol_id, lnum); in ubi_eba_unmap_leb()
470 down_read(&ubi->fm_eba_sem); in ubi_eba_unmap_leb()
472 up_read(&ubi->fm_eba_sem); in ubi_eba_unmap_leb()
473 err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 0); in ubi_eba_unmap_leb()
476 leb_write_unlock(ubi, vol_id, lnum); in ubi_eba_unmap_leb()
498 static int check_mapping(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, in check_mapping() argument
505 if (!ubi->fast_attach) in check_mapping()
511 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS); in check_mapping()
515 err = ubi_io_read_vid_hdr(ubi, *pnum, vidb, 0); in check_mapping()
532 down_read(&ubi->fm_eba_sem); in check_mapping()
534 up_read(&ubi->fm_eba_sem); in check_mapping()
535 ubi_wl_put_peb(ubi, vol->vol_id, lnum, *pnum, torture); in check_mapping()
539 ubi_err(ubi, "unable to read VID header back from PEB %i: %i", in check_mapping()
553 ubi_err(ubi, "EBA mismatch! PEB %i is LEB %i:%i instead of LEB %i:%i", in check_mapping()
555 ubi_ro_mode(ubi); in check_mapping()
570 static int check_mapping(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, in check_mapping() argument
596 int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, in ubi_eba_read_leb() argument
604 err = leb_read_lock(ubi, vol_id, lnum); in ubi_eba_read_leb()
610 err = check_mapping(ubi, vol, lnum, &pnum); in ubi_eba_read_leb()
623 leb_read_unlock(ubi, vol_id, lnum); in ubi_eba_read_leb()
637 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS); in ubi_eba_read_leb()
645 err = ubi_io_read_vid_hdr(ubi, pnum, vidb, 1); in ubi_eba_read_leb()
658 ubi_warn(ubi, "corrupted VID header at PEB %d, LEB %d:%d", in ubi_eba_read_leb()
675 if (ubi->fast_attach) { in ubi_eba_read_leb()
679 ubi_ro_mode(ubi); in ubi_eba_read_leb()
694 err = ubi_io_read_data(ubi, buf, pnum, offset, len); in ubi_eba_read_leb()
703 ubi_msg(ubi, "force data checking"); in ubi_eba_read_leb()
714 ubi_warn(ubi, "CRC error: calculated %#08x, must be %#08x", in ubi_eba_read_leb()
722 err = ubi_wl_scrub_peb(ubi, pnum); in ubi_eba_read_leb()
724 leb_read_unlock(ubi, vol_id, lnum); in ubi_eba_read_leb()
730 leb_read_unlock(ubi, vol_id, lnum); in ubi_eba_read_leb()
748 int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol, in ubi_eba_read_leb_sg() argument
764 ret = ubi_eba_read_leb(ubi, vol, lnum, in ubi_eba_read_leb_sg()
811 struct ubi_device *ubi = vol->ubi; in try_recover_peb() local
818 new_pnum = ubi_wl_get_peb(ubi); in try_recover_peb()
824 ubi_msg(ubi, "recover PEB %d, move data to PEB %d", in try_recover_peb()
827 err = ubi_io_read_vid_hdr(ubi, pnum, vidb, 1); in try_recover_peb()
837 mutex_lock(&ubi->buf_mutex); in try_recover_peb()
838 memset(ubi->peb_buf + offset, 0xFF, len); in try_recover_peb()
842 err = ubi_io_read_data(ubi, ubi->peb_buf, pnum, 0, offset); in try_recover_peb()
849 memcpy(ubi->peb_buf + offset, buf, len); in try_recover_peb()
852 crc = crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size); in try_recover_peb()
853 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in try_recover_peb()
857 err = ubi_io_write_vid_hdr(ubi, new_pnum, vidb); in try_recover_peb()
861 err = ubi_io_write_data(ubi, ubi->peb_buf, new_pnum, 0, data_size); in try_recover_peb()
864 mutex_unlock(&ubi->buf_mutex); in try_recover_peb()
870 up_read(&ubi->fm_eba_sem); in try_recover_peb()
873 ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); in try_recover_peb()
874 ubi_msg(ubi, "data was successfully recovered"); in try_recover_peb()
880 ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1); in try_recover_peb()
881 ubi_warn(ubi, "failed to write to PEB %d", new_pnum); in try_recover_peb()
903 static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum, in recover_peb() argument
906 int err, idx = vol_id2idx(ubi, vol_id), tries; in recover_peb()
907 struct ubi_volume *vol = ubi->volumes[idx]; in recover_peb()
910 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS); in recover_peb()
922 ubi_msg(ubi, "try again"); in recover_peb()
949 struct ubi_device *ubi = vol->ubi; in try_write_vid_and_data() local
952 pnum = ubi_wl_get_peb(ubi); in try_write_vid_and_data()
963 err = ubi_io_write_vid_hdr(ubi, pnum, vidb); in try_write_vid_and_data()
965 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d", in try_write_vid_and_data()
971 err = ubi_io_write_data(ubi, buf, pnum, offset, len); in try_write_vid_and_data()
973 ubi_warn(ubi, in try_write_vid_and_data()
983 up_read(&ubi->fm_eba_sem); in try_write_vid_and_data()
986 err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); in try_write_vid_and_data()
988 err = ubi_wl_put_peb(ubi, vol_id, lnum, opnum, 0); in try_write_vid_and_data()
1008 int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, in ubi_eba_write_leb() argument
1015 if (ubi->ro_mode) in ubi_eba_write_leb()
1018 err = leb_write_lock(ubi, vol_id, lnum); in ubi_eba_write_leb()
1024 err = check_mapping(ubi, vol, lnum, &pnum); in ubi_eba_write_leb()
1033 err = ubi_io_write_data(ubi, buf, pnum, offset, len); in ubi_eba_write_leb()
1035 ubi_warn(ubi, "failed to write data to PEB %d", pnum); in ubi_eba_write_leb()
1036 if (err == -EIO && ubi->bad_allowed) in ubi_eba_write_leb()
1037 err = recover_peb(ubi, pnum, vol_id, lnum, buf, in ubi_eba_write_leb()
1048 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS); in ubi_eba_write_leb()
1050 leb_write_unlock(ubi, vol_id, lnum); in ubi_eba_write_leb()
1057 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_write_leb()
1060 vid_hdr->compat = ubi_get_compat(ubi, vol_id); in ubi_eba_write_leb()
1065 if (err != -EIO || !ubi->bad_allowed) in ubi_eba_write_leb()
1074 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_write_leb()
1075 ubi_msg(ubi, "try another PEB"); in ubi_eba_write_leb()
1082 ubi_ro_mode(ubi); in ubi_eba_write_leb()
1084 leb_write_unlock(ubi, vol_id, lnum); in ubi_eba_write_leb()
1111 int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, in ubi_eba_write_leb_st() argument
1119 if (ubi->ro_mode) in ubi_eba_write_leb_st()
1124 len = ALIGN(data_size, ubi->min_io_size); in ubi_eba_write_leb_st()
1126 ubi_assert(!(len & (ubi->min_io_size - 1))); in ubi_eba_write_leb_st()
1128 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS); in ubi_eba_write_leb_st()
1134 err = leb_write_lock(ubi, vol_id, lnum); in ubi_eba_write_leb_st()
1138 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_write_leb_st()
1141 vid_hdr->compat = ubi_get_compat(ubi, vol_id); in ubi_eba_write_leb_st()
1154 if (err != -EIO || !ubi->bad_allowed) in ubi_eba_write_leb_st()
1157 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_write_leb_st()
1158 ubi_msg(ubi, "try another PEB"); in ubi_eba_write_leb_st()
1162 ubi_ro_mode(ubi); in ubi_eba_write_leb_st()
1164 leb_write_unlock(ubi, vol_id, lnum); in ubi_eba_write_leb_st()
1189 int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, in ubi_eba_atomic_leb_change() argument
1197 if (ubi->ro_mode) in ubi_eba_atomic_leb_change()
1205 err = ubi_eba_unmap_leb(ubi, vol, lnum); in ubi_eba_atomic_leb_change()
1208 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0); in ubi_eba_atomic_leb_change()
1211 vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS); in ubi_eba_atomic_leb_change()
1217 mutex_lock(&ubi->alc_mutex); in ubi_eba_atomic_leb_change()
1218 err = leb_write_lock(ubi, vol_id, lnum); in ubi_eba_atomic_leb_change()
1222 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_atomic_leb_change()
1225 vid_hdr->compat = ubi_get_compat(ubi, vol_id); in ubi_eba_atomic_leb_change()
1238 if (err != -EIO || !ubi->bad_allowed) in ubi_eba_atomic_leb_change()
1241 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_atomic_leb_change()
1242 ubi_msg(ubi, "try another PEB"); in ubi_eba_atomic_leb_change()
1251 ubi_ro_mode(ubi); in ubi_eba_atomic_leb_change()
1253 leb_write_unlock(ubi, vol_id, lnum); in ubi_eba_atomic_leb_change()
1256 mutex_unlock(&ubi->alc_mutex); in ubi_eba_atomic_leb_change()
1302 int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, in ubi_eba_copy_leb() argument
1310 ubi_assert(rwsem_is_locked(&ubi->fm_eba_sem)); in ubi_eba_copy_leb()
1319 aldata_size = ALIGN(data_size, ubi->min_io_size); in ubi_eba_copy_leb()
1322 ubi->leb_size - be32_to_cpu(vid_hdr->data_pad); in ubi_eba_copy_leb()
1324 idx = vol_id2idx(ubi, vol_id); in ubi_eba_copy_leb()
1325 spin_lock(&ubi->volumes_lock); in ubi_eba_copy_leb()
1332 vol = ubi->volumes[idx]; in ubi_eba_copy_leb()
1333 spin_unlock(&ubi->volumes_lock); in ubi_eba_copy_leb()
1355 err = leb_write_trylock(ubi, vol_id, lnum); in ubi_eba_copy_leb()
1379 mutex_lock(&ubi->buf_mutex); in ubi_eba_copy_leb()
1381 err = ubi_io_read_data(ubi, ubi->peb_buf, from, 0, aldata_size); in ubi_eba_copy_leb()
1383 ubi_warn(ubi, "error %d while reading data from PEB %d", in ubi_eba_copy_leb()
1401 ubi_calc_data_len(ubi, ubi->peb_buf, data_size); in ubi_eba_copy_leb()
1404 crc = crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size); in ubi_eba_copy_leb()
1418 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_eba_copy_leb()
1420 err = ubi_io_write_vid_hdr(ubi, to, vidb); in ubi_eba_copy_leb()
1430 err = ubi_io_read_vid_hdr(ubi, to, vidb, 1); in ubi_eba_copy_leb()
1433 ubi_warn(ubi, "error %d while reading VID header back from PEB %d", in ubi_eba_copy_leb()
1443 err = ubi_io_write_data(ubi, ubi->peb_buf, to, 0, aldata_size); in ubi_eba_copy_leb()
1457 mutex_unlock(&ubi->buf_mutex); in ubi_eba_copy_leb()
1459 leb_write_unlock(ubi, vol_id, lnum); in ubi_eba_copy_leb()
1481 static void print_rsvd_warning(struct ubi_device *ubi, in print_rsvd_warning() argument
1489 int min = ubi->beb_rsvd_level / 10; in print_rsvd_warning()
1493 if (ubi->beb_rsvd_pebs > min) in print_rsvd_warning()
1497 ubi_warn(ubi, "cannot reserve enough PEBs for bad PEB handling, reserved %d, need %d", in print_rsvd_warning()
1498 ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); in print_rsvd_warning()
1499 if (ubi->corr_peb_count) in print_rsvd_warning()
1500 ubi_warn(ubi, "%d PEBs are corrupted and not used", in print_rsvd_warning()
1501 ubi->corr_peb_count); in print_rsvd_warning()
1514 int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap, in self_check_eba() argument
1524 num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT; in self_check_eba()
1537 vol = ubi->volumes[i]; in self_check_eba()
1560 av = ubi_find_av(ai_scan, idx2vol_id(ubi, i)); in self_check_eba()
1567 av = ubi_find_av(ai_fastmap, idx2vol_id(ubi, i)); in self_check_eba()
1580 ubi_err(ubi, "LEB:%i:%i is PEB:%i instead of %i!", in self_check_eba()
1590 if (!ubi->volumes[i]) in self_check_eba()
1610 int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai) in ubi_eba_init() argument
1620 spin_lock_init(&ubi->ltree_lock); in ubi_eba_init()
1621 mutex_init(&ubi->alc_mutex); in ubi_eba_init()
1622 ubi->ltree = RB_ROOT; in ubi_eba_init()
1624 ubi->global_sqnum = ai->max_sqnum + 1; in ubi_eba_init()
1625 num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT; in ubi_eba_init()
1630 vol = ubi->volumes[i]; in ubi_eba_init()
1644 av = ubi_find_av(ai, idx2vol_id(ubi, i)); in ubi_eba_init()
1664 if (ubi->avail_pebs < EBA_RESERVED_PEBS) { in ubi_eba_init()
1665 ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)", in ubi_eba_init()
1666 ubi->avail_pebs, EBA_RESERVED_PEBS); in ubi_eba_init()
1667 if (ubi->corr_peb_count) in ubi_eba_init()
1668 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_eba_init()
1669 ubi->corr_peb_count); in ubi_eba_init()
1673 ubi->avail_pebs -= EBA_RESERVED_PEBS; in ubi_eba_init()
1674 ubi->rsvd_pebs += EBA_RESERVED_PEBS; in ubi_eba_init()
1676 if (ubi->bad_allowed) { in ubi_eba_init()
1677 ubi_calculate_reserved(ubi); in ubi_eba_init()
1679 if (ubi->avail_pebs < ubi->beb_rsvd_level) { in ubi_eba_init()
1681 ubi->beb_rsvd_pebs = ubi->avail_pebs; in ubi_eba_init()
1682 print_rsvd_warning(ubi, ai); in ubi_eba_init()
1684 ubi->beb_rsvd_pebs = ubi->beb_rsvd_level; in ubi_eba_init()
1686 ubi->avail_pebs -= ubi->beb_rsvd_pebs; in ubi_eba_init()
1687 ubi->rsvd_pebs += ubi->beb_rsvd_pebs; in ubi_eba_init()
1695 if (!ubi->volumes[i]) in ubi_eba_init()
1697 ubi_eba_replace_table(ubi->volumes[i], NULL); in ubi_eba_init()