Lines Matching refs: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()
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()
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 || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) 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()
112 static bool has_enough_free_count(struct ubi_device *ubi, bool is_wl_pool) in has_enough_free_count() argument
117 if (!ubi->free.rb_node) in has_enough_free_count()
120 beb_rsvd_pebs = is_wl_pool ? ubi->beb_rsvd_pebs : 0; in has_enough_free_count()
121 if (ubi->fm_wl_pool.size > 0 && !(ubi->ro_mode || ubi->fm_disabled)) in has_enough_free_count()
122 fm_used = ubi->fm_size / ubi->leb_size - 1; in has_enough_free_count()
124 return ubi->free_count - beb_rsvd_pebs > fm_used; in has_enough_free_count()
131 void ubi_refill_pools(struct ubi_device *ubi) in ubi_refill_pools() argument
133 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_refill_pools()
134 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_refill_pools()
138 spin_lock(&ubi->wl_lock); in ubi_refill_pools()
140 return_unused_pool_pebs(ubi, wl_pool); in ubi_refill_pools()
141 return_unused_pool_pebs(ubi, pool); in ubi_refill_pools()
146 if (ubi->fm_anchor) { in ubi_refill_pools()
147 wl_tree_add(ubi->fm_anchor, &ubi->free); in ubi_refill_pools()
148 ubi->free_count++; in ubi_refill_pools()
155 ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_refill_pools()
160 if (!has_enough_free_count(ubi, false)) in ubi_refill_pools()
163 e = wl_get_wle(ubi); in ubi_refill_pools()
173 if (!has_enough_free_count(ubi, true)) in ubi_refill_pools()
176 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF); in ubi_refill_pools()
177 self_check_in_wl_tree(ubi, e, &ubi->free); in ubi_refill_pools()
178 rb_erase(&e->u.rb, &ubi->free); in ubi_refill_pools()
179 ubi->free_count--; in ubi_refill_pools()
193 spin_unlock(&ubi->wl_lock); in ubi_refill_pools()
205 static int produce_free_peb(struct ubi_device *ubi) in produce_free_peb() argument
209 while (!ubi->free.rb_node && ubi->works_count) { in produce_free_peb()
211 err = do_work(ubi); in produce_free_peb()
228 int ubi_wl_get_peb(struct ubi_device *ubi) in ubi_wl_get_peb() argument
231 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_wl_get_peb()
232 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_wl_get_peb()
235 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
236 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
241 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
242 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
243 ret = ubi_update_fastmap(ubi); in ubi_wl_get_peb()
245 ubi_msg(ubi, "Unable to write a new fastmap: %i", ret); in ubi_wl_get_peb()
246 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
249 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
250 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
254 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
257 ubi_err(ubi, "Unable to get a free PEB from user WL pool"); in ubi_wl_get_peb()
261 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
262 ret = produce_free_peb(ubi); in ubi_wl_get_peb()
264 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
272 prot_queue_add(ubi, ubi->lookuptbl[ret]); in ubi_wl_get_peb()
273 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
284 static struct ubi_wl_entry *next_peb_for_wl(struct ubi_device *ubi) in next_peb_for_wl() argument
286 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in next_peb_for_wl()
293 return ubi->lookuptbl[pnum]; in next_peb_for_wl()
304 static bool need_wear_leveling(struct ubi_device *ubi) in need_wear_leveling() argument
309 if (!ubi->used.rb_node) in need_wear_leveling()
312 e = next_peb_for_wl(ubi); in need_wear_leveling()
314 if (!ubi->free.rb_node) in need_wear_leveling()
316 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF); in need_wear_leveling()
320 if (ubi->free.rb_node) { in need_wear_leveling()
321 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF); in need_wear_leveling()
325 e = rb_entry(rb_first(&ubi->used), struct ubi_wl_entry, u.rb); in need_wear_leveling()
334 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi) in get_peb_for_wl() argument
336 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in get_peb_for_wl()
339 ubi_assert(rwsem_is_locked(&ubi->fm_eba_sem)); in get_peb_for_wl()
345 if (!ubi->fm_work_scheduled) { in get_peb_for_wl()
346 ubi->fm_work_scheduled = 1; in get_peb_for_wl()
347 schedule_work(&ubi->fm_work); in get_peb_for_wl()
353 return ubi->lookuptbl[pnum]; in get_peb_for_wl()
360 int ubi_ensure_anchor_pebs(struct ubi_device *ubi) in ubi_ensure_anchor_pebs() argument
365 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
368 if (ubi->fm_anchor) { in ubi_ensure_anchor_pebs()
369 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
374 anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_ensure_anchor_pebs()
376 ubi->fm_anchor = anchor; in ubi_ensure_anchor_pebs()
377 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
381 ubi->fm_do_produce_anchor = 1; in ubi_ensure_anchor_pebs()
383 if (ubi->wl_scheduled) { in ubi_ensure_anchor_pebs()
384 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
387 ubi->wl_scheduled = 1; in ubi_ensure_anchor_pebs()
388 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
392 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
393 ubi->wl_scheduled = 0; in ubi_ensure_anchor_pebs()
394 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
399 __schedule_ubi_work(ubi, wrk); in ubi_ensure_anchor_pebs()
413 int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e, in ubi_wl_put_fm_peb() argument
422 ubi_assert(pnum < ubi->peb_count); in ubi_wl_put_fm_peb()
424 spin_lock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
425 e = ubi->lookuptbl[pnum]; in ubi_wl_put_fm_peb()
434 ubi->lookuptbl[pnum] = e; in ubi_wl_put_fm_peb()
437 spin_unlock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
440 return schedule_erase(ubi, e, vol_id, lnum, torture, true); in ubi_wl_put_fm_peb()
452 static void ubi_fastmap_close(struct ubi_device *ubi) in ubi_fastmap_close() argument
456 return_unused_pool_pebs(ubi, &ubi->fm_pool); in ubi_fastmap_close()
457 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); in ubi_fastmap_close()
459 if (ubi->fm_anchor) { in ubi_fastmap_close()
460 return_unused_peb(ubi, ubi->fm_anchor); in ubi_fastmap_close()
461 ubi->fm_anchor = NULL; in ubi_fastmap_close()
464 if (ubi->fm) { in ubi_fastmap_close()
465 for (i = 0; i < ubi->fm->used_blocks; i++) in ubi_fastmap_close()
466 kfree(ubi->fm->e[i]); in ubi_fastmap_close()
468 kfree(ubi->fm); in ubi_fastmap_close()
479 static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi, in may_reserve_for_fm() argument
482 if (e && !ubi->fm_disabled && !ubi->fm && in may_reserve_for_fm()