2 * inftlcore.c -- Linux driver for Inverse Flash Translation Layer (INFTL)
4 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
6 * Based heavily on the nftlcore.c code which is:
7 * (c) 1999 Machine Vision Holdings, Inc.
8 * Author: David Woodhouse <dwmw2@infradead.org>
10 * $Id: inftlcore.c,v 1.14 2003/06/26 08:28:26 dwmw2 Exp $
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/config.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 #include <linux/sched.h>
33 #include <linux/init.h>
34 #include <linux/kmod.h>
35 #include <linux/hdreg.h>
36 #include <linux/mtd/mtd.h>
37 #include <linux/mtd/nftl.h>
38 #include <linux/mtd/inftl.h>
39 #include <asm/uaccess.h>
40 #include <asm/errno.h>
44 * Maximum number of loops while examining next block, to have a
45 * chance to detect consistency problems (they should never happen
46 * because of the checks done in the mounting.
48 #define MAX_LOOPS 10000
50 extern void INFTL_dumptables(struct INFTLrecord *inftl);
51 extern void INFTL_dumpVUchains(struct INFTLrecord *inftl);
53 static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
55 struct INFTLrecord *inftl;
58 if (mtd->ecctype != MTD_ECC_RS_DiskOnChip)
61 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name);
63 inftl = kmalloc(sizeof(*inftl), GFP_KERNEL);
66 printk(KERN_WARNING "INFTL: Out of memory for data structures\n");
69 memset(inftl, 0, sizeof(*inftl));
72 inftl->mbd.devnum = -1;
73 inftl->mbd.blksize = 512;
76 if (INFTL_mount(inftl) < 0) {
77 printk(KERN_WARNING "INFTL: could not mount device\n");
82 /* OK, it's a new one. Set up all the data structures. */
84 /* Calculate geometry */
85 inftl->cylinders = 1024;
88 temp = inftl->cylinders * inftl->heads;
89 inftl->sectors = inftl->mbd.size / temp;
90 if (inftl->mbd.size % temp) {
92 temp = inftl->cylinders * inftl->sectors;
93 inftl->heads = inftl->mbd.size / temp;
95 if (inftl->mbd.size % temp) {
97 temp = inftl->heads * inftl->sectors;
98 inftl->cylinders = inftl->mbd.size / temp;
102 if (inftl->mbd.size != inftl->heads * inftl->cylinders * inftl->sectors) {
105 mbd.size == heads * cylinders * sectors
107 printk(KERN_WARNING "INFTL: cannot calculate a geometry to "
108 "match size of 0x%lx.\n", inftl->mbd.size);
109 printk(KERN_WARNING "INFTL: using C:%d H:%d S:%d "
110 "(== 0x%lx sects)\n",
111 inftl->cylinders, inftl->heads , inftl->sectors,
112 (long)inftl->cylinders * (long)inftl->heads *
113 (long)inftl->sectors );
116 if (add_mtd_blktrans_dev(&inftl->mbd)) {
118 kfree(inftl->PUtable);
120 kfree(inftl->VUtable);
125 printk(KERN_INFO "INFTL: Found new nftl%c\n", nftl->mbd.devnum + 'a');
130 static void inftl_remove_dev(struct mtd_blktrans_dev *dev)
132 struct INFTLrecord *inftl = (void *)dev;
134 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: remove_dev (i=%d)\n", dev->devnum);
136 del_mtd_blktrans_dev(dev);
139 kfree(inftl->PUtable);
141 kfree(inftl->VUtable);
146 * Actual INFTL access routines.
150 * INFTL_findfreeblock: Find a free Erase Unit on the INFTL partition.
151 * This function is used when the give Virtual Unit Chain.
153 static u16 INFTL_findfreeblock(struct INFTLrecord *inftl, int desperate)
155 u16 pot = inftl->LastFreeEUN;
156 int silly = inftl->nb_blocks;
158 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_findfreeblock(inftl=0x%x,"
159 "desperate=%d)\n", (int)inftl, desperate);
162 * Normally, we force a fold to happen before we run out of free
165 if (!desperate && inftl->numfreeEUNs < 2) {
166 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: there are too few free "
167 "EUNs (%d)\n", inftl->numfreeEUNs);
171 /* Scan for a free block */
173 if (inftl->PUtable[pot] == BLOCK_FREE) {
174 inftl->LastFreeEUN = pot;
178 if (++pot > inftl->lastEUN)
182 printk(KERN_WARNING "INFTL: no free blocks found! "
183 "EUN range = %d - %d\n", 0, inftl->LastFreeEUN);
186 } while (pot != inftl->LastFreeEUN);
191 static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned pendingblock)
193 u16 BlockMap[MAX_SECTORS_PER_UNIT];
194 unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
195 unsigned int thisEUN, prevEUN, status;
197 unsigned int targetEUN;
198 struct inftl_oob oob;
201 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=0x%x,thisVUC=%d,"
202 "pending=%d)\n", (int)inftl, thisVUC, pendingblock);
204 memset(BlockMap, 0xff, sizeof(BlockMap));
205 memset(BlockDeleted, 0, sizeof(BlockDeleted));
207 thisEUN = targetEUN = inftl->VUtable[thisVUC];
209 if (thisEUN == BLOCK_NIL) {
210 printk(KERN_WARNING "INFTL: trying to fold non-existent "
211 "Virtual Unit Chain %d!\n", thisVUC);
216 * Scan to find the Erase Unit which holds the actual data for each
217 * 512-byte block within the Chain.
220 while (thisEUN < inftl->nb_blocks) {
221 for (block = 0; block < inftl->EraseSize/SECTORSIZE; block ++) {
222 if ((BlockMap[block] != 0xffff) || BlockDeleted[block])
225 if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
226 + (block * SECTORSIZE), 16 , &retlen,
228 status = SECTOR_IGNORE;
230 status = oob.b.Status | oob.b.Status1;
237 BlockMap[block] = thisEUN;
240 BlockDeleted[block] = 1;
243 printk(KERN_WARNING "INFTL: unknown status "
244 "for block %d in EUN %d: %x\n",
245 block, thisEUN, status);
251 printk(KERN_WARNING "INFTL: infinite loop in Virtual "
252 "Unit Chain 0x%x\n", thisVUC);
256 thisEUN = inftl->PUtable[thisEUN];
260 * OK. We now know the location of every block in the Virtual Unit
261 * Chain, and the Erase Unit into which we are supposed to be copying.
264 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: folding chain %d into unit %d\n",
267 for (block = 0; block < inftl->EraseSize/SECTORSIZE ; block++) {
268 unsigned char movebuf[SECTORSIZE];
272 * If it's in the target EUN already, or if it's pending write,
275 if (BlockMap[block] == targetEUN || (pendingblock ==
276 (thisVUC * (inftl->EraseSize / SECTORSIZE) + block))) {
281 * Copy only in non free block (free blocks can only
282 * happen in case of media errors or deleted blocks).
284 if (BlockMap[block] == BLOCK_NIL)
287 ret = MTD_READECC(inftl->mbd.mtd, (inftl->EraseSize *
288 BlockMap[block]) + (block * SECTORSIZE), SECTORSIZE,
289 &retlen, movebuf, (char *)&oob, NULL);
291 ret = MTD_READECC(inftl->mbd.mtd, (inftl->EraseSize *
292 BlockMap[block]) + (block * SECTORSIZE),
293 SECTORSIZE, &retlen, movebuf, (char *)&oob,
296 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
299 MTD_WRITEECC(inftl->mbd.mtd, (inftl->EraseSize * targetEUN) +
300 (block * SECTORSIZE), SECTORSIZE, &retlen,
301 movebuf, (char *)&oob, NULL);
305 * Newest unit in chain now contains data from _all_ older units.
306 * So go through and erase each unit in chain, oldest first. (This
307 * is important, by doing oldest first if we crash/reboot then it
308 * it is relatively simple to clean up the mess).
310 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: want to erase virtual chain %d\n",
314 /* Find oldest unit in chain. */
315 thisEUN = inftl->VUtable[thisVUC];
317 while (inftl->PUtable[thisEUN] != BLOCK_NIL) {
319 thisEUN = inftl->PUtable[thisEUN];
322 /* Check if we are all done */
323 if (thisEUN == targetEUN)
326 if (INFTL_formatblock(inftl, thisEUN) < 0) {
328 * Could not erase : mark block as reserved.
329 * FixMe: Update Bad Unit Table on disk.
331 inftl->PUtable[thisEUN] = BLOCK_RESERVED;
333 /* Correctly erased : mark it as free */
334 inftl->PUtable[thisEUN] = BLOCK_FREE;
335 inftl->PUtable[prevEUN] = BLOCK_NIL;
336 inftl->numfreeEUNs++;
343 u16 INFTL_makefreeblock(struct INFTLrecord *inftl, unsigned pendingblock)
346 * This is the part that needs some cleverness applied.
347 * For now, I'm doing the minimum applicable to actually
348 * get the thing to work.
349 * Wear-levelling and other clever stuff needs to be implemented
350 * and we also need to do some assessment of the results when
351 * the system loses power half-way through the routine.
353 u16 LongestChain = 0;
354 u16 ChainLength = 0, thislen;
357 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_makefreeblock(inftl=0x%x,"
358 "pending=%d)\n", (int)inftl, pendingblock);
360 for (chain = 0; chain < inftl->nb_blocks; chain++) {
361 EUN = inftl->VUtable[chain];
364 while (EUN <= inftl->lastEUN) {
366 EUN = inftl->PUtable[EUN];
367 if (thislen > 0xff00) {
368 printk(KERN_WARNING "INFTL: endless loop in "
369 "Virtual Chain %d: Unit %x\n",
372 * Actually, don't return failure.
373 * Just ignore this chain and get on with it.
380 if (thislen > ChainLength) {
381 ChainLength = thislen;
382 LongestChain = chain;
386 if (ChainLength < 2) {
387 printk(KERN_WARNING "INFTL: no Virtual Unit Chains available "
388 "for folding. Failing request\n");
392 return INFTL_foldchain(inftl, LongestChain, pendingblock);
395 static int nrbits(unsigned int val, int bitcount)
399 for (i = 0; (i < bitcount); i++)
400 total += (((0x1 << i) & val) ? 1 : 0);
405 * INFTL_findwriteunit: Return the unit number into which we can write
406 * for this block. Make it available if it isn't already.
408 static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
410 unsigned int thisVUC = block / (inftl->EraseSize / SECTORSIZE);
411 unsigned int thisEUN, writeEUN, prev_block, status;
412 unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize -1);
413 struct inftl_oob oob;
414 struct inftl_bci bci;
415 unsigned char anac, nacs, parity;
417 int silly, silly2 = 3;
419 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_findwriteunit(inftl=0x%x,"
420 "block=%d)\n", (int)inftl, block);
424 * Scan the media to find a unit in the VUC which has
425 * a free space for the block in question.
427 writeEUN = BLOCK_NIL;
428 thisEUN = inftl->VUtable[thisVUC];
431 while (thisEUN <= inftl->lastEUN) {
432 MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
433 blockofs, 8, &retlen, (char *)&bci);
435 status = bci.Status | bci.Status1;
436 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in "
437 "EUN %d is %x\n", block , writeEUN, status);
445 /* Can't go any further */
451 * Invalid block. Don't use it any more.
458 printk(KERN_WARNING "INFTL: infinite loop in "
459 "Virtual Unit Chain 0x%x\n", thisVUC);
463 /* Skip to next block in chain */
464 thisEUN = inftl->PUtable[thisEUN];
468 if (writeEUN != BLOCK_NIL)
473 * OK. We didn't find one in the existing chain, or there
474 * is no existing chain. Allocate a new one.
476 writeEUN = INFTL_findfreeblock(inftl, 0);
478 if (writeEUN == BLOCK_NIL) {
480 * That didn't work - there were no free blocks just
481 * waiting to be picked up. We're going to have to fold
482 * a chain to make room.
484 thisEUN = INFTL_makefreeblock(inftl, 0xffff);
487 * Hopefully we free something, lets try again.
488 * This time we are desperate...
490 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: using desperate==1 "
491 "to find free EUN to accommodate write to "
492 "VUC %d\n", thisVUC);
493 writeEUN = INFTL_findfreeblock(inftl, 1);
494 if (writeEUN == BLOCK_NIL) {
496 * Ouch. This should never happen - we should
497 * always be able to make some room somehow.
498 * If we get here, we've allocated more storage
499 * space than actual media, or our makefreeblock
500 * routine is missing something.
502 printk(KERN_WARNING "INFTL: cannot make free "
505 INFTL_dumptables(inftl);
506 INFTL_dumpVUchains(inftl);
513 * Insert new block into virtual chain. Firstly update the
514 * block headers in flash...
518 thisEUN = inftl->VUtable[thisVUC];
519 if (thisEUN != BLOCK_NIL) {
520 MTD_READOOB(inftl->mbd.mtd, thisEUN * inftl->EraseSize
521 + 8, 8, &retlen, (char *)&oob.u);
522 anac = oob.u.a.ANAC + 1;
523 nacs = oob.u.a.NACs + 1;
526 prev_block = inftl->VUtable[thisVUC];
527 if (prev_block < inftl->nb_blocks)
528 prev_block -= inftl->firstEUN;
530 parity = (nrbits(thisVUC, 16) & 0x1) ? 0x1 : 0;
531 parity |= (nrbits(prev_block, 16) & 0x1) ? 0x2 : 0;
532 parity |= (nrbits(anac, 8) & 0x1) ? 0x4 : 0;
533 parity |= (nrbits(nacs, 8) & 0x1) ? 0x8 : 0;
535 oob.u.a.virtualUnitNo = cpu_to_le16(thisVUC);
536 oob.u.a.prevUnitNo = cpu_to_le16(prev_block);
539 oob.u.a.parityPerField = parity;
540 oob.u.a.discarded = 0xaa;
542 MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize + 8, 8,
543 &retlen, (char *)&oob.u);
545 /* Also back up header... */
546 oob.u.b.virtualUnitNo = cpu_to_le16(thisVUC);
547 oob.u.b.prevUnitNo = cpu_to_le16(prev_block);
550 oob.u.b.parityPerField = parity;
551 oob.u.b.discarded = 0xaa;
553 MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize +
554 SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);
556 inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC];
557 inftl->VUtable[thisVUC] = writeEUN;
559 inftl->numfreeEUNs--;
564 printk(KERN_WARNING "INFTL: error folding to make room for Virtual "
565 "Unit Chain 0x%x\n", thisVUC);
570 * Given a Virtual Unit Chain, see if it can be deleted, and if so do it.
572 static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
574 unsigned char BlockUsed[MAX_SECTORS_PER_UNIT];
575 unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
576 unsigned int thisEUN, status;
578 struct inftl_bci bci;
581 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_trydeletechain(inftl=0x%x,"
582 "thisVUC=%d)\n", (int)inftl, thisVUC);
584 memset(BlockUsed, 0, sizeof(BlockUsed));
585 memset(BlockDeleted, 0, sizeof(BlockDeleted));
587 thisEUN = inftl->VUtable[thisVUC];
588 if (thisEUN == BLOCK_NIL) {
589 printk(KERN_WARNING "INFTL: trying to delete non-existent "
590 "Virtual Unit Chain %d!\n", thisVUC);
595 * Scan through the Erase Units to determine whether any data is in
596 * each of the 512-byte blocks within the Chain.
599 while (thisEUN < inftl->nb_blocks) {
600 for (block = 0; block < inftl->EraseSize/SECTORSIZE; block++) {
601 if (BlockUsed[block] || BlockDeleted[block])
604 if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
605 + (block * SECTORSIZE), 8 , &retlen,
607 status = SECTOR_IGNORE;
609 status = bci.Status | bci.Status1;
616 BlockUsed[block] = 1;
619 BlockDeleted[block] = 1;
622 printk(KERN_WARNING "INFTL: unknown status "
623 "for block %d in EUN %d: 0x%x\n",
624 block, thisEUN, status);
629 printk(KERN_WARNING "INFTL: infinite loop in Virtual "
630 "Unit Chain 0x%x\n", thisVUC);
634 thisEUN = inftl->PUtable[thisEUN];
637 for (block = 0; block < inftl->EraseSize/SECTORSIZE; block++)
638 if (BlockUsed[block])
642 * For each block in the chain free it and make it available
643 * for future use. Erase from the oldest unit first.
645 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: deleting empty VUC %d\n", thisVUC);
648 u16 *prevEUN = &inftl->VUtable[thisVUC];
651 /* If the chain is all gone already, we're done */
652 if (thisEUN == BLOCK_NIL) {
653 DEBUG(MTD_DEBUG_LEVEL2, "INFTL: Empty VUC %d for deletion was already absent\n", thisEUN);
657 /* Find oldest unit in chain. */
658 while (inftl->PUtable[thisEUN] != BLOCK_NIL) {
659 BUG_ON(thisEUN >= inftl->nb_blocks);
661 prevEUN = &inftl->PUtable[thisEUN];
665 DEBUG(MTD_DEBUG_LEVEL3, "Deleting EUN %d from VUC %d\n",
668 if (INFTL_formatblock(inftl, thisEUN) < 0) {
670 * Could not erase : mark block as reserved.
671 * FixMe: Update Bad Unit Table on medium.
673 inftl->PUtable[thisEUN] = BLOCK_RESERVED;
675 /* Correctly erased : mark it as free */
676 inftl->PUtable[thisEUN] = BLOCK_FREE;
677 inftl->numfreeEUNs++;
680 /* Now sort out whatever was pointing to it... */
681 *prevEUN = BLOCK_NIL;
683 /* Ideally we'd actually be responsive to new
684 requests while we're doing this -- if there's
685 free space why should others be made to wait? */
689 inftl->VUtable[thisVUC] = BLOCK_NIL;
692 static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
694 unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
695 unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
697 int silly = MAX_LOOPS;
699 struct inftl_bci bci;
701 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_deleteblock(inftl=0x%x,"
702 "block=%d)\n", (int)inftl, block);
704 while (thisEUN < inftl->nb_blocks) {
705 if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
706 blockofs, 8, &retlen, (char *)&bci) < 0)
707 status = SECTOR_IGNORE;
709 status = bci.Status | bci.Status1;
721 printk(KERN_WARNING "INFTL: unknown status for "
722 "block %d in EUN %d: 0x%x\n",
723 block, thisEUN, status);
728 printk(KERN_WARNING "INFTL: infinite loop in Virtual "
730 block / (inftl->EraseSize / SECTORSIZE));
733 thisEUN = inftl->PUtable[thisEUN];
737 if (thisEUN != BLOCK_NIL) {
738 loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
740 if (MTD_READOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
742 bci.Status = bci.Status1 = SECTOR_DELETED;
743 if (MTD_WRITEOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
745 INFTL_trydeletechain(inftl, block / (inftl->EraseSize / SECTORSIZE));
750 static int inftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block,
753 struct INFTLrecord *inftl = (void *)mbd;
754 unsigned int writeEUN;
755 unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
760 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: inftl_writeblock(inftl=0x%x,block=%ld,"
761 "buffer=0x%x)\n", (int)inftl, block, (int)buffer);
763 /* Is block all zero? */
764 pend = buffer + SECTORSIZE;
765 for (p = buffer; p < pend && !*p; p++)
769 writeEUN = INFTL_findwriteunit(inftl, block);
771 if (writeEUN == BLOCK_NIL) {
772 printk(KERN_WARNING "inftl_writeblock(): cannot find "
773 "block to write to\n");
775 * If we _still_ haven't got a block to use,
781 MTD_WRITEECC(inftl->mbd.mtd, (writeEUN * inftl->EraseSize) +
782 blockofs, SECTORSIZE, &retlen, (char *)buffer,
783 (char *)eccbuf, NULL);
785 * No need to write SECTOR_USED flags since they are written
789 INFTL_deleteblock(inftl, block);
795 static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
798 struct INFTLrecord *inftl = (void *)mbd;
799 unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
800 unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
802 int silly = MAX_LOOPS;
803 struct inftl_bci bci;
806 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: inftl_readblock(inftl=0x%x,block=%ld,"
807 "buffer=0x%x)\n", (int)inftl, block, (int)buffer);
809 while (thisEUN < inftl->nb_blocks) {
810 if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
811 blockofs, 8, &retlen, (char *)&bci) < 0)
812 status = SECTOR_IGNORE;
814 status = bci.Status | bci.Status1;
826 printk(KERN_WARNING "INFTL: unknown status for "
827 "block %ld in EUN %d: 0x%04x\n",
828 block, thisEUN, status);
833 printk(KERN_WARNING "INFTL: infinite loop in "
834 "Virtual Unit Chain 0x%lx\n",
835 block / (inftl->EraseSize / SECTORSIZE));
839 thisEUN = inftl->PUtable[thisEUN];
843 if (thisEUN == BLOCK_NIL) {
844 /* The requested block is not on the media, return all 0x00 */
845 memset(buffer, 0, SECTORSIZE);
848 loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
850 if (MTD_READECC(inftl->mbd.mtd, ptr, SECTORSIZE, &retlen,
851 buffer, eccbuf, NULL))
857 static int inftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
859 struct INFTLrecord *inftl = (void *)dev;
861 geo->heads = inftl->heads;
862 geo->sectors = inftl->sectors;
863 geo->cylinders = inftl->cylinders;
868 struct mtd_blktrans_ops inftl_tr = {
870 .major = INFTL_MAJOR,
871 .part_bits = INFTL_PARTN_BITS,
872 .getgeo = inftl_getgeo,
873 .readsect = inftl_readblock,
874 .writesect = inftl_writeblock,
875 .add_mtd = inftl_add_mtd,
876 .remove_dev = inftl_remove_dev,
877 .owner = THIS_MODULE,
880 extern char inftlmountrev[];
882 int __init init_inftl(void)
884 printk(KERN_INFO "INFTL: inftlcore.c $Revision: 1.14 $, "
885 "inftlmount.c %s\n", inftlmountrev);
887 return register_mtd_blktrans(&inftl_tr);
890 static void __exit cleanup_inftl(void)
892 deregister_mtd_blktrans(&inftl_tr);
895 module_init(init_inftl);
896 module_exit(cleanup_inftl);
898 MODULE_LICENSE("GPL");
899 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>, David Woodhouse <dwmw2@infradead.org>, Fabrice Bellard <fabrice.bellard@netgem.com> et al.");
900 MODULE_DESCRIPTION("Support code for Inverse Flash Translation Layer, used on M-Systems DiskOnChip 2000, Millennium and Millennium Plus");