All of lore.kernel.org
 help / color / mirror / Atom feed
From: Schrempf Frieder <frieder.schrempf@kontron.de>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
	Boris Brezillon <bbrezillon@kernel.org>,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	"Marek Vasut" <marek.vasut@gmail.com>,
	Tudor Ambarus <Tudor.Ambarus@microchip.com>
Cc: Vignesh R <vigneshr@ti.com>, Julien Su <juliensu@mxic.com.tw>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Mason Yang <masonccyang@mxic.com.tw>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 09/15] mtd: rawnand: Provide an helper to get chip->data_buf
Date: Sat, 23 Feb 2019 13:13:20 +0000	[thread overview]
Message-ID: <6992b4bc-f9e9-f948-ec3d-46b83d093480@kontron.de> (raw)
In-Reply-To: <20190221091527.20497-10-miquel.raynal@bootlin.com>

On 21.02.19 10:15, Miquel Raynal wrote:
> From: Boris Brezillon <bbrezillon@kernel.org>
> 
> 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>

Minor spelling correction in patch title: "a helper" instead of "an 
helper" (same for patch 2 and 3 in this series).

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

> ---
>   drivers/mtd/nand/raw/brcmnand/brcmnand.c   |  7 +---
>   drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c |  4 +-
>   drivers/mtd/nand/raw/marvell_nand.c        | 43 +++++++++-------------
>   drivers/mtd/nand/raw/nand_base.c           |  7 ++--
>   drivers/mtd/nand/raw/nand_bbt.c            |  4 +-
>   drivers/mtd/nand/raw/qcom_nandc.c          |  8 ++--
>   drivers/mtd/nand/raw/sunxi_nand.c          | 11 +++---
>   include/linux/mtd/rawnand.h                | 21 +++++++++++
>   8 files changed, 56 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> index 482c6f093f99..ce0b8ffc7812 100644
> --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> @@ -1676,11 +1676,8 @@ static int brcmstb_nand_verify_erased_page(struct mtd_info *mtd,
>   	int page = addr >> chip->page_shift;
>   	int ret;
>   
> -	if (!buf) {
> -		buf = chip->data_buf;
> -		/* Invalidate page cache */
> -		chip->pagebuf = -1;
> -	}
> +	if (!buf)
> +		buf = nand_get_data_buf(chip);
>   
>   	sas = mtd->oobsize / chip->ecc.steps;
>   
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index ed405c9434fe..05f6f68e4e0d 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> @@ -1602,7 +1602,7 @@ static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
>   	unsigned int search_area_size_in_strides;
>   	unsigned int stride;
>   	unsigned int page;
> -	uint8_t *buffer = chip->data_buf;
> +	u8 *buffer = nand_get_data_buf(chip);
>   	int saved_chip_number;
>   	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 stride;
>   	unsigned int page;
> -	uint8_t      *buffer = chip->data_buf;
> +	u8 *buffer = nand_get_data_buf(chip);
>   	int saved_chip_number;
>   	int status;
>   
> diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
> index 84283c6bb0ff..e8023b32be93 100644
> --- a/drivers/mtd/nand/raw/marvell_nand.c
> +++ b/drivers/mtd/nand/raw/marvell_nand.c
> @@ -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)
>   {
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
>   	marvell_nfc_select_target(chip, chip->cur_cs);
> -	return marvell_nfc_hw_ecc_hmg_do_read_page(chip, chip->data_buf,
> -						   chip->oob_poi, true, page);
> +	return marvell_nfc_hw_ecc_hmg_do_read_page(chip, buf, chip->oob_poi,
> +						   true, page);
>   }
>   
>   /* Hamming write helpers */
> @@ -1179,15 +1178,13 @@ static int marvell_nfc_hw_ecc_hmg_write_oob_raw(struct nand_chip *chip,
>   						int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> -
> -	memset(chip->data_buf, 0xFF, mtd->writesize);
> +	memset(buf, 0xFF, mtd->writesize);
>   
>   	marvell_nfc_select_target(chip, chip->cur_cs);
> -	return marvell_nfc_hw_ecc_hmg_do_write_page(chip, chip->data_buf,
> -						    chip->oob_poi, true, page);
> +	return marvell_nfc_hw_ecc_hmg_do_write_page(chip, buf, chip->oob_poi,
> +						    true, page);
>   }
>   
>   /* 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)
>   {
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	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)
>   {
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	return chip->ecc.read_page(chip, chip->data_buf, true, page);
> +	return chip->ecc.read_page(chip, buf, true, page);
>   }
>   
>   /* BCH write helpers */
> @@ -1619,25 +1614,21 @@ static int marvell_nfc_hw_ecc_bch_write_oob_raw(struct nand_chip *chip,
>   						int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	memset(buf, 0xFF, mtd->writesize);
>   
> -	memset(chip->data_buf, 0xFF, mtd->writesize);
> -
> -	return chip->ecc.write_page_raw(chip, chip->data_buf, true, page);
> +	return chip->ecc.write_page_raw(chip, buf, true, page);
>   }
>   
>   static int marvell_nfc_hw_ecc_bch_write_oob(struct nand_chip *chip, int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	memset(buf, 0xFF, mtd->writesize);
>   
> -	memset(chip->data_buf, 0xFF, mtd->writesize);
> -
> -	return chip->ecc.write_page(chip, chip->data_buf, true, page);
> +	return chip->ecc.write_page(chip, buf, true, page);
>   }
>   
>   /* NAND framework ->exec_op() hooks and related helpers */
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index e8c1ad17f3c6..07985d2b91ac 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4033,10 +4033,9 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
>   					 __func__, buf);
>   			if (part_pagewr)
>   				bytes = min_t(int, bytes - column, writelen);
> -			chip->pagebuf = -1;
> -			memset(chip->data_buf, 0xff, mtd->writesize);
> -			memcpy(&chip->data_buf[column], buf, bytes);
> -			wbuf = chip->data_buf;
> +			wbuf = nand_get_data_buf(chip);
> +			memset(wbuf, 0xff, mtd->writesize);
> +			memcpy(&wbuf[column], buf, bytes);
>   		}
>   
>   		if (unlikely(oob)) {
> diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c
> index 1b722fe9213c..0b96c4cab967 100644
> --- a/drivers/mtd/nand/raw/nand_bbt.c
> +++ b/drivers/mtd/nand/raw/nand_bbt.c
> @@ -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,
>   				  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);
>   }
>   
>   /**
> diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
> index 46c62a31fa46..3f8005113fe2 100644
> --- a/drivers/mtd/nand/raw/qcom_nandc.c
> +++ b/drivers/mtd/nand/raw/qcom_nandc.c
> @@ -1680,14 +1680,12 @@ check_for_erased_page(struct qcom_nand_host *host, u8 *data_buf,
>   	u8 *cw_data_buf, *cw_oob_buf;
>   	int cw, data_size, oob_size, ret = 0;
>   
> -	if (!data_buf) {
> -		data_buf = chip->data_buf;
> -		chip->pagebuf = -1;
> -	}
> +	if (!data_buf)
> +		data_buf = nand_get_data_buf(chip);
>   
>   	if (!oob_buf) {
> +		nand_get_data_buf(chip);
>   		oob_buf = chip->oob_poi;
> -		chip->pagebuf = -1;
>   	}
>   
>   	for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) {
> diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
> index e828ee50a201..d5de0a7114bc 100644
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -1426,20 +1426,19 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *chip,
>   
>   static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *chip, int page)
>   {
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	return chip->ecc.read_page(chip, chip->data_buf, 1, page);
> +	return chip->ecc.read_page(chip, buf, 1, page);
>   }
>   
>   static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *chip, int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   	int ret;
>   
> -	chip->pagebuf = -1;
> -
> -	memset(chip->data_buf, 0xff, mtd->writesize);
> -	ret = chip->ecc.write_page(chip, chip->data_buf, 1, page);
> +	memset(buf, 0xff, mtd->writesize);
> +	ret = chip->ecc.write_page(chip, buf, 1, page);
>   	if (ret)
>   		return ret;
>   
> diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
> index dfeedfe2f3e0..e62c3ab4e0f7 100644
> --- a/include/linux/mtd/rawnand.h
> +++ b/include/linux/mtd/rawnand.h
> @@ -1358,4 +1358,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_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 */
> 
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

WARNING: multiple messages have this Message-ID (diff)
From: Schrempf Frieder <frieder.schrempf@kontron.de>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
	Boris Brezillon <bbrezillon@kernel.org>,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	"Marek Vasut" <marek.vasut@gmail.com>,
	Tudor Ambarus <Tudor.Ambarus@microchip.com>
Cc: Vignesh R <vigneshr@ti.com>, Julien Su <juliensu@mxic.com.tw>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Mason Yang <masonccyang@mxic.com.tw>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 09/15] mtd: rawnand: Provide an helper to get chip->data_buf
Date: Sat, 23 Feb 2019 13:13:20 +0000	[thread overview]
Message-ID: <6992b4bc-f9e9-f948-ec3d-46b83d093480@kontron.de> (raw)
In-Reply-To: <20190221091527.20497-10-miquel.raynal@bootlin.com>

On 21.02.19 10:15, Miquel Raynal wrote:
> From: Boris Brezillon <bbrezillon@kernel.org>
> 
> 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>

Minor spelling correction in patch title: "a helper" instead of "an 
helper" (same for patch 2 and 3 in this series).

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

> ---
>   drivers/mtd/nand/raw/brcmnand/brcmnand.c   |  7 +---
>   drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c |  4 +-
>   drivers/mtd/nand/raw/marvell_nand.c        | 43 +++++++++-------------
>   drivers/mtd/nand/raw/nand_base.c           |  7 ++--
>   drivers/mtd/nand/raw/nand_bbt.c            |  4 +-
>   drivers/mtd/nand/raw/qcom_nandc.c          |  8 ++--
>   drivers/mtd/nand/raw/sunxi_nand.c          | 11 +++---
>   include/linux/mtd/rawnand.h                | 21 +++++++++++
>   8 files changed, 56 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> index 482c6f093f99..ce0b8ffc7812 100644
> --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> @@ -1676,11 +1676,8 @@ static int brcmstb_nand_verify_erased_page(struct mtd_info *mtd,
>   	int page = addr >> chip->page_shift;
>   	int ret;
>   
> -	if (!buf) {
> -		buf = chip->data_buf;
> -		/* Invalidate page cache */
> -		chip->pagebuf = -1;
> -	}
> +	if (!buf)
> +		buf = nand_get_data_buf(chip);
>   
>   	sas = mtd->oobsize / chip->ecc.steps;
>   
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index ed405c9434fe..05f6f68e4e0d 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> @@ -1602,7 +1602,7 @@ static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
>   	unsigned int search_area_size_in_strides;
>   	unsigned int stride;
>   	unsigned int page;
> -	uint8_t *buffer = chip->data_buf;
> +	u8 *buffer = nand_get_data_buf(chip);
>   	int saved_chip_number;
>   	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 stride;
>   	unsigned int page;
> -	uint8_t      *buffer = chip->data_buf;
> +	u8 *buffer = nand_get_data_buf(chip);
>   	int saved_chip_number;
>   	int status;
>   
> diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
> index 84283c6bb0ff..e8023b32be93 100644
> --- a/drivers/mtd/nand/raw/marvell_nand.c
> +++ b/drivers/mtd/nand/raw/marvell_nand.c
> @@ -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)
>   {
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
>   	marvell_nfc_select_target(chip, chip->cur_cs);
> -	return marvell_nfc_hw_ecc_hmg_do_read_page(chip, chip->data_buf,
> -						   chip->oob_poi, true, page);
> +	return marvell_nfc_hw_ecc_hmg_do_read_page(chip, buf, chip->oob_poi,
> +						   true, page);
>   }
>   
>   /* Hamming write helpers */
> @@ -1179,15 +1178,13 @@ static int marvell_nfc_hw_ecc_hmg_write_oob_raw(struct nand_chip *chip,
>   						int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> -
> -	memset(chip->data_buf, 0xFF, mtd->writesize);
> +	memset(buf, 0xFF, mtd->writesize);
>   
>   	marvell_nfc_select_target(chip, chip->cur_cs);
> -	return marvell_nfc_hw_ecc_hmg_do_write_page(chip, chip->data_buf,
> -						    chip->oob_poi, true, page);
> +	return marvell_nfc_hw_ecc_hmg_do_write_page(chip, buf, chip->oob_poi,
> +						    true, page);
>   }
>   
>   /* 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)
>   {
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	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)
>   {
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	return chip->ecc.read_page(chip, chip->data_buf, true, page);
> +	return chip->ecc.read_page(chip, buf, true, page);
>   }
>   
>   /* BCH write helpers */
> @@ -1619,25 +1614,21 @@ static int marvell_nfc_hw_ecc_bch_write_oob_raw(struct nand_chip *chip,
>   						int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	memset(buf, 0xFF, mtd->writesize);
>   
> -	memset(chip->data_buf, 0xFF, mtd->writesize);
> -
> -	return chip->ecc.write_page_raw(chip, chip->data_buf, true, page);
> +	return chip->ecc.write_page_raw(chip, buf, true, page);
>   }
>   
>   static int marvell_nfc_hw_ecc_bch_write_oob(struct nand_chip *chip, int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	/* Invalidate page cache */
> -	chip->pagebuf = -1;
> +	memset(buf, 0xFF, mtd->writesize);
>   
> -	memset(chip->data_buf, 0xFF, mtd->writesize);
> -
> -	return chip->ecc.write_page(chip, chip->data_buf, true, page);
> +	return chip->ecc.write_page(chip, buf, true, page);
>   }
>   
>   /* NAND framework ->exec_op() hooks and related helpers */
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index e8c1ad17f3c6..07985d2b91ac 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4033,10 +4033,9 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
>   					 __func__, buf);
>   			if (part_pagewr)
>   				bytes = min_t(int, bytes - column, writelen);
> -			chip->pagebuf = -1;
> -			memset(chip->data_buf, 0xff, mtd->writesize);
> -			memcpy(&chip->data_buf[column], buf, bytes);
> -			wbuf = chip->data_buf;
> +			wbuf = nand_get_data_buf(chip);
> +			memset(wbuf, 0xff, mtd->writesize);
> +			memcpy(&wbuf[column], buf, bytes);
>   		}
>   
>   		if (unlikely(oob)) {
> diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c
> index 1b722fe9213c..0b96c4cab967 100644
> --- a/drivers/mtd/nand/raw/nand_bbt.c
> +++ b/drivers/mtd/nand/raw/nand_bbt.c
> @@ -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,
>   				  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);
>   }
>   
>   /**
> diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
> index 46c62a31fa46..3f8005113fe2 100644
> --- a/drivers/mtd/nand/raw/qcom_nandc.c
> +++ b/drivers/mtd/nand/raw/qcom_nandc.c
> @@ -1680,14 +1680,12 @@ check_for_erased_page(struct qcom_nand_host *host, u8 *data_buf,
>   	u8 *cw_data_buf, *cw_oob_buf;
>   	int cw, data_size, oob_size, ret = 0;
>   
> -	if (!data_buf) {
> -		data_buf = chip->data_buf;
> -		chip->pagebuf = -1;
> -	}
> +	if (!data_buf)
> +		data_buf = nand_get_data_buf(chip);
>   
>   	if (!oob_buf) {
> +		nand_get_data_buf(chip);
>   		oob_buf = chip->oob_poi;
> -		chip->pagebuf = -1;
>   	}
>   
>   	for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) {
> diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
> index e828ee50a201..d5de0a7114bc 100644
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -1426,20 +1426,19 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *chip,
>   
>   static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *chip, int page)
>   {
> -	chip->pagebuf = -1;
> +	u8 *buf = nand_get_data_buf(chip);
>   
> -	return chip->ecc.read_page(chip, chip->data_buf, 1, page);
> +	return chip->ecc.read_page(chip, buf, 1, page);
>   }
>   
>   static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *chip, int page)
>   {
>   	struct mtd_info *mtd = nand_to_mtd(chip);
> +	u8 *buf = nand_get_data_buf(chip);
>   	int ret;
>   
> -	chip->pagebuf = -1;
> -
> -	memset(chip->data_buf, 0xff, mtd->writesize);
> -	ret = chip->ecc.write_page(chip, chip->data_buf, 1, page);
> +	memset(buf, 0xff, mtd->writesize);
> +	ret = chip->ecc.write_page(chip, buf, 1, page);
>   	if (ret)
>   		return ret;
>   
> diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
> index dfeedfe2f3e0..e62c3ab4e0f7 100644
> --- a/include/linux/mtd/rawnand.h
> +++ b/include/linux/mtd/rawnand.h
> @@ -1358,4 +1358,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_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 */
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-02-23 13:13 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21  9:15 [PATCH 00/15] mtd: rawnand: 5th batch of cleanups Miquel Raynal
2019-02-21  9:15 ` Miquel Raynal
2019-02-21  9:15 ` [PATCH 01/15] mtd: nand: Add max_bad_eraseblocks_per_lun info to memorg Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:03   ` Schrempf Frieder
2019-02-23 13:03     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 02/15] mtd: nand: Add an helper returning the number of eraseblocks per target Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:04   ` Schrempf Frieder
2019-02-23 13:04     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 03/15] mtd: nand: Add an helper to retrieve the number of pages " Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:04   ` Schrempf Frieder
2019-02-23 13:04     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 04/15] mtd: spinand: Implement mtd->_max_bad_blocks Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:05   ` Schrempf Frieder
2019-02-23 13:05     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 05/15] mtd: rawnand: Use nand_to_mtd() in nand_{set, get}_flash_node() Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:05   ` Schrempf Frieder
2019-02-23 13:05     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 06/15] mtd: rawnand: Prepare things to reuse the generic NAND layer Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:06   ` Schrempf Frieder
2019-02-23 13:06     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 07/15] mtd: rawnand: Fill memorg during detection Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:00   ` Schrempf Frieder
2019-02-23 13:00     ` Schrempf Frieder
2019-02-26 13:09     ` Miquel Raynal
2019-02-26 13:09       ` Miquel Raynal
2019-02-21  9:15 ` [PATCH 08/15] mtd: rawnand: Initialize the nand_device object Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:20   ` Schrempf Frieder
2019-02-23 13:20     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 09/15] mtd: rawnand: Provide an helper to get chip->data_buf Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:13   ` Schrempf Frieder [this message]
2019-02-23 13:13     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 10/15] mtd: rawnand: Move all page cache related fields to a sub-struct Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:13   ` Schrempf Frieder
2019-02-23 13:13     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 11/15] mtd: rawnand: Use nanddev_mtd_max_bad_blocks() Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:14   ` Schrempf Frieder
2019-02-23 13:14     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 12/15] mtd: rawnand: Get rid of chip->bits_per_cell Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:14   ` Schrempf Frieder
2019-02-23 13:14     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 13/15] mtd: rawnand: Get rid of chip->chipsize Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:01   ` Schrempf Frieder
2019-02-23 13:01     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 14/15] mtd: rawnand: Get rid of chip->numchips Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:15   ` Schrempf Frieder
2019-02-23 13:15     ` Schrempf Frieder
2019-02-21  9:15 ` [PATCH 15/15] mtd: rawnand: Get rid of chip->ecc_{strength,step}_ds Miquel Raynal
2019-02-21  9:15   ` Miquel Raynal
2019-02-23 13:15   ` Schrempf Frieder
2019-02-23 13:15     ` Schrempf Frieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6992b4bc-f9e9-f948-ec3d-46b83d093480@kontron.de \
    --to=frieder.schrempf@kontron.de \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=bbrezillon@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=juliensu@mxic.com.tw \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=masonccyang@mxic.com.tw \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vigneshr@ti.com \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.