Lines Matching +full:wear +full:- +full:leveling

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
31 struct NFTLMediaHeader *mh = &nftl->MediaHdr; in find_boot_record()
32 struct mtd_info *mtd = nftl->mbd.mtd; in find_boot_record()
40 nftl->EraseSize if there were any point in doing so. */ in find_boot_record()
41 nftl->EraseSize = nftl->mbd.mtd->erasesize; in find_boot_record()
42 nftl->nb_blocks = (u32)nftl->mbd.mtd->size / nftl->EraseSize; in find_boot_record()
44 nftl->MediaUnit = BLOCK_NIL; in find_boot_record()
45 nftl->SpareMediaUnit = BLOCK_NIL; in find_boot_record()
48 for (block = 0; block < nftl->nb_blocks; block++) { in find_boot_record()
53 ret = mtd_read(mtd, block * nftl->EraseSize, SECTORSIZE, in find_boot_record()
62 block * nftl->EraseSize, nftl->mbd.mtd->index, ret); in find_boot_record()
63 if (!--warncount) in find_boot_record()
73 block * nftl->EraseSize, nftl->mbd.mtd->index); in find_boot_record()
79 ret = nftl_read_oob(mtd, block * nftl->EraseSize + in find_boot_record()
84 block * nftl->EraseSize, nftl->mbd.mtd->index, ret); in find_boot_record()
94 block * nftl->EraseSize, nftl->mbd.mtd->index, in find_boot_record()
100 ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE, in find_boot_record()
104 block * nftl->EraseSize, nftl->mbd.mtd->index, ret); in find_boot_record()
111 block * nftl->EraseSize, nftl->mbd.mtd->index); in find_boot_record()
123 nftl->MediaUnit * nftl->EraseSize, block * nftl->EraseSize); in find_boot_record()
127 return -1; in find_boot_record()
132 nftl->SpareMediaUnit = block; in find_boot_record()
135 nftl->ReplUnitTable[block] = BLOCK_RESERVED; in find_boot_record()
150 if (mh->UnitSizeFactor == 0) { in find_boot_record()
152 } else if (mh->UnitSizeFactor < 0xfc) { in find_boot_record()
154 mh->UnitSizeFactor); in find_boot_record()
155 return -1; in find_boot_record()
156 } else if (mh->UnitSizeFactor != 0xff) { in find_boot_record()
158 mh->UnitSizeFactor); in find_boot_record()
159 nftl->EraseSize = nftl->mbd.mtd->erasesize << (0xff - mh->UnitSizeFactor); in find_boot_record()
160 nftl->nb_blocks = (u32)nftl->mbd.mtd->size / nftl->EraseSize; in find_boot_record()
163 nftl->nb_boot_blocks = le16_to_cpu(mh->FirstPhysicalEUN); in find_boot_record()
164 if ((nftl->nb_boot_blocks + 2) >= nftl->nb_blocks) { in find_boot_record()
167 nftl->nb_boot_blocks, nftl->nb_blocks); in find_boot_record()
168 return -1; in find_boot_record()
171 nftl->numvunits = le32_to_cpu(mh->FormattedSize) / nftl->EraseSize; in find_boot_record()
172 if (nftl->numvunits > (nftl->nb_blocks - nftl->nb_boot_blocks - 2)) { in find_boot_record()
174 printk(KERN_NOTICE "numvunits (%d) > nb_blocks (%d) - nb_boot_blocks(%d) - 2\n", in find_boot_record()
175 nftl->numvunits, nftl->nb_blocks, nftl->nb_boot_blocks); in find_boot_record()
176 return -1; in find_boot_record()
179 nftl->mbd.size = nftl->numvunits * (nftl->EraseSize / SECTORSIZE); in find_boot_record()
183 nftl->nb_blocks = le16_to_cpu(mh->NumEraseUnits) + le16_to_cpu(mh->FirstPhysicalEUN); in find_boot_record()
186 nftl->lastEUN = nftl->nb_blocks - 1; in find_boot_record()
189 nftl->EUNtable = kmalloc_array(nftl->nb_blocks, sizeof(u16), in find_boot_record()
191 if (!nftl->EUNtable) in find_boot_record()
192 return -ENOMEM; in find_boot_record()
194 nftl->ReplUnitTable = kmalloc_array(nftl->nb_blocks, in find_boot_record()
197 if (!nftl->ReplUnitTable) { in find_boot_record()
198 kfree(nftl->EUNtable); in find_boot_record()
199 return -ENOMEM; in find_boot_record()
203 for (i = 0; i < nftl->nb_boot_blocks; i++) in find_boot_record()
204 nftl->ReplUnitTable[i] = BLOCK_RESERVED; in find_boot_record()
206 for (; i < nftl->nb_blocks; i++) { in find_boot_record()
207 nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED; in find_boot_record()
211 nftl->ReplUnitTable[block] = BLOCK_RESERVED; in find_boot_record()
214 for (i = 0; i < nftl->nb_blocks; i++) { in find_boot_record()
217 if ((i & (SECTORSIZE - 1)) == 0) { in find_boot_record()
219 ret = mtd->read(nftl->mbd.mtd, in find_boot_record()
220 block * nftl->EraseSize + i + in find_boot_record()
226 kfree(nftl->ReplUnitTable); in find_boot_record()
227 kfree(nftl->EUNtable); in find_boot_record()
228 return -1; in find_boot_record()
232 if (buf[i & (SECTORSIZE - 1)] != 0xff) in find_boot_record()
233 nftl->ReplUnitTable[i] = BLOCK_RESERVED; in find_boot_record()
235 if (mtd_block_isbad(nftl->mbd.mtd, in find_boot_record()
236 i * nftl->EraseSize)) in find_boot_record()
237 nftl->ReplUnitTable[i] = BLOCK_RESERVED; in find_boot_record()
240 nftl->MediaUnit = block; in find_boot_record()
245 return boot_record_count?0:-1; in find_boot_record()
262 struct mtd_info *mtd = nftl->mbd.mtd; in check_free_sectors()
267 buf = kmalloc(SECTORSIZE + mtd->oobsize, GFP_KERNEL); in check_free_sectors()
269 return -ENOMEM; in check_free_sectors()
271 ret = -1; in check_free_sectors()
279 if(nftl_read_oob(mtd, address, mtd->oobsize, in check_free_sectors()
282 if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0) in check_free_sectors()
298 * Return: 0 when succeed, -1 on error.
307 struct erase_info *instr = &nftl->instr; in NFTL_formatblock()
308 struct mtd_info *mtd = nftl->mbd.mtd; in NFTL_formatblock()
310 /* Read the Unit Control Information #1 for Wear-Leveling */ in NFTL_formatblock()
311 if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, in NFTL_formatblock()
326 instr->addr = block * nftl->EraseSize; in NFTL_formatblock()
327 instr->len = nftl->EraseSize; in NFTL_formatblock()
333 /* increase and write Wear-Leveling info */ in NFTL_formatblock()
345 if (check_free_sectors(nftl, instr->addr, nftl->EraseSize, 1) != 0) in NFTL_formatblock()
349 if (nftl_write_oob(mtd, block * nftl->EraseSize + SECTORSIZE + in NFTL_formatblock()
356 mtd_block_markbad(nftl->mbd.mtd, instr->addr); in NFTL_formatblock()
357 return -1; in NFTL_formatblock()
371 struct mtd_info *mtd = nftl->mbd.mtd; in check_sectors_in_chain()
377 sectors_per_block = nftl->EraseSize / SECTORSIZE; in check_sectors_in_chain()
382 block * nftl->EraseSize + i * SECTORSIZE, in check_sectors_in_chain()
393 check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE, in check_sectors_in_chain()
403 nftl->EraseSize + in check_sectors_in_chain()
414 block = nftl->ReplUnitTable[block]; in check_sectors_in_chain()
415 if (!(block == BLOCK_NIL || block < nftl->nb_blocks)) in check_sectors_in_chain()
417 if (block == BLOCK_NIL || block >= nftl->nb_blocks) in check_sectors_in_chain()
431 if (length >= nftl->nb_blocks) { in calc_chain_length()
436 block = nftl->ReplUnitTable[block]; in calc_chain_length()
437 if (!(block == BLOCK_NIL || block < nftl->nb_blocks)) in calc_chain_length()
439 if (block == BLOCK_NIL || block >= nftl->nb_blocks) in calc_chain_length()
462 block1 = nftl->ReplUnitTable[block]; in format_chain()
467 nftl->ReplUnitTable[block] = BLOCK_RESERVED; in format_chain()
469 nftl->ReplUnitTable[block] = BLOCK_FREE; in format_chain()
475 if (!(block == BLOCK_NIL || block < nftl->nb_blocks)) in format_chain()
477 if (block == BLOCK_NIL || block >= nftl->nb_blocks) in format_chain()
485 * Definition: Free Erase Unit -- A properly erased/formatted Free Erase Unit should have meet the
490 struct mtd_info *mtd = nftl->mbd.mtd; in check_and_mark_free_block()
496 if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, in check_and_mark_free_block()
498 return -1; in check_and_mark_free_block()
504 if (check_free_sectors (nftl, block * nftl->EraseSize, nftl->EraseSize, 1) != 0) in check_and_mark_free_block()
505 return -1; in check_and_mark_free_block()
512 block * nftl->EraseSize + SECTORSIZE + 8, 8, in check_and_mark_free_block()
514 return -1; in check_and_mark_free_block()
518 for (i = 0; i < nftl->EraseSize; i += SECTORSIZE) { in check_and_mark_free_block()
520 if (check_free_sectors (nftl, block * nftl->EraseSize + i, in check_and_mark_free_block()
522 return -1; in check_and_mark_free_block()
524 if (nftl_read_oob(mtd, block * nftl->EraseSize + i, in check_and_mark_free_block()
526 return -1; in check_and_mark_free_block()
530 return -1; in check_and_mark_free_block()
533 return -1; in check_and_mark_free_block()
551 struct mtd_info *mtd = nftl->mbd.mtd; in get_fold_mark()
555 if (nftl_read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8, in get_fold_mark()
570 struct mtd_info *mtd = s->mbd.mtd; in NFTL_mount()
576 return -1; in NFTL_mount()
580 for (i = 0; i < s->nb_blocks; i++) { in NFTL_mount()
581 s->EUNtable[i] = BLOCK_NIL; in NFTL_mount()
586 for (first_block = 0; first_block < s->nb_blocks; first_block++) { in NFTL_mount()
588 if (s->ReplUnitTable[first_block] == BLOCK_NOTEXPLORED) { in NFTL_mount()
596 block * s->EraseSize + 8, 8, in NFTL_mount()
599 block * s->EraseSize + in NFTL_mount()
602 s->ReplUnitTable[block] = BLOCK_NIL; in NFTL_mount()
615 if (erase_mark != ERASE_MARK || logical_block >= s->nb_blocks) { in NFTL_mount()
623 s->ReplUnitTable[block] = BLOCK_RESERVED; in NFTL_mount()
625 s->ReplUnitTable[block] = BLOCK_FREE; in NFTL_mount()
629 s->ReplUnitTable[block] = BLOCK_FREE; in NFTL_mount()
638 s->ReplUnitTable[block] = BLOCK_NIL; in NFTL_mount()
672 printk("Block %d: folding in progress - ignoring first block flag\n", in NFTL_mount()
680 s->ReplUnitTable[block] = BLOCK_NIL; in NFTL_mount()
682 } else if (rep_block >= s->nb_blocks) { in NFTL_mount()
686 s->ReplUnitTable[block] = BLOCK_NIL; in NFTL_mount()
688 } else if (s->ReplUnitTable[rep_block] != BLOCK_NOTEXPLORED) { in NFTL_mount()
694 if (s->ReplUnitTable[rep_block] == BLOCK_NIL && in NFTL_mount()
695 s->EUNtable[first_logical_block] == rep_block && in NFTL_mount()
698 printk("Block %d: folding in progress - ignoring first block flag\n", in NFTL_mount()
700 s->ReplUnitTable[block] = rep_block; in NFTL_mount()
701 s->EUNtable[first_logical_block] = BLOCK_NIL; in NFTL_mount()
707 s->ReplUnitTable[block] = BLOCK_NIL; in NFTL_mount()
712 s->ReplUnitTable[block] = rep_block; in NFTL_mount()
740 first_block1 = s->EUNtable[first_logical_block]; in NFTL_mount()
749 s->EUNtable[first_logical_block] = first_block; in NFTL_mount()
755 s->EUNtable[first_logical_block] = first_block; in NFTL_mount()
764 s->numfreeEUNs = 0; in NFTL_mount()
765 s->LastFreeEUN = le16_to_cpu(s->MediaHdr.FirstPhysicalEUN); in NFTL_mount()
767 for (block = 0; block < s->nb_blocks; block++) { in NFTL_mount()
768 if (s->ReplUnitTable[block] == BLOCK_NOTEXPLORED) { in NFTL_mount()
771 s->ReplUnitTable[block] = BLOCK_RESERVED; in NFTL_mount()
773 s->ReplUnitTable[block] = BLOCK_FREE; in NFTL_mount()
775 if (s->ReplUnitTable[block] == BLOCK_FREE) { in NFTL_mount()
776 s->numfreeEUNs++; in NFTL_mount()
777 s->LastFreeEUN = block; in NFTL_mount()