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()
104 void ubi_refill_pools(struct ubi_device *ubi) in ubi_refill_pools() argument
106 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_refill_pools()
107 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_refill_pools()
111 spin_lock(&ubi->wl_lock); in ubi_refill_pools()
113 return_unused_pool_pebs(ubi, wl_pool); in ubi_refill_pools()
114 return_unused_pool_pebs(ubi, pool); in ubi_refill_pools()
119 if (ubi->fm_anchor) { in ubi_refill_pools()
120 wl_tree_add(ubi->fm_anchor, &ubi->free); in ubi_refill_pools()
121 ubi->free_count++; in ubi_refill_pools()
123 if (ubi->fm_next_anchor) { in ubi_refill_pools()
124 wl_tree_add(ubi->fm_next_anchor, &ubi->free); in ubi_refill_pools()
125 ubi->free_count++; in ubi_refill_pools()
131 ubi->fm_anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_refill_pools()
132 ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_refill_pools()
137 if (!ubi->free.rb_node) in ubi_refill_pools()
140 e = wl_get_wle(ubi); in ubi_refill_pools()
150 if (!ubi->free.rb_node || in ubi_refill_pools()
151 (ubi->free_count - ubi->beb_rsvd_pebs < 5)) in ubi_refill_pools()
154 e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF); in ubi_refill_pools()
155 self_check_in_wl_tree(ubi, e, &ubi->free); in ubi_refill_pools()
156 rb_erase(&e->u.rb, &ubi->free); in ubi_refill_pools()
157 ubi->free_count--; in ubi_refill_pools()
171 spin_unlock(&ubi->wl_lock); in ubi_refill_pools()
183 static int produce_free_peb(struct ubi_device *ubi) in produce_free_peb() argument
187 while (!ubi->free.rb_node && ubi->works_count) { in produce_free_peb()
189 err = do_work(ubi); in produce_free_peb()
206 int ubi_wl_get_peb(struct ubi_device *ubi) in ubi_wl_get_peb() argument
209 struct ubi_fm_pool *pool = &ubi->fm_pool; in ubi_wl_get_peb()
210 struct ubi_fm_pool *wl_pool = &ubi->fm_wl_pool; in ubi_wl_get_peb()
213 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
214 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
219 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
220 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
221 ret = ubi_update_fastmap(ubi); in ubi_wl_get_peb()
223 ubi_msg(ubi, "Unable to write a new fastmap: %i", ret); in ubi_wl_get_peb()
224 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
227 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
228 spin_lock(&ubi->wl_lock); in ubi_wl_get_peb()
232 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
235 ubi_err(ubi, "Unable to get a free PEB from user WL pool"); in ubi_wl_get_peb()
239 up_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
240 ret = produce_free_peb(ubi); in ubi_wl_get_peb()
242 down_read(&ubi->fm_eba_sem); in ubi_wl_get_peb()
250 prot_queue_add(ubi, ubi->lookuptbl[ret]); in ubi_wl_get_peb()
251 spin_unlock(&ubi->wl_lock); in ubi_wl_get_peb()
260 static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi) in get_peb_for_wl() argument
262 struct ubi_fm_pool *pool = &ubi->fm_wl_pool; in get_peb_for_wl()
265 ubi_assert(rwsem_is_locked(&ubi->fm_eba_sem)); in get_peb_for_wl()
271 if (!ubi->fm_work_scheduled) { in get_peb_for_wl()
272 ubi->fm_work_scheduled = 1; in get_peb_for_wl()
273 schedule_work(&ubi->fm_work); in get_peb_for_wl()
279 return ubi->lookuptbl[pnum]; in get_peb_for_wl()
286 int ubi_ensure_anchor_pebs(struct ubi_device *ubi) in ubi_ensure_anchor_pebs() argument
290 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
293 if (!ubi->fm_next_anchor) { in ubi_ensure_anchor_pebs()
294 ubi->fm_next_anchor = ubi_wl_get_fm_peb(ubi, 1); in ubi_ensure_anchor_pebs()
295 if (!ubi->fm_next_anchor) in ubi_ensure_anchor_pebs()
297 ubi->fm_do_produce_anchor = 1; in ubi_ensure_anchor_pebs()
303 if (ubi->wl_scheduled) { in ubi_ensure_anchor_pebs()
304 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
307 ubi->wl_scheduled = 1; in ubi_ensure_anchor_pebs()
308 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
312 spin_lock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
313 ubi->wl_scheduled = 0; in ubi_ensure_anchor_pebs()
314 spin_unlock(&ubi->wl_lock); in ubi_ensure_anchor_pebs()
319 __schedule_ubi_work(ubi, wrk); in ubi_ensure_anchor_pebs()
333 int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e, in ubi_wl_put_fm_peb() argument
342 ubi_assert(pnum < ubi->peb_count); in ubi_wl_put_fm_peb()
344 spin_lock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
345 e = ubi->lookuptbl[pnum]; in ubi_wl_put_fm_peb()
354 ubi->lookuptbl[pnum] = e; in ubi_wl_put_fm_peb()
357 spin_unlock(&ubi->wl_lock); in ubi_wl_put_fm_peb()
360 return schedule_erase(ubi, e, vol_id, lnum, torture, true); in ubi_wl_put_fm_peb()
372 static void ubi_fastmap_close(struct ubi_device *ubi) in ubi_fastmap_close() argument
376 return_unused_pool_pebs(ubi, &ubi->fm_pool); in ubi_fastmap_close()
377 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); in ubi_fastmap_close()
379 if (ubi->fm_anchor) { in ubi_fastmap_close()
380 return_unused_peb(ubi, ubi->fm_anchor); in ubi_fastmap_close()
381 ubi->fm_anchor = NULL; in ubi_fastmap_close()
384 if (ubi->fm_next_anchor) { in ubi_fastmap_close()
385 return_unused_peb(ubi, ubi->fm_next_anchor); in ubi_fastmap_close()
386 ubi->fm_next_anchor = NULL; in ubi_fastmap_close()
389 if (ubi->fm) { in ubi_fastmap_close()
390 for (i = 0; i < ubi->fm->used_blocks; i++) in ubi_fastmap_close()
391 kfree(ubi->fm->e[i]); in ubi_fastmap_close()
393 kfree(ubi->fm); in ubi_fastmap_close()
404 static struct ubi_wl_entry *may_reserve_for_fm(struct ubi_device *ubi, in may_reserve_for_fm() argument
407 if (e && !ubi->fm_disabled && !ubi->fm && in may_reserve_for_fm()