All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set
@ 2019-01-09 21:51 Linus Walleij
  2019-01-09 22:12 ` Boris Brezillon
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Linus Walleij @ 2019-01-09 21:51 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, linux-mtd
  Cc: Linus Walleij

Hammering the "bank enable" (PBKEN) bit on and off between
every command crashes the Nomadik NHK15 with this message:

Scanning device for bad blocks
Unhandled fault: external abort on non-linefetch (0x008) at 0xcc95e000
pgd = (ptrval)
[cc95e000] *pgd=0b808811, *pte=40000653, *ppte=40000552
Internal error: : 8 [#1] PREEMPT ARM
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc2+ #72
Hardware name: Nomadik STn8815
PC is at fsmc_exec_op+0x194/0x204
(...)

After a discussion we (me and Boris Brezillion) start to suspect
that this bit does not immediately control the chip select line
at all, it rather enables access to the bank and the hardware
will drive the CS autonomously. If there is a NAND chip connected,
we should keep this enabled.

As fsmc_nand_setup() sets this bit, we can simply remove the
offending code.

Fixes: 550b9fc4e3af ("mtd: rawnand: fsmc: Stop implementing ->select_chip()")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/mtd/nand/raw/fsmc_nand.c | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/drivers/mtd/nand/raw/fsmc_nand.c b/drivers/mtd/nand/raw/fsmc_nand.c
index 325b4414dccc..c9149a37f8f0 100644
--- a/drivers/mtd/nand/raw/fsmc_nand.c
+++ b/drivers/mtd/nand/raw/fsmc_nand.c
@@ -593,23 +593,6 @@ static void fsmc_write_buf_dma(struct fsmc_nand_data *host, const u8 *buf,
 	dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE);
 }
 
-/* fsmc_select_chip - assert or deassert nCE */
-static void fsmc_ce_ctrl(struct fsmc_nand_data *host, bool assert)
-{
-	u32 pc = readl(host->regs_va + FSMC_PC);
-
-	if (!assert)
-		writel_relaxed(pc & ~FSMC_ENABLE, host->regs_va + FSMC_PC);
-	else
-		writel_relaxed(pc | FSMC_ENABLE, host->regs_va + FSMC_PC);
-
-	/*
-	 * nCE line changes must be applied before returning from this
-	 * function.
-	 */
-	mb();
-}
-
 /*
  * fsmc_exec_op - hook called by the core to execute NAND operations
  *
@@ -627,8 +610,6 @@ static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op,
 
 	pr_debug("Executing operation [%d instructions]:\n", op->ninstrs);
 
-	fsmc_ce_ctrl(host, true);
-
 	for (op_id = 0; op_id < op->ninstrs; op_id++) {
 		instr = &op->instrs[op_id];
 
@@ -686,8 +667,6 @@ static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op,
 		}
 	}
 
-	fsmc_ce_ctrl(host, false);
-
 	return ret;
 }
 
-- 
2.19.2

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

* Re: [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set
  2019-01-09 21:51 [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set Linus Walleij
@ 2019-01-09 22:12 ` Boris Brezillon
  2019-01-10  8:42   ` Miquel Raynal
  2019-01-14  8:51 ` Boris Brezillon
  2019-01-18 11:44 ` Boris Brezillon
  2 siblings, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2019-01-09 22:12 UTC (permalink / raw)
  To: Linus Walleij
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	linux-mtd

On Wed,  9 Jan 2019 22:51:44 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> Hammering the "bank enable" (PBKEN) bit on and off between
> every command crashes the Nomadik NHK15 with this message:
> 
> Scanning device for bad blocks
> Unhandled fault: external abort on non-linefetch (0x008) at 0xcc95e000
> pgd = (ptrval)
> [cc95e000] *pgd=0b808811, *pte=40000653, *ppte=40000552
> Internal error: : 8 [#1] PREEMPT ARM
> Modules linked in:
> CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc2+ #72
> Hardware name: Nomadik STn8815
> PC is at fsmc_exec_op+0x194/0x204
> (...)
> 
> After a discussion we (me and Boris Brezillion) start to suspect

				      ^ Brezillon :-)

> that this bit does not immediately control the chip select line
> at all, it rather enables access to the bank and the hardware
> will drive the CS autonomously. If there is a NAND chip connected,
> we should keep this enabled.
> 
> As fsmc_nand_setup() sets this bit, we can simply remove the
> offending code.
> 
> Fixes: 550b9fc4e3af ("mtd: rawnand: fsmc: Stop implementing ->select_chip()")
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Reviewed-by: Boris Brezillon <bbrezillon@kernel.org>

Would be great if someone could validate our assumption with a scope.
This being said, given the description of the FSMC logic, I have little
doubt that this bit does not directly controls the CE line, otherwise
concurrent accesses to different memories on the same bus wouldn't work
or would require a lot more synchronization than we currently have in
Linux.

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

* Re: [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set
  2019-01-09 22:12 ` Boris Brezillon
@ 2019-01-10  8:42   ` Miquel Raynal
  0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2019-01-10  8:42 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Linus Walleij, Marek Vasut, Brian Norris, David Woodhouse,
	linux-mtd, Richard Weinberger

Hi Linus,

Please don't forget to Cc: me when it comes to NAND-related changes :)

Boris Brezillon <bbrezillon@kernel.org> wrote on Wed, 9 Jan 2019
23:12:59 +0100:

> On Wed,  9 Jan 2019 22:51:44 +0100
> Linus Walleij <linus.walleij@linaro.org> wrote:
> 
> > Hammering the "bank enable" (PBKEN) bit on and off between
> > every command crashes the Nomadik NHK15 with this message:
> > 
> > Scanning device for bad blocks
> > Unhandled fault: external abort on non-linefetch (0x008) at 0xcc95e000
> > pgd = (ptrval)
> > [cc95e000] *pgd=0b808811, *pte=40000653, *ppte=40000552
> > Internal error: : 8 [#1] PREEMPT ARM
> > Modules linked in:
> > CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc2+ #72
> > Hardware name: Nomadik STn8815
> > PC is at fsmc_exec_op+0x194/0x204
> > (...)
> > 
> > After a discussion we (me and Boris Brezillion) start to suspect  
> 
> 				      ^ Brezillon :-)
> 
> > that this bit does not immediately control the chip select line
> > at all, it rather enables access to the bank and the hardware
> > will drive the CS autonomously. If there is a NAND chip connected,
> > we should keep this enabled.
> > 
> > As fsmc_nand_setup() sets this bit, we can simply remove the
> > offending code.
> > 
> > Fixes: 550b9fc4e3af ("mtd: rawnand: fsmc: Stop implementing ->select_chip()")
> > Signed-off-by: Linus Walleij <linus.walleij@linaro.org>  
> 
> Reviewed-by: Boris Brezillon <bbrezillon@kernel.org>
> 
> Would be great if someone could validate our assumption with a scope.
> This being said, given the description of the FSMC logic, I have little
> doubt that this bit does not directly controls the CE line, otherwise
> concurrent accesses to different memories on the same bus wouldn't work
> or would require a lot more synchronization than we currently have in
> Linux.
> 

Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>


Thanks,
Miquèl

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

* Re: [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set
  2019-01-09 21:51 [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set Linus Walleij
  2019-01-09 22:12 ` Boris Brezillon
@ 2019-01-14  8:51 ` Boris Brezillon
  2019-01-17 21:33   ` Linus Walleij
  2019-01-18 11:44 ` Boris Brezillon
  2 siblings, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2019-01-14  8:51 UTC (permalink / raw)
  To: Linus Walleij
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	linux-mtd

Hi Linus,

On Wed,  9 Jan 2019 22:51:44 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> Hammering the "bank enable" (PBKEN) bit on and off between
> every command crashes the Nomadik NHK15 with this message:
> 
> Scanning device for bad blocks
> Unhandled fault: external abort on non-linefetch (0x008) at 0xcc95e000
> pgd = (ptrval)
> [cc95e000] *pgd=0b808811, *pte=40000653, *ppte=40000552
> Internal error: : 8 [#1] PREEMPT ARM
> Modules linked in:
> CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc2+ #72
> Hardware name: Nomadik STn8815
> PC is at fsmc_exec_op+0x194/0x204
> (...)
> 
> After a discussion we (me and Boris Brezillion) start to suspect
> that this bit does not immediately control the chip select line
> at all, it rather enables access to the bank and the hardware
> will drive the CS autonomously. If there is a NAND chip connected,
> we should keep this enabled.
> 
> As fsmc_nand_setup() sets this bit, we can simply remove the
> offending code.
> 
> Fixes: 550b9fc4e3af ("mtd: rawnand: fsmc: Stop implementing ->select_chip()")
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/mtd/nand/raw/fsmc_nand.c | 21 ---------------------
>  1 file changed, 21 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/fsmc_nand.c b/drivers/mtd/nand/raw/fsmc_nand.c
> index 325b4414dccc..c9149a37f8f0 100644
> --- a/drivers/mtd/nand/raw/fsmc_nand.c
> +++ b/drivers/mtd/nand/raw/fsmc_nand.c
> @@ -593,23 +593,6 @@ static void fsmc_write_buf_dma(struct fsmc_nand_data *host, const u8 *buf,
>  	dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE);
>  }
>  
> -/* fsmc_select_chip - assert or deassert nCE */
> -static void fsmc_ce_ctrl(struct fsmc_nand_data *host, bool assert)
> -{
> -	u32 pc = readl(host->regs_va + FSMC_PC);
> -
> -	if (!assert)
> -		writel_relaxed(pc & ~FSMC_ENABLE, host->regs_va + FSMC_PC);
> -	else
> -		writel_relaxed(pc | FSMC_ENABLE, host->regs_va + FSMC_PC);
> -
> -	/*
> -	 * nCE line changes must be applied before returning from this
> -	 * function.
> -	 */
> -	mb();
> -}
> -
>  /*
>   * fsmc_exec_op - hook called by the core to execute NAND operations
>   *
> @@ -627,8 +610,6 @@ static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op,
>  
>  	pr_debug("Executing operation [%d instructions]:\n", op->ninstrs);
>  
> -	fsmc_ce_ctrl(host, true);
> -
>  	for (op_id = 0; op_id < op->ninstrs; op_id++) {
>  		instr = &op->instrs[op_id];
>  
> @@ -686,8 +667,6 @@ static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op,
>  		}
>  	}
>  
> -	fsmc_ce_ctrl(host, false);
> -
>  	return ret;
>  }
>  

Not related to this patch, but I think we're missing a nand_reset()
call in the ->resume() path. Without it FSMC timings might be wrong
after a suspend if they're not defined in the DT. Would you mind sending
another patch to fix that, and maybe an extra patch to clear
FSMC_ENABLE in the ->remove() path and the ->probe()'s error path as
you suggested?

Thanks,

Boris

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

* Re: [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set
  2019-01-14  8:51 ` Boris Brezillon
@ 2019-01-17 21:33   ` Linus Walleij
  2019-01-18  6:36     ` Boris Brezillon
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2019-01-17 21:33 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Marek Vasut, Brian Norris, David Woodhouse, linux-mtd,
	Richard Weinberger

On Mon, Jan 14, 2019 at 9:51 AM Boris Brezillon <bbrezillon@kernel.org> wrote:

> Not related to this patch, but I think we're missing a nand_reset()
> call in the ->resume() path. Without it FSMC timings might be wrong
> after a suspend if they're not defined in the DT. Would you mind sending
> another patch to fix that,

I looked into it, It looks like this:

static int fsmc_nand_resume(struct device *dev)
{
    struct fsmc_nand_data *host = dev_get_drvdata(dev);

    if (host) {
        clk_prepare_enable(host->clk);
        if (host->dev_timings)
            fsmc_nand_setup(host, host->dev_timings);
    }

    return 0;
}

fsmc_nand_setup() will set up the timings if we have any.

> and maybe an extra patch to clear
> FSMC_ENABLE in the ->remove() path and the ->probe()'s error path as
> you suggested?

That I can fix. I will resend this patch with that as another patch.

Yours,
Linus Walleij

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

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

* Re: [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set
  2019-01-17 21:33   ` Linus Walleij
@ 2019-01-18  6:36     ` Boris Brezillon
  0 siblings, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2019-01-18  6:36 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Marek Vasut, Brian Norris, David Woodhouse, linux-mtd,
	Richard Weinberger

On Thu, 17 Jan 2019 22:33:01 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Mon, Jan 14, 2019 at 9:51 AM Boris Brezillon <bbrezillon@kernel.org> wrote:
> 
> > Not related to this patch, but I think we're missing a nand_reset()
> > call in the ->resume() path. Without it FSMC timings might be wrong
> > after a suspend if they're not defined in the DT. Would you mind sending
> > another patch to fix that,  
> 
> I looked into it, It looks like this:
> 
> static int fsmc_nand_resume(struct device *dev)
> {
>     struct fsmc_nand_data *host = dev_get_drvdata(dev);
> 
>     if (host) {
>         clk_prepare_enable(host->clk);
>         if (host->dev_timings)
>             fsmc_nand_setup(host, host->dev_timings);

->dev_timings is only allocated if timings are defined in the DT, but
the driver can also let the framework configure the timings through the
->setup_data_interface() method (approach that should be preferred for
all new boards). In this case ->dev_timings is NULL and we need to
reset the chip to re-apply the timings.

BTW, resetting the NAND chip at resume time is a sane thing to do if
you want to start in known state, so I'd recommend adding

	nand_reset(&host->nand);

here.

>     }
> 
>     return 0;
> }
> 

Regards,

Boris

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

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

* Re: mtd: rawnand: fsmc: Keep bank enable bit set
  2019-01-09 21:51 [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set Linus Walleij
  2019-01-09 22:12 ` Boris Brezillon
  2019-01-14  8:51 ` Boris Brezillon
@ 2019-01-18 11:44 ` Boris Brezillon
  2 siblings, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2019-01-18 11:44 UTC (permalink / raw)
  To: Linus Walleij, David Woodhouse, Brian Norris, Boris Brezillon,
	Marek Vasut, Richard Weinberger, linux-mtd

On Wed, 2019-01-09 at 21:51:44 UTC, Linus Walleij wrote:
> Hammering the "bank enable" (PBKEN) bit on and off between
> every command crashes the Nomadik NHK15 with this message:
> 
> Scanning device for bad blocks
> Unhandled fault: external abort on non-linefetch (0x008) at 0xcc95e000
> pgd = (ptrval)
> [cc95e000] *pgd=0b808811, *pte=40000653, *ppte=40000552
> Internal error: : 8 [#1] PREEMPT ARM
> Modules linked in:
> CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc2+ #72
> Hardware name: Nomadik STn8815
> PC is at fsmc_exec_op+0x194/0x204
> (...)
> 
> After a discussion we (me and Boris Brezillion) start to suspect
> that this bit does not immediately control the chip select line
> at all, it rather enables access to the bank and the hardware
> will drive the CS autonomously. If there is a NAND chip connected,
> we should keep this enabled.
> 
> As fsmc_nand_setup() sets this bit, we can simply remove the
> offending code.
> 
> Fixes: 550b9fc4e3af ("mtd: rawnand: fsmc: Stop implementing ->select_chip()")
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> Reviewed-by: Boris Brezillon <bbrezillon@kernel.org>
> Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to http://git.infradead.org/linux-mtd.git mtd/fixes, thanks.

Boris

______________________________________________________
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, other threads:[~2019-01-18 11:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-09 21:51 [PATCH] mtd: rawnand: fsmc: Keep bank enable bit set Linus Walleij
2019-01-09 22:12 ` Boris Brezillon
2019-01-10  8:42   ` Miquel Raynal
2019-01-14  8:51 ` Boris Brezillon
2019-01-17 21:33   ` Linus Walleij
2019-01-18  6:36     ` Boris Brezillon
2019-01-18 11:44 ` Boris Brezillon

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.