Lines Matching refs:pnum
87 static int self_check_not_bad(const struct ubi_device *ubi, int pnum);
88 static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum);
89 static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum,
91 static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum);
92 static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum,
94 static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum,
119 int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, in ubi_io_read() argument
126 dbg_io("read %d bytes from PEB %d:%d", len, pnum, offset); in ubi_io_read()
128 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_read()
132 err = self_check_not_bad(ubi, pnum); in ubi_io_read()
158 addr = (loff_t)pnum * ubi->peb_size + offset; in ubi_io_read()
174 pnum); in ubi_io_read()
181 err, errstr, len, pnum, offset, read); in ubi_io_read()
187 err, errstr, len, pnum, offset, read); in ubi_io_read()
228 int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, in ubi_io_write() argument
235 dbg_io("write %d bytes to PEB %d:%d", len, pnum, offset); in ubi_io_write()
237 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_write()
247 err = self_check_not_bad(ubi, pnum); in ubi_io_write()
252 err = ubi_self_check_all_ff(ubi, pnum, offset, len); in ubi_io_write()
261 err = self_check_peb_ec_hdr(ubi, pnum); in ubi_io_write()
264 err = self_check_peb_vid_hdr(ubi, pnum); in ubi_io_write()
271 len, pnum, offset); in ubi_io_write()
276 addr = (loff_t)pnum * ubi->peb_size + offset; in ubi_io_write()
280 err, len, pnum, offset, written); in ubi_io_write()
282 ubi_dump_flash(ubi, pnum, offset, len); in ubi_io_write()
287 err = self_check_write(ubi, buf, pnum, offset, len); in ubi_io_write()
298 err = ubi_self_check_all_ff(ubi, pnum, offset, len); in ubi_io_write()
325 static int do_sync_erase(struct ubi_device *ubi, int pnum) in do_sync_erase() argument
331 dbg_io("erase PEB %d", pnum); in do_sync_erase()
332 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in do_sync_erase()
344 ei.addr = (loff_t)pnum * ubi->peb_size; in do_sync_erase()
353 err, pnum); in do_sync_erase()
357 ubi_err(ubi, "cannot erase PEB %d, error %d", pnum, err); in do_sync_erase()
365 ubi_err(ubi, "interrupted PEB %d erasure", pnum); in do_sync_erase()
372 pnum); in do_sync_erase()
376 ubi_err(ubi, "cannot erase PEB %d", pnum); in do_sync_erase()
381 err = ubi_self_check_all_ff(ubi, pnum, 0, ubi->peb_size); in do_sync_erase()
386 ubi_err(ubi, "cannot erase PEB %d (emulated)", pnum); in do_sync_erase()
405 static int torture_peb(struct ubi_device *ubi, int pnum) in torture_peb() argument
409 ubi_msg(ubi, "run torture test for PEB %d", pnum); in torture_peb()
415 err = do_sync_erase(ubi, pnum); in torture_peb()
420 err = ubi_io_read(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size); in torture_peb()
427 pnum); in torture_peb()
434 err = ubi_io_write(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size); in torture_peb()
439 err = ubi_io_read(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size); in torture_peb()
447 patterns[i], pnum); in torture_peb()
454 ubi_msg(ubi, "PEB %d passed torture test, do not mark it as bad", pnum); in torture_peb()
465 pnum); in torture_peb()
491 static int nor_erase_prepare(struct ubi_device *ubi, int pnum) in nor_erase_prepare() argument
515 addr = (loff_t)pnum * ubi->peb_size; in nor_erase_prepare()
516 err = ubi_io_read_ec_hdr(ubi, pnum, &ec_hdr, 0); in nor_erase_prepare()
524 err = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); in nor_erase_prepare()
540 ubi_err(ubi, "cannot invalidate PEB %d, write returned %d", pnum, err); in nor_erase_prepare()
541 ubi_dump_flash(ubi, pnum, 0, ubi->peb_size); in nor_erase_prepare()
561 int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) in ubi_io_sync_erase() argument
565 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_sync_erase()
567 err = self_check_not_bad(ubi, pnum); in ubi_io_sync_erase()
577 err = nor_erase_prepare(ubi, pnum); in ubi_io_sync_erase()
583 ret = torture_peb(ubi, pnum); in ubi_io_sync_erase()
588 err = do_sync_erase(ubi, pnum); in ubi_io_sync_erase()
603 int ubi_io_is_bad(const struct ubi_device *ubi, int pnum) in ubi_io_is_bad() argument
607 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_is_bad()
612 ret = mtd_block_isbad(mtd, (loff_t)pnum * ubi->peb_size); in ubi_io_is_bad()
615 ret, pnum); in ubi_io_is_bad()
617 dbg_io("PEB %d is bad", pnum); in ubi_io_is_bad()
632 int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum) in ubi_io_mark_bad() argument
637 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_mark_bad()
647 err = mtd_block_markbad(mtd, (loff_t)pnum * ubi->peb_size); in ubi_io_mark_bad()
649 ubi_err(ubi, "cannot mark PEB %d bad, error %d", pnum, err); in ubi_io_mark_bad()
725 int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, in ubi_io_read_ec_hdr() argument
731 dbg_io("read EC header from PEB %d", pnum); in ubi_io_read_ec_hdr()
732 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_read_ec_hdr()
734 read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); in ubi_io_read_ec_hdr()
764 pnum); in ubi_io_read_ec_hdr()
766 pnum); in ubi_io_read_ec_hdr()
779 pnum, magic, UBI_EC_HDR_MAGIC); in ubi_io_read_ec_hdr()
783 pnum, magic, UBI_EC_HDR_MAGIC); in ubi_io_read_ec_hdr()
793 pnum, crc, hdr_crc); in ubi_io_read_ec_hdr()
797 pnum, crc, hdr_crc); in ubi_io_read_ec_hdr()
808 ubi_err(ubi, "validation failed for PEB %d", pnum); in ubi_io_read_ec_hdr()
834 int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum, in ubi_io_write_ec_hdr() argument
840 dbg_io("write EC header to PEB %d", pnum); in ubi_io_write_ec_hdr()
841 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_write_ec_hdr()
851 err = self_check_ec_hdr(ubi, pnum, ec_hdr); in ubi_io_write_ec_hdr()
858 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); in ubi_io_write_ec_hdr()
998 int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, in ubi_io_read_vid_hdr() argument
1005 dbg_io("read VID header from PEB %d", pnum); in ubi_io_read_vid_hdr()
1006 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_read_vid_hdr()
1009 read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, in ubi_io_read_vid_hdr()
1022 pnum); in ubi_io_read_vid_hdr()
1024 pnum); in ubi_io_read_vid_hdr()
1033 pnum, magic, UBI_VID_HDR_MAGIC); in ubi_io_read_vid_hdr()
1037 pnum, magic, UBI_VID_HDR_MAGIC); in ubi_io_read_vid_hdr()
1047 pnum, crc, hdr_crc); in ubi_io_read_vid_hdr()
1051 pnum, crc, hdr_crc); in ubi_io_read_vid_hdr()
1060 ubi_err(ubi, "validation failed for PEB %d", pnum); in ubi_io_read_vid_hdr()
1082 int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, in ubi_io_write_vid_hdr() argument
1089 dbg_io("write VID header to PEB %d", pnum); in ubi_io_write_vid_hdr()
1090 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); in ubi_io_write_vid_hdr()
1092 err = self_check_peb_ec_hdr(ubi, pnum); in ubi_io_write_vid_hdr()
1101 err = self_check_vid_hdr(ubi, pnum, vid_hdr); in ubi_io_write_vid_hdr()
1109 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, in ubi_io_write_vid_hdr()
1122 static int self_check_not_bad(const struct ubi_device *ubi, int pnum) in self_check_not_bad() argument
1129 err = ubi_io_is_bad(ubi, pnum); in self_check_not_bad()
1133 ubi_err(ubi, "self-check failed for PEB %d", pnum); in self_check_not_bad()
1147 static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum, in self_check_ec_hdr() argument
1165 ubi_err(ubi, "self-check failed for PEB %d", pnum); in self_check_ec_hdr()
1185 static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) in self_check_peb_ec_hdr() argument
1198 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); in self_check_peb_ec_hdr()
1207 ubi_err(ubi, "self-check failed for PEB %d", pnum); in self_check_peb_ec_hdr()
1214 err = self_check_ec_hdr(ubi, pnum, ec_hdr); in self_check_peb_ec_hdr()
1230 static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum, in self_check_vid_hdr() argument
1242 magic, pnum, UBI_VID_HDR_MAGIC); in self_check_vid_hdr()
1248 ubi_err(ubi, "self-check failed for PEB %d", pnum); in self_check_vid_hdr()
1255 ubi_err(ubi, "self-check failed for PEB %d", pnum); in self_check_vid_hdr()
1270 static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) in self_check_peb_vid_hdr() argument
1285 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, in self_check_peb_vid_hdr()
1294 pnum, crc, hdr_crc); in self_check_peb_vid_hdr()
1295 ubi_err(ubi, "self-check failed for PEB %d", pnum); in self_check_peb_vid_hdr()
1302 err = self_check_vid_hdr(ubi, pnum, vid_hdr); in self_check_peb_vid_hdr()
1321 static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum, in self_check_write() argument
1327 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; in self_check_write()
1353 pnum, offset, len); in self_check_write()
1387 int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) in ubi_self_check_all_ff() argument
1392 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; in ubi_self_check_all_ff()
1406 err, len, pnum, offset, read); in ubi_self_check_all_ff()
1413 pnum, offset, len); in ubi_self_check_all_ff()
1421 ubi_err(ubi, "self-check failed for PEB %d", pnum); in ubi_self_check_all_ff()