mtd: rawnand: Provide a helper to get chip->data_buf

We plan to move cache related fields to a pagecache struct in nand_chip
but some drivers access ->pagebuf directly to invalidate the cache
before they start using ->data_buf.

Let's provide an helper that returns a pointer to ->data_buf after
invalidating the cache.

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 15:27:55 +01:00 committed by Miquel Raynal
parent a7ab085d7c
commit eeab717483
8 changed files with 56 additions and 49 deletions

View File

@ -1676,11 +1676,8 @@ static int brcmstb_nand_verify_erased_page(struct mtd_info *mtd,
int page = addr >> chip->page_shift; int page = addr >> chip->page_shift;
int ret; int ret;
if (!buf) { if (!buf)
buf = chip->data_buf; buf = nand_get_data_buf(chip);
/* Invalidate page cache */
chip->pagebuf = -1;
}
sas = mtd->oobsize / chip->ecc.steps; sas = mtd->oobsize / chip->ecc.steps;

View File

@ -1602,7 +1602,7 @@ static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
unsigned int search_area_size_in_strides; unsigned int search_area_size_in_strides;
unsigned int stride; unsigned int stride;
unsigned int page; unsigned int page;
uint8_t *buffer = chip->data_buf; u8 *buffer = nand_get_data_buf(chip);
int saved_chip_number; int saved_chip_number;
int found_an_ncb_fingerprint = false; int found_an_ncb_fingerprint = false;
@ -1664,7 +1664,7 @@ static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
unsigned int block; unsigned int block;
unsigned int stride; unsigned int stride;
unsigned int page; unsigned int page;
uint8_t *buffer = chip->data_buf; u8 *buffer = nand_get_data_buf(chip);
int saved_chip_number; int saved_chip_number;
int status; int status;

View File

@ -1083,12 +1083,11 @@ static int marvell_nfc_hw_ecc_hmg_read_page(struct nand_chip *chip, u8 *buf,
*/ */
static int marvell_nfc_hw_ecc_hmg_read_oob_raw(struct nand_chip *chip, int page) static int marvell_nfc_hw_ecc_hmg_read_oob_raw(struct nand_chip *chip, int page)
{ {
/* Invalidate page cache */ u8 *buf = nand_get_data_buf(chip);
chip->pagebuf = -1;
marvell_nfc_select_target(chip, chip->cur_cs); marvell_nfc_select_target(chip, chip->cur_cs);
return marvell_nfc_hw_ecc_hmg_do_read_page(chip, chip->data_buf, return marvell_nfc_hw_ecc_hmg_do_read_page(chip, buf, chip->oob_poi,
chip->oob_poi, true, page); true, page);
} }
/* Hamming write helpers */ /* Hamming write helpers */
@ -1179,15 +1178,13 @@ static int marvell_nfc_hw_ecc_hmg_write_oob_raw(struct nand_chip *chip,
int page) int page)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
u8 *buf = nand_get_data_buf(chip);
/* Invalidate page cache */ memset(buf, 0xFF, mtd->writesize);
chip->pagebuf = -1;
memset(chip->data_buf, 0xFF, mtd->writesize);
marvell_nfc_select_target(chip, chip->cur_cs); marvell_nfc_select_target(chip, chip->cur_cs);
return marvell_nfc_hw_ecc_hmg_do_write_page(chip, chip->data_buf, return marvell_nfc_hw_ecc_hmg_do_write_page(chip, buf, chip->oob_poi,
chip->oob_poi, true, page); true, page);
} }
/* BCH read helpers */ /* BCH read helpers */
@ -1434,18 +1431,16 @@ static int marvell_nfc_hw_ecc_bch_read_page(struct nand_chip *chip,
static int marvell_nfc_hw_ecc_bch_read_oob_raw(struct nand_chip *chip, int page) static int marvell_nfc_hw_ecc_bch_read_oob_raw(struct nand_chip *chip, int page)
{ {
/* Invalidate page cache */ u8 *buf = nand_get_data_buf(chip);
chip->pagebuf = -1;
return chip->ecc.read_page_raw(chip, chip->data_buf, true, page); return chip->ecc.read_page_raw(chip, buf, true, page);
} }
static int marvell_nfc_hw_ecc_bch_read_oob(struct nand_chip *chip, int page) static int marvell_nfc_hw_ecc_bch_read_oob(struct nand_chip *chip, int page)
{ {
/* Invalidate page cache */ u8 *buf = nand_get_data_buf(chip);
chip->pagebuf = -1;
return chip->ecc.read_page(chip, chip->data_buf, true, page); return chip->ecc.read_page(chip, buf, true, page);
} }
/* BCH write helpers */ /* BCH write helpers */
@ -1619,25 +1614,21 @@ static int marvell_nfc_hw_ecc_bch_write_oob_raw(struct nand_chip *chip,
int page) int page)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
u8 *buf = nand_get_data_buf(chip);
/* Invalidate page cache */ memset(buf, 0xFF, mtd->writesize);
chip->pagebuf = -1;
memset(chip->data_buf, 0xFF, mtd->writesize); return chip->ecc.write_page_raw(chip, buf, true, page);
return chip->ecc.write_page_raw(chip, chip->data_buf, true, page);
} }
static int marvell_nfc_hw_ecc_bch_write_oob(struct nand_chip *chip, int page) static int marvell_nfc_hw_ecc_bch_write_oob(struct nand_chip *chip, int page)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
u8 *buf = nand_get_data_buf(chip);
/* Invalidate page cache */ memset(buf, 0xFF, mtd->writesize);
chip->pagebuf = -1;
memset(chip->data_buf, 0xFF, mtd->writesize); return chip->ecc.write_page(chip, buf, true, page);
return chip->ecc.write_page(chip, chip->data_buf, true, page);
} }
/* NAND framework ->exec_op() hooks and related helpers */ /* NAND framework ->exec_op() hooks and related helpers */

View File

@ -4004,10 +4004,9 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
__func__, buf); __func__, buf);
if (part_pagewr) if (part_pagewr)
bytes = min_t(int, bytes - column, writelen); bytes = min_t(int, bytes - column, writelen);
chip->pagebuf = -1; wbuf = nand_get_data_buf(chip);
memset(chip->data_buf, 0xff, mtd->writesize); memset(wbuf, 0xff, mtd->writesize);
memcpy(&chip->data_buf[column], buf, bytes); memcpy(&wbuf[column], buf, bytes);
wbuf = chip->data_buf;
} }
if (unlikely(oob)) { if (unlikely(oob)) {

View File

@ -901,7 +901,9 @@ static int write_bbt(struct nand_chip *this, uint8_t *buf,
static inline int nand_memory_bbt(struct nand_chip *this, static inline int nand_memory_bbt(struct nand_chip *this,
struct nand_bbt_descr *bd) struct nand_bbt_descr *bd)
{ {
return create_bbt(this, this->data_buf, bd, -1); u8 *pagebuf = nand_get_data_buf(this);
return create_bbt(this, pagebuf, bd, -1);
} }
/** /**

View File

@ -1680,14 +1680,12 @@ check_for_erased_page(struct qcom_nand_host *host, u8 *data_buf,
u8 *cw_data_buf, *cw_oob_buf; u8 *cw_data_buf, *cw_oob_buf;
int cw, data_size, oob_size, ret = 0; int cw, data_size, oob_size, ret = 0;
if (!data_buf) { if (!data_buf)
data_buf = chip->data_buf; data_buf = nand_get_data_buf(chip);
chip->pagebuf = -1;
}
if (!oob_buf) { if (!oob_buf) {
nand_get_data_buf(chip);
oob_buf = chip->oob_poi; oob_buf = chip->oob_poi;
chip->pagebuf = -1;
} }
for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) { for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) {

View File

@ -1313,20 +1313,19 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand,
static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *nand, int page) static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *nand, int page)
{ {
nand->pagebuf = -1; u8 *buf = nand_get_data_buf(nand);
return nand->ecc.read_page(nand, nand->data_buf, 1, page); return nand->ecc.read_page(nand, buf, 1, page);
} }
static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page) static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page)
{ {
struct mtd_info *mtd = nand_to_mtd(nand); struct mtd_info *mtd = nand_to_mtd(nand);
u8 *buf = nand_get_data_buf(nand);
int ret; int ret;
nand->pagebuf = -1; memset(buf, 0xff, mtd->writesize);
ret = nand->ecc.write_page(nand, buf, 1, page);
memset(nand->data_buf, 0xff, mtd->writesize);
ret = nand->ecc.write_page(nand, nand->data_buf, 1, page);
if (ret) if (ret)
return ret; return ret;

View File

@ -1350,4 +1350,25 @@ int nand_gpio_waitrdy(struct nand_chip *chip, struct gpio_desc *gpiod,
void nand_select_target(struct nand_chip *chip, unsigned int cs); void nand_select_target(struct nand_chip *chip, unsigned int cs);
void nand_deselect_target(struct nand_chip *chip); void nand_deselect_target(struct nand_chip *chip);
/**
* nand_get_data_buf() - Get the internal page buffer
* @chip: NAND chip object
*
* Returns the pre-allocated page buffer after invalidating the cache. This
* function should be used by drivers that do not want to allocate their own
* bounce buffer and still need such a buffer for specific operations (most
* commonly when reading OOB data only).
*
* Be careful to never call this function in the write/write_oob path, because
* the core may have placed the data to be written out in this buffer.
*
* Return: pointer to the page cache buffer
*/
static inline void *nand_get_data_buf(struct nand_chip *chip)
{
chip->pagebuf = -1;
return chip->data_buf;
}
#endif /* __LINUX_MTD_RAWNAND_H */ #endif /* __LINUX_MTD_RAWNAND_H */