aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2011-12-23 08:25:39 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-01-09 13:25:11 -0500
commit7e1f0dc0551b99acb5e8fa161a7ac401994d57d8 (patch)
tree19108039bb082d42fbda40d4bd3ddb11a1185cd1
parent969e57adc2589a0a0ae5edbbe7b92062565ce70b (diff)
mtd: introduce mtd_erase interface
This patch is part of a patch-set which changes the MTD interface from 'mtd->func()' form to 'mtd_func()' form. We need this because we want to add common code to to all drivers in the mtd core level, which is impossible with the current interface when MTD clients call driver functions like 'read()' or 'write()' directly. At this point we just introduce a new inline wrapper function, but later some of them are expected to gain more code. E.g., the input parameters check should be moved to the wrappers rather than be duplicated at many drivers. This particular patch introduced the 'mtd_erase()' interface. The following patches add all the other interfaces one by one. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--drivers/mtd/ftl.c2
-rw-r--r--drivers/mtd/inftlmount.c4
-rw-r--r--drivers/mtd/mtdblock.c2
-rw-r--r--drivers/mtd/mtdchar.c2
-rw-r--r--drivers/mtd/mtdconcat.c2
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/mtdpart.c2
-rw-r--r--drivers/mtd/mtdswap.c2
-rw-r--r--drivers/mtd/nftlmount.c2
-rw-r--r--drivers/mtd/rfd_ftl.c2
-rw-r--r--drivers/mtd/sm_ftl.c2
-rw-r--r--drivers/mtd/tests/mtd_oobtest.c2
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c2
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c4
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c2
-rw-r--r--drivers/mtd/tests/mtd_subpagetest.c2
-rw-r--r--drivers/mtd/tests/mtd_torturetest.c2
-rw-r--r--drivers/mtd/ubi/io.c2
-rw-r--r--drivers/staging/spectra/lld_mtd.c2
-rw-r--r--fs/jffs2/erase.c2
-rw-r--r--fs/logfs/dev_mtd.c2
-rw-r--r--include/linux/mtd/mtd.h19
22 files changed, 37 insertions, 28 deletions
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index c7382bb686c6..a982889277c8 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -355,7 +355,7 @@ static int erase_xfer(partition_t *part,
355 erase->len = 1 << part->header.EraseUnitSize; 355 erase->len = 1 << part->header.EraseUnitSize;
356 erase->priv = (u_long)part; 356 erase->priv = (u_long)part;
357 357
358 ret = part->mbd.mtd->erase(part->mbd.mtd, erase); 358 ret = mtd_erase(part->mbd.mtd, erase);
359 359
360 if (!ret) 360 if (!ret)
361 xfer->EraseCount++; 361 xfer->EraseCount++;
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index 2ff601f816ce..0d946f10a682 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -220,7 +220,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
220 */ 220 */
221 instr->addr = ip->Reserved0 * inftl->EraseSize; 221 instr->addr = ip->Reserved0 * inftl->EraseSize;
222 instr->len = inftl->EraseSize; 222 instr->len = inftl->EraseSize;
223 mtd->erase(mtd, instr); 223 mtd_erase(mtd, instr);
224 } 224 }
225 if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) { 225 if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
226 printk(KERN_WARNING "INFTL: Media Header " 226 printk(KERN_WARNING "INFTL: Media Header "
@@ -393,7 +393,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
393 mark only the failed block in the bbt. */ 393 mark only the failed block in the bbt. */
394 for (physblock = 0; physblock < inftl->EraseSize; 394 for (physblock = 0; physblock < inftl->EraseSize;
395 physblock += instr->len, instr->addr += instr->len) { 395 physblock += instr->len, instr->addr += instr->len) {
396 mtd->erase(inftl->mbd.mtd, instr); 396 mtd_erase(inftl->mbd.mtd, instr);
397 397
398 if (instr->state == MTD_ERASE_FAILED) { 398 if (instr->state == MTD_ERASE_FAILED) {
399 printk(KERN_WARNING "INFTL: error while formatting block %d\n", 399 printk(KERN_WARNING "INFTL: error while formatting block %d\n",
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 7c1dc908a174..9b01cb0266e4 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -85,7 +85,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
85 set_current_state(TASK_INTERRUPTIBLE); 85 set_current_state(TASK_INTERRUPTIBLE);
86 add_wait_queue(&wait_q, &wait); 86 add_wait_queue(&wait_q, &wait);
87 87
88 ret = mtd->erase(mtd, &erase); 88 ret = mtd_erase(mtd, &erase);
89 if (ret) { 89 if (ret) {
90 set_current_state(TASK_RUNNING); 90 set_current_state(TASK_RUNNING);
91 remove_wait_queue(&wait_q, &wait); 91 remove_wait_queue(&wait_q, &wait);
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 00423cc85807..41d64ff4c252 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -731,7 +731,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
731 wq_head is no longer there when the 731 wq_head is no longer there when the
732 callback routine tries to wake us up. 732 callback routine tries to wake us up.
733 */ 733 */
734 ret = mtd->erase(mtd, erase); 734 ret = mtd_erase(mtd, erase);
735 if (!ret) { 735 if (!ret) {
736 set_current_state(TASK_UNINTERRUPTIBLE); 736 set_current_state(TASK_UNINTERRUPTIBLE);
737 add_wait_queue(&waitq, &wait); 737 add_wait_queue(&waitq, &wait);
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 6df4d4d4eb92..76123bd49314 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -379,7 +379,7 @@ static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
379 * FIXME: Allow INTERRUPTIBLE. Which means 379 * FIXME: Allow INTERRUPTIBLE. Which means
380 * not having the wait_queue head on the stack. 380 * not having the wait_queue head on the stack.
381 */ 381 */
382 err = mtd->erase(mtd, erase); 382 err = mtd_erase(mtd, erase);
383 if (!err) { 383 if (!err) {
384 set_current_state(TASK_UNINTERRUPTIBLE); 384 set_current_state(TASK_UNINTERRUPTIBLE);
385 add_wait_queue(&waitq, &wait); 385 add_wait_queue(&waitq, &wait);
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index f3cdce9a85a6..9b2d86323169 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -112,7 +112,7 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset)
112 set_current_state(TASK_INTERRUPTIBLE); 112 set_current_state(TASK_INTERRUPTIBLE);
113 add_wait_queue(&wait_q, &wait); 113 add_wait_queue(&wait_q, &wait);
114 114
115 ret = mtd->erase(mtd, &erase); 115 ret = mtd_erase(mtd, &erase);
116 if (ret) { 116 if (ret) {
117 set_current_state(TASK_RUNNING); 117 set_current_state(TASK_RUNNING);
118 remove_wait_queue(&wait_q, &wait); 118 remove_wait_queue(&wait_q, &wait);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a0bd2de4752b..d318fee28595 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -257,7 +257,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
257 if (instr->addr >= mtd->size) 257 if (instr->addr >= mtd->size)
258 return -EINVAL; 258 return -EINVAL;
259 instr->addr += part->offset; 259 instr->addr += part->offset;
260 ret = part->master->erase(part->master, instr); 260 ret = mtd_erase(part->master, instr);
261 if (ret) { 261 if (ret) {
262 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) 262 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
263 instr->fail_addr -= part->offset; 263 instr->fail_addr -= part->offset;
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index bd9590c723e4..4e12875a916c 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -567,7 +567,7 @@ retry:
567 erase.len = mtd->erasesize; 567 erase.len = mtd->erasesize;
568 erase.priv = (u_long)&wq; 568 erase.priv = (u_long)&wq;
569 569
570 ret = mtd->erase(mtd, &erase); 570 ret = mtd_erase(mtd, &erase);
571 if (ret) { 571 if (ret) {
572 if (retries++ < MTDSWAP_ERASE_RETRIES) { 572 if (retries++ < MTDSWAP_ERASE_RETRIES) {
573 dev_warn(d->dev, 573 dev_warn(d->dev,
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index ac4092591aea..9164a56fb5c0 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -326,7 +326,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
326 instr->mtd = nftl->mbd.mtd; 326 instr->mtd = nftl->mbd.mtd;
327 instr->addr = block * nftl->EraseSize; 327 instr->addr = block * nftl->EraseSize;
328 instr->len = nftl->EraseSize; 328 instr->len = nftl->EraseSize;
329 mtd->erase(mtd, instr); 329 mtd_erase(mtd, instr);
330 330
331 if (instr->state == MTD_ERASE_FAILED) { 331 if (instr->state == MTD_ERASE_FAILED) {
332 printk("Error while formatting block %d\n", block); 332 printk("Error while formatting block %d\n", block);
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 73ae217a4252..39de8727a524 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -342,7 +342,7 @@ static int erase_block(struct partition *part, int block)
342 part->blocks[block].state = BLOCK_ERASING; 342 part->blocks[block].state = BLOCK_ERASING;
343 part->blocks[block].free_sectors = 0; 343 part->blocks[block].free_sectors = 0;
344 344
345 rc = part->mbd.mtd->erase(part->mbd.mtd, erase); 345 rc = mtd_erase(part->mbd.mtd, erase);
346 346
347 if (rc) { 347 if (rc) {
348 printk(KERN_ERR PREFIX "erase of region %llx,%llx on '%s' " 348 printk(KERN_ERR PREFIX "erase of region %llx,%llx on '%s' "
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index 1c9f307ae0a1..2f1acb1ab5e8 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -479,7 +479,7 @@ static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block,
479 return -EIO; 479 return -EIO;
480 } 480 }
481 481
482 if (mtd->erase(mtd, &erase)) { 482 if (mtd_erase(mtd, &erase)) {
483 sm_printk("erase of block %d in zone %d failed", 483 sm_printk("erase of block %d in zone %d failed",
484 block, zone_num); 484 block, zone_num);
485 goto error; 485 goto error;
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c
index 933f7e5f32d3..7d52854c16dd 100644
--- a/drivers/mtd/tests/mtd_oobtest.c
+++ b/drivers/mtd/tests/mtd_oobtest.c
@@ -78,7 +78,7 @@ static int erase_eraseblock(int ebnum)
78 ei.addr = addr; 78 ei.addr = addr;
79 ei.len = mtd->erasesize; 79 ei.len = mtd->erasesize;
80 80
81 err = mtd->erase(mtd, &ei); 81 err = mtd_erase(mtd, &ei);
82 if (err) { 82 if (err) {
83 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); 83 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
84 return err; 84 return err;
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index afafb6935fd0..271819fabb55 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -77,7 +77,7 @@ static int erase_eraseblock(int ebnum)
77 ei.addr = addr; 77 ei.addr = addr;
78 ei.len = mtd->erasesize; 78 ei.len = mtd->erasesize;
79 79
80 err = mtd->erase(mtd, &ei); 80 err = mtd_erase(mtd, &ei);
81 if (err) { 81 if (err) {
82 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); 82 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
83 return err; 83 return err;
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 493b367bdd35..f67a65e21043 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -79,7 +79,7 @@ static int erase_eraseblock(int ebnum)
79 ei.addr = addr; 79 ei.addr = addr;
80 ei.len = mtd->erasesize; 80 ei.len = mtd->erasesize;
81 81
82 err = mtd->erase(mtd, &ei); 82 err = mtd_erase(mtd, &ei);
83 if (err) { 83 if (err) {
84 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); 84 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
85 return err; 85 return err;
@@ -105,7 +105,7 @@ static int multiblock_erase(int ebnum, int blocks)
105 ei.addr = addr; 105 ei.addr = addr;
106 ei.len = mtd->erasesize * blocks; 106 ei.len = mtd->erasesize * blocks;
107 107
108 err = mtd->erase(mtd, &ei); 108 err = mtd_erase(mtd, &ei);
109 if (err) { 109 if (err) {
110 printk(PRINT_PREF "error %d while erasing EB %d, blocks %d\n", 110 printk(PRINT_PREF "error %d while erasing EB %d, blocks %d\n",
111 err, ebnum, blocks); 111 err, ebnum, blocks);
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 811642fea6b4..a204a9f90524 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -112,7 +112,7 @@ static int erase_eraseblock(int ebnum)
112 ei.addr = addr; 112 ei.addr = addr;
113 ei.len = mtd->erasesize; 113 ei.len = mtd->erasesize;
114 114
115 err = mtd->erase(mtd, &ei); 115 err = mtd_erase(mtd, &ei);
116 if (unlikely(err)) { 116 if (unlikely(err)) {
117 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); 117 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
118 return err; 118 return err;
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index 1a05bfac4eee..16d0c05024d7 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -80,7 +80,7 @@ static int erase_eraseblock(int ebnum)
80 ei.addr = addr; 80 ei.addr = addr;
81 ei.len = mtd->erasesize; 81 ei.len = mtd->erasesize;
82 82
83 err = mtd->erase(mtd, &ei); 83 err = mtd_erase(mtd, &ei);
84 if (err) { 84 if (err) {
85 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); 85 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
86 return err; 86 return err;
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 03ab649a6964..102c79b7ac66 100644
--- a/drivers/mtd/tests/mtd_torturetest.c
+++ b/drivers/mtd/tests/mtd_torturetest.c
@@ -105,7 +105,7 @@ static inline int erase_eraseblock(int ebnum)
105 ei.addr = addr; 105 ei.addr = addr;
106 ei.len = mtd->erasesize; 106 ei.len = mtd->erasesize;
107 107
108 err = mtd->erase(mtd, &ei); 108 err = mtd_erase(mtd, &ei);
109 if (err) { 109 if (err) {
110 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); 110 printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum);
111 return err; 111 return err;
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index f20b6f22f240..b6c8959e6c7e 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -361,7 +361,7 @@ retry:
361 ei.callback = erase_callback; 361 ei.callback = erase_callback;
362 ei.priv = (unsigned long)&wq; 362 ei.priv = (unsigned long)&wq;
363 363
364 err = ubi->mtd->erase(ubi->mtd, &ei); 364 err = mtd_erase(ubi->mtd, &ei);
365 if (err) { 365 if (err) {
366 if (retries++ < UBI_IO_RETRIES) { 366 if (retries++ < UBI_IO_RETRIES) {
367 dbg_io("error %d while erasing PEB %d, retry", 367 dbg_io("error %d while erasing PEB %d, retry",
diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c
index a9c309a167c2..d638fafab649 100644
--- a/drivers/staging/spectra/lld_mtd.c
+++ b/drivers/staging/spectra/lld_mtd.c
@@ -188,7 +188,7 @@ u16 mtd_Erase_Block(u32 block_add)
188 erase.len = spectra_mtd->erasesize; 188 erase.len = spectra_mtd->erasesize;
189 erase.priv = (unsigned long)&comp; 189 erase.priv = (unsigned long)&comp;
190 190
191 ret = spectra_mtd->erase(spectra_mtd, &erase); 191 ret = mtd_erase(spectra_mtd, &erase);
192 if (!ret) { 192 if (!ret) {
193 wait_for_completion(&comp); 193 wait_for_completion(&comp);
194 if (erase.state != MTD_ERASE_DONE) 194 if (erase.state != MTD_ERASE_DONE)
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index e513f1913c15..540e8eca1b49 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -74,7 +74,7 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
74 ((struct erase_priv_struct *)instr->priv)->jeb = jeb; 74 ((struct erase_priv_struct *)instr->priv)->jeb = jeb;
75 ((struct erase_priv_struct *)instr->priv)->c = c; 75 ((struct erase_priv_struct *)instr->priv)->c = c;
76 76
77 ret = c->mtd->erase(c->mtd, instr); 77 ret = mtd_erase(c->mtd, instr);
78 if (!ret) 78 if (!ret)
79 return; 79 return;
80 80
diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c
index eb423ebcf538..046362894352 100644
--- a/fs/logfs/dev_mtd.c
+++ b/fs/logfs/dev_mtd.c
@@ -105,7 +105,7 @@ static int logfs_mtd_erase(struct super_block *sb, loff_t ofs, size_t len,
105 ei.len = len; 105 ei.len = len;
106 ei.callback = logfs_erase_callback; 106 ei.callback = logfs_erase_callback;
107 ei.priv = (long)&complete; 107 ei.priv = (long)&complete;
108 ret = mtd->erase(mtd, &ei); 108 ret = mtd_erase(mtd, &ei);
109 if (ret) 109 if (ret)
110 return -EIO; 110 return -EIO;
111 111
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 9f5b312af783..201bad557047 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -171,11 +171,8 @@ struct mtd_info {
171 struct mtd_erase_region_info *eraseregions; 171 struct mtd_erase_region_info *eraseregions;
172 172
173 /* 173 /*
174 * Erase is an asynchronous operation. Device drivers are supposed 174 * Do not call via these pointers, use corresponding mtd_*()
175 * to call instr->callback() whenever the operation completes, even 175 * wrappers instead.
176 * if it completes with a failure.
177 * Callers are supposed to pass a callback function and wait for it
178 * to be called before writing to the block.
179 */ 176 */
180 int (*erase) (struct mtd_info *mtd, struct erase_info *instr); 177 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
181 178
@@ -274,6 +271,18 @@ struct mtd_info {
274 void (*put_device) (struct mtd_info *mtd); 271 void (*put_device) (struct mtd_info *mtd);
275}; 272};
276 273
274/*
275 * Erase is an asynchronous operation. Device drivers are supposed
276 * to call instr->callback() whenever the operation completes, even
277 * if it completes with a failure.
278 * Callers are supposed to pass a callback function and wait for it
279 * to be called before writing to the block.
280 */
281static inline int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
282{
283 return mtd->erase(mtd, instr);
284}
285
277static inline struct mtd_info *dev_to_mtd(struct device *dev) 286static inline struct mtd_info *dev_to_mtd(struct device *dev)
278{ 287{
279 return dev ? dev_get_drvdata(dev) : NULL; 288 return dev ? dev_get_drvdata(dev) : NULL;