mtd: rawnand: Move all page cache related fields to a sub-struct

Looking at the field names it's hard to tell what ->data_buf, ->pagebuf
and ->pagebuf_bitflips are for. Clarify that by moving those fields
in a sub-struct named pagecache.

Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
This commit is contained in:
Boris Brezillon 2018-10-28 16:12:45 +01:00 committed by Miquel Raynal
parent eeab717483
commit d974541e23
2 changed files with 25 additions and 21 deletions

View File

@ -459,8 +459,8 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to,
} }
/* Invalidate the page cache, if we write to the cached page */ /* Invalidate the page cache, if we write to the cached page */
if (page == chip->pagebuf) if (page == chip->pagecache.page)
chip->pagebuf = -1; chip->pagecache.page = -1;
nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops);
@ -3173,7 +3173,7 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
use_bufpoi = 0; use_bufpoi = 0;
/* Is the current page in the buffer? */ /* Is the current page in the buffer? */
if (realpage != chip->pagebuf || oob) { if (realpage != chip->pagecache.page || oob) {
bufpoi = use_bufpoi ? chip->data_buf : buf; bufpoi = use_bufpoi ? chip->data_buf : buf;
if (use_bufpoi && aligned) if (use_bufpoi && aligned)
@ -3199,7 +3199,7 @@ read_retry:
if (ret < 0) { if (ret < 0) {
if (use_bufpoi) if (use_bufpoi)
/* Invalidate page cache */ /* Invalidate page cache */
chip->pagebuf = -1; chip->pagecache.page = -1;
break; break;
} }
@ -3208,11 +3208,11 @@ read_retry:
if (!NAND_HAS_SUBPAGE_READ(chip) && !oob && if (!NAND_HAS_SUBPAGE_READ(chip) && !oob &&
!(mtd->ecc_stats.failed - ecc_failures) && !(mtd->ecc_stats.failed - ecc_failures) &&
(ops->mode != MTD_OPS_RAW)) { (ops->mode != MTD_OPS_RAW)) {
chip->pagebuf = realpage; chip->pagecache.page = realpage;
chip->pagebuf_bitflips = ret; chip->pagecache.bitflips = ret;
} else { } else {
/* Invalidate page cache */ /* Invalidate page cache */
chip->pagebuf = -1; chip->pagecache.page = -1;
} }
memcpy(buf, chip->data_buf + col, bytes); memcpy(buf, chip->data_buf + col, bytes);
} }
@ -3252,7 +3252,7 @@ read_retry:
memcpy(buf, chip->data_buf + col, bytes); memcpy(buf, chip->data_buf + col, bytes);
buf += bytes; buf += bytes;
max_bitflips = max_t(unsigned int, max_bitflips, max_bitflips = max_t(unsigned int, max_bitflips,
chip->pagebuf_bitflips); chip->pagecache.bitflips);
} }
readlen -= bytes; readlen -= bytes;
@ -3973,9 +3973,9 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
page = realpage & chip->pagemask; page = realpage & chip->pagemask;
/* Invalidate the page cache, when we write to the cached page */ /* Invalidate the page cache, when we write to the cached page */
if (to <= ((loff_t)chip->pagebuf << chip->page_shift) && if (to <= ((loff_t)chip->pagecache.page << chip->page_shift) &&
((loff_t)chip->pagebuf << chip->page_shift) < (to + ops->len)) ((loff_t)chip->pagecache.page << chip->page_shift) < (to + ops->len))
chip->pagebuf = -1; chip->pagecache.page = -1;
/* Don't allow multipage oob writes with offset */ /* Don't allow multipage oob writes with offset */
if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) { if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) {
@ -4196,9 +4196,9 @@ int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr,
* Invalidate the page cache, if we erase the block which * Invalidate the page cache, if we erase the block which
* contains the current cached page. * contains the current cached page.
*/ */
if (page <= chip->pagebuf && chip->pagebuf < if (page <= chip->pagecache.page && chip->pagecache.page <
(page + pages_per_block)) (page + pages_per_block))
chip->pagebuf = -1; chip->pagecache.page = -1;
ret = nand_erase_op(chip, (page & chip->pagemask) >> ret = nand_erase_op(chip, (page & chip->pagemask) >>
(chip->phys_erase_shift - chip->page_shift)); (chip->phys_erase_shift - chip->page_shift));
@ -5782,7 +5782,7 @@ static int nand_scan_tail(struct nand_chip *chip)
chip->subpagesize = mtd->writesize >> mtd->subpage_sft; chip->subpagesize = mtd->writesize >> mtd->subpage_sft;
/* Invalidate the pagebuffer reference */ /* Invalidate the pagebuffer reference */
chip->pagebuf = -1; chip->pagecache.page = -1;
/* Large page NAND with SOFT_ECC should support subpage reads */ /* Large page NAND with SOFT_ECC should support subpage reads */
switch (ecc->mode) { switch (ecc->mode) {

View File

@ -1007,10 +1007,10 @@ struct nand_legacy {
* @chipsize: [INTERN] the size of one chip for multichip arrays * @chipsize: [INTERN] the size of one chip for multichip arrays
* @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
* @data_buf: [INTERN] buffer for data, size is (page size + oobsize). * @data_buf: [INTERN] buffer for data, size is (page size + oobsize).
* @pagebuf: [INTERN] holds the pagenumber which is currently in * @pagecache: Structure containing page cache related fields
* data_buf. * @pagecache.bitflips: Number of bitflips of the cached page
* @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is * @pagecache.page: Page number currently in the cache. -1 means no page is
* currently in data_buf. * currently cached
* @subpagesize: [INTERN] holds the subpagesize * @subpagesize: [INTERN] holds the subpagesize
* @id: [INTERN] holds NAND ID * @id: [INTERN] holds NAND ID
* @parameters: [INTERN] holds generic parameters under an easily * @parameters: [INTERN] holds generic parameters under an easily
@ -1060,8 +1060,12 @@ struct nand_chip {
uint64_t chipsize; uint64_t chipsize;
int pagemask; int pagemask;
u8 *data_buf; u8 *data_buf;
int pagebuf;
unsigned int pagebuf_bitflips; struct {
unsigned int bitflips;
int page;
} pagecache;
int subpagesize; int subpagesize;
uint8_t bits_per_cell; uint8_t bits_per_cell;
uint16_t ecc_strength_ds; uint16_t ecc_strength_ds;
@ -1366,7 +1370,7 @@ void nand_deselect_target(struct nand_chip *chip);
*/ */
static inline void *nand_get_data_buf(struct nand_chip *chip) static inline void *nand_get_data_buf(struct nand_chip *chip)
{ {
chip->pagebuf = -1; chip->pagecache.page = -1;
return chip->data_buf; return chip->data_buf;
} }