X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_mtdif1.c;h=70876bc34bb3283226b314ef50510871237ec791;hp=f4d35fc5a659900f62f191d3b0f366fb4c88329a;hb=e33554a67753729f6b74677473cf0ec3b8d35a7e;hpb=3e5718ec7f0df7b76837d10583419b745cb27474 diff --git a/yaffs_mtdif1.c b/yaffs_mtdif1.c index f4d35fc..70876bc 100644 --- a/yaffs_mtdif1.c +++ b/yaffs_mtdif1.c @@ -2,7 +2,7 @@ * YAFFS: Yet another FFS. A NAND-flash specific file system. * yaffs_mtdif1.c NAND mtd interface functions for small-page NAND. * - * Copyright (C) 2002 Aleph One Ltd. + * Copyright (C) 2002-2010 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering * * This program is free software; you can redistribute it and/or modify @@ -24,9 +24,11 @@ */ #include "yportenv.h" +#include "yaffs_trace.h" #include "yaffs_guts.h" #include "yaffs_packedtags1.h" -#include "yaffs_tagscompat.h" /* for yaffs_CalcTagsECC */ +#include "yaffs_tagscompat.h" /* for yaffs_calc_tags_ecc */ +#include "yaffs_linux.h" #include "linux/kernel.h" #include "linux/version.h" @@ -36,8 +38,6 @@ /* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ #if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.9 2009-03-06 17:20:52 wookey Exp $"; - #ifndef CONFIG_YAFFS_9BYTE_TAGS # define YTAG1_SIZE 8 #else @@ -91,7 +91,7 @@ static struct nand_ecclayout nand_oob_16 = { int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *etags) { - struct mtd_info *mtd = dev->genericDevice; + struct mtd_info *mtd = yaffs_dev_to_mtd(dev); int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; struct mtd_oob_ops ops; @@ -102,10 +102,8 @@ int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, compile_time_assertion(sizeof(yaffs_PackedTags1) == 12); compile_time_assertion(sizeof(yaffs_Tags) == 8); - dev->nPageWrites++; - yaffs_PackTags1(&pt1, etags); - yaffs_CalcTagsECC((yaffs_Tags *)&pt1); + yaffs_calc_tags_ecc((yaffs_Tags *)&pt1); /* When deleting a chunk, the upper layer provides only skeletal * etags, one with chunkDeleted set. However, we need to update the @@ -137,9 +135,9 @@ int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, retval = mtd->write_oob(mtd, addr, &ops); if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "write_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); + T(YAFFS_TRACE_MTD, + (TSTR("write_oob failed, chunk %d, mtd error %d"TENDSTR), + chunkInNAND, retval)); } return retval ? YAFFS_FAIL : YAFFS_OK; } @@ -171,7 +169,7 @@ static int rettags(yaffs_ExtendedTags *etags, int eccResult, int retval) int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags) { - struct mtd_info *mtd = dev->genericDevice; + struct mtd_info *mtd = yaffs_dev_to_mtd(dev); int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; int eccres = YAFFS_ECC_RESULT_NO_ERROR; @@ -180,8 +178,6 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int retval; int deleted; - dev->nPageReads++; - memset(&ops, 0, sizeof(ops)); ops.mode = MTD_OOB_AUTO; ops.len = (data) ? chunkBytes : 0; @@ -200,9 +196,9 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, */ retval = mtd->read_oob(mtd, addr, &ops); if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "read_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); + T(YAFFS_TRACE_MTD, + (TSTR("read_oob failed, chunk %d, mtd error %d"TENDSTR), + chunkInNAND, retval)); } switch (retval) { @@ -228,7 +224,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, /* Check for a blank/erased chunk. */ - if (yaffs_CheckFF((__u8 *)&pt1, 8)) { + if (yaffs_check_ff((__u8 *)&pt1, 8)) { /* when blank, upper layers want eccResult to be <= NO_ERROR */ return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); } @@ -241,12 +237,12 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, deleted = !pt1.deleted; pt1.deleted = 1; #else - deleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); + deleted = (yaffs_count_bits(((__u8 *)&pt1)[8]) < 7); #endif /* Check the packed tags mini-ECC and correct if necessary/possible. */ - retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); + retval = yaffs_check_tags_ecc((yaffs_Tags *)&pt1); switch (retval) { case 0: /* no tags error, use MTD result */ @@ -264,10 +260,10 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, } /* Unpack the tags to extended form and set ECC result. - * [set shouldBeFF just to keep yaffs_UnpackTags1 happy] + * [set shouldBeFF just to keep yaffs_unpack_tags1 happy] */ pt1.shouldBeFF = 0xFFFFFFFF; - yaffs_UnpackTags1(etags, &pt1); + yaffs_unpack_tags1(etags, &pt1); etags->eccResult = eccres; /* Set deleted state */ @@ -284,11 +280,11 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, */ int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) { - struct mtd_info *mtd = dev->genericDevice; - int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; + struct mtd_info *mtd = yaffs_dev_to_mtd(dev); + int blocksize = dev->param.nChunksPerBlock * dev->nDataBytesPerChunk; int retval; - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo); + T(YAFFS_TRACE_BAD_BLOCKS,(TSTR("marking block %d bad"TENDSTR), blockNo)); retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); return (retval) ? YAFFS_FAIL : YAFFS_OK; @@ -305,9 +301,9 @@ static int nandmtd1_TestPrerequists(struct mtd_info *mtd) int oobavail = mtd->ecclayout->oobavail; if (oobavail < YTAG1_SIZE) { - yaffs_trace(YAFFS_TRACE_ERROR, - "mtd device has only %d bytes for tags, need %d\n", - oobavail, YTAG1_SIZE); + T(YAFFS_TRACE_ERROR, + (TSTR("mtd device has only %d bytes for tags, need %d"TENDSTR), + oobavail, YTAG1_SIZE)); return YAFFS_FAIL; } return YAFFS_OK; @@ -325,8 +321,8 @@ static int nandmtd1_TestPrerequists(struct mtd_info *mtd) int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState *pState, __u32 *pSequenceNumber) { - struct mtd_info *mtd = dev->genericDevice; - int chunkNo = blockNo * dev->nChunksPerBlock; + struct mtd_info *mtd = yaffs_dev_to_mtd(dev); + int chunkNo = blockNo * dev->param.nChunksPerBlock; loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk; yaffs_ExtendedTags etags; int state = YAFFS_BLOCK_STATE_DEAD; @@ -336,15 +332,14 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, /* We don't yet have a good place to test for MTD config prerequists. * Do it here as we are called during the initial scan. */ - if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) { + if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) return YAFFS_FAIL; - } retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); etags.blockBad = (mtd->block_isbad)(mtd, addr); if (etags.blockBad) { - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad\n", blockNo); + T(YAFFS_TRACE_BAD_BLOCKS, + (TSTR("block %d is marked bad"TENDSTR), blockNo)); state = YAFFS_BLOCK_STATE_DEAD; } else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) { /* bad tags, need to look more closely */