/*
* 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
*
+ * Created by Charles Manning <charles@aleph1.co.uk>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#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_CalcTagsECC */
+#include "yaffs_linux.h"
#include "linux/kernel.h"
#include "linux/version.h"
#include "linux/mtd/mtd.h"
/* 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.7 2007-12-13 15:35:18 wookey Exp $";
+#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
#ifndef CONFIG_YAFFS_9BYTE_TAGS
# define YTAG1_SIZE 8
* Returns YAFFS_OK or YAFFS_FAIL.
*/
int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
- int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags)
+ int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *etags)
{
- struct mtd_info * mtd = dev->genericDevice;
+ struct mtd_info *mtd = yaffs_DeviceToMtd(dev);
int chunkBytes = dev->nDataBytesPerChunk;
loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
struct mtd_oob_ops ops;
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);
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;
}
/* Return with empty ExtendedTags but add eccResult.
*/
-static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval)
+static int rettags(yaffs_ExtendedTags *etags, int eccResult, int retval)
{
if (etags) {
memset(etags, 0, sizeof(*etags));
* Returns YAFFS_OK or YAFFS_FAIL.
*/
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
- int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags)
+ int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags)
{
- struct mtd_info * mtd = dev->genericDevice;
+ struct mtd_info *mtd = yaffs_DeviceToMtd(dev);
int chunkBytes = dev->nDataBytesPerChunk;
loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
int eccres = YAFFS_ECC_RESULT_NO_ERROR;
int retval;
int deleted;
- dev->nPageReads++;
-
memset(&ops, 0, sizeof(ops));
ops.mode = MTD_OOB_AUTO;
ops.len = (data) ? chunkBytes : 0;
ops.datbuf = data;
ops.oobbuf = (__u8 *)&pt1;
-#if (MTD_VERSION_CODE < MTD_VERSION(2,6,20))
+#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 20))
/* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug;
* help it out with ops.len = ops.ooblen when ops.datbuf == NULL.
*/
*/
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) {
*/
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_DeviceToMtd(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;
*
* Returns YAFFS_OK or YAFFS_FAIL.
*/
-static int nandmtd1_TestPrerequists(struct mtd_info * mtd)
+static int nandmtd1_TestPrerequists(struct mtd_info *mtd)
{
/* 2.6.18 has mtd->ecclayout->oobavail */
/* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */
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;
* Always returns YAFFS_OK.
*/
int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
- yaffs_BlockState * pState, int *pSequenceNumber)
+ yaffs_BlockState *pState, __u32 *pSequenceNumber)
{
- struct mtd_info * mtd = dev->genericDevice;
- int chunkNo = blockNo * dev->nChunksPerBlock;
+ struct mtd_info *mtd = yaffs_DeviceToMtd(dev);
+ int chunkNo = blockNo * dev->param.nChunksPerBlock;
loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk;
yaffs_ExtendedTags etags;
int state = YAFFS_BLOCK_STATE_DEAD;
/* 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) {
+ } else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) {
/* bad tags, need to look more closely */
state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
- }
- else if (etags.chunkUsed) {
+ } else if (etags.chunkUsed) {
state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
seqnum = etags.sequenceNumber;
- }
- else {
+ } else {
state = YAFFS_BLOCK_STATE_EMPTY;
}