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()
282 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi) in get_peb_for_wl() argument
284 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in get_peb_for_wl()
287 ubi_assert(rwsem_is_locked(&ubi->fm_eba_sem)); in get_peb_for_wl()
293 if (!ubi->fm_work_scheduled) { in get_peb_for_wl()
294 ubi->fm_work_scheduled = 1; in get_peb_for_wl()
295 schedule_work(&ubi->fm_work); in get_peb_for_wl()
301 return ubi->lookuptbl[pnum]; in get_peb_for_wl()
308 int ubi_ensure_anchor_pebs(struct ubi_device *ubi) in ubi_ensure_anchor_pebs() argument
313 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
316 if (ubi->fm_anchor) { in ubi_ensure_anchor_pebs()
317 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
322 anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_ensure_anchor_pebs()
324 ubi->fm_anchor = anchor; in ubi_ensure_anchor_pebs()
325 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
329 ubi->fm_do_produce_anchor = 1; in ubi_ensure_anchor_pebs()
331 if (ubi->wl_scheduled) { in ubi_ensure_anchor_pebs()
332 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
335 ubi->wl_scheduled = 1; in ubi_ensure_anchor_pebs()
336 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
340 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
341 ubi->wl_scheduled = 0; in ubi_ensure_anchor_pebs()
342 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
347 __schedule_ubi_work(ubi, wrk); in ubi_ensure_anchor_pebs()
361 int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e, in ubi_wl_put_fm_peb() argument
370 ubi_assert(pnum < ubi->peb_count); in ubi_wl_put_fm_peb()
372 spin_lock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
373 e = ubi->lookuptbl[pnum]; in ubi_wl_put_fm_peb()
382 ubi->lookuptbl[pnum] = e; in ubi_wl_put_fm_peb()
385 spin_unlock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
388 return schedule_erase(ubi, e, vol_id, lnum, torture, true); in ubi_wl_put_fm_peb()
400 static void ubi_fastmap_close(struct ubi_device *ubi) in ubi_fastmap_close() argument
404 return_unused_pool_pebs(ubi, &ubi->fm_pool); in ubi_fastmap_close()
405 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); in ubi_fastmap_close()
407 if (ubi->fm_anchor) { in ubi_fastmap_close()
408 return_unused_peb(ubi, ubi->fm_anchor); in ubi_fastmap_close()
409 ubi->fm_anchor = NULL; in ubi_fastmap_close()
412 if (ubi->fm) { in ubi_fastmap_close()
413 for (i = 0; i < ubi->fm->used_blocks; i++) in ubi_fastmap_close()
414 kfree(ubi->fm->e[i]); in ubi_fastmap_close()
416 kfree(ubi->fm); in ubi_fastmap_close()
427 static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi, in may_reserve_for_fm() argument
430 if (e && !ubi->fm_disabled && !ubi->fm && in may_reserve_for_fm()