Skip to content

Commit

Permalink
[MTD] Introduce writesize
Browse files Browse the repository at this point in the history
At least two flashes exists that have the concept of a minimum write unit,
similar to NAND pages, but no other NAND characteristics.  Therefore, rename
the minimum write unit to "writesize" for all flashes, including NAND.

Signed-off-by: Joern Engel <[email protected]>
  • Loading branch information
Joern Engel committed May 22, 2006
1 parent 8ca9ed5 commit 2831877
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 114 deletions.
4 changes: 2 additions & 2 deletions drivers/mtd/chips/cfi_cmdset_0001.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,12 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
if (extp->MinorVersion >= '4') {
struct cfi_intelext_programming_regioninfo *prinfo;
prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs];
MTD_PROGREGION_SIZE(mtd) = cfi->interleave << prinfo->ProgRegShift;
mtd->writesize = cfi->interleave << prinfo->ProgRegShift;
MTD_PROGREGION_CTRLMODE_VALID(mtd) = cfi->interleave * prinfo->ControlValid;
MTD_PROGREGION_CTRLMODE_INVALID(mtd) = cfi->interleave * prinfo->ControlInvalid;
mtd->flags |= MTD_PROGRAM_REGIONS;
printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n",
map->name, MTD_PROGREGION_SIZE(mtd),
map->name, mtd->writesize,
MTD_PROGREGION_CTRLMODE_VALID(mtd),
MTD_PROGREGION_CTRLMODE_INVALID(mtd));
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/devices/doc2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ void DoC2k_init(struct mtd_info *mtd)
mtd->ecctype = MTD_ECC_RS_DiskOnChip;
mtd->size = 0;
mtd->erasesize = 0;
mtd->oobblock = 512;
mtd->writesize = 512;
mtd->oobsize = 16;
mtd->owner = THIS_MODULE;
mtd->erase = doc_erase;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/devices/doc2001.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void DoCMil_init(struct mtd_info *mtd)
/* FIXME: erase size is not always 8KiB */
mtd->erasesize = 0x2000;

mtd->oobblock = 512;
mtd->writesize = 512;
mtd->oobsize = 16;
mtd->owner = THIS_MODULE;
mtd->erase = doc_erase;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/devices/doc2001plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void DoCMilPlus_init(struct mtd_info *mtd)
mtd->size = 0;

mtd->erasesize = 0;
mtd->oobblock = 512;
mtd->writesize = 512;
mtd->oobsize = 16;
mtd->owner = THIS_MODULE;
mtd->erase = doc_erase;
Expand Down
10 changes: 5 additions & 5 deletions drivers/mtd/mtdconcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ concat_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
return -EINVAL;

/* Check alignment */
if (mtd->oobblock > 1) {
if (mtd->writesize > 1) {
loff_t __to = to;
if (do_div(__to, mtd->oobblock) || (total_len % mtd->oobblock))
if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize))
return -EINVAL;
}

Expand Down Expand Up @@ -334,7 +334,7 @@ concat_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
*retlen += retsize;
total_len -= wsize;
if (concat->mtd.type == MTD_NANDFLASH && eccbuf)
eccbuf += mtd->oobavail * (wsize / mtd->oobblock);
eccbuf += mtd->oobavail * (wsize / mtd->writesize);

if (total_len == 0)
break;
Expand Down Expand Up @@ -833,7 +833,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
concat->mtd.flags = subdev[0]->flags;
concat->mtd.size = subdev[0]->size;
concat->mtd.erasesize = subdev[0]->erasesize;
concat->mtd.oobblock = subdev[0]->oobblock;
concat->mtd.writesize = subdev[0]->writesize;
concat->mtd.oobsize = subdev[0]->oobsize;
concat->mtd.ecctype = subdev[0]->ecctype;
concat->mtd.eccsize = subdev[0]->eccsize;
Expand Down Expand Up @@ -881,7 +881,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
subdev[i]->flags & MTD_WRITEABLE;
}
concat->mtd.size += subdev[i]->size;
if (concat->mtd.oobblock != subdev[i]->oobblock ||
if (concat->mtd.writesize != subdev[i]->writesize ||
concat->mtd.oobsize != subdev[i]->oobsize ||
concat->mtd.ecctype != subdev[i]->ecctype ||
concat->mtd.eccsize != subdev[i]->eccsize ||
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ int add_mtd_partitions(struct mtd_info *master,
slave->mtd.type = master->type;
slave->mtd.flags = master->flags & ~parts[i].mask_flags;
slave->mtd.size = parts[i].size;
slave->mtd.oobblock = master->oobblock;
slave->mtd.writesize = master->writesize;
slave->mtd.oobsize = master->oobsize;
slave->mtd.oobavail = master->oobavail;
slave->mtd.ecctype = master->ecctype;
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/nand/au1550nd.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ static void au1550_command(struct mtd_info *mtd, unsigned command, int column, i
if (command == NAND_CMD_SEQIN) {
int readcmd;

if (column >= mtd->oobblock) {
if (column >= mtd->writesize) {
/* OOB area */
column -= mtd->oobblock;
column -= mtd->writesize;
readcmd = NAND_CMD_READOOB;
} else if (column < 256) {
/* First 256 bytes --> READ0 */
Expand Down
16 changes: 8 additions & 8 deletions drivers/mtd/nand/diskonchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,9 @@ static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int colu
if (command == NAND_CMD_SEQIN) {
int readcmd;

if (column >= mtd->oobblock) {
if (column >= mtd->writesize) {
/* OOB area */
column -= mtd->oobblock;
column -= mtd->writesize;
readcmd = NAND_CMD_READOOB;
} else if (column < 256) {
/* First 256 bytes --> READ0 */
Expand Down Expand Up @@ -1093,8 +1093,8 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch
size_t retlen;

for (offs = 0; offs < mtd->size; offs += mtd->erasesize) {
ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf);
if (retlen != mtd->oobblock)
ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf);
if (retlen != mtd->writesize)
continue;
if (ret) {
printk(KERN_WARNING "ECC error scanning DOC at 0x%x\n", offs);
Expand All @@ -1118,8 +1118,8 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch
/* Only one mediaheader was found. We want buf to contain a
mediaheader on return, so we'll have to re-read the one we found. */
offs = doc->mh0_page << this->page_shift;
ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf);
if (retlen != mtd->oobblock) {
ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf);
if (retlen != mtd->writesize) {
/* Insanity. Give up. */
printk(KERN_ERR "Read DiskOnChip Media Header once, but can't reread it???\n");
return 0;
Expand All @@ -1139,7 +1139,7 @@ static inline int __init nftl_partscan(struct mtd_info *mtd, struct mtd_partitio
unsigned blocks, maxblocks;
int offs, numheaders;

buf = kmalloc(mtd->oobblock, GFP_KERNEL);
buf = kmalloc(mtd->writesize, GFP_KERNEL);
if (!buf) {
printk(KERN_ERR "DiskOnChip mediaheader kmalloc failed!\n");
return 0;
Expand Down Expand Up @@ -1247,7 +1247,7 @@ static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partiti
if (inftl_bbt_write)
end -= (INFTL_BBT_RESERVED_BLOCKS << this->phys_erase_shift);

buf = kmalloc(mtd->oobblock, GFP_KERNEL);
buf = kmalloc(mtd->writesize, GFP_KERNEL);
if (!buf) {
printk(KERN_ERR "DiskOnChip mediaheader kmalloc failed!\n");
return 0;
Expand Down
64 changes: 32 additions & 32 deletions drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,9 @@ static void nand_command(struct mtd_info *mtd, unsigned command, int column, int
if (command == NAND_CMD_SEQIN) {
int readcmd;

if (column >= mtd->oobblock) {
if (column >= mtd->writesize) {
/* OOB area */
column -= mtd->oobblock;
column -= mtd->writesize;
readcmd = NAND_CMD_READOOB;
} else if (column < 256) {
/* First 256 bytes --> READ0 */
Expand Down Expand Up @@ -658,7 +658,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned command, int column,

/* Emulate NAND_CMD_READOOB */
if (command == NAND_CMD_READOOB) {
column += mtd->oobblock;
column += mtd->writesize;
command = NAND_CMD_READ0;
}

Expand Down Expand Up @@ -889,7 +889,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int pag
/* No ecc, write all */
case NAND_ECC_NONE:
printk(KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n");
this->write_buf(mtd, this->data_poi, mtd->oobblock);
this->write_buf(mtd, this->data_poi, mtd->writesize);
break;

/* Software ecc 3/256, write all */
Expand All @@ -900,7 +900,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int pag
oob_buf[oob_config[eccidx]] = ecc_code[i];
datidx += this->eccsize;
}
this->write_buf(mtd, this->data_poi, mtd->oobblock);
this->write_buf(mtd, this->data_poi, mtd->writesize);
break;
default:
eccbytes = this->eccbytes;
Expand Down Expand Up @@ -1161,9 +1161,9 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
page = realpage & this->pagemask;

/* Get raw starting column */
col = from & (mtd->oobblock - 1);
col = from & (mtd->writesize - 1);

end = mtd->oobblock;
end = mtd->writesize;
ecc = this->eccsize;
eccbytes = this->eccbytes;

Expand Down Expand Up @@ -1321,7 +1321,7 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
buf[read++] = data_poi[j];
this->pagebuf = realpage;
} else
read += mtd->oobblock;
read += mtd->writesize;

/* Apply delay or wait for ready/busy pin
* Do this before the AUTOINCR check, so no problems
Expand Down Expand Up @@ -1479,7 +1479,7 @@ int nand_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, s
int chip = (int)(from >> this->chip_shift);
int sndcmd = 1;
int cnt = 0;
int pagesize = mtd->oobblock + mtd->oobsize;
int pagesize = mtd->writesize + mtd->oobsize;
int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1;

/* Do not allow reads past end of device */
Expand Down Expand Up @@ -1581,7 +1581,7 @@ static u_char *nand_prepare_oobbuf(struct mtd_info *mtd, u_char *fsbuf, struct n
return this->oob_buf;
}

#define NOTALIGNED(x) (x & (mtd->oobblock-1)) != 0
#define NOTALIGNED(x) (x & (mtd->writesize-1)) != 0

/**
* nand_write - [MTD Interface] compability function for nand_write_ecc
Expand Down Expand Up @@ -1694,7 +1694,7 @@ static int nand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
/* Next oob page */
oob += mtd->oobsize;
/* Update written bytes count */
written += mtd->oobblock;
written += mtd->writesize;
if (written == len)
goto cmp;

Expand Down Expand Up @@ -1805,7 +1805,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *r

if (NAND_MUST_PAD(this)) {
/* Write out desired data */
this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->oobblock, page & this->pagemask);
this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page & this->pagemask);
/* prepad 0xff for partial programming */
this->write_buf(mtd, ffchars, column);
/* write data */
Expand All @@ -1814,7 +1814,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *r
this->write_buf(mtd, ffchars, mtd->oobsize - (len + column));
} else {
/* Write out desired data */
this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->oobblock + column, page & this->pagemask);
this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + column, page & this->pagemask);
/* write data */
this->write_buf(mtd, buf, len);
}
Expand Down Expand Up @@ -1947,7 +1947,7 @@ static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, unsign
/* If the given tuple is >= pagesize then
* write it out from the iov
*/
if ((vecs->iov_len - len) >= mtd->oobblock) {
if ((vecs->iov_len - len) >= mtd->writesize) {
/* Calc number of pages we can write
* out of this iov in one go */
numpages = (vecs->iov_len - len) >> this->page_shift;
Expand All @@ -1967,8 +1967,8 @@ static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, unsign
&oobbuf[oob], oobsel, i != numpages);
if (ret)
goto out;
this->data_poi += mtd->oobblock;
len += mtd->oobblock;
this->data_poi += mtd->writesize;
len += mtd->writesize;
oob += mtd->oobsize;
page++;
}
Expand All @@ -1983,7 +1983,7 @@ static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, unsign
* tuple until we have a full page to write
*/
int cnt = 0;
while (cnt < mtd->oobblock) {
while (cnt < mtd->writesize) {
if (vecs->iov_base != NULL && vecs->iov_len)
this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++];
/* Check, if we have to switch to the next tuple */
Expand All @@ -2009,7 +2009,7 @@ static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, unsign
if (ret)
goto out;

written += mtd->oobblock * numpages;
written += mtd->writesize * numpages;
/* All done ? */
if (!count)
break;
Expand Down Expand Up @@ -2411,10 +2411,10 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
/* The 4th id byte is the important one */
extid = this->read_byte(mtd);
/* Calc pagesize */
mtd->oobblock = 1024 << (extid & 0x3);
mtd->writesize = 1024 << (extid & 0x3);
extid >>= 2;
/* Calc oobsize */
mtd->oobsize = (8 << (extid & 0x01)) * (mtd->oobblock >> 9);
mtd->oobsize = (8 << (extid & 0x01)) * (mtd->writesize >> 9);
extid >>= 2;
/* Calc blocksize. Blocksize is multiples of 64KiB */
mtd->erasesize = (64 * 1024) << (extid & 0x03);
Expand All @@ -2426,8 +2426,8 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
/* Old devices have this data hardcoded in the
* device id table */
mtd->erasesize = nand_flash_ids[i].erasesize;
mtd->oobblock = nand_flash_ids[i].pagesize;
mtd->oobsize = mtd->oobblock / 32;
mtd->writesize = nand_flash_ids[i].pagesize;
mtd->oobsize = mtd->writesize / 32;
busw = nand_flash_ids[i].options & NAND_BUSWIDTH_16;
}

Expand All @@ -2451,12 +2451,12 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
}

/* Calculate the address shift from the page size */
this->page_shift = ffs(mtd->oobblock) - 1;
this->page_shift = ffs(mtd->writesize) - 1;
this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1;
this->chip_shift = ffs(this->chipsize) - 1;

/* Set the bad block position */
this->badblockpos = mtd->oobblock > 512 ? NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
this->badblockpos = mtd->writesize > 512 ? NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;

/* Get chip options, preserve non chip based options */
this->options &= ~NAND_CHIPOPTIONS_MSK;
Expand All @@ -2476,7 +2476,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
this->erase_cmd = single_erase_cmd;

/* Do not replace user supplied command function ! */
if (mtd->oobblock > 512 && this->cmdfunc == nand_command)
if (mtd->writesize > 512 && this->cmdfunc == nand_command)
this->cmdfunc = nand_command_lp;

printk(KERN_INFO "NAND device: Manufacturer ID:"
Expand Down Expand Up @@ -2519,7 +2519,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)

if (!this->data_buf) {
size_t len;
len = mtd->oobblock + mtd->oobsize;
len = mtd->writesize + mtd->oobsize;
this->data_buf = kmalloc(len, GFP_KERNEL);
if (!this->data_buf) {
if (this->options & NAND_OOBBUF_ALLOC)
Expand Down Expand Up @@ -2575,9 +2575,9 @@ int nand_scan(struct mtd_info *mtd, int maxchips)

switch (this->eccmode) {
case NAND_ECC_HW12_2048:
if (mtd->oobblock < 2048) {
if (mtd->writesize < 2048) {
printk(KERN_WARNING "2048 byte HW ECC not possible on %d byte page size, fallback to SW ECC\n",
mtd->oobblock);
mtd->writesize);
this->eccmode = NAND_ECC_SOFT;
this->calculate_ecc = nand_calculate_ecc;
this->correct_data = nand_correct_data;
Expand All @@ -2588,7 +2588,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
case NAND_ECC_HW3_512:
case NAND_ECC_HW6_512:
case NAND_ECC_HW8_512:
if (mtd->oobblock == 256) {
if (mtd->writesize == 256) {
printk(KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n");
this->eccmode = NAND_ECC_SOFT;
this->calculate_ecc = nand_calculate_ecc;
Expand Down Expand Up @@ -2638,16 +2638,16 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
/* Set the number of read / write steps for one page to ensure ECC generation */
switch (this->eccmode) {
case NAND_ECC_HW12_2048:
this->eccsteps = mtd->oobblock / 2048;
this->eccsteps = mtd->writesize / 2048;
break;
case NAND_ECC_HW3_512:
case NAND_ECC_HW6_512:
case NAND_ECC_HW8_512:
this->eccsteps = mtd->oobblock / 512;
this->eccsteps = mtd->writesize / 512;
break;
case NAND_ECC_HW3_256:
case NAND_ECC_SOFT:
this->eccsteps = mtd->oobblock / 256;
this->eccsteps = mtd->writesize / 256;
break;

case NAND_ECC_NONE:
Expand Down
Loading

0 comments on commit 2831877

Please sign in to comment.