Lines Matching full:ubi
14 struct ubi_device *ubi = container_of(wrk, struct ubi_device, fm_work); in update_fastmap_work_fn() local
16 ubi_update_fastmap(ubi); in update_fastmap_work_fn()
17 spin_lock(&ubi->wl_lock); in update_fastmap_work_fn()
18 ubi->fm_work_scheduled = 0; in update_fastmap_work_fn()
19 spin_unlock(&ubi->wl_lock); in update_fastmap_work_fn()
42 static inline void return_unused_peb(struct ubi_device *ubi, in return_unused_peb() argument
45 wl_tree_add(e, &ubi->free); in return_unused_peb()
46 ubi->free_count++; in return_unused_peb()
51 * @ubi: UBI device description object
54 static void return_unused_pool_pebs(struct ubi_device *ubi, in return_unused_pool_pebs() argument
61 e = ubi->lookuptbl[pool->pebs[i]]; in return_unused_pool_pebs()
62 return_unused_peb(ubi, e); in return_unused_pool_pebs()
68 * @ubi: UBI device description object
75 struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor) in ubi_wl_get_fm_peb() argument
79 if (!ubi->free.rb_node) in ubi_wl_get_fm_peb()
83 e = find_anchor_wl_entry(&ubi->free); in ubi_wl_get_fm_peb()
85 e = find_mean_wl_entry(ubi, &ubi->free); in ubi_wl_get_fm_peb()
90 self_check_in_wl_tree(ubi, e, &ubi->free); in ubi_wl_get_fm_peb()
94 rb_erase(&e->u.rb, &ubi->free); in ubi_wl_get_fm_peb()
95 ubi->free_count--; in ubi_wl_get_fm_peb()
102 * @ubi: UBI device description object
108 static void wait_free_pebs_for_pool(struct ubi_device *ubi) in wait_free_pebs_for_pool() argument
110 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in wait_free_pebs_for_pool()
111 struct ubi_fm_pool *pool = &ubi->fm_pool; in wait_free_pebs_for_pool()
114 * There are at least following free pebs which reserved by UBI: in wait_free_pebs_for_pool()
118 * 4. beb_rsvd_pebs: This value should be get under lock ubi->wl_lock in wait_free_pebs_for_pool()
121 ubi->fm_size / ubi->leb_size - 1 + ubi->fm_pool_rsv_cnt; in wait_free_pebs_for_pool()
124 spin_lock(&ubi->wl_lock); in wait_free_pebs_for_pool()
125 free = ubi->free_count; in wait_free_pebs_for_pool()
127 expect_free = reserved + ubi->beb_rsvd_pebs; in wait_free_pebs_for_pool()
128 spin_unlock(&ubi->wl_lock); in wait_free_pebs_for_pool()
135 if (do_work(ubi, &executed) || !executed) in wait_free_pebs_for_pool()
142 * @ubi: UBI device description object
147 static int left_free_count(struct ubi_device *ubi) in left_free_count() argument
151 if (!ubi->free.rb_node) in left_free_count()
154 if (!ubi->ro_mode && !ubi->fm_disabled) in left_free_count()
155 fm_used = ubi->fm_size / ubi->leb_size - 1; in left_free_count()
157 return ubi->free_count - fm_used; in left_free_count()
162 * @ubi: UBI device description object
168 static int can_fill_pools(struct ubi_device *ubi, int free) in can_fill_pools() argument
170 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in can_fill_pools()
171 struct ubi_fm_pool *pool = &ubi->fm_pool; in can_fill_pools()
183 * @ubi: UBI device description object
185 void ubi_refill_pools_and_lock(struct ubi_device *ubi) in ubi_refill_pools_and_lock() argument
187 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_refill_pools_and_lock()
188 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_refill_pools_and_lock()
192 if (!ubi->ro_mode && !ubi->fm_disabled) in ubi_refill_pools_and_lock()
193 wait_free_pebs_for_pool(ubi); in ubi_refill_pools_and_lock()
195 down_write(&ubi->fm_protect); in ubi_refill_pools_and_lock()
196 down_write(&ubi->work_sem); in ubi_refill_pools_and_lock()
197 down_write(&ubi->fm_eba_sem); in ubi_refill_pools_and_lock()
199 spin_lock(&ubi->wl_lock); in ubi_refill_pools_and_lock()
201 return_unused_pool_pebs(ubi, wl_pool); in ubi_refill_pools_and_lock()
202 return_unused_pool_pebs(ubi, pool); in ubi_refill_pools_and_lock()
207 if (ubi->fm_anchor) { in ubi_refill_pools_and_lock()
208 wl_tree_add(ubi->fm_anchor, &ubi->free); in ubi_refill_pools_and_lock()
209 ubi->free_count++; in ubi_refill_pools_and_lock()
210 ubi->fm_anchor = NULL; in ubi_refill_pools_and_lock()
213 if (!ubi->fm_disabled) in ubi_refill_pools_and_lock()
215 * All available PEBs are in ubi->free, now is the time to get in ubi_refill_pools_and_lock()
218 ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_refill_pools_and_lock()
223 if (left_free_count(ubi) <= 0) in ubi_refill_pools_and_lock()
226 e = wl_get_wle(ubi); in ubi_refill_pools_and_lock()
236 int left_free = left_free_count(ubi); in ubi_refill_pools_and_lock()
241 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, in ubi_refill_pools_and_lock()
242 !can_fill_pools(ubi, left_free)); in ubi_refill_pools_and_lock()
243 self_check_in_wl_tree(ubi, e, &ubi->free); in ubi_refill_pools_and_lock()
244 rb_erase(&e->u.rb, &ubi->free); in ubi_refill_pools_and_lock()
245 ubi->free_count--; in ubi_refill_pools_and_lock()
259 spin_unlock(&ubi->wl_lock); in ubi_refill_pools_and_lock()
264 * @ubi: UBI device description object
271 static int produce_free_peb(struct ubi_device *ubi) in produce_free_peb() argument
275 while (!ubi->free.rb_node && ubi->works_count) { in produce_free_peb()
277 err = do_work(ubi, NULL); in produce_free_peb()
288 * @ubi: UBI device description object
292 * Returns with ubi->fm_eba_sem held in read mode!
294 int ubi_wl_get_peb(struct ubi_device *ubi) in ubi_wl_get_peb() argument
297 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_wl_get_peb()
298 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_wl_get_peb()
301 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
302 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
307 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
308 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
309 ret = ubi_update_fastmap(ubi); in ubi_wl_get_peb()
311 ubi_msg(ubi, "Unable to write a new fastmap: %i", ret); in ubi_wl_get_peb()
312 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
315 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
316 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
320 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
323 ubi_err(ubi, "Unable to get a free PEB from user WL pool"); in ubi_wl_get_peb()
327 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
328 ret = produce_free_peb(ubi); in ubi_wl_get_peb()
330 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
338 prot_queue_add(ubi, ubi->lookuptbl[ret]); in ubi_wl_get_peb()
339 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
348 * @ubi: UBI device description object
350 static struct ubi_wl_entry *next_peb_for_wl(struct ubi_device *ubi) in next_peb_for_wl() argument
352 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in next_peb_for_wl()
359 return ubi->lookuptbl[pnum]; in next_peb_for_wl()
364 * UBI fetches free PEB from wl_pool, we check free PEBs from both 'wl_pool'
365 * and 'ubi->free', because free PEB in 'ubi->free' tree maybe moved into
368 * @ubi: UBI device description object
370 static bool need_wear_leveling(struct ubi_device *ubi) in need_wear_leveling() argument
375 if (!ubi->used.rb_node) in need_wear_leveling()
378 e = next_peb_for_wl(ubi); in need_wear_leveling()
380 if (!ubi->free.rb_node) in need_wear_leveling()
382 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, 0); in need_wear_leveling()
386 if (ubi->free.rb_node) { in need_wear_leveling()
387 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, 0); in need_wear_leveling()
391 e = rb_entry(rb_first(&ubi->used), struct ubi_wl_entry, u.rb); in need_wear_leveling()
398 * @ubi: UBI device description object
400 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi) in get_peb_for_wl() argument
402 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in get_peb_for_wl()
405 ubi_assert(rwsem_is_locked(&ubi->fm_eba_sem)); in get_peb_for_wl()
411 if (!ubi->fm_work_scheduled) { in get_peb_for_wl()
412 ubi->fm_work_scheduled = 1; in get_peb_for_wl()
413 schedule_work(&ubi->fm_work); in get_peb_for_wl()
419 return ubi->lookuptbl[pnum]; in get_peb_for_wl()
424 * @ubi: UBI device description object
426 int ubi_ensure_anchor_pebs(struct ubi_device *ubi) in ubi_ensure_anchor_pebs() argument
431 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
434 if (ubi->fm_anchor) { in ubi_ensure_anchor_pebs()
435 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
440 anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_ensure_anchor_pebs()
442 ubi->fm_anchor = anchor; in ubi_ensure_anchor_pebs()
443 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
447 ubi->fm_do_produce_anchor = 1; in ubi_ensure_anchor_pebs()
449 if (ubi->wl_scheduled) { in ubi_ensure_anchor_pebs()
450 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
453 ubi->wl_scheduled = 1; in ubi_ensure_anchor_pebs()
454 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
458 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
459 ubi->wl_scheduled = 0; in ubi_ensure_anchor_pebs()
460 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
465 __schedule_ubi_work(ubi, wrk); in ubi_ensure_anchor_pebs()
474 * @ubi: UBI device description object
479 int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e, in ubi_wl_put_fm_peb() argument
488 ubi_assert(pnum < ubi->peb_count); in ubi_wl_put_fm_peb()
490 spin_lock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
491 e = ubi->lookuptbl[pnum]; in ubi_wl_put_fm_peb()
500 ubi->lookuptbl[pnum] = e; in ubi_wl_put_fm_peb()
503 spin_unlock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
506 return schedule_erase(ubi, e, vol_id, lnum, torture, true); in ubi_wl_put_fm_peb()
518 static void ubi_fastmap_close(struct ubi_device *ubi) in ubi_fastmap_close() argument
522 return_unused_pool_pebs(ubi, &ubi->fm_pool); in ubi_fastmap_close()
523 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); in ubi_fastmap_close()
525 if (ubi->fm_anchor) { in ubi_fastmap_close()
526 return_unused_peb(ubi, ubi->fm_anchor); in ubi_fastmap_close()
527 ubi->fm_anchor = NULL; in ubi_fastmap_close()
530 if (ubi->fm) { in ubi_fastmap_close()
531 for (i = 0; i < ubi->fm->used_blocks; i++) in ubi_fastmap_close()
532 kfree(ubi->fm->e[i]); in ubi_fastmap_close()
534 kfree(ubi->fm); in ubi_fastmap_close()
541 * @ubi: UBI device description object
545 static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi, in may_reserve_for_fm() argument
548 if (e && !ubi->fm_disabled && !ubi->fm && !ubi->fm_anchor && in may_reserve_for_fm()