Lines Matching +full:- +full:e
6 * SPDX-License-Identifier: GPL-2.0+
11 * update_fastmap_work_fn - calls ubi_update_fastmap from a work queue
25 spin_lock(&ubi->wl_lock); in update_fastmap_work_fn()
26 ubi->fm_work_scheduled = 0; in update_fastmap_work_fn()
27 spin_unlock(&ubi->wl_lock); in update_fastmap_work_fn()
31 * find_anchor_wl_entry - find wear-leveling entry to used as anchor PEB.
32 * @root: the RB-tree where to look for
37 struct ubi_wl_entry *e, *victim = NULL; in find_anchor_wl_entry() local
40 ubi_rb_for_each_entry(p, e, root, u.rb) { in find_anchor_wl_entry()
41 if (e->pnum < UBI_FM_MAX_START && e->ec < max_ec) { in find_anchor_wl_entry()
42 victim = e; in find_anchor_wl_entry()
43 max_ec = e->ec; in find_anchor_wl_entry()
51 * return_unused_pool_pebs - returns unused PEB to the free tree.
59 struct ubi_wl_entry *e; in return_unused_pool_pebs() local
61 for (i = pool->used; i < pool->size; i++) { in return_unused_pool_pebs()
62 e = ubi->lookuptbl[pool->pebs[i]]; in return_unused_pool_pebs()
63 wl_tree_add(e, &ubi->free); in return_unused_pool_pebs()
64 ubi->free_count++; in return_unused_pool_pebs()
71 struct ubi_wl_entry *e; in anchor_pebs_avalible() local
73 ubi_rb_for_each_entry(p, e, root, u.rb) in anchor_pebs_avalible()
74 if (e->pnum < UBI_FM_MAX_START) in anchor_pebs_avalible()
81 * ubi_wl_get_fm_peb - find a physical erase block with a given maximal number.
91 struct ubi_wl_entry *e = NULL; in ubi_wl_get_fm_peb() local
93 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) in ubi_wl_get_fm_peb()
97 e = find_anchor_wl_entry(&ubi->free); in ubi_wl_get_fm_peb()
99 e = find_mean_wl_entry(ubi, &ubi->free); in ubi_wl_get_fm_peb()
101 if (!e) in ubi_wl_get_fm_peb()
104 self_check_in_wl_tree(ubi, e, &ubi->free); in ubi_wl_get_fm_peb()
108 rb_erase(&e->u.rb, &ubi->free); in ubi_wl_get_fm_peb()
109 ubi->free_count--; in ubi_wl_get_fm_peb()
111 return e; in ubi_wl_get_fm_peb()
115 * ubi_refill_pools - refills all fastmap PEB pools.
120 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_refill_pools()
121 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_refill_pools()
122 struct ubi_wl_entry *e; in ubi_refill_pools() local
125 spin_lock(&ubi->wl_lock); in ubi_refill_pools()
130 wl_pool->size = 0; in ubi_refill_pools()
131 pool->size = 0; in ubi_refill_pools()
135 if (pool->size < pool->max_size) { in ubi_refill_pools()
136 if (!ubi->free.rb_node) in ubi_refill_pools()
139 e = wl_get_wle(ubi); in ubi_refill_pools()
140 if (!e) in ubi_refill_pools()
143 pool->pebs[pool->size] = e->pnum; in ubi_refill_pools()
144 pool->size++; in ubi_refill_pools()
148 if (wl_pool->size < wl_pool->max_size) { in ubi_refill_pools()
149 if (!ubi->free.rb_node || in ubi_refill_pools()
150 (ubi->free_count - ubi->beb_rsvd_pebs < 5)) in ubi_refill_pools()
153 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF); in ubi_refill_pools()
154 self_check_in_wl_tree(ubi, e, &ubi->free); in ubi_refill_pools()
155 rb_erase(&e->u.rb, &ubi->free); in ubi_refill_pools()
156 ubi->free_count--; in ubi_refill_pools()
158 wl_pool->pebs[wl_pool->size] = e->pnum; in ubi_refill_pools()
159 wl_pool->size++; in ubi_refill_pools()
167 wl_pool->used = 0; in ubi_refill_pools()
168 pool->used = 0; in ubi_refill_pools()
170 spin_unlock(&ubi->wl_lock); in ubi_refill_pools()
174 * produce_free_peb - produce a free physical eraseblock.
186 while (!ubi->free.rb_node && ubi->works_count) { in produce_free_peb()
198 * ubi_wl_get_peb - get a physical eraseblock.
203 * Returns with ubi->fm_eba_sem held in read mode!
208 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_wl_get_peb()
209 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_wl_get_peb()
212 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
213 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
217 if (pool->used == pool->size || wl_pool->used == wl_pool->size) { in ubi_wl_get_peb()
218 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
219 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
223 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
224 return -ENOSPC; in ubi_wl_get_peb()
226 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
227 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
230 if (pool->used == pool->size) { in ubi_wl_get_peb()
231 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
234 ret = -ENOSPC; in ubi_wl_get_peb()
238 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
241 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
247 ubi_assert(pool->used < pool->size); in ubi_wl_get_peb()
248 ret = pool->pebs[pool->used++]; in ubi_wl_get_peb()
249 prot_queue_add(ubi, ubi->lookuptbl[ret]); in ubi_wl_get_peb()
250 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
255 /* get_peb_for_wl - returns a PEB to be used internally by the WL sub-system.
261 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in get_peb_for_wl()
264 if (pool->used == pool->size) { in get_peb_for_wl()
269 if (!ubi->fm_work_scheduled) { in get_peb_for_wl()
270 ubi->fm_work_scheduled = 1; in get_peb_for_wl()
271 schedule_work(&ubi->fm_work); in get_peb_for_wl()
276 * No work queues in U-Boot, we must do this immediately in get_peb_for_wl()
282 pnum = pool->pebs[pool->used++]; in get_peb_for_wl()
283 return ubi->lookuptbl[pnum]; in get_peb_for_wl()
287 * ubi_ensure_anchor_pebs - schedule wear-leveling to produce an anchor PEB.
294 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
295 if (ubi->wl_scheduled) { in ubi_ensure_anchor_pebs()
296 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
299 ubi->wl_scheduled = 1; in ubi_ensure_anchor_pebs()
300 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
304 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
305 ubi->wl_scheduled = 0; in ubi_ensure_anchor_pebs()
306 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
307 return -ENOMEM; in ubi_ensure_anchor_pebs()
310 wrk->anchor = 1; in ubi_ensure_anchor_pebs()
311 wrk->func = &wear_leveling_worker; in ubi_ensure_anchor_pebs()
317 * ubi_wl_put_fm_peb - returns a PEB used in a fastmap to the wear-leveling
318 * sub-system.
329 struct ubi_wl_entry *e; in ubi_wl_put_fm_peb() local
330 int vol_id, pnum = fm_e->pnum; in ubi_wl_put_fm_peb()
335 ubi_assert(pnum < ubi->peb_count); in ubi_wl_put_fm_peb()
337 spin_lock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
338 e = ubi->lookuptbl[pnum]; in ubi_wl_put_fm_peb()
344 if (!e) { in ubi_wl_put_fm_peb()
345 e = fm_e; in ubi_wl_put_fm_peb()
346 ubi_assert(e->ec >= 0); in ubi_wl_put_fm_peb()
347 ubi->lookuptbl[pnum] = e; in ubi_wl_put_fm_peb()
350 spin_unlock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
353 return schedule_erase(ubi, e, vol_id, lnum, torture); in ubi_wl_put_fm_peb()
357 * ubi_is_erase_work - checks whether a work is erase work.
362 return wrk->func == erase_worker; in ubi_is_erase_work()
369 return_unused_pool_pebs(ubi, &ubi->fm_pool); in ubi_fastmap_close()
370 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); in ubi_fastmap_close()
372 if (ubi->fm) { in ubi_fastmap_close()
373 for (i = 0; i < ubi->fm->used_blocks; i++) in ubi_fastmap_close()
374 kfree(ubi->fm->e[i]); in ubi_fastmap_close()
376 kfree(ubi->fm); in ubi_fastmap_close()
380 * may_reserve_for_fm - tests whether a PEB shall be reserved for fastmap.
384 * @e: physical eraseblock to return
388 struct ubi_wl_entry *e, in may_reserve_for_fm() argument
390 if (e && !ubi->fm_disabled && !ubi->fm && in may_reserve_for_fm()
391 e->pnum < UBI_FM_MAX_START) in may_reserve_for_fm()
392 e = rb_entry(rb_next(root->rb_node), in may_reserve_for_fm()
395 return e; in may_reserve_for_fm()