diff options
author | Thomas Gleixner <tglx@cruncher.tec.linutronix.de> | 2006-05-28 21:26:58 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@cruncher.tec.linutronix.de> | 2006-05-29 09:06:51 -0400 |
commit | 8593fbc68b0df1168995de76d1af38eb62fd6b62 (patch) | |
tree | dd244def53d2be4f1fbff9f74eac404fab8e240f /drivers/mtd/nftlmount.c | |
parent | f4a43cfcecfcaeeaa40a9dbc1d1378298c22446e (diff) |
[MTD] Rework the out of band handling completely
Hopefully the last iteration on this!
The handling of out of band data on NAND was accompanied by tons of fruitless
discussions and halfarsed patches to make it work for a particular
problem. Sufficiently annoyed by I all those "I know it better" mails and the
resonable amount of discarded "it solves my problem" patches, I finally decided
to go for the big rework. After removing the _ecc variants of mtd read/write
functions the solution to satisfy the various requirements was to refactor the
read/write _oob functions in mtd.
The major change is that read/write_oob now takes a pointer to an operation
descriptor structure "struct mtd_oob_ops".instead of having a function with at
least seven arguments.
read/write_oob which should probably renamed to a more descriptive name, can do
the following tasks:
- read/write out of band data
- read/write data content and out of band data
- read/write raw data content and out of band data (ecc disabled)
struct mtd_oob_ops has a mode field, which determines the oob handling mode.
Aside of the MTD_OOB_RAW mode, which is intended to be especially for
diagnostic purposes and some internal functions e.g. bad block table creation,
the other two modes are for mtd clients:
MTD_OOB_PLACE puts/gets the given oob data exactly to/from the place which is
described by the ooboffs and ooblen fields of the mtd_oob_ops strcuture. It's
up to the caller to make sure that the byte positions are not used by the ECC
placement algorithms.
MTD_OOB_AUTO puts/gets the given oob data automaticaly to/from the places in
the out of band area which are described by the oobfree tuples in the ecclayout
data structre which is associated to the devicee.
The decision whether data plus oob or oob only handling is done depends on the
setting of the datbuf member of the data structure. When datbuf == NULL then
the internal read/write_oob functions are selected, otherwise the read/write
data routines are invoked.
Tested on a few platforms with all variants. Please be aware of possible
regressions for your particular device / application scenario
Disclaimer: Any whining will be ignored from those who just contributed "hot
air blurb" and never sat down to tackle the underlying problem of the mess in
the NAND driver grown over time and the big chunk of work to fix up the
existing users. The problem was not the holiness of the existing MTD
interfaces. The problems was the lack of time to go for the big overhaul. It's
easy to add more mess to the existing one, but it takes alot of effort to go
for a real solution.
Improvements and bugfixes are welcome!
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/mtd/nftlmount.c')
-rw-r--r-- | drivers/mtd/nftlmount.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index 521b07cd2326..067262ee8df0 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c | |||
@@ -33,6 +33,11 @@ | |||
33 | 33 | ||
34 | char nftlmountrev[]="$Revision: 1.41 $"; | 34 | char nftlmountrev[]="$Revision: 1.41 $"; |
35 | 35 | ||
36 | extern int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len, | ||
37 | size_t *retlen, uint8_t *buf); | ||
38 | extern int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, | ||
39 | size_t *retlen, uint8_t *buf); | ||
40 | |||
36 | /* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the | 41 | /* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the |
37 | * various device information of the NFTL partition and Bad Unit Table. Update | 42 | * various device information of the NFTL partition and Bad Unit Table. Update |
38 | * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[] | 43 | * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[] |
@@ -92,7 +97,7 @@ static int find_boot_record(struct NFTLrecord *nftl) | |||
92 | } | 97 | } |
93 | 98 | ||
94 | /* To be safer with BIOS, also use erase mark as discriminant */ | 99 | /* To be safer with BIOS, also use erase mark as discriminant */ |
95 | if ((ret = mtd->read_oob(mtd, block * nftl->EraseSize + | 100 | if ((ret = nftl_read_oob(mtd, block * nftl->EraseSize + |
96 | SECTORSIZE + 8, 8, &retlen, | 101 | SECTORSIZE + 8, 8, &retlen, |
97 | (char *)&h1) < 0)) { | 102 | (char *)&h1) < 0)) { |
98 | printk(KERN_WARNING "ANAND header found at 0x%x in mtd%d, but OOB data read failed (err %d)\n", | 103 | printk(KERN_WARNING "ANAND header found at 0x%x in mtd%d, but OOB data read failed (err %d)\n", |
@@ -283,7 +288,7 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int | |||
283 | return -1; | 288 | return -1; |
284 | 289 | ||
285 | if (check_oob) { | 290 | if (check_oob) { |
286 | if(mtd->read_oob(mtd, address, mtd->oobsize, | 291 | if(nftl_read_oob(mtd, address, mtd->oobsize, |
287 | &retlen, &buf[SECTORSIZE]) < 0) | 292 | &retlen, &buf[SECTORSIZE]) < 0) |
288 | return -1; | 293 | return -1; |
289 | if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0) | 294 | if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0) |
@@ -311,7 +316,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) | |||
311 | struct mtd_info *mtd = nftl->mbd.mtd; | 316 | struct mtd_info *mtd = nftl->mbd.mtd; |
312 | 317 | ||
313 | /* Read the Unit Control Information #1 for Wear-Leveling */ | 318 | /* Read the Unit Control Information #1 for Wear-Leveling */ |
314 | if (mtd->read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, | 319 | if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, |
315 | 8, &retlen, (char *)&uci) < 0) | 320 | 8, &retlen, (char *)&uci) < 0) |
316 | goto default_uci1; | 321 | goto default_uci1; |
317 | 322 | ||
@@ -351,7 +356,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) | |||
351 | goto fail; | 356 | goto fail; |
352 | 357 | ||
353 | uci.WearInfo = le32_to_cpu(nb_erases); | 358 | uci.WearInfo = le32_to_cpu(nb_erases); |
354 | if (mtd->write_oob(mtd, block * nftl->EraseSize + SECTORSIZE + | 359 | if (nftl_write_oob(mtd, block * nftl->EraseSize + SECTORSIZE + |
355 | 8, 8, &retlen, (char *)&uci) < 0) | 360 | 8, 8, &retlen, (char *)&uci) < 0) |
356 | goto fail; | 361 | goto fail; |
357 | return 0; | 362 | return 0; |
@@ -383,7 +388,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b | |||
383 | block = first_block; | 388 | block = first_block; |
384 | for (;;) { | 389 | for (;;) { |
385 | for (i = 0; i < sectors_per_block; i++) { | 390 | for (i = 0; i < sectors_per_block; i++) { |
386 | if (mtd->read_oob(mtd, | 391 | if (nftl_read_oob(mtd, |
387 | block * nftl->EraseSize + i * SECTORSIZE, | 392 | block * nftl->EraseSize + i * SECTORSIZE, |
388 | 8, &retlen, (char *)&bci) < 0) | 393 | 8, &retlen, (char *)&bci) < 0) |
389 | status = SECTOR_IGNORE; | 394 | status = SECTOR_IGNORE; |
@@ -404,7 +409,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b | |||
404 | /* sector not free actually : mark it as SECTOR_IGNORE */ | 409 | /* sector not free actually : mark it as SECTOR_IGNORE */ |
405 | bci.Status = SECTOR_IGNORE; | 410 | bci.Status = SECTOR_IGNORE; |
406 | bci.Status1 = SECTOR_IGNORE; | 411 | bci.Status1 = SECTOR_IGNORE; |
407 | mtd->write_oob(mtd, block * | 412 | nftl_write_oob(mtd, block * |
408 | nftl->EraseSize + | 413 | nftl->EraseSize + |
409 | i * SECTORSIZE, 8, | 414 | i * SECTORSIZE, 8, |
410 | &retlen, (char *)&bci); | 415 | &retlen, (char *)&bci); |
@@ -498,7 +503,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) | |||
498 | size_t retlen; | 503 | size_t retlen; |
499 | 504 | ||
500 | /* check erase mark. */ | 505 | /* check erase mark. */ |
501 | if (mtd->read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, | 506 | if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, |
502 | &retlen, (char *)&h1) < 0) | 507 | &retlen, (char *)&h1) < 0) |
503 | return -1; | 508 | return -1; |
504 | 509 | ||
@@ -513,7 +518,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) | |||
513 | h1.EraseMark = cpu_to_le16(ERASE_MARK); | 518 | h1.EraseMark = cpu_to_le16(ERASE_MARK); |
514 | h1.EraseMark1 = cpu_to_le16(ERASE_MARK); | 519 | h1.EraseMark1 = cpu_to_le16(ERASE_MARK); |
515 | h1.WearInfo = cpu_to_le32(0); | 520 | h1.WearInfo = cpu_to_le32(0); |
516 | if (mtd->write_oob(mtd, | 521 | if (nftl_write_oob(mtd, |
517 | block * nftl->EraseSize + SECTORSIZE + 8, 8, | 522 | block * nftl->EraseSize + SECTORSIZE + 8, 8, |
518 | &retlen, (char *)&h1) < 0) | 523 | &retlen, (char *)&h1) < 0) |
519 | return -1; | 524 | return -1; |
@@ -526,7 +531,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) | |||
526 | SECTORSIZE, 0) != 0) | 531 | SECTORSIZE, 0) != 0) |
527 | return -1; | 532 | return -1; |
528 | 533 | ||
529 | if (mtd->read_oob(mtd, block * nftl->EraseSize + i, | 534 | if (nftl_read_oob(mtd, block * nftl->EraseSize + i, |
530 | 16, &retlen, buf) < 0) | 535 | 16, &retlen, buf) < 0) |
531 | return -1; | 536 | return -1; |
532 | if (i == SECTORSIZE) { | 537 | if (i == SECTORSIZE) { |
@@ -557,7 +562,7 @@ static int get_fold_mark(struct NFTLrecord *nftl, unsigned int block) | |||
557 | struct nftl_uci2 uci; | 562 | struct nftl_uci2 uci; |
558 | size_t retlen; | 563 | size_t retlen; |
559 | 564 | ||
560 | if (mtd->read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8, | 565 | if (nftl_read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8, |
561 | 8, &retlen, (char *)&uci) < 0) | 566 | 8, &retlen, (char *)&uci) < 0) |
562 | return 0; | 567 | return 0; |
563 | 568 | ||
@@ -597,10 +602,10 @@ int NFTL_mount(struct NFTLrecord *s) | |||
597 | 602 | ||
598 | for (;;) { | 603 | for (;;) { |
599 | /* read the block header. If error, we format the chain */ | 604 | /* read the block header. If error, we format the chain */ |
600 | if (mtd->read_oob(mtd, | 605 | if (nftl_read_oob(mtd, |
601 | block * s->EraseSize + 8, 8, | 606 | block * s->EraseSize + 8, 8, |
602 | &retlen, (char *)&h0) < 0 || | 607 | &retlen, (char *)&h0) < 0 || |
603 | mtd->read_oob(mtd, | 608 | nftl_read_oob(mtd, |
604 | block * s->EraseSize + | 609 | block * s->EraseSize + |
605 | SECTORSIZE + 8, 8, | 610 | SECTORSIZE + 8, 8, |
606 | &retlen, (char *)&h1) < 0) { | 611 | &retlen, (char *)&h1) < 0) { |