Commit f4a43cfc authored by Thomas Gleixner's avatar Thomas Gleixner

[MTD] Remove silly MTD_WRITE/READ macros

Most of those macros are unused and the used ones just obfuscate
the code. Remove them and fixup all users.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 5bd34c09
...@@ -197,10 +197,11 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned ...@@ -197,10 +197,11 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
u16 BlockMap[MAX_SECTORS_PER_UNIT]; u16 BlockMap[MAX_SECTORS_PER_UNIT];
unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT]; unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
unsigned int thisEUN, prevEUN, status; unsigned int thisEUN, prevEUN, status;
struct mtd_info *mtd = inftl->mbd.mtd;
int block, silly; int block, silly;
unsigned int targetEUN; unsigned int targetEUN;
struct inftl_oob oob; struct inftl_oob oob;
size_t retlen; size_t retlen;
DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d," DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
"pending=%d)\n", inftl, thisVUC, pendingblock); "pending=%d)\n", inftl, thisVUC, pendingblock);
...@@ -226,9 +227,9 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned ...@@ -226,9 +227,9 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
if ((BlockMap[block] != 0xffff) || BlockDeleted[block]) if ((BlockMap[block] != 0xffff) || BlockDeleted[block])
continue; continue;
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize)
+ (block * SECTORSIZE), 16 , &retlen, + (block * SECTORSIZE), 16 , &retlen,
(char *)&oob) < 0) (char *)&oob) < 0)
status = SECTOR_IGNORE; status = SECTOR_IGNORE;
else else
status = oob.b.Status | oob.b.Status1; status = oob.b.Status | oob.b.Status1;
...@@ -288,13 +289,14 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned ...@@ -288,13 +289,14 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
if (BlockMap[block] == BLOCK_NIL) if (BlockMap[block] == BLOCK_NIL)
continue; continue;
ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize * ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
BlockMap[block]) + (block * SECTORSIZE), SECTORSIZE, (block * SECTORSIZE), SECTORSIZE, &retlen,
&retlen, movebuf); movebuf);
if (ret < 0) { if (ret < 0) {
ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize * ret = mtd->read(mtd,
BlockMap[block]) + (block * SECTORSIZE), (inftl->EraseSize * BlockMap[block]) +
SECTORSIZE, &retlen, movebuf); (block * SECTORSIZE), SECTORSIZE,
&retlen, movebuf);
if (ret != -EIO) if (ret != -EIO)
DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went " DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
"away on retry?\n"); "away on retry?\n");
...@@ -415,6 +417,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) ...@@ -415,6 +417,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
unsigned int thisVUC = block / (inftl->EraseSize / SECTORSIZE); unsigned int thisVUC = block / (inftl->EraseSize / SECTORSIZE);
unsigned int thisEUN, writeEUN, prev_block, status; unsigned int thisEUN, writeEUN, prev_block, status;
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize -1); unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize -1);
struct mtd_info *mtd = inftl->mbd.mtd;
struct inftl_oob oob; struct inftl_oob oob;
struct inftl_bci bci; struct inftl_bci bci;
unsigned char anac, nacs, parity; unsigned char anac, nacs, parity;
...@@ -434,8 +437,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) ...@@ -434,8 +437,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
silly = MAX_LOOPS; silly = MAX_LOOPS;
while (thisEUN <= inftl->lastEUN) { while (thisEUN <= inftl->lastEUN) {
MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) + mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci); blockofs, 8, &retlen, (char *)&bci);
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in " DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in "
...@@ -522,8 +525,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) ...@@ -522,8 +525,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
nacs = 0; nacs = 0;
thisEUN = inftl->VUtable[thisVUC]; thisEUN = inftl->VUtable[thisVUC];
if (thisEUN != BLOCK_NIL) { if (thisEUN != BLOCK_NIL) {
MTD_READOOB(inftl->mbd.mtd, thisEUN * inftl->EraseSize mtd->read_oob(mtd, thisEUN * inftl->EraseSize
+ 8, 8, &retlen, (char *)&oob.u); + 8, 8, &retlen, (char *)&oob.u);
anac = oob.u.a.ANAC + 1; anac = oob.u.a.ANAC + 1;
nacs = oob.u.a.NACs + 1; nacs = oob.u.a.NACs + 1;
} }
...@@ -544,8 +547,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) ...@@ -544,8 +547,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
oob.u.a.parityPerField = parity; oob.u.a.parityPerField = parity;
oob.u.a.discarded = 0xaa; oob.u.a.discarded = 0xaa;
MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize + 8, 8, mtd->write_oob(mtd, writeEUN * inftl->EraseSize + 8, 8,
&retlen, (char *)&oob.u); &retlen, (char *)&oob.u);
/* Also back up header... */ /* Also back up header... */
oob.u.b.virtualUnitNo = cpu_to_le16(thisVUC); oob.u.b.virtualUnitNo = cpu_to_le16(thisVUC);
...@@ -555,8 +558,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) ...@@ -555,8 +558,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
oob.u.b.parityPerField = parity; oob.u.b.parityPerField = parity;
oob.u.b.discarded = 0xaa; oob.u.b.discarded = 0xaa;
MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize + mtd->write_oob(mtd, writeEUN * inftl->EraseSize +
SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u); SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);
inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC]; inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC];
inftl->VUtable[thisVUC] = writeEUN; inftl->VUtable[thisVUC] = writeEUN;
...@@ -576,6 +579,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) ...@@ -576,6 +579,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
*/ */
static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC) static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
{ {
struct mtd_info *mtd = inftl->mbd.mtd;
unsigned char BlockUsed[MAX_SECTORS_PER_UNIT]; unsigned char BlockUsed[MAX_SECTORS_PER_UNIT];
unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT]; unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
unsigned int thisEUN, status; unsigned int thisEUN, status;
...@@ -606,9 +610,9 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC) ...@@ -606,9 +610,9 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
if (BlockUsed[block] || BlockDeleted[block]) if (BlockUsed[block] || BlockDeleted[block])
continue; continue;
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize)
+ (block * SECTORSIZE), 8 , &retlen, + (block * SECTORSIZE), 8 , &retlen,
(char *)&bci) < 0) (char *)&bci) < 0)
status = SECTOR_IGNORE; status = SECTOR_IGNORE;
else else
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
...@@ -697,6 +701,7 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block) ...@@ -697,6 +701,7 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
{ {
unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)]; unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1); unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
struct mtd_info *mtd = inftl->mbd.mtd;
unsigned int status; unsigned int status;
int silly = MAX_LOOPS; int silly = MAX_LOOPS;
size_t retlen; size_t retlen;
...@@ -706,8 +711,8 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block) ...@@ -706,8 +711,8 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
"block=%d)\n", inftl, block); "block=%d)\n", inftl, block);
while (thisEUN < inftl->nb_blocks) { while (thisEUN < inftl->nb_blocks) {
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) + if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci) < 0) blockofs, 8, &retlen, (char *)&bci) < 0)
status = SECTOR_IGNORE; status = SECTOR_IGNORE;
else else
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
...@@ -741,10 +746,10 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block) ...@@ -741,10 +746,10 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
if (thisEUN != BLOCK_NIL) { if (thisEUN != BLOCK_NIL) {
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs; loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
if (MTD_READOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0) if (mtd->read_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
return -EIO; return -EIO;
bci.Status = bci.Status1 = SECTOR_DELETED; bci.Status = bci.Status1 = SECTOR_DELETED;
if (MTD_WRITEOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0) if (mtd->write_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
return -EIO; return -EIO;
INFTL_trydeletechain(inftl, block / (inftl->EraseSize / SECTORSIZE)); INFTL_trydeletechain(inftl, block / (inftl->EraseSize / SECTORSIZE));
} }
...@@ -805,6 +810,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, ...@@ -805,6 +810,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
struct INFTLrecord *inftl = (void *)mbd; struct INFTLrecord *inftl = (void *)mbd;
unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)]; unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1); unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
struct mtd_info *mtd = inftl->mbd.mtd;
unsigned int status; unsigned int status;
int silly = MAX_LOOPS; int silly = MAX_LOOPS;
struct inftl_bci bci; struct inftl_bci bci;
...@@ -814,8 +820,8 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, ...@@ -814,8 +820,8 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
"buffer=%p)\n", inftl, block, buffer); "buffer=%p)\n", inftl, block, buffer);
while (thisEUN < inftl->nb_blocks) { while (thisEUN < inftl->nb_blocks) {
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) + if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci) < 0) blockofs, 8, &retlen, (char *)&bci) < 0)
status = SECTOR_IGNORE; status = SECTOR_IGNORE;
else else
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
...@@ -853,8 +859,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, ...@@ -853,8 +859,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
} else { } else {
size_t retlen; size_t retlen;
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs; loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
if (MTD_READ(inftl->mbd.mtd, ptr, SECTORSIZE, &retlen, if (mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer))
buffer))
return -EIO; return -EIO;
} }
return 0; return 0;
......
...@@ -57,6 +57,7 @@ static int find_boot_record(struct INFTLrecord *inftl) ...@@ -57,6 +57,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
unsigned int i, block; unsigned int i, block;
u8 buf[SECTORSIZE]; u8 buf[SECTORSIZE];
struct INFTLMediaHeader *mh = &inftl->MediaHdr; struct INFTLMediaHeader *mh = &inftl->MediaHdr;
struct mtd_info *mtd = inftl->mbd.mtd;
struct INFTLPartition *ip; struct INFTLPartition *ip;
size_t retlen; size_t retlen;
...@@ -80,8 +81,8 @@ static int find_boot_record(struct INFTLrecord *inftl) ...@@ -80,8 +81,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
* Check for BNAND header first. Then whinge if it's found * Check for BNAND header first. Then whinge if it's found
* but later checks fail. * but later checks fail.
*/ */
ret = MTD_READ(inftl->mbd.mtd, block * inftl->EraseSize, ret = mtd->read(mtd, block * inftl->EraseSize,
SECTORSIZE, &retlen, buf); SECTORSIZE, &retlen, buf);
/* We ignore ret in case the ECC of the MediaHeader is invalid /* We ignore ret in case the ECC of the MediaHeader is invalid
(which is apparently acceptable) */ (which is apparently acceptable) */
if (retlen != SECTORSIZE) { if (retlen != SECTORSIZE) {
...@@ -106,8 +107,9 @@ static int find_boot_record(struct INFTLrecord *inftl) ...@@ -106,8 +107,9 @@ static int find_boot_record(struct INFTLrecord *inftl)
} }
/* To be safer with BIOS, also use erase mark as discriminant */ /* To be safer with BIOS, also use erase mark as discriminant */
if ((ret = MTD_READOOB(inftl->mbd.mtd, block * inftl->EraseSize + if ((ret = mtd->read_oob(mtd, block * inftl->EraseSize +
SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0)) { SECTORSIZE + 8, 8, &retlen,
(char *)&h1) < 0)) {
printk(KERN_WARNING "INFTL: ANAND header found at " printk(KERN_WARNING "INFTL: ANAND header found at "
"0x%x in mtd%d, but OOB data read failed " "0x%x in mtd%d, but OOB data read failed "
"(err %d)\n", block * inftl->EraseSize, "(err %d)\n", block * inftl->EraseSize,
...@@ -123,8 +125,8 @@ static int find_boot_record(struct INFTLrecord *inftl) ...@@ -123,8 +125,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
memcpy(mh, buf, sizeof(struct INFTLMediaHeader)); memcpy(mh, buf, sizeof(struct INFTLMediaHeader));
/* Read the spare media header at offset 4096 */ /* Read the spare media header at offset 4096 */
MTD_READ(inftl->mbd.mtd, block * inftl->EraseSize + 4096, mtd->read(mtd, block * inftl->EraseSize + 4096,
SECTORSIZE, &retlen, buf); SECTORSIZE, &retlen, buf);
if (retlen != SECTORSIZE) { if (retlen != SECTORSIZE) {
printk(KERN_WARNING "INFTL: Unable to read spare " printk(KERN_WARNING "INFTL: Unable to read spare "
"Media Header\n"); "Media Header\n");
...@@ -233,7 +235,7 @@ static int find_boot_record(struct INFTLrecord *inftl) ...@@ -233,7 +235,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
*/ */
instr->addr = ip->Reserved0 * inftl->EraseSize; instr->addr = ip->Reserved0 * inftl->EraseSize;
instr->len = inftl->EraseSize; instr->len = inftl->EraseSize;
MTD_ERASE(inftl->mbd.mtd, instr); mtd->erase(mtd, instr);
} }
if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) { if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
printk(KERN_WARNING "INFTL: Media Header " printk(KERN_WARNING "INFTL: Media Header "
...@@ -387,6 +389,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) ...@@ -387,6 +389,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
size_t retlen; size_t retlen;
struct inftl_unittail uci; struct inftl_unittail uci;
struct erase_info *instr = &inftl->instr; struct erase_info *instr = &inftl->instr;
struct mtd_info *mtd = inftl->mbd.mtd;
int physblock; int physblock;
DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=%p," DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=%p,"
...@@ -404,8 +407,9 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) ...@@ -404,8 +407,9 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
/* Erase one physical eraseblock at a time, even though the NAND api /* Erase one physical eraseblock at a time, even though the NAND api
allows us to group them. This way we if we have a failure, we can allows us to group them. This way we if we have a failure, we can
mark only the failed block in the bbt. */ mark only the failed block in the bbt. */
for (physblock = 0; physblock < inftl->EraseSize; physblock += instr->len, instr->addr += instr->len) { for (physblock = 0; physblock < inftl->EraseSize;
MTD_ERASE(inftl->mbd.mtd, instr); physblock += instr->len, instr->addr += instr->len) {
mtd->erase(inftl->mbd.mtd, instr);
if (instr->state == MTD_ERASE_FAILED) { if (instr->state == MTD_ERASE_FAILED) {
printk(KERN_WARNING "INFTL: error while formatting block %d\n", printk(KERN_WARNING "INFTL: error while formatting block %d\n",
...@@ -414,10 +418,10 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) ...@@ -414,10 +418,10 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
} }
/* /*
* Check the "freeness" of Erase Unit before updating metadata. * Check the "freeness" of Erase Unit before updating metadata.
* FixMe: is this check really necessary? Since we have check the * FixMe: is this check really necessary? Since we have check
* return code after the erase operation. * the return code after the erase operation.
*/ */
if (check_free_sectors(inftl, instr->addr, instr->len, 1) != 0) if (check_free_sectors(inftl, instr->addr, instr->len, 1) != 0)
goto fail; goto fail;
} }
...@@ -429,8 +433,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) ...@@ -429,8 +433,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
uci.Reserved[2] = 0; uci.Reserved[2] = 0;
uci.Reserved[3] = 0; uci.Reserved[3] = 0;
instr->addr = block * inftl->EraseSize + SECTORSIZE * 2; instr->addr = block * inftl->EraseSize + SECTORSIZE * 2;
if (MTD_WRITEOOB(inftl->mbd.mtd, instr->addr + if (mtd->write_oob(mtd, instr->addr + 8, 8, &retlen, (char *)&uci) < 0)
8, 8, &retlen, (char *)&uci) < 0)
goto fail; goto fail;
return 0; return 0;
fail: fail:
...@@ -549,6 +552,7 @@ void INFTL_dumpVUchains(struct INFTLrecord *s) ...@@ -549,6 +552,7 @@ void INFTL_dumpVUchains(struct INFTLrecord *s)
int INFTL_mount(struct INFTLrecord *s) int INFTL_mount(struct INFTLrecord *s)
{ {
struct mtd_info *mtd = s->mbd.mtd;
unsigned int block, first_block, prev_block, last_block; unsigned int block, first_block, prev_block, last_block;
unsigned int first_logical_block, logical_block, erase_mark; unsigned int first_logical_block, logical_block, erase_mark;
int chain_length, do_format_chain; int chain_length, do_format_chain;
...@@ -607,10 +611,11 @@ int INFTL_mount(struct INFTLrecord *s) ...@@ -607,10 +611,11 @@ int INFTL_mount(struct INFTLrecord *s)
break; break;
} }
if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, if (mtd->read_oob(mtd, block * s->EraseSize + 8,
8, &retlen, (char *)&h0) < 0 || 8, &retlen, (char *)&h0) < 0 ||
MTD_READOOB(s->mbd.mtd, block * s->EraseSize + mtd->read_oob(mtd, block * s->EraseSize +
2 * SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0) { 2 * SECTORSIZE + 8, 8, &retlen,
(char *)&h1) < 0) {
/* Should never happen? */ /* Should never happen? */
do_format_chain++; do_format_chain++;
break; break;
......
...@@ -190,7 +190,7 @@ int nettel_eraseconfig(void) ...@@ -190,7 +190,7 @@ int nettel_eraseconfig(void)
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&wait_q, &wait); add_wait_queue(&wait_q, &wait);
ret = MTD_ERASE(mtd, &nettel_erase); ret = mtd->erase(mtd, &nettel_erase);
if (ret) { if (ret) {
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait); remove_wait_queue(&wait_q, &wait);
......
...@@ -71,7 +71,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, ...@@ -71,7 +71,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&wait_q, &wait); add_wait_queue(&wait_q, &wait);
ret = MTD_ERASE(mtd, &erase); ret = mtd->erase(mtd, &erase);
if (ret) { if (ret) {
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait); remove_wait_queue(&wait_q, &wait);
...@@ -88,7 +88,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, ...@@ -88,7 +88,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
* Next, writhe data to flash. * Next, writhe data to flash.
*/ */
ret = MTD_WRITE (mtd, pos, len, &retlen, buf); ret = mtd->write(mtd, pos, len, &retlen, buf);
if (ret) if (ret)
return ret; return ret;
if (retlen != len) if (retlen != len)
...@@ -138,7 +138,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, ...@@ -138,7 +138,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
mtd->name, pos, len); mtd->name, pos, len);
if (!sect_size) if (!sect_size)
return MTD_WRITE (mtd, pos, len, &retlen, buf); return mtd->write(mtd, pos, len, &retlen, buf);
while (len > 0) { while (len > 0) {
unsigned long sect_start = (pos/sect_size)*sect_size; unsigned long sect_start = (pos/sect_size)*sect_size;
...@@ -170,7 +170,8 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, ...@@ -170,7 +170,8 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
mtdblk->cache_offset != sect_start) { mtdblk->cache_offset != sect_start) {
/* fill the cache with the current sector */ /* fill the cache with the current sector */
mtdblk->cache_state = STATE_EMPTY; mtdblk->cache_state = STATE_EMPTY;
ret = MTD_READ(mtd, sect_start, sect_size, &retlen, mtdblk->cache_data); ret = mtd->read(mtd, sect_start, sect_size,
&retlen, mtdblk->cache_data);
if (ret) if (ret)
return ret; return ret;
if (retlen != sect_size) if (retlen != sect_size)
...@@ -207,7 +208,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, ...@@ -207,7 +208,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
mtd->name, pos, len); mtd->name, pos, len);
if (!sect_size) if (!sect_size)
return MTD_READ (mtd, pos, len, &retlen, buf); return mtd->read(mtd, pos, len, &retlen, buf);
while (len > 0) { while (len > 0) {
unsigned long sect_start = (pos/sect_size)*sect_size; unsigned long sect_start = (pos/sect_size)*sect_size;
...@@ -226,7 +227,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, ...@@ -226,7 +227,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
mtdblk->cache_offset == sect_start) { mtdblk->cache_offset == sect_start) {
memcpy (buf, mtdblk->cache_data + offset, size); memcpy (buf, mtdblk->cache_data + offset, size);
} else { } else {
ret = MTD_READ (mtd, pos, size, &retlen, buf); ret = mtd->read(mtd, pos, size, &retlen, buf);
if (ret) if (ret)
return ret; return ret;
if (retlen != size) if (retlen != size)
......
...@@ -194,7 +194,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t ...@@ -194,7 +194,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
break; break;
default: default:
ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf); ret = mtd->read(mtd, *ppos, len, &retlen, kbuf);
} }
/* Nand returns -EBADMSG on ecc errors, but it returns /* Nand returns -EBADMSG on ecc errors, but it returns
* the data. For our userspace tools it is important * the data. For our userspace tools it is important
...@@ -205,7 +205,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t ...@@ -205,7 +205,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
if (!ret || (ret == -EBADMSG)) { if (!ret || (ret == -EBADMSG)) {
*ppos += retlen; *ppos += retlen;
if (copy_to_user(buf, kbuf, retlen)) { if (copy_to_user(buf, kbuf, retlen)) {
kfree(kbuf); kfree(kbuf);
return -EFAULT; return -EFAULT;
} }
else else
......
...@@ -183,6 +183,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate ) ...@@ -183,6 +183,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate )
static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned pendingblock ) static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned pendingblock )
{ {
struct mtd_info *mtd = nftl->mbd.mtd;
u16 BlockMap[MAX_SECTORS_PER_UNIT]; u16 BlockMap[MAX_SECTORS_PER_UNIT];
unsigned char BlockLastState[MAX_SECTORS_PER_UNIT]; unsigned char BlockLastState[MAX_SECTORS_PER_UNIT];
unsigned char BlockFreeFound[MAX_SECTORS_PER_UNIT]; unsigned char BlockFreeFound[MAX_SECTORS_PER_UNIT];
...@@ -192,7 +193,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -192,7 +193,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
unsigned int targetEUN; unsigned int targetEUN;
struct nftl_oob oob; struct nftl_oob oob;
int inplace = 1; int inplace = 1;
size_t retlen; size_t retlen;
memset(BlockMap, 0xff, sizeof(BlockMap)); memset(BlockMap, 0xff, sizeof(BlockMap));
memset(BlockFreeFound, 0, sizeof(BlockFreeFound)); memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
...@@ -208,21 +209,21 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -208,21 +209,21 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
/* Scan to find the Erase Unit which holds the actual data for each /* Scan to find the Erase Unit which holds the actual data for each
512-byte block within the Chain. 512-byte block within the Chain.
*/ */
silly = MAX_LOOPS; silly = MAX_LOOPS;
targetEUN = BLOCK_NIL; targetEUN = BLOCK_NIL;
while (thisEUN <= nftl->lastEUN ) { while (thisEUN <= nftl->lastEUN ) {
unsigned int status, foldmark; unsigned int status, foldmark;
targetEUN = thisEUN; targetEUN = thisEUN;
for (block = 0; block < nftl->EraseSize / 512; block ++) { for (block = 0; block < nftl->EraseSize / 512; block ++) {
MTD_READOOB(nftl->mbd.mtd, mtd->read_oob(mtd, (thisEUN * nftl->EraseSize) +
(thisEUN * nftl->EraseSize) + (block * 512), (block * 512), 16 , &retlen,
16 , &retlen, (char *)&oob); (char *)&oob);
if (block == 2) { if (block == 2) {
foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1; foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1;
if (foldmark == FOLD_MARK_IN_PROGRESS) { if (foldmark == FOLD_MARK_IN_PROGRESS) {
DEBUG(MTD_DEBUG_LEVEL1, DEBUG(MTD_DEBUG_LEVEL1,
"Write Inhibited on EUN %d\n", thisEUN); "Write Inhibited on EUN %d\n", thisEUN);
inplace = 0; inplace = 0;
} else { } else {
/* There's no other reason not to do inplace, /* There's no other reason not to do inplace,
...@@ -231,7 +232,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -231,7 +232,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
inplace = 1; inplace = 1;
} }
} }
status = oob.b.Status | oob.b.Status1; status = oob.b.Status | oob.b.Status1;
BlockLastState[block] = status; BlockLastState[block] = status;
switch(status) { switch(status) {
...@@ -326,15 +327,15 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -326,15 +327,15 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
return BLOCK_NIL; return BLOCK_NIL;
} }
} else { } else {
/* We put a fold mark in the chain we are folding only if /* We put a fold mark in the chain we are folding only if we
we fold in place to help the mount check code. If we do fold in place to help the mount check code. If we do not fold in
not fold in place, it is possible to find the valid place, it is possible to find the valid chain by selecting the
chain by selecting the longer one */ longer one */
oob.u.c.FoldMark = oob.u.c.FoldMark1 = cpu_to_le16(FOLD_MARK_IN_PROGRESS); oob.u.c.FoldMark = oob.u.c.FoldMark1 = cpu_to_le16(FOLD_MARK_IN_PROGRESS);
oob.u.c.unused = 0xffffffff; oob.u.c.unused = 0xffffffff;
MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 2 * 512 + 8, mtd->write_oob(mtd, (nftl->EraseSize * targetEUN) + 2 * 512 + 8,
8, &retlen, (char *)&oob.u); 8, &retlen, (char *)&oob.u);
} }
/* OK. We now know the location of every block in the Virtual Unit Chain, /* OK. We now know the location of every block in the Virtual Unit Chain,
and the Erase Unit into which we are supposed to be copying. and the Erase Unit into which we are supposed to be copying.
...@@ -351,20 +352,20 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -351,20 +352,20 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
continue; continue;
} }
/* copy only in non free block (free blocks can only /* copy only in non free block (free blocks can only
happen in case of media errors or deleted blocks) */ happen in case of media errors or deleted blocks) */
if (BlockMap[block] == BLOCK_NIL) if (BlockMap[block] == BLOCK_NIL)
continue; continue;
ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512),
512, &retlen, movebuf); 512, &retlen, movebuf);
if (ret < 0) { if (ret < 0) {
ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block])
+ (block * 512), 512, &retlen, + (block * 512), 512, &retlen,
movebuf); movebuf);
if (ret != -EIO) if (ret != -EIO)
printk("Error went away on retry.\n"); printk("Error went away on retry.\n");
} }
memset(&oob, 0xff, sizeof(struct nftl_oob)); memset(&oob, 0xff, sizeof(struct nftl_oob));
oob.b.Status = oob.b.Status1 = SECTOR_USED; oob.b.Status = oob.b.Status1 = SECTOR_USED;
...@@ -374,13 +375,12 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -374,13 +375,12 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
} }
/* add the header so that it is now a valid chain */ /* add the header so that it is now a valid chain */
oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC);
= cpu_to_le16(thisVUC); oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff;
oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff;
MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 8, mtd->write_oob(mtd, (nftl->EraseSize * targetEUN) + 8,
8, &retlen, (char *)&oob.u); 8, &retlen, (char *)&oob.u);
/* OK. We've moved the whole lot into the new block. Now we have to free the original blocks. */ /* OK. We've moved the whole lot into the new block. Now we have to free the original blocks. */
...@@ -397,18 +397,18 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p ...@@ -397,18 +397,18 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
while (thisEUN <= nftl->lastEUN && thisEUN != targetEUN) { while (thisEUN <= nftl->lastEUN && thisEUN != targetEUN) {
unsigned int EUNtmp; unsigned int EUNtmp;
EUNtmp = nftl->ReplUnitTable[thisEUN]; EUNtmp = nftl->ReplUnitTable[thisEUN];
if (NFTL_formatblock(nftl, thisEUN) < 0) { if (NFTL_formatblock(nftl, thisEUN) < 0) {
/* could not erase : mark block as reserved /* could not erase : mark block as reserved
*/ */
nftl->ReplUnitTable[thisEUN] = BLOCK_RESERVED; nftl->ReplUnitTable[thisEUN] = BLOCK_RESERVED;
} else { } else {
/* correctly erased : mark it as free */ /* correctly erased : mark it as free */
nftl->ReplUnitTable[thisEUN] = BLOCK_FREE; nftl->ReplUnitTable[thisEUN] = BLOCK_FREE;
nftl->numfreeEUNs++; nftl->numfreeEUNs++;
} }
thisEUN = EUNtmp; thisEUN = EUNtmp;
} }
/* Make this the new start of chain for thisVUC */ /* Make this the new start of chain for thisVUC */
...@@ -474,6 +474,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) ...@@ -474,6 +474,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
{ {
u16 lastEUN; u16 lastEUN;
u16 thisVUC = block / (nftl->EraseSize / 512); u16 thisVUC = block / (nftl->EraseSize / 512);
struct mtd_info *mtd = nftl->mbd.mtd;
unsigned int writeEUN; unsigned int writeEUN;
unsigned long blockofs = (block * 512) & (nftl->EraseSize -1); unsigned long blockofs = (block * 512) & (nftl->EraseSize -1);
size_t retlen; size_t retlen;
...@@ -490,21 +491,22 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) ...@@ -490,21 +491,22 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
*/ */
lastEUN = BLOCK_NIL; lastEUN = BLOCK_NIL;
writeEUN = nftl->EUNtable[thisVUC]; writeEUN = nftl->EUNtable[thisVUC];
silly = MAX_LOOPS; silly = MAX_LOOPS;
while (writeEUN <= nftl->lastEUN) { while (writeEUN <= nftl->lastEUN) {
struct nftl_bci bci; struct nftl_bci bci;
size_t retlen; size_t retlen;
unsigned int status; unsigned int status;
lastEUN = writeEUN; lastEUN = writeEUN;
MTD_READOOB(nftl->mbd.mtd, (writeEUN * nftl->EraseSize) + blockofs, mtd->read_oob(mtd,
8, &retlen, (char *)&bci); (writeEUN * nftl->EraseSize) + blockofs,
8, &retlen, (char *)&bci);
DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n", DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n",
block , writeEUN, le16_to_cpu(bci.Status)); block , writeEUN, le16_to_cpu(bci.Status));
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
switch(status) { switch(status) {
case SECTOR_FREE: case SECTOR_FREE:
return writeEUN; return writeEUN;
...@@ -575,10 +577,10 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) ...@@ -575,10 +577,10 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
/* We've found a free block. Insert it into the chain. */ /* We've found a free block. Insert it into the chain. */
if (lastEUN != BLOCK_NIL) { if (lastEUN != BLOCK_NIL) {
thisVUC |= 0x8000; /* It's a replacement block */ thisVUC |= 0x8000; /* It's a replacement block */
} else { } else {
/* The first block in a new chain */ /* The first block in a new chain */
nftl->EUNtable[thisVUC] = writeEUN; nftl->EUNtable[thisVUC] = writeEUN;
} }
/* set up the actual EUN we're writing into */ /* set up the actual EUN we're writing into */
...@@ -586,29 +588,29 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) ...@@ -586,29 +588,29 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
nftl->ReplUnitTable[writeEUN] = BLOCK_NIL; nftl->ReplUnitTable[writeEUN] = BLOCK_NIL;
/* ... and on the flash itself */ /* ... and on the flash itself */
MTD_READOOB(nftl->mbd.mtd, writeEUN * nftl->EraseSize + 8, 8, mtd->read_oob(mtd, writeEUN * nftl->EraseSize + 8, 8,
&retlen, (char *)&oob.u); &retlen, (char *)&oob.u);
oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC); oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC);
MTD_WRITEOOB(nftl->mbd.mtd, writeEUN * nftl->EraseSize + 8, 8, mtd->write_oob(mtd, writeEUN * nftl->EraseSize + 8, 8,
&retlen, (char *)&oob.u); &retlen, (char *)&oob.u);
/* we link the new block to the chain only after the /* we link the new block to the chain only after the
block is ready. It avoids the case where the chain block is ready. It avoids the case where the chain
could point to a free block */ could point to a free block */
if (lastEUN != BLOCK_NIL) { if (lastEUN != BLOCK_NIL) {
/* Both in our cache... */ /* Both in our cache... */
nftl->ReplUnitTable[lastEUN] = writeEUN; nftl->ReplUnitTable[lastEUN] = writeEUN;
/* ... and on the flash itself */ /* ... and on the flash itself */
MTD_READOOB(nftl->mbd.mtd, (lastEUN * nftl->EraseSize) + 8, mtd->read_oob(mtd, (lastEUN * nftl->EraseSize) + 8,
8, &retlen, (char *)&oob.u); 8, &retlen, (char *)&oob.u);
oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum
= cpu_to_le16(writeEUN); = cpu_to_le16(writeEUN);
MTD_WRITEOOB(nftl->mbd.mtd, (lastEUN * nftl->EraseSize) + 8, mtd->write_oob(mtd, (lastEUN * nftl->EraseSize) + 8,
8, &retlen, (char *)&oob.u); 8, &retlen, (char *)&oob.u);
} }
return writeEUN; return writeEUN;
...@@ -652,20 +654,22 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, ...@@ -652,20 +654,22 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
char *buffer) char *buffer)
{ {
struct NFTLrecord *nftl = (void *)mbd; struct NFTLrecord *nftl = (void *)mbd;
struct mtd_info *mtd = nftl->mbd.mtd;
u16 lastgoodEUN; u16 lastgoodEUN;
u16 thisEUN = nftl->EUNtable[block / (nftl->EraseSize / 512)]; u16 thisEUN = nftl->EUNtable[block / (nftl->EraseSize / 512)];
unsigned long blockofs = (block * 512) & (nftl->EraseSize - 1); unsigned long blockofs = (block * 512) & (nftl->EraseSize - 1);
unsigned int status; unsigned int status;
int silly = MAX_LOOPS; int silly = MAX_LOOPS;
size_t retlen; size_t retlen;
struct nftl_bci bci; struct nftl_bci bci;
lastgoodEUN = BLOCK_NIL; lastgoodEUN = BLOCK_NIL;
if (thisEUN != BLOCK_NIL) { if (thisEUN != BLOCK_NIL) {
while (thisEUN < nftl->nb_blocks) { while (thisEUN < nftl->nb_blocks) {
if (MTD_READOOB(nftl->mbd.mtd, (thisEUN * nftl->EraseSize) + blockofs, if (mtd->read_oob(mtd, (thisEUN * nftl->EraseSize) +
8, &retlen, (char *)&bci) < 0) blockofs, 8, &retlen,
(char *)&bci) < 0)
status = SECTOR_IGNORE; status = SECTOR_IGNORE;
else else
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
...@@ -695,7 +699,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, ...@@ -695,7 +699,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
} }
thisEUN = nftl->ReplUnitTable[thisEUN]; thisEUN = nftl->ReplUnitTable[thisEUN];
} }
} }
the_end: the_end:
if (lastgoodEUN == BLOCK_NIL) { if (lastgoodEUN == BLOCK_NIL) {
...@@ -704,7 +708,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, ...@@ -704,7 +708,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
} else { } else {
loff_t ptr = (lastgoodEUN * nftl->EraseSize) + blockofs; loff_t ptr = (lastgoodEUN * nftl->EraseSize) + blockofs;
size_t retlen; size_t retlen;
if (MTD_READ(nftl->mbd.mtd, ptr, 512, &retlen, buffer)) if (mtd->read(mtd, ptr, 512, &retlen, buffer))
return -EIO; return -EIO;
} }
return 0; return 0;
......
...@@ -45,6 +45,7 @@ static int find_boot_record(struct NFTLrecord *nftl) ...@@ -45,6 +45,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
size_t retlen; size_t retlen;
u8 buf[SECTORSIZE]; u8 buf[SECTORSIZE];
struct NFTLMediaHeader *mh = &nftl->MediaHdr; struct NFTLMediaHeader *mh = &nftl->MediaHdr;
struct mtd_info *mtd = nftl->mbd.mtd;
unsigned int i; unsigned int i;
/* Assume logical EraseSize == physical erasesize for starting the scan. /* Assume logical EraseSize == physical erasesize for starting the scan.
...@@ -65,7 +66,8 @@ static int find_boot_record(struct NFTLrecord *nftl) ...@@ -65,7 +66,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
/* Check for ANAND header first. Then can whinge if it's found but later /* Check for ANAND header first. Then can whinge if it's found but later
checks fail */ checks fail */
ret = MTD_READ(nftl->mbd.mtd, block * nftl->EraseSize, SECTORSIZE, &retlen, buf); ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE,
&retlen, buf);
/* We ignore ret in case the ECC of the MediaHeader is invalid /* We ignore ret in case the ECC of the MediaHeader is invalid
(which is apparently acceptable) */ (which is apparently acceptable) */
if (retlen != SECTORSIZE) { if (retlen != SECTORSIZE) {
...@@ -90,8 +92,9 @@ static int find_boot_record(struct NFTLrecord *nftl) ...@@ -90,8 +92,9 @@ static int find_boot_record(struct NFTLrecord *nftl)
} }
/* To be safer with BIOS, also use erase mark as discriminant */ /* To be safer with BIOS, also use erase mark as discriminant */
if ((ret = MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, if ((ret = mtd->read_oob(mtd, block * nftl->EraseSize +
8, &retlen, (char *)&h1) < 0)) { 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", 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); block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
continue; continue;
...@@ -109,8 +112,8 @@ static int find_boot_record(struct NFTLrecord *nftl) ...@@ -109,8 +112,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
} }
/* Finally reread to check ECC */ /* Finally reread to check ECC */
if ((ret = MTD_READECC(nftl->mbd.mtd, block * nftl->EraseSize, SECTORSIZE, if ((ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE,
&retlen, buf, (char *)&oob, NULL) < 0)) { &retlen, buf) < 0)) {
printk(KERN_NOTICE "ANAND header found at 0x%x in mtd%d, but ECC read failed (err %d)\n", 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); block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
continue; continue;
...@@ -228,9 +231,9 @@ device is already correct. ...@@ -228,9 +231,9 @@ device is already correct.
The new DiskOnChip driver already scanned the bad block table. Just query it. The new DiskOnChip driver already scanned the bad block table. Just query it.
if ((i & (SECTORSIZE - 1)) == 0) { if ((i & (SECTORSIZE - 1)) == 0) {
/* read one sector for every SECTORSIZE of blocks */ /* read one sector for every SECTORSIZE of blocks */
if ((ret = MTD_READECC(nftl->mbd.mtd, block * nftl->EraseSize + if ((ret = mtd->read(nftl->mbd.mtd, block * nftl->EraseSize +
i + SECTORSIZE, SECTORSIZE, &retlen, buf, i + SECTORSIZE, SECTORSIZE, &retlen,
(char *)&oob, NULL)) < 0) { buf)) < 0) {
printk(KERN_NOTICE "Read of bad sector table failed (err %d)\n", printk(KERN_NOTICE "Read of bad sector table failed (err %d)\n",
ret); ret);
kfree(nftl->ReplUnitTable); kfree(nftl->ReplUnitTable);
...@@ -305,10 +308,11 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) ...@@ -305,10 +308,11 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
unsigned int nb_erases, erase_mark; unsigned int nb_erases, erase_mark;
struct nftl_uci1 uci; struct nftl_uci1 uci;
struct erase_info *instr = &nftl->instr; struct erase_info *instr = &nftl->instr;
struct mtd_info *mtd = nftl->mbd.mtd;
/* Read the Unit Control Information #1 for Wear-Leveling */ /* Read the Unit Control Information #1 for Wear-Leveling */
if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, if (mtd->read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8,
8, &retlen, (char *)&uci) < 0) 8, &retlen, (char *)&uci) < 0)
goto default_uci1; goto default_uci1;
erase_mark = le16_to_cpu ((uci.EraseMark | uci.EraseMark1)); erase_mark = le16_to_cpu ((uci.EraseMark | uci.EraseMark1));
...@@ -325,7 +329,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) ...@@ -325,7 +329,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
instr->mtd = nftl->mbd.mtd; instr->mtd = nftl->mbd.mtd;
instr->addr = block * nftl->EraseSize; instr->addr = block * nftl->EraseSize;
instr->len = nftl->EraseSize; instr->len = nftl->EraseSize;
MTD_ERASE(nftl->mbd.mtd, instr); mtd->erase(mtd, instr);
if (instr->state == MTD_ERASE_FAILED) { if (instr->state == MTD_ERASE_FAILED) {
printk("Error while formatting block %d\n", block); printk("Error while formatting block %d\n", block);
...@@ -347,8 +351,8 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) ...@@ -347,8 +351,8 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
goto fail; goto fail;
uci.WearInfo = le32_to_cpu(nb_erases); uci.WearInfo = le32_to_cpu(nb_erases);
if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, if (mtd->write_oob(mtd, block * nftl->EraseSize + SECTORSIZE +
&retlen, (char *)&uci) < 0) 8, 8, &retlen, (char *)&uci) < 0)
goto fail; goto fail;
return 0; return 0;
fail: fail:
...@@ -369,6 +373,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) ...@@ -369,6 +373,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
* case. */ * case. */
static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_block) 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; unsigned int block, i, status;
struct nftl_bci bci; struct nftl_bci bci;
int sectors_per_block; int sectors_per_block;
...@@ -378,8 +383,9 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b ...@@ -378,8 +383,9 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
block = first_block; block = first_block;
for (;;) { for (;;) {
for (i = 0; i < sectors_per_block; i++) { for (i = 0; i < sectors_per_block; i++) {
if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + i * SECTORSIZE, if (mtd->read_oob(mtd,
8, &retlen, (char *)&bci) < 0) block * nftl->EraseSize + i * SECTORSIZE,
8, &retlen, (char *)&bci) < 0)
status = SECTOR_IGNORE; status = SECTOR_IGNORE;
else else
status = bci.Status | bci.Status1; status = bci.Status | bci.Status1;
...@@ -398,9 +404,10 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b ...@@ -398,9 +404,10 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
/* sector not free actually : mark it as SECTOR_IGNORE */ /* sector not free actually : mark it as SECTOR_IGNORE */
bci.Status = SECTOR_IGNORE; bci.Status = SECTOR_IGNORE;
bci.Status1 = SECTOR_IGNORE; bci.Status1 = SECTOR_IGNORE;
MTD_WRITEOOB(nftl->mbd.mtd, mtd->write_oob(mtd, block *
block * nftl->EraseSize + i * SECTORSIZE, nftl->EraseSize +
8, &retlen, (char *)&bci); i * SECTORSIZE, 8,
&retlen, (char *)&bci);
} }
break; break;
default: default:
...@@ -485,13 +492,14 @@ static void format_chain(struct NFTLrecord *nftl, unsigned int first_block) ...@@ -485,13 +492,14 @@ static void format_chain(struct NFTLrecord *nftl, unsigned int first_block)
* 1. */ * 1. */
static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
{ {
struct mtd_info *mtd = nftl->mbd.mtd;
struct nftl_uci1 h1; struct nftl_uci1 h1;
unsigned int erase_mark; unsigned int erase_mark;
size_t retlen; size_t retlen;
/* check erase mark. */ /* check erase mark. */
if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, if (mtd->read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
&retlen, (char *)&h1) < 0) &retlen, (char *)&h1) < 0)
return -1; return -1;
erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1)); erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1));
...@@ -505,8 +513,9 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) ...@@ -505,8 +513,9 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
h1.EraseMark = cpu_to_le16(ERASE_MARK); h1.EraseMark = cpu_to_le16(ERASE_MARK);
h1.EraseMark1 = cpu_to_le16(ERASE_MARK); h1.EraseMark1 = cpu_to_le16(ERASE_MARK);
h1.WearInfo = cpu_to_le32(0); h1.WearInfo = cpu_to_le32(0);
if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, if (mtd->write_oob(mtd,
&retlen, (char *)&h1) < 0) block * nftl->EraseSize + SECTORSIZE + 8, 8,
&retlen, (char *)&h1) < 0)
return -1; return -1;
} else { } else {
#if 0 #if 0
...@@ -517,8 +526,8 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) ...@@ -517,8 +526,8 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
SECTORSIZE, 0) != 0) SECTORSIZE, 0) != 0)
return -1; return -1;
if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + i, if (mtd->read_oob(mtd, block * nftl->EraseSize + i,
16, &retlen, buf) < 0) 16, &retlen, buf) < 0)
return -1; return -1;
if (i == SECTORSIZE) { if (i == SECTORSIZE) {
/* skip erase mark */ /* skip erase mark */
...@@ -544,11 +553,12 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) ...@@ -544,11 +553,12 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
*/ */
static int get_fold_mark(struct NFTLrecord *nftl, unsigned int block) static int get_fold_mark(struct NFTLrecord *nftl, unsigned int block)
{ {
struct mtd_info *mtd = nftl->mbd.mtd;
struct nftl_uci2 uci; struct nftl_uci2 uci;
size_t retlen; size_t retlen;
if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8, if (mtd->read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8,
8, &retlen, (char *)&uci) < 0) 8, &retlen, (char *)&uci) < 0)
return 0; return 0;
return le16_to_cpu((uci.FoldMark | uci.FoldMark1)); return le16_to_cpu((uci.FoldMark | uci.FoldMark1));
...@@ -562,6 +572,7 @@ int NFTL_mount(struct NFTLrecord *s) ...@@ -562,6 +572,7 @@ int NFTL_mount(struct NFTLrecord *s)
int chain_length, do_format_chain; int chain_length, do_format_chain;
struct nftl_uci0 h0; struct nftl_uci0 h0;
struct nftl_uci1 h1; struct nftl_uci1 h1;
struct mtd_info *mtd = s->mbd.mtd;
size_t retlen; size_t retlen;
/* search for NFTL MediaHeader and Spare NFTL Media Header */ /* search for NFTL MediaHeader and Spare NFTL Media Header */
...@@ -586,10 +597,13 @@ int NFTL_mount(struct NFTLrecord *s) ...@@ -586,10 +597,13 @@ int NFTL_mount(struct NFTLrecord *s)
for (;;) { for (;;) {
/* read the block header. If error, we format the chain */ /* read the block header. If error, we format the chain */
if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, 8, if (mtd->read_oob(mtd,
&retlen, (char *)&h0) < 0 || block * s->EraseSize + 8, 8,
MTD_READOOB(s->mbd.mtd, block * s->EraseSize + SECTORSIZE + 8, 8, &retlen, (char *)&h0) < 0 ||
&retlen, (char *)&h1) < 0) { mtd->read_oob(mtd,
block * s->EraseSize +
SECTORSIZE + 8, 8,
&retlen, (char *)&h1) < 0) {
s->ReplUnitTable[block] = BLOCK_NIL; s->ReplUnitTable[block] = BLOCK_NIL;
do_format_chain = 1; do_format_chain = 1;
break; break;
......
...@@ -247,7 +247,7 @@ flash_safe_read(struct mtd_info *mtd, loff_t from, ...@@ -247,7 +247,7 @@ flash_safe_read(struct mtd_info *mtd, loff_t from,
D3(printk(KERN_NOTICE "flash_safe_read(%p, %08x, %p, %08x)\n", D3(printk(KERN_NOTICE "flash_safe_read(%p, %08x, %p, %08x)\n",
mtd, (unsigned int) from, buf, count)); mtd, (unsigned int) from, buf, count));
res = MTD_READ(mtd, from, count, &retlen, buf); res = mtd->read(mtd, from, count, &retlen, buf);
if (retlen != count) { if (retlen != count) {
panic("Didn't read all bytes in flash_safe_read(). Returned %d\n", res); panic("Didn't read all bytes in flash_safe_read(). Returned %d\n", res);
} }
...@@ -262,7 +262,7 @@ flash_read_u32(struct mtd_info *mtd, loff_t from) ...@@ -262,7 +262,7 @@ flash_read_u32(struct mtd_info *mtd, loff_t from)
__u32 ret; __u32 ret;
int res; int res;
res = MTD_READ(mtd, from, 4, &retlen, (unsigned char *)&ret); res = mtd->read(mtd, from, 4, &retlen, (unsigned char *)&ret);
if (retlen != 4) { if (retlen != 4) {
printk("Didn't read all bytes in flash_read_u32(). Returned %d\n", res); printk("Didn't read all bytes in flash_read_u32(). Returned %d\n", res);
return 0; return 0;
...@@ -282,7 +282,7 @@ flash_safe_write(struct mtd_info *mtd, loff_t to, ...@@ -282,7 +282,7 @@ flash_safe_write(struct mtd_info *mtd, loff_t to,
D3(printk(KERN_NOTICE "flash_safe_write(%p, %08x, %p, %08x)\n", D3(printk(KERN_NOTICE "flash_safe_write(%p, %08x, %p, %08x)\n",
mtd, (unsigned int) to, buf, count)); mtd, (unsigned int) to, buf, count));
res = MTD_WRITE(mtd, to, count, &retlen, buf); res = mtd->write(mtd, to, count, &retlen, buf);
if (retlen != count) { if (retlen != count) {
printk("Didn't write all bytes in flash_safe_write(). Returned %d\n", res); printk("Didn't write all bytes in flash_safe_write(). Returned %d\n", res);
} }
...@@ -300,9 +300,9 @@ flash_safe_writev(struct mtd_info *mtd, const struct kvec *vecs, ...@@ -300,9 +300,9 @@ flash_safe_writev(struct mtd_info *mtd, const struct kvec *vecs,
D3(printk(KERN_NOTICE "flash_safe_writev(%p, %08x, %p)\n", D3(printk(KERN_NOTICE "flash_safe_writev(%p, %08x, %p)\n",
mtd, (unsigned int) to, vecs)); mtd, (unsigned int) to, vecs));
if (mtd->writev) { if (mtd->writev) {
res = MTD_WRITEV(mtd, vecs, iovec_cnt, to, &retlen); res = mtd->writev(mtd, vecs, iovec_cnt, to, &retlen);
return res ? res : retlen; return res ? res : retlen;
} }
/* Not implemented writev. Repeatedly use write - on the not so /* Not implemented writev. Repeatedly use write - on the not so
...@@ -312,7 +312,8 @@ flash_safe_writev(struct mtd_info *mtd, const struct kvec *vecs, ...@@ -312,7 +312,8 @@ flash_safe_writev(struct mtd_info *mtd, const struct kvec *vecs,
retlen=0; retlen=0;
for (i=0; !res && i<iovec_cnt; i++) { for (i=0; !res && i<iovec_cnt; i++) {
res = MTD_WRITE(mtd, to, vecs[i].iov_len, &retlen_a, vecs[i].iov_base); res = mtd->write(mtd, to, vecs[i].iov_len, &retlen_a,
vecs[i].iov_base);
if (retlen_a != vecs[i].iov_len) { if (retlen_a != vecs[i].iov_len) {
printk("Didn't write all bytes in flash_safe_writev(). Returned %d\n", res); printk("Didn't write all bytes in flash_safe_writev(). Returned %d\n", res);
if (i != iovec_cnt-1) if (i != iovec_cnt-1)
...@@ -393,7 +394,7 @@ flash_erase_region(struct mtd_info *mtd, loff_t start, ...@@ -393,7 +394,7 @@ flash_erase_region(struct mtd_info *mtd, loff_t start,
set_current_state(TASK_UNINTERRUPTIBLE); set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&wait_q, &wait); add_wait_queue(&wait_q, &wait);
if (MTD_ERASE(mtd, erase) < 0) { if (mtd->erase(mtd, erase) < 0) {
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait); remove_wait_queue(&wait_q, &wait);
kfree(erase); kfree(erase);
......
...@@ -199,20 +199,6 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, ...@@ -199,20 +199,6 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs, int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
unsigned long count, loff_t from, size_t *retlen); unsigned long count, loff_t from, size_t *retlen);
#define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
#define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
#define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
#define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
#define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
#define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
#define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
#define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
#define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
#define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
#define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
#define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0)
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
void mtd_erase_callback(struct erase_info *instr); void mtd_erase_callback(struct erase_info *instr);
#else #else
...@@ -233,7 +219,7 @@ static inline void mtd_erase_callback(struct erase_info *instr) ...@@ -233,7 +219,7 @@ static inline void mtd_erase_callback(struct erase_info *instr)
#ifdef CONFIG_MTD_DEBUG #ifdef CONFIG_MTD_DEBUG
#define DEBUG(n, args...) \ #define DEBUG(n, args...) \
do { \ do { \
if (n <= CONFIG_MTD_DEBUG_VERBOSE) \ if (n <= CONFIG_MTD_DEBUG_VERBOSE) \
printk(KERN_INFO args); \ printk(KERN_INFO args); \
} while(0) } while(0)
......
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