Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/4] mtd: rawnand: cadence: get meta data size from registers
@ 2020-02-10  9:55 Piotr Sroka
  2020-02-10  9:55 ` [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size Piotr Sroka
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Piotr Sroka @ 2020-02-10  9:55 UTC (permalink / raw)
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Miquel Raynal, Brian Norris,
	David Woodhouse, Kazuhiro Kasai, Piotr Sroka

Add checking size of BCH meta data size in capabilities registers
instead of using fixed value. BCH meta data is used to keep data
from nand flash oob area.

Signed-off-by: Piotr Sroka <piotrs@cadence.com>
---
 .../mtd/nand/raw/cadence-nand-controller.c    | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
index f6c7102a1e32..5063a8b493a4 100644
--- a/drivers/mtd/nand/raw/cadence-nand-controller.c
+++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
@@ -30,7 +30,6 @@
  * Generic mode is used for executing rest of commands.
  */
 
-#define MAX_OOB_SIZE_PER_SECTOR	32
 #define MAX_ADDRESS_CYC		6
 #define MAX_ERASE_ADDRESS_CYC	3
 #define MAX_DATA_SIZE		0xFFFC
@@ -190,6 +189,7 @@
 
 /* BCH Engine identification register 3. */
 #define BCH_CFG_3				0x844
+#define		BCH_CFG_3_METADATA_SIZE		GENMASK(23, 16)
 
 /* Ready/Busy# line status. */
 #define RBN_SETINGS				0x1004
@@ -499,6 +499,7 @@ struct cdns_nand_ctrl {
 
 	unsigned long assigned_cs;
 	struct list_head chips;
+	u8 bch_metadata_size;
 };
 
 struct cdns_nand_chip {
@@ -1077,6 +1078,14 @@ static int cadence_nand_read_bch_caps(struct cdns_nand_ctrl *cdns_ctrl)
 	int max_step_size = 0, nstrengths, i;
 	u32 reg;
 
+	reg = readl_relaxed(cdns_ctrl->reg + BCH_CFG_3);
+	cdns_ctrl->bch_metadata_size = FIELD_GET(BCH_CFG_3_METADATA_SIZE, reg);
+	if (cdns_ctrl->bch_metadata_size < 4) {
+		dev_err(cdns_ctrl->dev,
+			"Driver needs at least 4 bytes of BCH meta data\n");
+		return -EIO;
+	}
+
 	reg = readl_relaxed(cdns_ctrl->reg + BCH_CFG_0);
 	cdns_ctrl->ecc_strengths[0] = FIELD_GET(BCH_CFG_0_CORR_CAP_0, reg);
 	cdns_ctrl->ecc_strengths[1] = FIELD_GET(BCH_CFG_0_CORR_CAP_1, reg);
@@ -1170,7 +1179,8 @@ static int cadence_nand_hw_init(struct cdns_nand_ctrl *cdns_ctrl)
 	writel_relaxed(0xFFFFFFFF, cdns_ctrl->reg + INTR_STATUS);
 
 	cadence_nand_get_caps(cdns_ctrl);
-	cadence_nand_read_bch_caps(cdns_ctrl);
+	if (cadence_nand_read_bch_caps(cdns_ctrl))
+		return -EIO;
 
 	/*
 	 * Set IO width access to 8.
@@ -2587,7 +2597,6 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
 	struct cdns_nand_chip *cdns_chip = to_cdns_nand_chip(chip);
 	u32 ecc_size = cdns_chip->sector_count * chip->ecc.bytes;
 	struct mtd_info *mtd = nand_to_mtd(chip);
-	u32 max_oob_data_size;
 	int ret;
 
 	if (chip->options & NAND_BUSWIDTH_16) {
@@ -2628,10 +2637,8 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
 
 	cdns_chip->avail_oob_size = mtd->oobsize - ecc_size;
 
-	max_oob_data_size = MAX_OOB_SIZE_PER_SECTOR;
-
-	if (cdns_chip->avail_oob_size > max_oob_data_size)
-		cdns_chip->avail_oob_size = max_oob_data_size;
+	if (cdns_chip->avail_oob_size > cdns_ctrl->bch_metadata_size)
+		cdns_chip->avail_oob_size = cdns_ctrl->bch_metadata_size;
 
 	if ((cdns_chip->avail_oob_size + cdns_chip->bbm_len + ecc_size)
 	    > mtd->oobsize)
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size
  2020-02-10  9:55 [PATCH 1/4] mtd: rawnand: cadence: get meta data size from registers Piotr Sroka
@ 2020-02-10  9:55 ` Piotr Sroka
  2020-02-18 10:45   ` Miquel Raynal
  2020-02-10  9:55 ` [PATCH 3/4] mtd: rawnand: cadence: change bad block marker size Piotr Sroka
  2020-02-10  9:55 ` [PATCH 4/4] mtd: rawnand: cadence: reinit complete before execute command Piotr Sroka
  2 siblings, 1 reply; 7+ messages in thread
From: Piotr Sroka @ 2020-02-10  9:55 UTC (permalink / raw)
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Miquel Raynal, Brian Norris,
	David Woodhouse, Kazuhiro Kasai, Piotr Sroka

Previously ecc_sector size was used for calculation but its value
was not yet known.

Signed-off-by: Piotr Sroka <piotrs@cadence.com>
---
 drivers/mtd/nand/raw/cadence-nand-controller.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
index 5063a8b493a4..2ebfd0934739 100644
--- a/drivers/mtd/nand/raw/cadence-nand-controller.c
+++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
@@ -2595,7 +2595,7 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
 {
 	struct cdns_nand_ctrl *cdns_ctrl = to_cdns_nand_ctrl(chip->controller);
 	struct cdns_nand_chip *cdns_chip = to_cdns_nand_chip(chip);
-	u32 ecc_size = cdns_chip->sector_count * chip->ecc.bytes;
+	u32 ecc_size;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	int ret;
 
@@ -2634,6 +2634,7 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
 	/* Error correction configuration. */
 	cdns_chip->sector_size = chip->ecc.size;
 	cdns_chip->sector_count = mtd->writesize / cdns_chip->sector_size;
+	ecc_size = cdns_chip->sector_count * chip->ecc.bytes;
 
 	cdns_chip->avail_oob_size = mtd->oobsize - ecc_size;
 
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] mtd: rawnand: cadence: change bad block marker size
  2020-02-10  9:55 [PATCH 1/4] mtd: rawnand: cadence: get meta data size from registers Piotr Sroka
  2020-02-10  9:55 ` [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size Piotr Sroka
@ 2020-02-10  9:55 ` Piotr Sroka
  2020-02-18 10:47   ` Miquel Raynal
  2020-02-10  9:55 ` [PATCH 4/4] mtd: rawnand: cadence: reinit complete before execute command Piotr Sroka
  2 siblings, 1 reply; 7+ messages in thread
From: Piotr Sroka @ 2020-02-10  9:55 UTC (permalink / raw)
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Miquel Raynal, Brian Norris,
	David Woodhouse, Kazuhiro Kasai, Piotr Sroka

Increase bad block marker size from one byte to two bytes.
Bad block marker is handled by skip bytes feature of HPNFC.
Controller excpects this value to be an even number.

Signed-off-by: Piotr Sroka <piotrs@cadence.com>
---
 drivers/mtd/nand/raw/cadence-nand-controller.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
index 2ebfd0934739..5c1bbb05ab51 100644
--- a/drivers/mtd/nand/raw/cadence-nand-controller.c
+++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
@@ -2612,12 +2612,9 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
 	chip->options |= NAND_NO_SUBPAGE_WRITE;
 
 	cdns_chip->bbm_offs = chip->badblockpos;
-	if (chip->options & NAND_BUSWIDTH_16) {
-		cdns_chip->bbm_offs &= ~0x01;
-		cdns_chip->bbm_len = 2;
-	} else {
-		cdns_chip->bbm_len = 1;
-	}
+	cdns_chip->bbm_offs &= ~0x01;
+	/* this value should be even number */
+	cdns_chip->bbm_len = 2;
 
 	ret = nand_ecc_choose_conf(chip,
 				   &cdns_ctrl->ecc_caps,
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/4] mtd: rawnand: cadence: reinit complete before execute command
  2020-02-10  9:55 [PATCH 1/4] mtd: rawnand: cadence: get meta data size from registers Piotr Sroka
  2020-02-10  9:55 ` [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size Piotr Sroka
  2020-02-10  9:55 ` [PATCH 3/4] mtd: rawnand: cadence: change bad block marker size Piotr Sroka
@ 2020-02-10  9:55 ` Piotr Sroka
  2020-02-18 10:48   ` Miquel Raynal
  2 siblings, 1 reply; 7+ messages in thread
From: Piotr Sroka @ 2020-02-10  9:55 UTC (permalink / raw)
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Miquel Raynal, Brian Norris,
	David Woodhouse, Kazuhiro Kasai, Piotr Sroka

Reinitilaize complete object before executing CDMA command to make sure
that done flag is ok.

Signed-off-by: Piotr Sroka <piotrs@cadence.com>
---
 drivers/mtd/nand/raw/cadence-nand-controller.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
index 5c1bbb05ab51..efddc5c68afb 100644
--- a/drivers/mtd/nand/raw/cadence-nand-controller.c
+++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
@@ -998,6 +998,7 @@ static int cadence_nand_cdma_send(struct cdns_nand_ctrl *cdns_ctrl,
 		return status;
 
 	cadence_nand_reset_irq(cdns_ctrl);
+	reinit_completion(&cdns_ctrl->complete);
 
 	writel_relaxed((u32)cdns_ctrl->dma_cdma_desc,
 		       cdns_ctrl->reg + CMD_REG2);
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size
  2020-02-10  9:55 ` [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size Piotr Sroka
@ 2020-02-18 10:45   ` Miquel Raynal
  0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2020-02-18 10:45 UTC (permalink / raw)
  To: Piotr Sroka
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Brian Norris, David Woodhouse,
	Kazuhiro Kasai

Hi Piotr,

Piotr Sroka <piotrs@cadence.com> wrote on Mon, 10 Feb 2020 10:55:26
+0100:

There is a typo in the title (available).

> Previously ecc_sector size was used for calculation but its value
> was not yet known.

Can we rework a little bit this? What about:

	The value of cdns_chip->sector_count is not known at the moment
	of the derivation of ecc_size, leading to a zero value. Fix
	this by assigning ecc_size later in the code.

Also, I think it deserves a Fixes/Cc:stable tag!

> 
> Signed-off-by: Piotr Sroka <piotrs@cadence.com>
> ---
>  drivers/mtd/nand/raw/cadence-nand-controller.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
> index 5063a8b493a4..2ebfd0934739 100644
> --- a/drivers/mtd/nand/raw/cadence-nand-controller.c
> +++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
> @@ -2595,7 +2595,7 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
>  {
>  	struct cdns_nand_ctrl *cdns_ctrl = to_cdns_nand_ctrl(chip->controller);
>  	struct cdns_nand_chip *cdns_chip = to_cdns_nand_chip(chip);
> -	u32 ecc_size = cdns_chip->sector_count * chip->ecc.bytes;
> +	u32 ecc_size;
>  	struct mtd_info *mtd = nand_to_mtd(chip);
>  	int ret;
>  
> @@ -2634,6 +2634,7 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
>  	/* Error correction configuration. */
>  	cdns_chip->sector_size = chip->ecc.size;
>  	cdns_chip->sector_count = mtd->writesize / cdns_chip->sector_size;
> +	ecc_size = cdns_chip->sector_count * chip->ecc.bytes;
>  
>  	cdns_chip->avail_oob_size = mtd->oobsize - ecc_size;
>  

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4] mtd: rawnand: cadence: change bad block marker size
  2020-02-10  9:55 ` [PATCH 3/4] mtd: rawnand: cadence: change bad block marker size Piotr Sroka
@ 2020-02-18 10:47   ` Miquel Raynal
  0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2020-02-18 10:47 UTC (permalink / raw)
  To: Piotr Sroka
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Brian Norris, David Woodhouse,
	Kazuhiro Kasai

Hi Piotr,

Piotr Sroka <piotrs@cadence.com> wrote on Mon, 10 Feb 2020 10:55:27
+0100:

> Increase bad block marker size from one byte to two bytes.
> Bad block marker is handled by skip bytes feature of HPNFC.
> Controller excpects this value to be an even number.

             expects

Do we break existing users with this change? Do you know how the
controller behaved until now?

Also needs a Fixes/stable tag I guess?

> 
> Signed-off-by: Piotr Sroka <piotrs@cadence.com>
> ---
>  drivers/mtd/nand/raw/cadence-nand-controller.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
> index 2ebfd0934739..5c1bbb05ab51 100644
> --- a/drivers/mtd/nand/raw/cadence-nand-controller.c
> +++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
> @@ -2612,12 +2612,9 @@ int cadence_nand_attach_chip(struct nand_chip *chip)
>  	chip->options |= NAND_NO_SUBPAGE_WRITE;
>  
>  	cdns_chip->bbm_offs = chip->badblockpos;
> -	if (chip->options & NAND_BUSWIDTH_16) {
> -		cdns_chip->bbm_offs &= ~0x01;
> -		cdns_chip->bbm_len = 2;
> -	} else {
> -		cdns_chip->bbm_len = 1;
> -	}
> +	cdns_chip->bbm_offs &= ~0x01;
> +	/* this value should be even number */
> +	cdns_chip->bbm_len = 2;
>  
>  	ret = nand_ecc_choose_conf(chip,
>  				   &cdns_ctrl->ecc_caps,

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4] mtd: rawnand: cadence: reinit complete before execute command
  2020-02-10  9:55 ` [PATCH 4/4] mtd: rawnand: cadence: reinit complete before execute command Piotr Sroka
@ 2020-02-18 10:48   ` Miquel Raynal
  0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2020-02-18 10:48 UTC (permalink / raw)
  To: Piotr Sroka
  Cc: Vignesh Raghavendra, Richard Weinberger, linux-kernel,
	Marek Vasut, linux-mtd, Brian Norris, David Woodhouse,
	Kazuhiro Kasai

Hi Piotr,

Piotr Sroka <piotrs@cadence.com> wrote on Mon, 10 Feb 2020 10:55:28
+0100:

> Reinitilaize complete object before executing CDMA command to make sure
> that done flag is ok.

Looks fine, besides the need for Fixes/Stable tags, what do you think?

> 
> Signed-off-by: Piotr Sroka <piotrs@cadence.com>
> ---
>  drivers/mtd/nand/raw/cadence-nand-controller.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c
> index 5c1bbb05ab51..efddc5c68afb 100644
> --- a/drivers/mtd/nand/raw/cadence-nand-controller.c
> +++ b/drivers/mtd/nand/raw/cadence-nand-controller.c
> @@ -998,6 +998,7 @@ static int cadence_nand_cdma_send(struct cdns_nand_ctrl *cdns_ctrl,
>  		return status;
>  
>  	cadence_nand_reset_irq(cdns_ctrl);
> +	reinit_completion(&cdns_ctrl->complete);
>  
>  	writel_relaxed((u32)cdns_ctrl->dma_cdma_desc,
>  		       cdns_ctrl->reg + CMD_REG2);

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10  9:55 [PATCH 1/4] mtd: rawnand: cadence: get meta data size from registers Piotr Sroka
2020-02-10  9:55 ` [PATCH 2/4] mtd: rawnand: cadence: fix calculating avaialble oob size Piotr Sroka
2020-02-18 10:45   ` Miquel Raynal
2020-02-10  9:55 ` [PATCH 3/4] mtd: rawnand: cadence: change bad block marker size Piotr Sroka
2020-02-18 10:47   ` Miquel Raynal
2020-02-10  9:55 ` [PATCH 4/4] mtd: rawnand: cadence: reinit complete before execute command Piotr Sroka
2020-02-18 10:48   ` Miquel Raynal

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git