linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / mtd / nftlmount.c
index 067262e..3b104eb 100644 (file)
 
 char nftlmountrev[]="$Revision: 1.41 $";
 
-extern int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
-                        size_t *retlen, uint8_t *buf);
-extern int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
-                         size_t *retlen, uint8_t *buf);
-
 /* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the
  *     various device information of the NFTL partition and Bad Unit Table. Update
  *     the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[]
@@ -50,7 +45,6 @@ static int find_boot_record(struct NFTLrecord *nftl)
        size_t retlen;
        u8 buf[SECTORSIZE];
        struct NFTLMediaHeader *mh = &nftl->MediaHdr;
-       struct mtd_info *mtd = nftl->mbd.mtd;
        unsigned int i;
 
         /* Assume logical EraseSize == physical erasesize for starting the scan.
@@ -71,8 +65,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
 
                /* Check for ANAND header first. Then can whinge if it's found but later
                   checks fail */
-               ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE,
-                               &retlen, buf);
+               ret = MTD_READ(nftl->mbd.mtd, block * nftl->EraseSize, SECTORSIZE, &retlen, buf);
                /* We ignore ret in case the ECC of the MediaHeader is invalid
                   (which is apparently acceptable) */
                if (retlen != SECTORSIZE) {
@@ -97,9 +90,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
                }
 
                /* To be safer with BIOS, also use erase mark as discriminant */
-               if ((ret = nftl_read_oob(mtd, block * nftl->EraseSize +
-                                        SECTORSIZE + 8, 8, &retlen,
-                                        (char *)&h1) < 0)) {
+               if ((ret = MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8,
+                               8, &retlen, (char *)&h1) < 0)) {
                        printk(KERN_WARNING "ANAND header found at 0x%x in mtd%d, but OOB data read failed (err %d)\n",
                               block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
                        continue;
@@ -117,8 +109,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
                }
 
                /* Finally reread to check ECC */
-               if ((ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE,
-                                    &retlen, buf) < 0)) {
+               if ((ret = MTD_READECC(nftl->mbd.mtd, block * nftl->EraseSize, SECTORSIZE,
+                               &retlen, buf, (char *)&oob, NULL) < 0)) {
                        printk(KERN_NOTICE "ANAND header found at 0x%x in mtd%d, but ECC read failed (err %d)\n",
                               block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
                        continue;
@@ -236,9 +228,9 @@ device is already correct.
 The new DiskOnChip driver already scanned the bad block table.  Just query it.
                        if ((i & (SECTORSIZE - 1)) == 0) {
                                /* read one sector for every SECTORSIZE of blocks */
-                               if ((ret = mtd->read(nftl->mbd.mtd, block * nftl->EraseSize +
-                                                    i + SECTORSIZE, SECTORSIZE, &retlen,
-                                                    buf)) < 0) {
+                               if ((ret = MTD_READECC(nftl->mbd.mtd, block * nftl->EraseSize +
+                                                      i + SECTORSIZE, SECTORSIZE, &retlen, buf,
+                                                      (char *)&oob, NULL)) < 0) {
                                        printk(KERN_NOTICE "Read of bad sector table failed (err %d)\n",
                                               ret);
                                        kfree(nftl->ReplUnitTable);
@@ -276,22 +268,18 @@ static int memcmpb(void *a, int c, int n)
 static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len,
                              int check_oob)
 {
-       u8 buf[SECTORSIZE + nftl->mbd.mtd->oobsize];
-       struct mtd_info *mtd = nftl->mbd.mtd;
-       size_t retlen;
        int i;
+       size_t retlen;
+       u8 buf[SECTORSIZE + nftl->mbd.mtd->oobsize];
 
        for (i = 0; i < len; i += SECTORSIZE) {
-               if (mtd->read(mtd, address, SECTORSIZE, &retlen, buf))
+               if (MTD_READECC(nftl->mbd.mtd, address, SECTORSIZE, &retlen, buf, &buf[SECTORSIZE], &nftl->oobinfo) < 0)
                        return -1;
                if (memcmpb(buf, 0xff, SECTORSIZE) != 0)
                        return -1;
 
                if (check_oob) {
-                       if(nftl_read_oob(mtd, address, mtd->oobsize,
-                                        &retlen, &buf[SECTORSIZE]) < 0)
-                               return -1;
-                       if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0)
+                       if (memcmpb(buf + SECTORSIZE, 0xff, nftl->mbd.mtd->oobsize) != 0)
                                return -1;
                }
                address += SECTORSIZE;
@@ -313,11 +301,10 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
        unsigned int nb_erases, erase_mark;
        struct nftl_uci1 uci;
        struct erase_info *instr = &nftl->instr;
-       struct mtd_info *mtd = nftl->mbd.mtd;
 
        /* Read the Unit Control Information #1 for Wear-Leveling */
-       if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8,
-                         8, &retlen, (char *)&uci) < 0)
+       if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8,
+                       8, &retlen, (char *)&uci) < 0)
                goto default_uci1;
 
        erase_mark = le16_to_cpu ((uci.EraseMark | uci.EraseMark1));
@@ -334,7 +321,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
        instr->mtd = nftl->mbd.mtd;
        instr->addr = block * nftl->EraseSize;
        instr->len = nftl->EraseSize;
-       mtd->erase(mtd, instr);
+       MTD_ERASE(nftl->mbd.mtd, instr);
 
        if (instr->state == MTD_ERASE_FAILED) {
                printk("Error while formatting block %d\n", block);
@@ -356,8 +343,8 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
                        goto fail;
 
                uci.WearInfo = le32_to_cpu(nb_erases);
-               if (nftl_write_oob(mtd, block * nftl->EraseSize + SECTORSIZE +
-                                  8, 8, &retlen, (char *)&uci) < 0)
+               if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
+                                &retlen, (char *)&uci) < 0)
                        goto fail;
                return 0;
 fail:
@@ -378,7 +365,6 @@ fail:
  *     case. */
 static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_block)
 {
-       struct mtd_info *mtd = nftl->mbd.mtd;
        unsigned int block, i, status;
        struct nftl_bci bci;
        int sectors_per_block;
@@ -388,9 +374,8 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
        block = first_block;
        for (;;) {
                for (i = 0; i < sectors_per_block; i++) {
-                       if (nftl_read_oob(mtd,
-                                         block * nftl->EraseSize + i * SECTORSIZE,
-                                         8, &retlen, (char *)&bci) < 0)
+                       if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + i * SECTORSIZE,
+                                       8, &retlen, (char *)&bci) < 0)
                                status = SECTOR_IGNORE;
                        else
                                status = bci.Status | bci.Status1;
@@ -409,10 +394,9 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
                                        /* sector not free actually : mark it as SECTOR_IGNORE  */
                                        bci.Status = SECTOR_IGNORE;
                                        bci.Status1 = SECTOR_IGNORE;
-                                       nftl_write_oob(mtd, block *
-                                                      nftl->EraseSize +
-                                                      i * SECTORSIZE, 8,
-                                                      &retlen, (char *)&bci);
+                                       MTD_WRITEOOB(nftl->mbd.mtd,
+                                                    block * nftl->EraseSize + i * SECTORSIZE,
+                                                    8, &retlen, (char *)&bci);
                                }
                                break;
                        default:
@@ -497,14 +481,13 @@ static void format_chain(struct NFTLrecord *nftl, unsigned int first_block)
  *     1. */
 static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
 {
-       struct mtd_info *mtd = nftl->mbd.mtd;
        struct nftl_uci1 h1;
        unsigned int erase_mark;
        size_t retlen;
 
        /* check erase mark. */
-       if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
-                         &retlen, (char *)&h1) < 0)
+       if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
+                       &retlen, (char *)&h1) < 0)
                return -1;
 
        erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1));
@@ -518,9 +501,8 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
                h1.EraseMark = cpu_to_le16(ERASE_MARK);
                h1.EraseMark1 = cpu_to_le16(ERASE_MARK);
                h1.WearInfo = cpu_to_le32(0);
-               if (nftl_write_oob(mtd,
-                                  block * nftl->EraseSize + SECTORSIZE + 8, 8,
-                                  &retlen, (char *)&h1) < 0)
+               if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
+                                &retlen, (char *)&h1) < 0)
                        return -1;
        } else {
 #if 0
@@ -531,8 +513,8 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
                                                SECTORSIZE, 0) != 0)
                                return -1;
 
-                       if (nftl_read_oob(mtd, block * nftl->EraseSize + i,
-                                         16, &retlen, buf) < 0)
+                       if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + i,
+                                       16, &retlen, buf) < 0)
                                return -1;
                        if (i == SECTORSIZE) {
                                /* skip erase mark */
@@ -558,12 +540,11 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
  */
 static int get_fold_mark(struct NFTLrecord *nftl, unsigned int block)
 {
-       struct mtd_info *mtd = nftl->mbd.mtd;
        struct nftl_uci2 uci;
        size_t retlen;
 
-       if (nftl_read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8,
-                         8, &retlen, (char *)&uci) < 0)
+       if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8,
+                       8, &retlen, (char *)&uci) < 0)
                return 0;
 
        return le16_to_cpu((uci.FoldMark | uci.FoldMark1));
@@ -577,7 +558,6 @@ int NFTL_mount(struct NFTLrecord *s)
        int chain_length, do_format_chain;
        struct nftl_uci0 h0;
        struct nftl_uci1 h1;
-       struct mtd_info *mtd = s->mbd.mtd;
        size_t retlen;
 
        /* search for NFTL MediaHeader and Spare NFTL Media Header */
@@ -602,13 +582,10 @@ int NFTL_mount(struct NFTLrecord *s)
 
                        for (;;) {
                                /* read the block header. If error, we format the chain */
-                               if (nftl_read_oob(mtd,
-                                                 block * s->EraseSize + 8, 8,
-                                                 &retlen, (char *)&h0) < 0 ||
-                                   nftl_read_oob(mtd,
-                                                 block * s->EraseSize +
-                                                 SECTORSIZE + 8, 8,
-                                                 &retlen, (char *)&h1) < 0) {
+                               if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, 8,
+                                               &retlen, (char *)&h0) < 0 ||
+                                   MTD_READOOB(s->mbd.mtd, block * s->EraseSize + SECTORSIZE + 8, 8,
+                                               &retlen, (char *)&h1) < 0) {
                                        s->ReplUnitTable[block] = BLOCK_NIL;
                                        do_format_chain = 1;
                                        break;