Commit a2cc5ba0 authored by Artem Bityutskiy's avatar Artem Bityutskiy Committed by David Woodhouse

mtd: introduce mtd_write_oob interface

Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent fd2819bb
...@@ -178,7 +178,7 @@ int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, ...@@ -178,7 +178,7 @@ int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
ops.oobbuf = buf; ops.oobbuf = buf;
ops.datbuf = NULL; ops.datbuf = NULL;
res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); res = mtd_write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
*retlen = ops.oobretlen; *retlen = ops.oobretlen;
return res; return res;
} }
...@@ -199,7 +199,7 @@ static int inftl_write(struct mtd_info *mtd, loff_t offs, size_t len, ...@@ -199,7 +199,7 @@ static int inftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
ops.datbuf = buf; ops.datbuf = buf;
ops.len = len; ops.len = len;
res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); res = mtd_write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
*retlen = ops.retlen; *retlen = ops.retlen;
return res; return res;
} }
......
...@@ -325,7 +325,7 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c ...@@ -325,7 +325,7 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c
ops.ooboffs = 0; ops.ooboffs = 0;
ops.len = len; ops.len = len;
ret = mtd->write_oob(mtd, *ppos, &ops); ret = mtd_write_oob(mtd, *ppos, &ops);
retlen = ops.retlen; retlen = ops.retlen;
break; break;
} }
...@@ -426,7 +426,7 @@ static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd, ...@@ -426,7 +426,7 @@ static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd,
return PTR_ERR(ops.oobbuf); return PTR_ERR(ops.oobbuf);
start &= ~((uint64_t)mtd->writesize - 1); start &= ~((uint64_t)mtd->writesize - 1);
ret = mtd->write_oob(mtd, start, &ops); ret = mtd_write_oob(mtd, start, &ops);
if (ops.oobretlen > 0xFFFFFFFFU) if (ops.oobretlen > 0xFFFFFFFFU)
ret = -EOVERFLOW; ret = -EOVERFLOW;
...@@ -609,7 +609,7 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd, ...@@ -609,7 +609,7 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
ops.oobbuf = NULL; ops.oobbuf = NULL;
} }
ret = mtd->write_oob(mtd, (loff_t)req.start, &ops); ret = mtd_write_oob(mtd, (loff_t)req.start, &ops);
kfree(ops.datbuf); kfree(ops.datbuf);
kfree(ops.oobbuf); kfree(ops.oobbuf);
......
...@@ -333,7 +333,7 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) ...@@ -333,7 +333,7 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
if (to + devops.len > subdev->size) if (to + devops.len > subdev->size)
devops.len = subdev->size - to; devops.len = subdev->size - to;
err = subdev->write_oob(subdev, to, &devops); err = mtd_write_oob(subdev, to, &devops);
ops->retlen += devops.oobretlen; ops->retlen += devops.oobretlen;
if (err) if (err)
return err; return err;
......
...@@ -217,7 +217,7 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to, ...@@ -217,7 +217,7 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
return -EINVAL; return -EINVAL;
if (ops->datbuf && to + ops->len > mtd->size) if (ops->datbuf && to + ops->len > mtd->size)
return -EINVAL; return -EINVAL;
return part->master->write_oob(part->master, to + part->offset, ops); return mtd_write_oob(part->master, to + part->offset, ops);
} }
static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from, static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
......
...@@ -403,7 +403,7 @@ static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb, ...@@ -403,7 +403,7 @@ static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb,
offset = mtdswap_eb_offset(d, eb) + d->mtd->writesize; offset = mtdswap_eb_offset(d, eb) + d->mtd->writesize;
} }
ret = d->mtd->write_oob(d->mtd, offset , &ops); ret = mtd_write_oob(d->mtd, offset, &ops);
if (ret) { if (ret) {
dev_warn(d->dev, "Write OOB failed for block at %08llx " dev_warn(d->dev, "Write OOB failed for block at %08llx "
...@@ -946,7 +946,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev *d, ...@@ -946,7 +946,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev *d,
patt = mtdswap_test_patt(test + i); patt = mtdswap_test_patt(test + i);
memset(d->page_buf, patt, mtd->writesize); memset(d->page_buf, patt, mtd->writesize);
memset(d->oob_buf, patt, mtd->ecclayout->oobavail); memset(d->oob_buf, patt, mtd->ecclayout->oobavail);
ret = mtd->write_oob(mtd, pos, &ops); ret = mtd_write_oob(mtd, pos, &ops);
if (ret) if (ret)
goto error; goto error;
......
...@@ -350,7 +350,7 @@ static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len, ...@@ -350,7 +350,7 @@ static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len,
ops.oobbuf = oob; ops.oobbuf = oob;
ops.len = len; ops.len = len;
return mtd->write_oob(mtd, offs, &ops); return mtd_write_oob(mtd, offs, &ops);
} }
static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td) static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td)
......
...@@ -55,7 +55,7 @@ static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs) ...@@ -55,7 +55,7 @@ static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs)
ops.datbuf = NULL; ops.datbuf = NULL;
ret = mtd->write_oob(mtd, ofs, &ops); ret = mtd_write_oob(mtd, ofs, &ops);
if (ret < 0 || ops.oobretlen != SM_OOB_SIZE) { if (ret < 0 || ops.oobretlen != SM_OOB_SIZE) {
printk(KERN_NOTICE printk(KERN_NOTICE
"sm_common: can't mark sector at %i as bad\n", "sm_common: can't mark sector at %i as bad\n",
......
...@@ -174,7 +174,7 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, ...@@ -174,7 +174,7 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
ops.oobbuf = buf; ops.oobbuf = buf;
ops.datbuf = NULL; ops.datbuf = NULL;
res = mtd->write_oob(mtd, offs & ~mask, &ops); res = mtd_write_oob(mtd, offs & ~mask, &ops);
*retlen = ops.oobretlen; *retlen = ops.oobretlen;
return res; return res;
} }
...@@ -198,7 +198,7 @@ static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len, ...@@ -198,7 +198,7 @@ static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
ops.datbuf = buf; ops.datbuf = buf;
ops.len = len; ops.len = len;
res = mtd->write_oob(mtd, offs & ~mask, &ops); res = mtd_write_oob(mtd, offs & ~mask, &ops);
*retlen = ops.retlen; *retlen = ops.retlen;
return res; return res;
} }
......
...@@ -343,7 +343,7 @@ static int sm_write_sector(struct sm_ftl *ftl, ...@@ -343,7 +343,7 @@ static int sm_write_sector(struct sm_ftl *ftl,
ops.ooblen = SM_OOB_SIZE; ops.ooblen = SM_OOB_SIZE;
ops.oobbuf = (void *)oob; ops.oobbuf = (void *)oob;
ret = mtd->write_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); ret = mtd_write_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops);
/* Now we assume that hardware will catch write bitflip errors */ /* Now we assume that hardware will catch write bitflip errors */
/* If you are paranoid, use CONFIG_MTD_NAND_VERIFY_WRITE */ /* If you are paranoid, use CONFIG_MTD_NAND_VERIFY_WRITE */
......
...@@ -139,7 +139,7 @@ static int write_eraseblock(int ebnum) ...@@ -139,7 +139,7 @@ static int write_eraseblock(int ebnum)
ops.ooboffs = use_offset; ops.ooboffs = use_offset;
ops.datbuf = NULL; ops.datbuf = NULL;
ops.oobbuf = writebuf; ops.oobbuf = writebuf;
err = mtd->write_oob(mtd, addr, &ops); err = mtd_write_oob(mtd, addr, &ops);
if (err || ops.oobretlen != use_len) { if (err || ops.oobretlen != use_len) {
printk(PRINT_PREF "error: writeoob failed at %#llx\n", printk(PRINT_PREF "error: writeoob failed at %#llx\n",
(long long)addr); (long long)addr);
...@@ -524,7 +524,7 @@ static int __init mtd_oobtest_init(void) ...@@ -524,7 +524,7 @@ static int __init mtd_oobtest_init(void)
ops.oobbuf = writebuf; ops.oobbuf = writebuf;
printk(PRINT_PREF "attempting to start write past end of OOB\n"); printk(PRINT_PREF "attempting to start write past end of OOB\n");
printk(PRINT_PREF "an error is expected...\n"); printk(PRINT_PREF "an error is expected...\n");
err = mtd->write_oob(mtd, addr0, &ops); err = mtd_write_oob(mtd, addr0, &ops);
if (err) { if (err) {
printk(PRINT_PREF "error occurred as expected\n"); printk(PRINT_PREF "error occurred as expected\n");
err = 0; err = 0;
...@@ -568,7 +568,7 @@ static int __init mtd_oobtest_init(void) ...@@ -568,7 +568,7 @@ static int __init mtd_oobtest_init(void)
ops.oobbuf = writebuf; ops.oobbuf = writebuf;
printk(PRINT_PREF "attempting to write past end of device\n"); printk(PRINT_PREF "attempting to write past end of device\n");
printk(PRINT_PREF "an error is expected...\n"); printk(PRINT_PREF "an error is expected...\n");
err = mtd->write_oob(mtd, mtd->size - mtd->writesize, &ops); err = mtd_write_oob(mtd, mtd->size - mtd->writesize, &ops);
if (err) { if (err) {
printk(PRINT_PREF "error occurred as expected\n"); printk(PRINT_PREF "error occurred as expected\n");
err = 0; err = 0;
...@@ -612,7 +612,7 @@ static int __init mtd_oobtest_init(void) ...@@ -612,7 +612,7 @@ static int __init mtd_oobtest_init(void)
ops.oobbuf = writebuf; ops.oobbuf = writebuf;
printk(PRINT_PREF "attempting to write past end of device\n"); printk(PRINT_PREF "attempting to write past end of device\n");
printk(PRINT_PREF "an error is expected...\n"); printk(PRINT_PREF "an error is expected...\n");
err = mtd->write_oob(mtd, mtd->size - mtd->writesize, &ops); err = mtd_write_oob(mtd, mtd->size - mtd->writesize, &ops);
if (err) { if (err) {
printk(PRINT_PREF "error occurred as expected\n"); printk(PRINT_PREF "error occurred as expected\n");
err = 0; err = 0;
...@@ -670,7 +670,7 @@ static int __init mtd_oobtest_init(void) ...@@ -670,7 +670,7 @@ static int __init mtd_oobtest_init(void)
ops.ooboffs = 0; ops.ooboffs = 0;
ops.datbuf = NULL; ops.datbuf = NULL;
ops.oobbuf = writebuf; ops.oobbuf = writebuf;
err = mtd->write_oob(mtd, addr, &ops); err = mtd_write_oob(mtd, addr, &ops);
if (err) if (err)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
......
...@@ -411,7 +411,7 @@ u16 mtd_Write_Page_Main_Spare(u8 *write_data, u32 Block, ...@@ -411,7 +411,7 @@ u16 mtd_Write_Page_Main_Spare(u8 *write_data, u32 Block,
ops.ooblen = BTSIG_BYTES; ops.ooblen = BTSIG_BYTES;
ops.ooboffs = 0; ops.ooboffs = 0;
ret = spectra_mtd->write_oob(spectra_mtd, ret = mtd_write_oob(spectra_mtd,
(Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
&ops); &ops);
if (ret) { if (ret) {
......
...@@ -1101,7 +1101,7 @@ int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, ...@@ -1101,7 +1101,7 @@ int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c,
ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
ops.datbuf = NULL; ops.datbuf = NULL;
ret = c->mtd->write_oob(c->mtd, jeb->offset, &ops); ret = mtd_write_oob(c->mtd, jeb->offset, &ops);
if (ret || ops.oobretlen != ops.ooblen) { if (ret || ops.oobretlen != ops.ooblen) {
printk(KERN_ERR "cannot write OOB for EB at %08x, requested %zd" printk(KERN_ERR "cannot write OOB for EB at %08x, requested %zd"
" bytes, read %zd bytes, error %d\n", " bytes, read %zd bytes, error %d\n",
......
...@@ -190,16 +190,14 @@ struct mtd_info { ...@@ -190,16 +190,14 @@ struct mtd_info {
size_t *retlen, const u_char *buf); size_t *retlen, const u_char *buf);
int (*read_oob) (struct mtd_info *mtd, loff_t from, int (*read_oob) (struct mtd_info *mtd, loff_t from,
struct mtd_oob_ops *ops); struct mtd_oob_ops *ops);
int (*write_oob) (struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops);
/* Backing device capabilities for this device /* Backing device capabilities for this device
* - provides mmap capabilities * - provides mmap capabilities
*/ */
struct backing_dev_info *backing_dev_info; struct backing_dev_info *backing_dev_info;
int (*write_oob) (struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops);
/* /*
* Methods to access the protection register area, present in some * Methods to access the protection register area, present in some
* flash devices. The user data is one time programmable but the * flash devices. The user data is one time programmable but the
...@@ -326,6 +324,12 @@ static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from, ...@@ -326,6 +324,12 @@ static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from,
return mtd->read_oob(mtd, from, ops); return mtd->read_oob(mtd, from, ops);
} }
static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops)
{
return mtd->write_oob(mtd, to, ops);
}
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%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment