diff options
author | Thomas Gleixner <tglx@cruncher.tec.linutronix.de> | 2006-05-28 05:01:53 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@cruncher.tec.linutronix.de> | 2006-05-29 09:06:50 -0400 |
commit | f4a43cfcecfcaeeaa40a9dbc1d1378298c22446e (patch) | |
tree | 5647ebccb720c9d8ca314c8a3a5f6a660d000019 /drivers/mtd/nftlcore.c | |
parent | 5bd34c091a044d130601370c370f84b1c59f1627 (diff) |
[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: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/mtd/nftlcore.c')
-rw-r--r-- | drivers/mtd/nftlcore.c | 144 |
1 files changed, 74 insertions, 70 deletions
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index dd03349946c2..359533b33d9b 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c | |||
@@ -183,6 +183,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate ) | |||
183 | 183 | ||
184 | static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned pendingblock ) | 184 | static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned pendingblock ) |
185 | { | 185 | { |
186 | struct mtd_info *mtd = nftl->mbd.mtd; | ||
186 | u16 BlockMap[MAX_SECTORS_PER_UNIT]; | 187 | u16 BlockMap[MAX_SECTORS_PER_UNIT]; |
187 | unsigned char BlockLastState[MAX_SECTORS_PER_UNIT]; | 188 | unsigned char BlockLastState[MAX_SECTORS_PER_UNIT]; |
188 | unsigned char BlockFreeFound[MAX_SECTORS_PER_UNIT]; | 189 | unsigned char BlockFreeFound[MAX_SECTORS_PER_UNIT]; |
@@ -192,7 +193,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p | |||
192 | unsigned int targetEUN; | 193 | unsigned int targetEUN; |
193 | struct nftl_oob oob; | 194 | struct nftl_oob oob; |
194 | int inplace = 1; | 195 | int inplace = 1; |
195 | size_t retlen; | 196 | size_t retlen; |
196 | 197 | ||
197 | memset(BlockMap, 0xff, sizeof(BlockMap)); | 198 | memset(BlockMap, 0xff, sizeof(BlockMap)); |
198 | memset(BlockFreeFound, 0, sizeof(BlockFreeFound)); | 199 | memset(BlockFreeFound, 0, sizeof(BlockFreeFound)); |
@@ -208,21 +209,21 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p | |||
208 | /* Scan to find the Erase Unit which holds the actual data for each | 209 | /* Scan to find the Erase Unit which holds the actual data for each |
209 | 512-byte block within the Chain. | 210 | 512-byte block within the Chain. |
210 | */ | 211 | */ |
211 | silly = MAX_LOOPS; | 212 | silly = MAX_LOOPS; |
212 | targetEUN = BLOCK_NIL; | 213 | targetEUN = BLOCK_NIL; |
213 | while (thisEUN <= nftl->lastEUN ) { | 214 | while (thisEUN <= nftl->lastEUN ) { |
214 | unsigned int status, foldmark; | 215 | unsigned int status, foldmark; |
215 | 216 | ||
216 | targetEUN = thisEUN; | 217 | targetEUN = thisEUN; |
217 | for (block = 0; block < nftl->EraseSize / 512; block ++) { | 218 | for (block = 0; block < nftl->EraseSize / 512; block ++) { |
218 | MTD_READOOB(nftl->mbd.mtd, | 219 | mtd->read_oob(mtd, (thisEUN * nftl->EraseSize) + |
219 | (thisEUN * nftl->EraseSize) + (block * 512), | 220 | (block * 512), 16 , &retlen, |
220 | 16 , &retlen, (char *)&oob); | 221 | (char *)&oob); |
221 | if (block == 2) { | 222 | if (block == 2) { |
222 | foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1; | 223 | foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1; |
223 | if (foldmark == FOLD_MARK_IN_PROGRESS) { | 224 | if (foldmark == FOLD_MARK_IN_PROGRESS) { |
224 | DEBUG(MTD_DEBUG_LEVEL1, | 225 | DEBUG(MTD_DEBUG_LEVEL1, |
225 | "Write Inhibited on EUN %d\n", thisEUN); | 226 | "Write Inhibited on EUN %d\n", thisEUN); |
226 | inplace = 0; | 227 | inplace = 0; |
227 | } else { | 228 | } else { |
228 | /* There's no other reason not to do inplace, | 229 | /* 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 | inplace = 1; | 232 | inplace = 1; |
232 | } | 233 | } |
233 | } | 234 | } |
234 | status = oob.b.Status | oob.b.Status1; | 235 | status = oob.b.Status | oob.b.Status1; |
235 | BlockLastState[block] = status; | 236 | BlockLastState[block] = status; |
236 | 237 | ||
237 | switch(status) { | 238 | switch(status) { |
@@ -326,15 +327,15 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p | |||
326 | return BLOCK_NIL; | 327 | return BLOCK_NIL; |
327 | } | 328 | } |
328 | } else { | 329 | } else { |
329 | /* We put a fold mark in the chain we are folding only if | 330 | /* We put a fold mark in the chain we are folding only if we |
330 | we fold in place to help the mount check code. If we do | 331 | fold in place to help the mount check code. If we do not fold in |
331 | not fold in place, it is possible to find the valid | 332 | place, it is possible to find the valid chain by selecting the |
332 | chain by selecting the longer one */ | 333 | longer one */ |
333 | oob.u.c.FoldMark = oob.u.c.FoldMark1 = cpu_to_le16(FOLD_MARK_IN_PROGRESS); | 334 | oob.u.c.FoldMark = oob.u.c.FoldMark1 = cpu_to_le16(FOLD_MARK_IN_PROGRESS); |
334 | oob.u.c.unused = 0xffffffff; | 335 | oob.u.c.unused = 0xffffffff; |
335 | MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 2 * 512 + 8, | 336 | mtd->write_oob(mtd, (nftl->EraseSize * targetEUN) + 2 * 512 + 8, |
336 | 8, &retlen, (char *)&oob.u); | 337 | 8, &retlen, (char *)&oob.u); |
337 | } | 338 | } |
338 | 339 | ||
339 | /* OK. We now know the location of every block in the Virtual Unit Chain, | 340 | /* OK. We now know the location of every block in the Virtual Unit Chain, |
340 | and the Erase Unit into which we are supposed to be copying. | 341 | 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 | continue; | 352 | continue; |
352 | } | 353 | } |
353 | 354 | ||
354 | /* copy only in non free block (free blocks can only | 355 | /* copy only in non free block (free blocks can only |
355 | happen in case of media errors or deleted blocks) */ | 356 | happen in case of media errors or deleted blocks) */ |
356 | if (BlockMap[block] == BLOCK_NIL) | 357 | if (BlockMap[block] == BLOCK_NIL) |
357 | continue; | 358 | continue; |
358 | 359 | ||
359 | ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), | 360 | ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), |
360 | 512, &retlen, movebuf); | 361 | 512, &retlen, movebuf); |
361 | if (ret < 0) { | 362 | if (ret < 0) { |
362 | ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) | 363 | ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) |
363 | + (block * 512), 512, &retlen, | 364 | + (block * 512), 512, &retlen, |
364 | movebuf); | 365 | movebuf); |
365 | if (ret != -EIO) | 366 | if (ret != -EIO) |
366 | printk("Error went away on retry.\n"); | 367 | printk("Error went away on retry.\n"); |
367 | } | 368 | } |
368 | memset(&oob, 0xff, sizeof(struct nftl_oob)); | 369 | memset(&oob, 0xff, sizeof(struct nftl_oob)); |
369 | oob.b.Status = oob.b.Status1 = SECTOR_USED; | 370 | oob.b.Status = oob.b.Status1 = SECTOR_USED; |
370 | 371 | ||
@@ -374,13 +375,12 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p | |||
374 | 375 | ||
375 | } | 376 | } |
376 | 377 | ||
377 | /* add the header so that it is now a valid chain */ | 378 | /* add the header so that it is now a valid chain */ |
378 | oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum | 379 | oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC); |
379 | = cpu_to_le16(thisVUC); | 380 | oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff; |
380 | oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff; | ||
381 | 381 | ||
382 | MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 8, | 382 | mtd->write_oob(mtd, (nftl->EraseSize * targetEUN) + 8, |
383 | 8, &retlen, (char *)&oob.u); | 383 | 8, &retlen, (char *)&oob.u); |
384 | 384 | ||
385 | /* OK. We've moved the whole lot into the new block. Now we have to free the original blocks. */ | 385 | /* OK. We've moved the whole lot into the new block. Now we have to free the original blocks. */ |
386 | 386 | ||
@@ -397,18 +397,18 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p | |||
397 | while (thisEUN <= nftl->lastEUN && thisEUN != targetEUN) { | 397 | while (thisEUN <= nftl->lastEUN && thisEUN != targetEUN) { |
398 | unsigned int EUNtmp; | 398 | unsigned int EUNtmp; |
399 | 399 | ||
400 | EUNtmp = nftl->ReplUnitTable[thisEUN]; | 400 | EUNtmp = nftl->ReplUnitTable[thisEUN]; |
401 | 401 | ||
402 | if (NFTL_formatblock(nftl, thisEUN) < 0) { | 402 | if (NFTL_formatblock(nftl, thisEUN) < 0) { |
403 | /* could not erase : mark block as reserved | 403 | /* could not erase : mark block as reserved |
404 | */ | 404 | */ |
405 | nftl->ReplUnitTable[thisEUN] = BLOCK_RESERVED; | 405 | nftl->ReplUnitTable[thisEUN] = BLOCK_RESERVED; |
406 | } else { | 406 | } else { |
407 | /* correctly erased : mark it as free */ | 407 | /* correctly erased : mark it as free */ |
408 | nftl->ReplUnitTable[thisEUN] = BLOCK_FREE; | 408 | nftl->ReplUnitTable[thisEUN] = BLOCK_FREE; |
409 | nftl->numfreeEUNs++; | 409 | nftl->numfreeEUNs++; |
410 | } | 410 | } |
411 | thisEUN = EUNtmp; | 411 | thisEUN = EUNtmp; |
412 | } | 412 | } |
413 | 413 | ||
414 | /* Make this the new start of chain for thisVUC */ | 414 | /* Make this the new start of chain for thisVUC */ |
@@ -474,6 +474,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) | |||
474 | { | 474 | { |
475 | u16 lastEUN; | 475 | u16 lastEUN; |
476 | u16 thisVUC = block / (nftl->EraseSize / 512); | 476 | u16 thisVUC = block / (nftl->EraseSize / 512); |
477 | struct mtd_info *mtd = nftl->mbd.mtd; | ||
477 | unsigned int writeEUN; | 478 | unsigned int writeEUN; |
478 | unsigned long blockofs = (block * 512) & (nftl->EraseSize -1); | 479 | unsigned long blockofs = (block * 512) & (nftl->EraseSize -1); |
479 | size_t retlen; | 480 | size_t retlen; |
@@ -490,21 +491,22 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) | |||
490 | */ | 491 | */ |
491 | lastEUN = BLOCK_NIL; | 492 | lastEUN = BLOCK_NIL; |
492 | writeEUN = nftl->EUNtable[thisVUC]; | 493 | writeEUN = nftl->EUNtable[thisVUC]; |
493 | silly = MAX_LOOPS; | 494 | silly = MAX_LOOPS; |
494 | while (writeEUN <= nftl->lastEUN) { | 495 | while (writeEUN <= nftl->lastEUN) { |
495 | struct nftl_bci bci; | 496 | struct nftl_bci bci; |
496 | size_t retlen; | 497 | size_t retlen; |
497 | unsigned int status; | 498 | unsigned int status; |
498 | 499 | ||
499 | lastEUN = writeEUN; | 500 | lastEUN = writeEUN; |
500 | 501 | ||
501 | MTD_READOOB(nftl->mbd.mtd, (writeEUN * nftl->EraseSize) + blockofs, | 502 | mtd->read_oob(mtd, |
502 | 8, &retlen, (char *)&bci); | 503 | (writeEUN * nftl->EraseSize) + blockofs, |
504 | 8, &retlen, (char *)&bci); | ||
503 | 505 | ||
504 | DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n", | 506 | DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n", |
505 | block , writeEUN, le16_to_cpu(bci.Status)); | 507 | block , writeEUN, le16_to_cpu(bci.Status)); |
506 | 508 | ||
507 | status = bci.Status | bci.Status1; | 509 | status = bci.Status | bci.Status1; |
508 | switch(status) { | 510 | switch(status) { |
509 | case SECTOR_FREE: | 511 | case SECTOR_FREE: |
510 | return writeEUN; | 512 | return writeEUN; |
@@ -575,10 +577,10 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) | |||
575 | /* We've found a free block. Insert it into the chain. */ | 577 | /* We've found a free block. Insert it into the chain. */ |
576 | 578 | ||
577 | if (lastEUN != BLOCK_NIL) { | 579 | if (lastEUN != BLOCK_NIL) { |
578 | thisVUC |= 0x8000; /* It's a replacement block */ | 580 | thisVUC |= 0x8000; /* It's a replacement block */ |
579 | } else { | 581 | } else { |
580 | /* The first block in a new chain */ | 582 | /* The first block in a new chain */ |
581 | nftl->EUNtable[thisVUC] = writeEUN; | 583 | nftl->EUNtable[thisVUC] = writeEUN; |
582 | } | 584 | } |
583 | 585 | ||
584 | /* set up the actual EUN we're writing into */ | 586 | /* set up the actual EUN we're writing into */ |
@@ -586,29 +588,29 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) | |||
586 | nftl->ReplUnitTable[writeEUN] = BLOCK_NIL; | 588 | nftl->ReplUnitTable[writeEUN] = BLOCK_NIL; |
587 | 589 | ||
588 | /* ... and on the flash itself */ | 590 | /* ... and on the flash itself */ |
589 | MTD_READOOB(nftl->mbd.mtd, writeEUN * nftl->EraseSize + 8, 8, | 591 | mtd->read_oob(mtd, writeEUN * nftl->EraseSize + 8, 8, |
590 | &retlen, (char *)&oob.u); | 592 | &retlen, (char *)&oob.u); |
591 | 593 | ||
592 | oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC); | 594 | oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC); |
593 | 595 | ||
594 | MTD_WRITEOOB(nftl->mbd.mtd, writeEUN * nftl->EraseSize + 8, 8, | 596 | mtd->write_oob(mtd, writeEUN * nftl->EraseSize + 8, 8, |
595 | &retlen, (char *)&oob.u); | 597 | &retlen, (char *)&oob.u); |
596 | 598 | ||
597 | /* we link the new block to the chain only after the | 599 | /* we link the new block to the chain only after the |
598 | block is ready. It avoids the case where the chain | 600 | block is ready. It avoids the case where the chain |
599 | could point to a free block */ | 601 | could point to a free block */ |
600 | if (lastEUN != BLOCK_NIL) { | 602 | if (lastEUN != BLOCK_NIL) { |
601 | /* Both in our cache... */ | 603 | /* Both in our cache... */ |
602 | nftl->ReplUnitTable[lastEUN] = writeEUN; | 604 | nftl->ReplUnitTable[lastEUN] = writeEUN; |
603 | /* ... and on the flash itself */ | 605 | /* ... and on the flash itself */ |
604 | MTD_READOOB(nftl->mbd.mtd, (lastEUN * nftl->EraseSize) + 8, | 606 | mtd->read_oob(mtd, (lastEUN * nftl->EraseSize) + 8, |
605 | 8, &retlen, (char *)&oob.u); | 607 | 8, &retlen, (char *)&oob.u); |
606 | 608 | ||
607 | oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum | 609 | oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum |
608 | = cpu_to_le16(writeEUN); | 610 | = cpu_to_le16(writeEUN); |
609 | 611 | ||
610 | MTD_WRITEOOB(nftl->mbd.mtd, (lastEUN * nftl->EraseSize) + 8, | 612 | mtd->write_oob(mtd, (lastEUN * nftl->EraseSize) + 8, |
611 | 8, &retlen, (char *)&oob.u); | 613 | 8, &retlen, (char *)&oob.u); |
612 | } | 614 | } |
613 | 615 | ||
614 | return writeEUN; | 616 | return writeEUN; |
@@ -652,20 +654,22 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, | |||
652 | char *buffer) | 654 | char *buffer) |
653 | { | 655 | { |
654 | struct NFTLrecord *nftl = (void *)mbd; | 656 | struct NFTLrecord *nftl = (void *)mbd; |
657 | struct mtd_info *mtd = nftl->mbd.mtd; | ||
655 | u16 lastgoodEUN; | 658 | u16 lastgoodEUN; |
656 | u16 thisEUN = nftl->EUNtable[block / (nftl->EraseSize / 512)]; | 659 | u16 thisEUN = nftl->EUNtable[block / (nftl->EraseSize / 512)]; |
657 | unsigned long blockofs = (block * 512) & (nftl->EraseSize - 1); | 660 | unsigned long blockofs = (block * 512) & (nftl->EraseSize - 1); |
658 | unsigned int status; | 661 | unsigned int status; |
659 | int silly = MAX_LOOPS; | 662 | int silly = MAX_LOOPS; |
660 | size_t retlen; | 663 | size_t retlen; |
661 | struct nftl_bci bci; | 664 | struct nftl_bci bci; |
662 | 665 | ||
663 | lastgoodEUN = BLOCK_NIL; | 666 | lastgoodEUN = BLOCK_NIL; |
664 | 667 | ||
665 | if (thisEUN != BLOCK_NIL) { | 668 | if (thisEUN != BLOCK_NIL) { |
666 | while (thisEUN < nftl->nb_blocks) { | 669 | while (thisEUN < nftl->nb_blocks) { |
667 | if (MTD_READOOB(nftl->mbd.mtd, (thisEUN * nftl->EraseSize) + blockofs, | 670 | if (mtd->read_oob(mtd, (thisEUN * nftl->EraseSize) + |
668 | 8, &retlen, (char *)&bci) < 0) | 671 | blockofs, 8, &retlen, |
672 | (char *)&bci) < 0) | ||
669 | status = SECTOR_IGNORE; | 673 | status = SECTOR_IGNORE; |
670 | else | 674 | else |
671 | status = bci.Status | bci.Status1; | 675 | status = bci.Status | bci.Status1; |
@@ -695,7 +699,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, | |||
695 | } | 699 | } |
696 | thisEUN = nftl->ReplUnitTable[thisEUN]; | 700 | thisEUN = nftl->ReplUnitTable[thisEUN]; |
697 | } | 701 | } |
698 | } | 702 | } |
699 | 703 | ||
700 | the_end: | 704 | the_end: |
701 | if (lastgoodEUN == BLOCK_NIL) { | 705 | if (lastgoodEUN == BLOCK_NIL) { |
@@ -704,7 +708,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, | |||
704 | } else { | 708 | } else { |
705 | loff_t ptr = (lastgoodEUN * nftl->EraseSize) + blockofs; | 709 | loff_t ptr = (lastgoodEUN * nftl->EraseSize) + blockofs; |
706 | size_t retlen; | 710 | size_t retlen; |
707 | if (MTD_READ(nftl->mbd.mtd, ptr, 512, &retlen, buffer)) | 711 | if (mtd->read(mtd, ptr, 512, &retlen, buffer)) |
708 | return -EIO; | 712 | return -EIO; |
709 | } | 713 | } |
710 | return 0; | 714 | return 0; |