Lines Matching refs:ai

87 static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai);
114 static int add_to_list(struct ubi_attach_info *ai, int pnum, int vol_id, in add_to_list() argument
119 if (list == &ai->free) { in add_to_list()
121 } else if (list == &ai->erase) { in add_to_list()
123 } else if (list == &ai->alien) { in add_to_list()
125 ai->alien_peb_count += 1; in add_to_list()
129 aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); in add_to_list()
155 static int add_corrupted(struct ubi_attach_info *ai, int pnum, int ec) in add_corrupted() argument
161 aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); in add_corrupted()
165 ai->corr_peb_count += 1; in add_corrupted()
168 list_add(&aeb->u.list, &ai->corr); in add_corrupted()
253 static struct ubi_ainf_volume *add_volume(struct ubi_attach_info *ai, in add_volume() argument
258 struct rb_node **p = &ai->volumes.rb_node, *parent = NULL; in add_volume()
289 if (vol_id > ai->highest_vol_id) in add_volume()
290 ai->highest_vol_id = vol_id; in add_volume()
293 rb_insert_color(&av->rb, &ai->volumes); in add_volume()
294 ai->vols_found += 1; in add_volume()
444 int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum, in ubi_add_to_av() argument
460 av = add_volume(ai, vol_id, pnum, vid_hdr); in ubi_add_to_av()
464 if (ai->max_sqnum < sqnum) in ubi_add_to_av()
465 ai->max_sqnum = sqnum; in ubi_add_to_av()
531 err = add_to_list(ai, aeb->pnum, aeb->vol_id, in ubi_add_to_av()
533 &ai->erase); in ubi_add_to_av()
555 return add_to_list(ai, pnum, vol_id, lnum, ec, in ubi_add_to_av()
556 cmp_res & 4, &ai->erase); in ubi_add_to_av()
569 aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); in ubi_add_to_av()
600 struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai, in ubi_find_av() argument
604 struct rb_node *p = ai->volumes.rb_node; in ubi_find_av()
626 void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) in ubi_remove_av() argument
636 list_add_tail(&aeb->u.list, &ai->erase); in ubi_remove_av()
639 rb_erase(&av->rb, &ai->volumes); in ubi_remove_av()
641 ai->vols_found -= 1; in ubi_remove_av()
658 const struct ubi_attach_info *ai, int pnum, int ec) in early_erase_peb() argument
705 struct ubi_attach_info *ai) in ubi_early_get_peb() argument
710 if (!list_empty(&ai->free)) { in ubi_early_get_peb()
711 aeb = list_entry(ai->free.next, struct ubi_ainf_peb, u.list); in ubi_early_get_peb()
723 list_for_each_entry_safe(aeb, tmp_aeb, &ai->erase, u.list) { in ubi_early_get_peb()
725 aeb->ec = ai->mean_ec; in ubi_early_get_peb()
727 err = early_erase_peb(ubi, ai, aeb->pnum, aeb->ec+1); in ubi_early_get_peb()
814 static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, in scan_peb() argument
827 ai->bad_peb_count += 1; in scan_peb()
841 ai->empty_peb_count += 1; in scan_peb()
842 return add_to_list(ai, pnum, UBI_UNKNOWN, UBI_UNKNOWN, in scan_peb()
843 UBI_UNKNOWN, 0, &ai->erase); in scan_peb()
845 ai->empty_peb_count += 1; in scan_peb()
846 return add_to_list(ai, pnum, UBI_UNKNOWN, UBI_UNKNOWN, in scan_peb()
847 UBI_UNKNOWN, 1, &ai->erase); in scan_peb()
931 ai->maybe_bad_peb_count += 1; in scan_peb()
958 err = add_to_list(ai, pnum, UBI_UNKNOWN, in scan_peb()
959 UBI_UNKNOWN, ec, 1, &ai->erase); in scan_peb()
962 err = add_corrupted(ai, pnum, ec); in scan_peb()
967 err = add_to_list(ai, pnum, UBI_UNKNOWN, UBI_UNKNOWN, in scan_peb()
968 ec, 1, &ai->erase); in scan_peb()
974 err = add_to_list(ai, pnum, UBI_UNKNOWN, in scan_peb()
975 UBI_UNKNOWN, ec, 1, &ai->erase); in scan_peb()
977 err = add_to_list(ai, pnum, UBI_UNKNOWN, in scan_peb()
978 UBI_UNKNOWN, ec, 0, &ai->free); in scan_peb()
1004 err = add_to_list(ai, pnum, vol_id, lnum, in scan_peb()
1005 ec, 1, &ai->erase); in scan_peb()
1019 err = add_to_list(ai, pnum, vol_id, lnum, in scan_peb()
1020 ec, 0, &ai->alien); in scan_peb()
1035 err = ubi_add_to_av(ubi, ai, pnum, ec, vidh, bitflips); in scan_peb()
1041 ai->ec_sum += ec; in scan_peb()
1042 ai->ec_count += 1; in scan_peb()
1043 if (ec > ai->max_ec) in scan_peb()
1044 ai->max_ec = ec; in scan_peb()
1045 if (ec < ai->min_ec) in scan_peb()
1046 ai->min_ec = ec; in scan_peb()
1063 static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai) in late_analysis() argument
1068 peb_count = ubi->peb_count - ai->bad_peb_count - ai->alien_peb_count; in late_analysis()
1076 if (ai->corr_peb_count) { in late_analysis()
1078 ai->corr_peb_count); in late_analysis()
1080 list_for_each_entry(aeb, &ai->corr, u.list) in late_analysis()
1088 if (ai->corr_peb_count >= max_corr) { in late_analysis()
1094 if (ai->empty_peb_count + ai->maybe_bad_peb_count == peb_count) { in late_analysis()
1110 if (ai->maybe_bad_peb_count <= 2) { in late_analysis()
1111 ai->is_empty = 1; in late_analysis()
1132 static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) in destroy_av() argument
1152 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_av()
1162 static void destroy_ai(struct ubi_attach_info *ai) in destroy_ai() argument
1168 list_for_each_entry_safe(aeb, aeb_tmp, &ai->alien, u.list) { in destroy_ai()
1170 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1172 list_for_each_entry_safe(aeb, aeb_tmp, &ai->erase, u.list) { in destroy_ai()
1174 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1176 list_for_each_entry_safe(aeb, aeb_tmp, &ai->corr, u.list) { in destroy_ai()
1178 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1180 list_for_each_entry_safe(aeb, aeb_tmp, &ai->free, u.list) { in destroy_ai()
1182 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1186 rb = ai->volumes.rb_node; in destroy_ai()
1203 destroy_av(ai, av); in destroy_ai()
1207 kmem_cache_destroy(ai->aeb_slab_cache); in destroy_ai()
1209 kfree(ai); in destroy_ai()
1222 static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai, in scan_all() argument
1244 err = scan_peb(ubi, ai, pnum, NULL, NULL); in scan_all()
1252 if (ai->ec_count) in scan_all()
1253 ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); in scan_all()
1255 err = late_analysis(ubi, ai); in scan_all()
1263 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { in scan_all()
1266 aeb->ec = ai->mean_ec; in scan_all()
1269 list_for_each_entry(aeb, &ai->free, u.list) { in scan_all()
1271 aeb->ec = ai->mean_ec; in scan_all()
1274 list_for_each_entry(aeb, &ai->corr, u.list) in scan_all()
1276 aeb->ec = ai->mean_ec; in scan_all()
1278 list_for_each_entry(aeb, &ai->erase, u.list) in scan_all()
1280 aeb->ec = ai->mean_ec; in scan_all()
1282 err = self_check_ai(ubi, ai); in scan_all()
1300 struct ubi_attach_info *ai; in alloc_ai() local
1302 ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL); in alloc_ai()
1303 if (!ai) in alloc_ai()
1304 return ai; in alloc_ai()
1306 INIT_LIST_HEAD(&ai->corr); in alloc_ai()
1307 INIT_LIST_HEAD(&ai->free); in alloc_ai()
1308 INIT_LIST_HEAD(&ai->erase); in alloc_ai()
1309 INIT_LIST_HEAD(&ai->alien); in alloc_ai()
1310 ai->volumes = RB_ROOT; in alloc_ai()
1311 ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache", in alloc_ai()
1314 if (!ai->aeb_slab_cache) { in alloc_ai()
1315 kfree(ai); in alloc_ai()
1316 ai = NULL; in alloc_ai()
1319 return ai; in alloc_ai()
1334 static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai) in scan_fast() argument
1355 err = scan_peb(ubi, *ai, pnum, &vol_id, &sqnum); in scan_fast()
1371 destroy_ai(*ai); in scan_fast()
1372 *ai = alloc_ai(); in scan_fast()
1373 if (!*ai) in scan_fast()
1376 return ubi_scan_fastmap(ubi, *ai, fm_anchor); in scan_fast()
1399 struct ubi_attach_info *ai; in ubi_attach() local
1401 ai = alloc_ai(); in ubi_attach()
1402 if (!ai) in ubi_attach()
1413 err = scan_all(ubi, ai, 0); in ubi_attach()
1415 err = scan_fast(ubi, &ai); in ubi_attach()
1418 destroy_ai(ai); in ubi_attach()
1419 ai = alloc_ai(); in ubi_attach()
1420 if (!ai) in ubi_attach()
1423 err = scan_all(ubi, ai, 0); in ubi_attach()
1425 err = scan_all(ubi, ai, UBI_FM_MAX_START); in ubi_attach()
1430 err = scan_all(ubi, ai, 0); in ubi_attach()
1435 ubi->bad_peb_count = ai->bad_peb_count; in ubi_attach()
1437 ubi->corr_peb_count = ai->corr_peb_count; in ubi_attach()
1438 ubi->max_ec = ai->max_ec; in ubi_attach()
1439 ubi->mean_ec = ai->mean_ec; in ubi_attach()
1440 dbg_gen("max. sequence number: %llu", ai->max_sqnum); in ubi_attach()
1442 err = ubi_read_volume_table(ubi, ai); in ubi_attach()
1446 err = ubi_wl_init(ubi, ai); in ubi_attach()
1450 err = ubi_eba_init(ubi, ai); in ubi_attach()
1470 err = self_check_eba(ubi, ai, scan_ai); in ubi_attach()
1478 destroy_ai(ai); in ubi_attach()
1487 destroy_ai(ai); in ubi_attach()
1499 static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai) in self_check_ai() argument
1513 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { in self_check_ai()
1520 if (ai->is_empty) { in self_check_ai()
1538 if (av->vol_id > ai->highest_vol_id) { in self_check_ai()
1540 ai->highest_vol_id, av->vol_id); in self_check_ai()
1567 if (aeb->ec < ai->min_ec) { in self_check_ai()
1569 ai->min_ec, aeb->ec); in self_check_ai()
1573 if (aeb->ec > ai->max_ec) { in self_check_ai()
1575 ai->max_ec, aeb->ec); in self_check_ai()
1620 if (vols_found != ai->vols_found) { in self_check_ai()
1622 ai->vols_found, vols_found); in self_check_ai()
1627 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { in self_check_ai()
1715 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) in self_check_ai()
1719 list_for_each_entry(aeb, &ai->free, u.list) in self_check_ai()
1722 list_for_each_entry(aeb, &ai->corr, u.list) in self_check_ai()
1725 list_for_each_entry(aeb, &ai->erase, u.list) in self_check_ai()
1728 list_for_each_entry(aeb, &ai->alien, u.list) in self_check_ai()