]> Pileus Git - ~andy/linux/blobdiff - drivers/mtd/nftlcore.c
mtd: introduce mtd_get_user_prot_info interface
[~andy/linux] / drivers / mtd / nftlcore.c
index f3b3239746c8464aad7b68a15f104cb64b530d62..8847e60ad167e9b38b840519ea512a9b24d4bdcb 100644 (file)
@@ -63,7 +63,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
                return;
        }
 
-       DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name);
+       pr_debug("NFTL: add_mtd for %s\n", mtd->name);
 
        nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
 
@@ -130,7 +130,7 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
 {
        struct NFTLrecord *nftl = (void *)dev;
 
-       DEBUG(MTD_DEBUG_LEVEL1, "NFTL: remove_dev (i=%d)\n", dev->devnum);
+       pr_debug("NFTL: remove_dev (i=%d)\n", dev->devnum);
 
        del_mtd_blktrans_dev(dev);
        kfree(nftl->ReplUnitTable);
@@ -147,13 +147,13 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
        struct mtd_oob_ops ops;
        int res;
 
-       ops.mode = MTD_OOB_PLACE;
+       ops.mode = MTD_OPS_PLACE_OOB;
        ops.ooboffs = offs & mask;
        ops.ooblen = len;
        ops.oobbuf = buf;
        ops.datbuf = NULL;
 
-       res = mtd->read_oob(mtd, offs & ~mask, &ops);
+       res = mtd_read_oob(mtd, offs & ~mask, &ops);
        *retlen = ops.oobretlen;
        return res;
 }
@@ -168,13 +168,13 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
        struct mtd_oob_ops ops;
        int res;
 
-       ops.mode = MTD_OOB_PLACE;
+       ops.mode = MTD_OPS_PLACE_OOB;
        ops.ooboffs = offs & mask;
        ops.ooblen = len;
        ops.oobbuf = buf;
        ops.datbuf = NULL;
 
-       res = mtd->write_oob(mtd, offs & ~mask, &ops);
+       res = mtd_write_oob(mtd, offs & ~mask, &ops);
        *retlen = ops.oobretlen;
        return res;
 }
@@ -191,14 +191,14 @@ static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
        struct mtd_oob_ops ops;
        int res;
 
-       ops.mode = MTD_OOB_PLACE;
+       ops.mode = MTD_OPS_PLACE_OOB;
        ops.ooboffs = offs & mask;
        ops.ooblen = mtd->oobsize;
        ops.oobbuf = oob;
        ops.datbuf = buf;
        ops.len = len;
 
-       res = mtd->write_oob(mtd, offs & ~mask, &ops);
+       res = mtd_write_oob(mtd, offs & ~mask, &ops);
        *retlen = ops.retlen;
        return res;
 }
@@ -218,7 +218,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate )
 
        /* Normally, we force a fold to happen before we run out of free blocks completely */
        if (!desperate && nftl->numfreeEUNs < 2) {
-               DEBUG(MTD_DEBUG_LEVEL1, "NFTL_findfreeblock: there are too few free EUNs\n");
+               pr_debug("NFTL_findfreeblock: there are too few free EUNs\n");
                return BLOCK_NIL;
        }
 
@@ -289,8 +289,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
                        if (block == 2) {
                                foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1;
                                if (foldmark == FOLD_MARK_IN_PROGRESS) {
-                                       DEBUG(MTD_DEBUG_LEVEL1,
-                                             "Write Inhibited on EUN %d\n", thisEUN);
+                                       pr_debug("Write Inhibited on EUN %d\n", thisEUN);
                                        inplace = 0;
                                } else {
                                        /* There's no other reason not to do inplace,
@@ -355,7 +354,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
                        if (BlockLastState[block] != SECTOR_FREE &&
                            BlockMap[block] != BLOCK_NIL &&
                            BlockMap[block] != targetEUN) {
-                               DEBUG(MTD_DEBUG_LEVEL1, "Setting inplace to 0. VUC %d, "
+                               pr_debug("Setting inplace to 0. VUC %d, "
                                      "block %d was %x lastEUN, "
                                      "and is in EUN %d (%s) %d\n",
                                      thisVUC, block, BlockLastState[block],
@@ -371,14 +370,14 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
                    pendingblock < ((thisVUC + 1)* (nftl->EraseSize / 512)) &&
                    BlockLastState[pendingblock - (thisVUC * (nftl->EraseSize / 512))] !=
                    SECTOR_FREE) {
-                       DEBUG(MTD_DEBUG_LEVEL1, "Pending write not free in EUN %d. "
+                       pr_debug("Pending write not free in EUN %d. "
                              "Folding out of place.\n", targetEUN);
                        inplace = 0;
                }
        }
 
        if (!inplace) {
-               DEBUG(MTD_DEBUG_LEVEL1, "Cannot fold Virtual Unit Chain %d in place. "
+               pr_debug("Cannot fold Virtual Unit Chain %d in place. "
                      "Trying out-of-place\n", thisVUC);
                /* We need to find a targetEUN to fold into. */
                targetEUN = NFTL_findfreeblock(nftl, 1);
@@ -408,7 +407,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
           and the Erase Unit into which we are supposed to be copying.
           Go for it.
        */
-       DEBUG(MTD_DEBUG_LEVEL1,"Folding chain %d into unit %d\n", thisVUC, targetEUN);
+       pr_debug("Folding chain %d into unit %d\n", thisVUC, targetEUN);
        for (block = 0; block < nftl->EraseSize / 512 ; block++) {
                unsigned char movebuf[512];
                int ret;
@@ -424,12 +423,17 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
                if (BlockMap[block] == BLOCK_NIL)
                        continue;
 
-               ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512),
-                               512, &retlen, movebuf);
-               if (ret < 0 && ret != -EUCLEAN) {
-                       ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block])
-                                       + (block * 512), 512, &retlen,
-                                       movebuf);
+               ret = mtd_read(mtd,
+                              (nftl->EraseSize * BlockMap[block]) + (block * 512),
+                              512,
+                              &retlen,
+                              movebuf);
+               if (ret < 0 && !mtd_is_bitflip(ret)) {
+                       ret = mtd_read(mtd,
+                                      (nftl->EraseSize * BlockMap[block]) + (block * 512),
+                                      512,
+                                      &retlen,
+                                      movebuf);
                        if (ret != -EIO)
                                printk("Error went away on retry.\n");
                }
@@ -455,7 +459,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
           has duplicate chains, we need to free one of the chains because it's not necessary any more.
        */
        thisEUN = nftl->EUNtable[thisVUC];
-       DEBUG(MTD_DEBUG_LEVEL1,"Want to erase\n");
+       pr_debug("Want to erase\n");
 
        /* For each block in the old chain (except the targetEUN of course),
           free it and make it available for future use */
@@ -568,7 +572,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
                                      (writeEUN * nftl->EraseSize) + blockofs,
                                      8, &retlen, (char *)&bci);
 
-                       DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n",
+                       pr_debug("Status of block %d in EUN %d is %x\n",
                              block , writeEUN, le16_to_cpu(bci.Status));
 
                        status = bci.Status | bci.Status1;
@@ -621,7 +625,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
                                   but they are reserved for when we're
                                   desperate. Well, now we're desperate.
                                */
-                               DEBUG(MTD_DEBUG_LEVEL1, "Using desperate==1 to find free EUN to accommodate write to VUC %d\n", thisVUC);
+                               pr_debug("Using desperate==1 to find free EUN to accommodate write to VUC %d\n", thisVUC);
                                writeEUN = NFTL_findfreeblock(nftl, 1);
                        }
                        if (writeEUN == BLOCK_NIL) {
@@ -772,9 +776,9 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
        } else {
                loff_t ptr = (lastgoodEUN * nftl->EraseSize) + blockofs;
                size_t retlen;
-               int res = mtd->read(mtd, ptr, 512, &retlen, buffer);
+               int res = mtd_read(mtd, ptr, 512, &retlen, buffer);
 
-               if (res < 0 && res != -EUCLEAN)
+               if (res < 0 && !mtd_is_bitflip(res))
                        return -EIO;
        }
        return 0;