提交 7086c19d 编写于 作者: A Artem Bityutskiy 提交者: David Woodhouse

mtd: introduce mtd_block_isbad interface

Signed-off-by: NArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: NDavid Woodhouse <David.Woodhouse@intel.com>
上级 ead995f8
...@@ -404,8 +404,7 @@ static int __init init_axis_flash(void) ...@@ -404,8 +404,7 @@ static int __init init_axis_flash(void)
*/ */
int blockstat; int blockstat;
do { do {
blockstat = main_mtd->block_isbad(main_mtd, blockstat = mtd_block_isbad(main_mtd, ptable_sector);
ptable_sector);
if (blockstat < 0) if (blockstat < 0)
ptable_sector = 0; /* read error */ ptable_sector = 0; /* read error */
else if (blockstat) else if (blockstat)
......
...@@ -306,7 +306,8 @@ static int find_boot_record(struct INFTLrecord *inftl) ...@@ -306,7 +306,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
/* If any of the physical eraseblocks are bad, don't /* If any of the physical eraseblocks are bad, don't
use the unit. */ use the unit. */
for (physblock = 0; physblock < inftl->EraseSize; physblock += inftl->mbd.mtd->erasesize) { for (physblock = 0; physblock < inftl->EraseSize; physblock += inftl->mbd.mtd->erasesize) {
if (inftl->mbd.mtd->block_isbad(inftl->mbd.mtd, i * inftl->EraseSize + physblock)) if (mtd_block_isbad(inftl->mbd.mtd,
i * inftl->EraseSize + physblock))
inftl->PUtable[i] = BLOCK_RESERVED; inftl->PUtable[i] = BLOCK_RESERVED;
} }
} }
......
...@@ -886,7 +886,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) ...@@ -886,7 +886,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
if (!mtd->block_isbad) if (!mtd->block_isbad)
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
else else
return mtd->block_isbad(mtd, offs); return mtd_block_isbad(mtd, offs);
break; break;
} }
......
...@@ -667,7 +667,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs) ...@@ -667,7 +667,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
continue; continue;
} }
res = subdev->block_isbad(subdev, ofs); res = mtd_block_isbad(subdev, ofs);
break; break;
} }
......
...@@ -170,7 +170,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work) ...@@ -170,7 +170,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
} }
while (mtd->block_isbad) { while (mtd->block_isbad) {
ret = mtd->block_isbad(mtd, cxt->nextpage * record_size); ret = mtd_block_isbad(mtd, cxt->nextpage * record_size);
if (!ret) if (!ret)
break; break;
if (ret < 0) { if (ret < 0) {
...@@ -254,7 +254,7 @@ static void find_next_position(struct mtdoops_context *cxt) ...@@ -254,7 +254,7 @@ static void find_next_position(struct mtdoops_context *cxt)
for (page = 0; page < cxt->oops_pages; page++) { for (page = 0; page < cxt->oops_pages; page++) {
if (mtd->block_isbad && if (mtd->block_isbad &&
mtd->block_isbad(mtd, page * record_size)) mtd_block_isbad(mtd, page * record_size))
continue; continue;
/* Assume the page is used */ /* Assume the page is used */
mark_page_used(cxt, page); mark_page_used(cxt, page);
......
...@@ -322,7 +322,7 @@ static int part_block_isbad(struct mtd_info *mtd, loff_t ofs) ...@@ -322,7 +322,7 @@ static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
if (ofs >= mtd->size) if (ofs >= mtd->size)
return -EINVAL; return -EINVAL;
ofs += part->offset; ofs += part->offset;
return part->master->block_isbad(part->master, ofs); return mtd_block_isbad(part->master, ofs);
} }
static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
...@@ -553,8 +553,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, ...@@ -553,8 +553,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
uint64_t offs = 0; uint64_t offs = 0;
while (offs < slave->mtd.size) { while (offs < slave->mtd.size) {
if (master->block_isbad(master, if (mtd_block_isbad(master, offs + slave->offset))
offs + slave->offset))
slave->mtd.ecc_stats.badblocks++; slave->mtd.ecc_stats.badblocks++;
offs += slave->mtd.erasesize; offs += slave->mtd.erasesize;
} }
......
...@@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb) ...@@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
offset = mtdswap_eb_offset(d, eb); offset = mtdswap_eb_offset(d, eb);
/* Check first if the block is bad. */ /* Check first if the block is bad. */
if (d->mtd->block_isbad && d->mtd->block_isbad(d->mtd, offset)) if (d->mtd->block_isbad && mtd_block_isbad(d->mtd, offset))
return MTDSWAP_SCANNED_BAD; return MTDSWAP_SCANNED_BAD;
ops.ooblen = 2 * d->mtd->ecclayout->oobavail; ops.ooblen = 2 * d->mtd->ecclayout->oobavail;
...@@ -1061,7 +1061,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size) ...@@ -1061,7 +1061,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size)
if (mtd->block_isbad) if (mtd->block_isbad)
for (offset = 0; offset < size; offset += mtd->erasesize) for (offset = 0; offset < size; offset += mtd->erasesize)
if (mtd->block_isbad(mtd, offset)) if (mtd_block_isbad(mtd, offset))
badcnt++; badcnt++;
return badcnt; return badcnt;
......
...@@ -242,7 +242,8 @@ The new DiskOnChip driver already scanned the bad block table. Just query it. ...@@ -242,7 +242,8 @@ The new DiskOnChip driver already scanned the bad block table. Just query it.
if (buf[i & (SECTORSIZE - 1)] != 0xff) if (buf[i & (SECTORSIZE - 1)] != 0xff)
nftl->ReplUnitTable[i] = BLOCK_RESERVED; nftl->ReplUnitTable[i] = BLOCK_RESERVED;
#endif #endif
if (nftl->mbd.mtd->block_isbad(nftl->mbd.mtd, i * nftl->EraseSize)) if (mtd_block_isbad(nftl->mbd.mtd,
i * nftl->EraseSize))
nftl->ReplUnitTable[i] = BLOCK_RESERVED; nftl->ReplUnitTable[i] = BLOCK_RESERVED;
} }
......
...@@ -79,7 +79,7 @@ static int parse_redboot_partitions(struct mtd_info *master, ...@@ -79,7 +79,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
if ( directory < 0 ) { if ( directory < 0 ) {
offset = master->size + directory * master->erasesize; offset = master->size + directory * master->erasesize;
while (master->block_isbad && while (master->block_isbad &&
master->block_isbad(master, offset)) { mtd_block_isbad(master, offset)) {
if (!offset) { if (!offset) {
nogood: nogood:
printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n"); printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n");
...@@ -90,7 +90,7 @@ static int parse_redboot_partitions(struct mtd_info *master, ...@@ -90,7 +90,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
} else { } else {
offset = directory * master->erasesize; offset = directory * master->erasesize;
while (master->block_isbad && while (master->block_isbad &&
master->block_isbad(master, offset)) { mtd_block_isbad(master, offset)) {
offset += master->erasesize; offset += master->erasesize;
if (offset == master->size) if (offset == master->size)
goto nogood; goto nogood;
......
...@@ -122,7 +122,7 @@ static int get_valid_cis_sector(struct mtd_info *mtd) ...@@ -122,7 +122,7 @@ static int get_valid_cis_sector(struct mtd_info *mtd)
* is not SSFDC formatted * is not SSFDC formatted
*/ */
for (k = 0, offset = 0; k < 4; k++, offset += mtd->erasesize) { for (k = 0, offset = 0; k < 4; k++, offset += mtd->erasesize) {
if (!mtd->block_isbad(mtd, offset)) { if (mtd_block_isbad(mtd, offset)) {
ret = mtd_read(mtd, offset, SECTOR_SIZE, &retlen, ret = mtd_read(mtd, offset, SECTOR_SIZE, &retlen,
sect_buf); sect_buf);
...@@ -255,7 +255,7 @@ static int build_logical_block_map(struct ssfdcr_record *ssfdc) ...@@ -255,7 +255,7 @@ static int build_logical_block_map(struct ssfdcr_record *ssfdc)
for (phys_block = ssfdc->cis_block + 1; phys_block < ssfdc->map_len; for (phys_block = ssfdc->cis_block + 1; phys_block < ssfdc->map_len;
phys_block++) { phys_block++) {
offset = (unsigned long)phys_block * ssfdc->erase_size; offset = (unsigned long)phys_block * ssfdc->erase_size;
if (mtd->block_isbad(mtd, offset)) if (mtd_block_isbad(mtd, offset))
continue; /* skip bad blocks */ continue; /* skip bad blocks */
ret = read_raw_oob(mtd, offset, oob_buf); ret = read_raw_oob(mtd, offset, oob_buf);
......
...@@ -329,7 +329,7 @@ static int is_block_bad(int ebnum) ...@@ -329,7 +329,7 @@ static int is_block_bad(int ebnum)
int ret; int ret;
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
ret = mtd->block_isbad(mtd, addr); ret = mtd_block_isbad(mtd, addr);
if (ret) if (ret)
printk(PRINT_PREF "block %d is bad\n", ebnum); printk(PRINT_PREF "block %d is bad\n", ebnum);
return ret; return ret;
......
...@@ -469,7 +469,7 @@ static int is_block_bad(int ebnum) ...@@ -469,7 +469,7 @@ static int is_block_bad(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
int ret; int ret;
ret = mtd->block_isbad(mtd, addr); ret = mtd_block_isbad(mtd, addr);
if (ret) if (ret)
printk(PRINT_PREF "block %d is bad\n", ebnum); printk(PRINT_PREF "block %d is bad\n", ebnum);
return ret; return ret;
......
...@@ -132,7 +132,7 @@ static int is_block_bad(int ebnum) ...@@ -132,7 +132,7 @@ static int is_block_bad(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
int ret; int ret;
ret = mtd->block_isbad(mtd, addr); ret = mtd_block_isbad(mtd, addr);
if (ret) if (ret)
printk(PRINT_PREF "block %d is bad\n", ebnum); printk(PRINT_PREF "block %d is bad\n", ebnum);
return ret; return ret;
......
...@@ -296,7 +296,7 @@ static int is_block_bad(int ebnum) ...@@ -296,7 +296,7 @@ static int is_block_bad(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
int ret; int ret;
ret = mtd->block_isbad(mtd, addr); ret = mtd_block_isbad(mtd, addr);
if (ret) if (ret)
printk(PRINT_PREF "block %d is bad\n", ebnum); printk(PRINT_PREF "block %d is bad\n", ebnum);
return ret; return ret;
......
...@@ -132,7 +132,7 @@ static int is_block_bad(int ebnum) ...@@ -132,7 +132,7 @@ static int is_block_bad(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
int ret; int ret;
ret = mtd->block_isbad(mtd, addr); ret = mtd_block_isbad(mtd, addr);
if (ret) if (ret)
printk(PRINT_PREF "block %d is bad\n", ebnum); printk(PRINT_PREF "block %d is bad\n", ebnum);
return ret; return ret;
......
...@@ -344,7 +344,7 @@ static int is_block_bad(int ebnum) ...@@ -344,7 +344,7 @@ static int is_block_bad(int ebnum)
loff_t addr = ebnum * mtd->erasesize; loff_t addr = ebnum * mtd->erasesize;
int ret; int ret;
ret = mtd->block_isbad(mtd, addr); ret = mtd_block_isbad(mtd, addr);
if (ret) if (ret)
printk(PRINT_PREF "block %d is bad\n", ebnum); printk(PRINT_PREF "block %d is bad\n", ebnum);
return ret; return ret;
......
...@@ -292,8 +292,7 @@ static int __init tort_init(void) ...@@ -292,8 +292,7 @@ static int __init tort_init(void)
memset(&bad_ebs[0], 0, sizeof(int) * ebcnt); memset(&bad_ebs[0], 0, sizeof(int) * ebcnt);
if (mtd->block_isbad) { if (mtd->block_isbad) {
for (i = eb; i < eb + ebcnt; i++) { for (i = eb; i < eb + ebcnt; i++) {
err = mtd->block_isbad(mtd, err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize);
(loff_t)i * mtd->erasesize);
if (err < 0) { if (err < 0) {
printk(PRINT_PREF "block_isbad() returned %d " printk(PRINT_PREF "block_isbad() returned %d "
......
...@@ -634,7 +634,7 @@ int ubi_io_is_bad(const struct ubi_device *ubi, int pnum) ...@@ -634,7 +634,7 @@ int ubi_io_is_bad(const struct ubi_device *ubi, int pnum)
if (ubi->bad_allowed) { if (ubi->bad_allowed) {
int ret; int ret;
ret = mtd->block_isbad(mtd, (loff_t)pnum * ubi->peb_size); ret = mtd_block_isbad(mtd, (loff_t)pnum * ubi->peb_size);
if (ret < 0) if (ret < 0)
ubi_err("error %d while checking if PEB %d is bad", ubi_err("error %d while checking if PEB %d is bad",
ret, pnum); ret, pnum);
......
...@@ -455,7 +455,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo ...@@ -455,7 +455,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
if (jffs2_cleanmarker_oob(c)) { if (jffs2_cleanmarker_oob(c)) {
int ret; int ret;
if (c->mtd->block_isbad(c->mtd, jeb->offset)) if (mtd_block_isbad(c->mtd, jeb->offset))
return BLK_STATE_BADBLOCK; return BLK_STATE_BADBLOCK;
ret = jffs2_check_nand_cleanmarker(c, jeb); ret = jffs2_check_nand_cleanmarker(c, jeb);
......
...@@ -157,7 +157,7 @@ static struct page *logfs_mtd_find_first_sb(struct super_block *sb, u64 *ofs) ...@@ -157,7 +157,7 @@ static struct page *logfs_mtd_find_first_sb(struct super_block *sb, u64 *ofs)
return NULL; return NULL;
*ofs = 0; *ofs = 0;
while (mtd->block_isbad(mtd, *ofs)) { while (mtd_block_isbad(mtd, *ofs)) {
*ofs += mtd->erasesize; *ofs += mtd->erasesize;
if (*ofs >= mtd->size) if (*ofs >= mtd->size)
return NULL; return NULL;
...@@ -177,7 +177,7 @@ static struct page *logfs_mtd_find_last_sb(struct super_block *sb, u64 *ofs) ...@@ -177,7 +177,7 @@ static struct page *logfs_mtd_find_last_sb(struct super_block *sb, u64 *ofs)
return NULL; return NULL;
*ofs = mtd->size - mtd->erasesize; *ofs = mtd->size - mtd->erasesize;
while (mtd->block_isbad(mtd, *ofs)) { while (mtd_block_isbad(mtd, *ofs)) {
*ofs -= mtd->erasesize; *ofs -= mtd->erasesize;
if (*ofs <= 0) if (*ofs <= 0)
return NULL; return NULL;
......
...@@ -210,6 +210,7 @@ struct mtd_info { ...@@ -210,6 +210,7 @@ struct mtd_info {
int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
int (*suspend) (struct mtd_info *mtd); int (*suspend) (struct mtd_info *mtd);
void (*resume) (struct mtd_info *mtd); void (*resume) (struct mtd_info *mtd);
...@@ -219,7 +220,6 @@ struct mtd_info { ...@@ -219,7 +220,6 @@ struct mtd_info {
struct backing_dev_info *backing_dev_info; struct backing_dev_info *backing_dev_info;
/* Bad block management functions */ /* Bad block management functions */
int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
int (*block_markbad) (struct mtd_info *mtd, loff_t ofs); int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
struct notifier_block reboot_notifier; /* default mode before reboot */ struct notifier_block reboot_notifier; /* default mode before reboot */
...@@ -406,6 +406,11 @@ static inline void mtd_resume(struct mtd_info *mtd) ...@@ -406,6 +406,11 @@ static inline void mtd_resume(struct mtd_info *mtd)
mtd->resume(mtd); mtd->resume(mtd);
} }
static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
{
return mtd->block_isbad(mtd, ofs);
}
static inline struct mtd_info *dev_to_mtd(struct device *dev) static inline struct mtd_info *dev_to_mtd(struct device *dev)
{ {
return dev ? dev_get_drvdata(dev) : NULL; return dev ? dev_get_drvdata(dev) : NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册