aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/wl.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/wl.c')
-rw-r--r--drivers/mtd/ubi/wl.c80
1 files changed, 42 insertions, 38 deletions
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 6654f191868e..834f6fe1f5fa 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -253,7 +253,7 @@ static int do_work(struct ubi_device *ubi)
253 */ 253 */
254 err = wrk->func(ubi, wrk, 0); 254 err = wrk->func(ubi, wrk, 0);
255 if (err) 255 if (err)
256 ubi_err("work failed with error code %d", err); 256 ubi_err(ubi, "work failed with error code %d", err);
257 up_read(&ubi->work_sem); 257 up_read(&ubi->work_sem);
258 258
259 return err; 259 return err;
@@ -470,8 +470,11 @@ struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
470{ 470{
471 struct ubi_wl_entry *e = NULL; 471 struct ubi_wl_entry *e = NULL;
472 472
473 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) 473 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) {
474 ubi_warn(ubi, "Can't get peb for fastmap:anchor=%d, free_cnt=%d, reserved=%d",
475 anchor, ubi->free_count, ubi->beb_rsvd_pebs);
474 goto out; 476 goto out;
477 }
475 478
476 if (anchor) 479 if (anchor)
477 e = find_anchor_wl_entry(&ubi->free); 480 e = find_anchor_wl_entry(&ubi->free);
@@ -507,7 +510,7 @@ static int __wl_get_peb(struct ubi_device *ubi)
507retry: 510retry:
508 if (!ubi->free.rb_node) { 511 if (!ubi->free.rb_node) {
509 if (ubi->works_count == 0) { 512 if (ubi->works_count == 0) {
510 ubi_err("no free eraseblocks"); 513 ubi_err(ubi, "no free eraseblocks");
511 ubi_assert(list_empty(&ubi->works)); 514 ubi_assert(list_empty(&ubi->works));
512 return -ENOSPC; 515 return -ENOSPC;
513 } 516 }
@@ -520,7 +523,7 @@ retry:
520 523
521 e = find_mean_wl_entry(ubi, &ubi->free); 524 e = find_mean_wl_entry(ubi, &ubi->free);
522 if (!e) { 525 if (!e) {
523 ubi_err("no free eraseblocks"); 526 ubi_err(ubi, "no free eraseblocks");
524 return -ENOSPC; 527 return -ENOSPC;
525 } 528 }
526 529
@@ -692,7 +695,8 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
692 err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset, 695 err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset,
693 ubi->peb_size - ubi->vid_hdr_aloffset); 696 ubi->peb_size - ubi->vid_hdr_aloffset);
694 if (err) { 697 if (err) {
695 ubi_err("new PEB %d does not contain all 0xFF bytes", peb); 698 ubi_err(ubi, "new PEB %d does not contain all 0xFF bytes",
699 peb);
696 return err; 700 return err;
697 } 701 }
698 702
@@ -760,7 +764,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
760 * Erase counter overflow. Upgrade UBI and use 64-bit 764 * Erase counter overflow. Upgrade UBI and use 64-bit
761 * erase counters internally. 765 * erase counters internally.
762 */ 766 */
763 ubi_err("erase counter overflow at PEB %d, EC %llu", 767 ubi_err(ubi, "erase counter overflow at PEB %d, EC %llu",
764 e->pnum, ec); 768 e->pnum, ec);
765 err = -EINVAL; 769 err = -EINVAL;
766 goto out_free; 770 goto out_free;
@@ -1137,7 +1141,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1137 goto out_not_moved; 1141 goto out_not_moved;
1138 } 1142 }
1139 1143
1140 ubi_err("error %d while reading VID header from PEB %d", 1144 ubi_err(ubi, "error %d while reading VID header from PEB %d",
1141 err, e1->pnum); 1145 err, e1->pnum);
1142 goto out_error; 1146 goto out_error;
1143 } 1147 }
@@ -1181,7 +1185,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1181 * UBI from trying to move it over and over again. 1185 * UBI from trying to move it over and over again.
1182 */ 1186 */
1183 if (ubi->erroneous_peb_count > ubi->max_erroneous) { 1187 if (ubi->erroneous_peb_count > ubi->max_erroneous) {
1184 ubi_err("too many erroneous eraseblocks (%d)", 1188 ubi_err(ubi, "too many erroneous eraseblocks (%d)",
1185 ubi->erroneous_peb_count); 1189 ubi->erroneous_peb_count);
1186 goto out_error; 1190 goto out_error;
1187 } 1191 }
@@ -1197,7 +1201,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1197 1201
1198 /* The PEB has been successfully moved */ 1202 /* The PEB has been successfully moved */
1199 if (scrubbing) 1203 if (scrubbing)
1200 ubi_msg("scrubbed PEB %d (LEB %d:%d), data moved to PEB %d", 1204 ubi_msg(ubi, "scrubbed PEB %d (LEB %d:%d), data moved to PEB %d",
1201 e1->pnum, vol_id, lnum, e2->pnum); 1205 e1->pnum, vol_id, lnum, e2->pnum);
1202 ubi_free_vid_hdr(ubi, vid_hdr); 1206 ubi_free_vid_hdr(ubi, vid_hdr);
1203 1207
@@ -1212,7 +1216,6 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1212 1216
1213 err = do_sync_erase(ubi, e1, vol_id, lnum, 0); 1217 err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
1214 if (err) { 1218 if (err) {
1215 kmem_cache_free(ubi_wl_entry_slab, e1);
1216 if (e2) 1219 if (e2)
1217 kmem_cache_free(ubi_wl_entry_slab, e2); 1220 kmem_cache_free(ubi_wl_entry_slab, e2);
1218 goto out_ro; 1221 goto out_ro;
@@ -1226,10 +1229,8 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1226 dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase", 1229 dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase",
1227 e2->pnum, vol_id, lnum); 1230 e2->pnum, vol_id, lnum);
1228 err = do_sync_erase(ubi, e2, vol_id, lnum, 0); 1231 err = do_sync_erase(ubi, e2, vol_id, lnum, 0);
1229 if (err) { 1232 if (err)
1230 kmem_cache_free(ubi_wl_entry_slab, e2);
1231 goto out_ro; 1233 goto out_ro;
1232 }
1233 } 1234 }
1234 1235
1235 dbg_wl("done"); 1236 dbg_wl("done");
@@ -1265,19 +1266,18 @@ out_not_moved:
1265 1266
1266 ubi_free_vid_hdr(ubi, vid_hdr); 1267 ubi_free_vid_hdr(ubi, vid_hdr);
1267 err = do_sync_erase(ubi, e2, vol_id, lnum, torture); 1268 err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
1268 if (err) { 1269 if (err)
1269 kmem_cache_free(ubi_wl_entry_slab, e2);
1270 goto out_ro; 1270 goto out_ro;
1271 } 1271
1272 mutex_unlock(&ubi->move_mutex); 1272 mutex_unlock(&ubi->move_mutex);
1273 return 0; 1273 return 0;
1274 1274
1275out_error: 1275out_error:
1276 if (vol_id != -1) 1276 if (vol_id != -1)
1277 ubi_err("error %d while moving PEB %d to PEB %d", 1277 ubi_err(ubi, "error %d while moving PEB %d to PEB %d",
1278 err, e1->pnum, e2->pnum); 1278 err, e1->pnum, e2->pnum);
1279 else 1279 else
1280 ubi_err("error %d while moving PEB %d (LEB %d:%d) to PEB %d", 1280 ubi_err(ubi, "error %d while moving PEB %d (LEB %d:%d) to PEB %d",
1281 err, e1->pnum, vol_id, lnum, e2->pnum); 1281 err, e1->pnum, vol_id, lnum, e2->pnum);
1282 spin_lock(&ubi->wl_lock); 1282 spin_lock(&ubi->wl_lock);
1283 ubi->move_from = ubi->move_to = NULL; 1283 ubi->move_from = ubi->move_to = NULL;
@@ -1458,7 +1458,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1458 return err; 1458 return err;
1459 } 1459 }
1460 1460
1461 ubi_err("failed to erase PEB %d, error %d", pnum, err); 1461 ubi_err(ubi, "failed to erase PEB %d, error %d", pnum, err);
1462 kfree(wl_wrk); 1462 kfree(wl_wrk);
1463 1463
1464 if (err == -EINTR || err == -ENOMEM || err == -EAGAIN || 1464 if (err == -EINTR || err == -ENOMEM || err == -EAGAIN ||
@@ -1486,7 +1486,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1486 /* It is %-EIO, the PEB went bad */ 1486 /* It is %-EIO, the PEB went bad */
1487 1487
1488 if (!ubi->bad_allowed) { 1488 if (!ubi->bad_allowed) {
1489 ubi_err("bad physical eraseblock %d detected", pnum); 1489 ubi_err(ubi, "bad physical eraseblock %d detected", pnum);
1490 goto out_ro; 1490 goto out_ro;
1491 } 1491 }
1492 1492
@@ -1494,7 +1494,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1494 if (ubi->beb_rsvd_pebs == 0) { 1494 if (ubi->beb_rsvd_pebs == 0) {
1495 if (ubi->avail_pebs == 0) { 1495 if (ubi->avail_pebs == 0) {
1496 spin_unlock(&ubi->volumes_lock); 1496 spin_unlock(&ubi->volumes_lock);
1497 ubi_err("no reserved/available physical eraseblocks"); 1497 ubi_err(ubi, "no reserved/available physical eraseblocks");
1498 goto out_ro; 1498 goto out_ro;
1499 } 1499 }
1500 ubi->avail_pebs -= 1; 1500 ubi->avail_pebs -= 1;
@@ -1502,7 +1502,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1502 } 1502 }
1503 spin_unlock(&ubi->volumes_lock); 1503 spin_unlock(&ubi->volumes_lock);
1504 1504
1505 ubi_msg("mark PEB %d as bad", pnum); 1505 ubi_msg(ubi, "mark PEB %d as bad", pnum);
1506 err = ubi_io_mark_bad(ubi, pnum); 1506 err = ubi_io_mark_bad(ubi, pnum);
1507 if (err) 1507 if (err)
1508 goto out_ro; 1508 goto out_ro;
@@ -1523,11 +1523,12 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1523 ubi->good_peb_count -= 1; 1523 ubi->good_peb_count -= 1;
1524 ubi_calculate_reserved(ubi); 1524 ubi_calculate_reserved(ubi);
1525 if (available_consumed) 1525 if (available_consumed)
1526 ubi_warn("no PEBs in the reserved pool, used an available PEB"); 1526 ubi_warn(ubi, "no PEBs in the reserved pool, used an available PEB");
1527 else if (ubi->beb_rsvd_pebs) 1527 else if (ubi->beb_rsvd_pebs)
1528 ubi_msg("%d PEBs left in the reserve", ubi->beb_rsvd_pebs); 1528 ubi_msg(ubi, "%d PEBs left in the reserve",
1529 ubi->beb_rsvd_pebs);
1529 else 1530 else
1530 ubi_warn("last PEB from the reserve was used"); 1531 ubi_warn(ubi, "last PEB from the reserve was used");
1531 spin_unlock(&ubi->volumes_lock); 1532 spin_unlock(&ubi->volumes_lock);
1532 1533
1533 return err; 1534 return err;
@@ -1613,7 +1614,7 @@ retry:
1613 } else { 1614 } else {
1614 err = prot_queue_del(ubi, e->pnum); 1615 err = prot_queue_del(ubi, e->pnum);
1615 if (err) { 1616 if (err) {
1616 ubi_err("PEB %d not found", pnum); 1617 ubi_err(ubi, "PEB %d not found", pnum);
1617 ubi_ro_mode(ubi); 1618 ubi_ro_mode(ubi);
1618 spin_unlock(&ubi->wl_lock); 1619 spin_unlock(&ubi->wl_lock);
1619 return err; 1620 return err;
@@ -1646,7 +1647,7 @@ int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum)
1646{ 1647{
1647 struct ubi_wl_entry *e; 1648 struct ubi_wl_entry *e;
1648 1649
1649 ubi_msg("schedule PEB %d for scrubbing", pnum); 1650 ubi_msg(ubi, "schedule PEB %d for scrubbing", pnum);
1650 1651
1651retry: 1652retry:
1652 spin_lock(&ubi->wl_lock); 1653 spin_lock(&ubi->wl_lock);
@@ -1678,7 +1679,7 @@ retry:
1678 1679
1679 err = prot_queue_del(ubi, e->pnum); 1680 err = prot_queue_del(ubi, e->pnum);
1680 if (err) { 1681 if (err) {
1681 ubi_err("PEB %d not found", pnum); 1682 ubi_err(ubi, "PEB %d not found", pnum);
1682 ubi_ro_mode(ubi); 1683 ubi_ro_mode(ubi);
1683 spin_unlock(&ubi->wl_lock); 1684 spin_unlock(&ubi->wl_lock);
1684 return err; 1685 return err;
@@ -1798,15 +1799,18 @@ int ubi_thread(void *u)
1798 int failures = 0; 1799 int failures = 0;
1799 struct ubi_device *ubi = u; 1800 struct ubi_device *ubi = u;
1800 1801
1801 ubi_msg("background thread \"%s\" started, PID %d", 1802 ubi_msg(ubi, "background thread \"%s\" started, PID %d",
1802 ubi->bgt_name, task_pid_nr(current)); 1803 ubi->bgt_name, task_pid_nr(current));
1803 1804
1804 set_freezable(); 1805 set_freezable();
1805 for (;;) { 1806 for (;;) {
1806 int err; 1807 int err;
1807 1808
1808 if (kthread_should_stop()) 1809 if (kthread_should_stop()) {
1810 ubi_msg(ubi, "background thread \"%s\" should stop, PID %d",
1811 ubi->bgt_name, task_pid_nr(current));
1809 break; 1812 break;
1813 }
1810 1814
1811 if (try_to_freeze()) 1815 if (try_to_freeze())
1812 continue; 1816 continue;
@@ -1823,14 +1827,14 @@ int ubi_thread(void *u)
1823 1827
1824 err = do_work(ubi); 1828 err = do_work(ubi);
1825 if (err) { 1829 if (err) {
1826 ubi_err("%s: work failed with error code %d", 1830 ubi_err(ubi, "%s: work failed with error code %d",
1827 ubi->bgt_name, err); 1831 ubi->bgt_name, err);
1828 if (failures++ > WL_MAX_FAILURES) { 1832 if (failures++ > WL_MAX_FAILURES) {
1829 /* 1833 /*
1830 * Too many failures, disable the thread and 1834 * Too many failures, disable the thread and
1831 * switch to read-only mode. 1835 * switch to read-only mode.
1832 */ 1836 */
1833 ubi_msg("%s: %d consecutive failures", 1837 ubi_msg(ubi, "%s: %d consecutive failures",
1834 ubi->bgt_name, WL_MAX_FAILURES); 1838 ubi->bgt_name, WL_MAX_FAILURES);
1835 ubi_ro_mode(ubi); 1839 ubi_ro_mode(ubi);
1836 ubi->thread_enabled = 0; 1840 ubi->thread_enabled = 0;
@@ -1981,10 +1985,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1981#endif 1985#endif
1982 1986
1983 if (ubi->avail_pebs < reserved_pebs) { 1987 if (ubi->avail_pebs < reserved_pebs) {
1984 ubi_err("no enough physical eraseblocks (%d, need %d)", 1988 ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)",
1985 ubi->avail_pebs, reserved_pebs); 1989 ubi->avail_pebs, reserved_pebs);
1986 if (ubi->corr_peb_count) 1990 if (ubi->corr_peb_count)
1987 ubi_err("%d PEBs are corrupted and not used", 1991 ubi_err(ubi, "%d PEBs are corrupted and not used",
1988 ubi->corr_peb_count); 1992 ubi->corr_peb_count);
1989 goto out_free; 1993 goto out_free;
1990 } 1994 }
@@ -2072,8 +2076,8 @@ static int self_check_ec(struct ubi_device *ubi, int pnum, int ec)
2072 2076
2073 read_ec = be64_to_cpu(ec_hdr->ec); 2077 read_ec = be64_to_cpu(ec_hdr->ec);
2074 if (ec != read_ec && read_ec - ec > 1) { 2078 if (ec != read_ec && read_ec - ec > 1) {
2075 ubi_err("self-check failed for PEB %d", pnum); 2079 ubi_err(ubi, "self-check failed for PEB %d", pnum);
2076 ubi_err("read EC is %lld, should be %d", read_ec, ec); 2080 ubi_err(ubi, "read EC is %lld, should be %d", read_ec, ec);
2077 dump_stack(); 2081 dump_stack();
2078 err = 1; 2082 err = 1;
2079 } else 2083 } else
@@ -2102,7 +2106,7 @@ static int self_check_in_wl_tree(const struct ubi_device *ubi,
2102 if (in_wl_tree(e, root)) 2106 if (in_wl_tree(e, root))
2103 return 0; 2107 return 0;
2104 2108
2105 ubi_err("self-check failed for PEB %d, EC %d, RB-tree %p ", 2109 ubi_err(ubi, "self-check failed for PEB %d, EC %d, RB-tree %p ",
2106 e->pnum, e->ec, root); 2110 e->pnum, e->ec, root);
2107 dump_stack(); 2111 dump_stack();
2108 return -EINVAL; 2112 return -EINVAL;
@@ -2130,7 +2134,7 @@ static int self_check_in_pq(const struct ubi_device *ubi,
2130 if (p == e) 2134 if (p == e)
2131 return 0; 2135 return 0;
2132 2136
2133 ubi_err("self-check failed for PEB %d, EC %d, Protect queue", 2137 ubi_err(ubi, "self-check failed for PEB %d, EC %d, Protect queue",
2134 e->pnum, e->ec); 2138 e->pnum, e->ec);
2135 dump_stack(); 2139 dump_stack();
2136 return -EINVAL; 2140 return -EINVAL;