2022-08-16 07:38:45

by Alice Guo (OSS)

[permalink] [raw]
Subject: [PATCH 0/7] watchdog: imx7ulp_wdt: update i.MX7ULP WDOG timer driver

From: Alice Guo <[email protected]>

Alice Guo (1):
watchdog: imx93: add watchdog timer on imx93

Anson Huang (1):
watchdog: imx7ulp: Move suspend/resume to noirq phase

Jacky Bai (1):
watchdog: imx7ulp: Add explict memory barrier for unlock sequence

Jason Liu (1):
watchdog: imx7ulp_wdt: init wdog when it was active

Ye Li (3):
watchdog: imx7ulp_wdt: Check CMD32EN in wdog init
watchdog: imx7ulp_wdt: Fix RCS timeout issue
watchdog: imx7ulp_wdt: Handle wdog reconfigure failure

drivers/watchdog/imx7ulp_wdt.c | 212 ++++++++++++++++++++++++++-------
1 file changed, 168 insertions(+), 44 deletions(-)

--
2.17.1


2022-08-16 07:39:01

by Alice Guo (OSS)

[permalink] [raw]
Subject: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

From: Jacky Bai <[email protected]>

Add explict memory barrier for the wdog unlock sequence.

Suggested-by: Ye Li <[email protected]>
Signed-off-by: Jacky Bai <[email protected]>
Signed-off-by: Alice Guo <[email protected]>
Reviewed-by: Ye Li <[email protected]>
---
drivers/watchdog/imx7ulp_wdt.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c
index 014f497ea0dc..b8ac0cb04d2f 100644
--- a/drivers/watchdog/imx7ulp_wdt.c
+++ b/drivers/watchdog/imx7ulp_wdt.c
@@ -179,9 +179,13 @@ static int imx7ulp_wdt_init(void __iomem *base, unsigned int timeout)
int ret;

local_irq_disable();
+
+ mb();
/* unlock the wdog for reconfiguration */
writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
+ mb();
+
ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
if (ret)
goto init_out;
--
2.17.1

2022-08-16 07:57:14

by Alice Guo (OSS)

[permalink] [raw]
Subject: [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog init

From: Ye Li <[email protected]>

When bootloader has enabled the CMD32EN bit, switch to use 32bits
unlock command to unlock the CS register. Using 32bits command will
help on avoiding 16 bus cycle window violation for two 16 bits
commands.

Signed-off-by: Ye Li <[email protected]>
Signed-off-by: Alice Guo <[email protected]>
Reviewed-by: Jacky Bai <[email protected]>
Acked-by: Jason Liu <[email protected]>
---
drivers/watchdog/imx7ulp_wdt.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c
index b8ac0cb04d2f..a0f6b8cea78f 100644
--- a/drivers/watchdog/imx7ulp_wdt.c
+++ b/drivers/watchdog/imx7ulp_wdt.c
@@ -180,11 +180,16 @@ static int imx7ulp_wdt_init(void __iomem *base, unsigned int timeout)

local_irq_disable();

- mb();
- /* unlock the wdog for reconfiguration */
- writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
- writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
- mb();
+ val = readl(base + WDOG_CS);
+ if (val & WDOG_CS_CMD32EN) {
+ writel(UNLOCK, base + WDOG_CNT);
+ } else {
+ mb();
+ /* unlock the wdog for reconfiguration */
+ writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
+ writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
+ mb();
+ }

ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
if (ret)
--
2.17.1

2022-08-16 08:23:57

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On 22-08-16, Alice Guo (OSS) wrote:
> From: Jacky Bai <[email protected]>
>
> Add explict memory barrier for the wdog unlock sequence.

Did you inspected any failures? It's not enough to say what you did, you
need to specify the why as well.

Regards,
Marco


>
> Suggested-by: Ye Li <[email protected]>
> Signed-off-by: Jacky Bai <[email protected]>
> Signed-off-by: Alice Guo <[email protected]>
> Reviewed-by: Ye Li <[email protected]>
> ---
> drivers/watchdog/imx7ulp_wdt.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c
> index 014f497ea0dc..b8ac0cb04d2f 100644
> --- a/drivers/watchdog/imx7ulp_wdt.c
> +++ b/drivers/watchdog/imx7ulp_wdt.c
> @@ -179,9 +179,13 @@ static int imx7ulp_wdt_init(void __iomem *base, unsigned int timeout)
> int ret;
>
> local_irq_disable();
> +
> + mb();
> /* unlock the wdog for reconfiguration */
> writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> + mb();
> +
> ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> if (ret)
> goto init_out;
> --
> 2.17.1
>
>
>

2022-08-22 08:02:53

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

> -----Original Message-----
> From: Marco Felsch <[email protected]>
> Sent: Tuesday, August 16, 2022 2:24 PM
> To: Alice Guo (OSS) <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> On 22-08-16, Alice Guo (OSS) wrote:
> > From: Jacky Bai <[email protected]>
> >
> > Add explict memory barrier for the wdog unlock sequence.
>
> Did you inspected any failures? It's not enough to say what you did, you need
> to specify the why as well.
>
> Regards,
> Marco

Hi,

Two 16-bit writes of unlocking the Watchdog should be completed within a certain time. The first mb() is used to ensure that previous instructions are completed.
The second mb() is used to ensure that the unlock sequence cannot be affected by subsequent instructions. The reason will be added in the commit log of v2.

Best Regards,
Alice Guo

>
> >
> > Suggested-by: Ye Li <[email protected]>
> > Signed-off-by: Jacky Bai <[email protected]>
> > Signed-off-by: Alice Guo <[email protected]>
> > Reviewed-by: Ye Li <[email protected]>
> > ---
> > drivers/watchdog/imx7ulp_wdt.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > b/drivers/watchdog/imx7ulp_wdt.c index 014f497ea0dc..b8ac0cb04d2f
> > 100644
> > --- a/drivers/watchdog/imx7ulp_wdt.c
> > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > @@ -179,9 +179,13 @@ static int imx7ulp_wdt_init(void __iomem *base,
> unsigned int timeout)
> > int ret;
> >
> > local_irq_disable();
> > +
> > + mb();
> > /* unlock the wdog for reconfiguration */
> > writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > + mb();
> > +
> > ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> > if (ret)
> > goto init_out;
> > --
> > 2.17.1
> >
> >
> >

2022-08-22 08:25:26

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On 22-08-22, Alice Guo (OSS) wrote:
> > -----Original Message-----
> > From: Marco Felsch <[email protected]>
> > Sent: Tuesday, August 16, 2022 2:24 PM
> > To: Alice Guo (OSS) <[email protected]>
> > Cc: [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > [email protected]; [email protected];
> > dl-linux-imx <[email protected]>; [email protected];
> > [email protected]
> > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > unlock sequence
> >
> > On 22-08-16, Alice Guo (OSS) wrote:
> > > From: Jacky Bai <[email protected]>
> > >
> > > Add explict memory barrier for the wdog unlock sequence.
> >
> > Did you inspected any failures? It's not enough to say what you did, you need
> > to specify the why as well.
> >
> > Regards,
> > Marco
>
> Hi,
>
> Two 16-bit writes of unlocking the Watchdog should be completed within a certain time. The first mb() is used to ensure that previous instructions are completed.
> The second mb() is used to ensure that the unlock sequence cannot be affected by subsequent instructions. The reason will be added in the commit log of v2.

Hi,

I know what memory barriers are. My question was, did you see any
issues? Since the driver is used mainline and no one reported issues.

Also just don't use the *_relaxed() versions is more common, than adding
mb() calls around *_relaxed() versions.

Regards,
Marco

>
> Best Regards,
> Alice Guo
>
> >
> > >
> > > Suggested-by: Ye Li <[email protected]>
> > > Signed-off-by: Jacky Bai <[email protected]>
> > > Signed-off-by: Alice Guo <[email protected]>
> > > Reviewed-by: Ye Li <[email protected]>
> > > ---
> > > drivers/watchdog/imx7ulp_wdt.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > > b/drivers/watchdog/imx7ulp_wdt.c index 014f497ea0dc..b8ac0cb04d2f
> > > 100644
> > > --- a/drivers/watchdog/imx7ulp_wdt.c
> > > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > > @@ -179,9 +179,13 @@ static int imx7ulp_wdt_init(void __iomem *base,
> > unsigned int timeout)
> > > int ret;
> > >
> > > local_irq_disable();
> > > +
> > > + mb();
> > > /* unlock the wdog for reconfiguration */
> > > writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > > writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > > + mb();
> > > +
> > > ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> > > if (ret)
> > > goto init_out;
> > > --
> > > 2.17.1
> > >
> > >
> > >
>

2022-08-22 14:22:28

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> On 22-08-22, Alice Guo (OSS) wrote:
> > > -----Original Message-----
> > > From: Marco Felsch <[email protected]>
> > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > To: Alice Guo (OSS) <[email protected]>
> > > Cc: [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > dl-linux-imx <[email protected]>; [email protected];
> > > [email protected]
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > > unlock sequence
> > >
> > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > From: Jacky Bai <[email protected]>
> > > >
> > > > Add explict memory barrier for the wdog unlock sequence.
> > >
> > > Did you inspected any failures? It's not enough to say what you did, you need
> > > to specify the why as well.
> > >
> > > Regards,
> > > Marco
> >
> > Hi,
> >
> > Two 16-bit writes of unlocking the Watchdog should be completed within a certain time. The first mb() is used to ensure that previous instructions are completed.
> > The second mb() is used to ensure that the unlock sequence cannot be affected by subsequent instructions. The reason will be added in the commit log of v2.
>
> Hi,
>
> I know what memory barriers are. My question was, did you see any
> issues? Since the driver is used mainline and no one reported issues.
>
> Also just don't use the *_relaxed() versions is more common, than adding
> mb() calls around *_relaxed() versions.
>

Agreed with both. The series is a bit short in explaining _why_ the
changes are made.

Guenter

> Regards,
> Marco
>
> >
> > Best Regards,
> > Alice Guo
> >
> > >
> > > >
> > > > Suggested-by: Ye Li <[email protected]>
> > > > Signed-off-by: Jacky Bai <[email protected]>
> > > > Signed-off-by: Alice Guo <[email protected]>
> > > > Reviewed-by: Ye Li <[email protected]>
> > > > ---
> > > > drivers/watchdog/imx7ulp_wdt.c | 4 ++++
> > > > 1 file changed, 4 insertions(+)
> > > >
> > > > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > > > b/drivers/watchdog/imx7ulp_wdt.c index 014f497ea0dc..b8ac0cb04d2f
> > > > 100644
> > > > --- a/drivers/watchdog/imx7ulp_wdt.c
> > > > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > > > @@ -179,9 +179,13 @@ static int imx7ulp_wdt_init(void __iomem *base,
> > > unsigned int timeout)
> > > > int ret;
> > > >
> > > > local_irq_disable();
> > > > +
> > > > + mb();
> > > > /* unlock the wdog for reconfiguration */
> > > > writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > > > writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > > > + mb();
> > > > +
> > > > ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> > > > if (ret)
> > > > goto init_out;
> > > > --
> > > > 2.17.1
> > > >
> > > >
> > > >
> >

2022-08-22 14:41:48

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog init

On Tue, Aug 16, 2022 at 12:36:39PM +0800, Alice Guo (OSS) wrote:
> From: Ye Li <[email protected]>
>
> When bootloader has enabled the CMD32EN bit, switch to use 32bits
> unlock command to unlock the CS register. Using 32bits command will
> help on avoiding 16 bus cycle window violation for two 16 bits
> commands.
>
> Signed-off-by: Ye Li <[email protected]>
> Signed-off-by: Alice Guo <[email protected]>
> Reviewed-by: Jacky Bai <[email protected]>
> Acked-by: Jason Liu <[email protected]>
> ---
> drivers/watchdog/imx7ulp_wdt.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c
> index b8ac0cb04d2f..a0f6b8cea78f 100644
> --- a/drivers/watchdog/imx7ulp_wdt.c
> +++ b/drivers/watchdog/imx7ulp_wdt.c
> @@ -180,11 +180,16 @@ static int imx7ulp_wdt_init(void __iomem *base, unsigned int timeout)
>
> local_irq_disable();
>
> - mb();
> - /* unlock the wdog for reconfiguration */
> - writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> - writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> - mb();
> + val = readl(base + WDOG_CS);
> + if (val & WDOG_CS_CMD32EN) {
> + writel(UNLOCK, base + WDOG_CNT);
> + } else {
> + mb();
> + /* unlock the wdog for reconfiguration */
> + writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> + writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> + mb();

Now this is intermixing writel() with writel_relaxed(), making
the code all but impossible to understand.

Guenter

> + }
>
> ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> if (ret)
> --
> 2.17.1
>

2022-08-23 05:40:34

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence



> -----Original Message-----
> From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> Sent: Monday, August 22, 2022 10:04 PM
> To: Marco Felsch <[email protected]>
> Cc: Alice Guo (OSS) <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> > On 22-08-22, Alice Guo (OSS) wrote:
> > > > -----Original Message-----
> > > > From: Marco Felsch <[email protected]>
> > > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > > To: Alice Guo (OSS) <[email protected]>
> > > > Cc: [email protected]; [email protected];
> > > > [email protected]; [email protected]; [email protected];
> > > > [email protected];
> > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > [email protected]; [email protected]
> > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > barrier for unlock sequence
> > > >
> > > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > > From: Jacky Bai <[email protected]>
> > > > >
> > > > > Add explict memory barrier for the wdog unlock sequence.
> > > >
> > > > Did you inspected any failures? It's not enough to say what you
> > > > did, you need to specify the why as well.
> > > >
> > > > Regards,
> > > > Marco
> > >
> > > Hi,
> > >
> > > Two 16-bit writes of unlocking the Watchdog should be completed within a
> certain time. The first mb() is used to ensure that previous instructions are
> completed.
> > > The second mb() is used to ensure that the unlock sequence cannot be
> affected by subsequent instructions. The reason will be added in the commit
> log of v2.
> >
> > Hi,
> >
> > I know what memory barriers are. My question was, did you see any
> > issues? Since the driver is used mainline and no one reported issues.
> >
> > Also just don't use the *_relaxed() versions is more common, than
> > adding
> > mb() calls around *_relaxed() versions.
> >
>
> Agreed with both. The series is a bit short in explaining _why_ the changes are
> made.
>
> Guenter
>
> > Regards,
> > Marco
> >
> > >

Hi Guenter and Marco,

1. did you see any issues?
This WDOG Timer first appeared in i.MX7ULP, no one report issues probably because few people use i.MX7ULP. This issue was found when we did a stress test on it. When we reconfigure the WDOG Timer, there is a certain probability that it reset. The reason for the error is that when WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit writes (0xC520, 0xD928) to the CNT register within 16 bus clocks, and improper unlock sequence causes the WDOG to reset. Adding mb() is to guarantee that two 16-bit writes are finished within 16 bus clocks.

2. Also just don't use the *_relaxed() versions is more common, than adding mb() calls around *_relaxed() versions.
Memory barriers cannot be added between two 16-bit writes. I do not know the reason.

Best Regards,
Alice Guo

> > > Best Regards,
> > > Alice Guo
> > >
> > > >
> > > > >
> > > > > Suggested-by: Ye Li <[email protected]>
> > > > > Signed-off-by: Jacky Bai <[email protected]>
> > > > > Signed-off-by: Alice Guo <[email protected]>
> > > > > Reviewed-by: Ye Li <[email protected]>
> > > > > ---
> > > > > drivers/watchdog/imx7ulp_wdt.c | 4 ++++
> > > > > 1 file changed, 4 insertions(+)
> > > > >
> > > > > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > > > > b/drivers/watchdog/imx7ulp_wdt.c index
> > > > > 014f497ea0dc..b8ac0cb04d2f
> > > > > 100644
> > > > > --- a/drivers/watchdog/imx7ulp_wdt.c
> > > > > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > > > > @@ -179,9 +179,13 @@ static int imx7ulp_wdt_init(void __iomem
> > > > > *base,
> > > > unsigned int timeout)
> > > > > int ret;
> > > > >
> > > > > local_irq_disable();
> > > > > +
> > > > > + mb();
> > > > > /* unlock the wdog for reconfiguration */
> > > > > writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > > > > writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > > > > + mb();
> > > > > +
> > > > > ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> > > > > if (ret)
> > > > > goto init_out;
> > > > > --
> > > > > 2.17.1
> > > > >
> > > > >
> > > > >
> > >

2022-08-23 06:19:04

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog init



> -----Original Message-----
> From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> Sent: Monday, August 22, 2022 10:06 PM
> To: Alice Guo (OSS) <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]; [email protected]
> Subject: Re: [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog
> init
>
> On Tue, Aug 16, 2022 at 12:36:39PM +0800, Alice Guo (OSS) wrote:
> > From: Ye Li <[email protected]>
> >
> > When bootloader has enabled the CMD32EN bit, switch to use 32bits
> > unlock command to unlock the CS register. Using 32bits command will
> > help on avoiding 16 bus cycle window violation for two 16 bits
> > commands.
> >
> > Signed-off-by: Ye Li <[email protected]>
> > Signed-off-by: Alice Guo <[email protected]>
> > Reviewed-by: Jacky Bai <[email protected]>
> > Acked-by: Jason Liu <[email protected]>
> > ---
> > drivers/watchdog/imx7ulp_wdt.c | 15 ++++++++++-----
> > 1 file changed, 10 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > b/drivers/watchdog/imx7ulp_wdt.c index b8ac0cb04d2f..a0f6b8cea78f
> > 100644
> > --- a/drivers/watchdog/imx7ulp_wdt.c
> > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > @@ -180,11 +180,16 @@ static int imx7ulp_wdt_init(void __iomem *base,
> > unsigned int timeout)
> >
> > local_irq_disable();
> >
> > - mb();
> > - /* unlock the wdog for reconfiguration */
> > - writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > - writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > - mb();
> > + val = readl(base + WDOG_CS);
> > + if (val & WDOG_CS_CMD32EN) {
> > + writel(UNLOCK, base + WDOG_CNT);
> > + } else {
> > + mb();
> > + /* unlock the wdog for reconfiguration */
> > + writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > + writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > + mb();
>
> Now this is intermixing writel() with writel_relaxed(), making the code all but
> impossible to understand.
>
> Guenter

Hi Guenter,

Intermixing writel() with writel_relaxed() is unavoidable here. Because there cannot be a memory barrier between writing UNLOCK_SEQ0 and writing UNLOCK_SEQ1. This may be determined by hardware design.

Best Regards,
Alice Guo

> > + }
> >
> > ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> > if (ret)
> > --
> > 2.17.1
> >

2022-08-23 11:29:24

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On 22-08-23, Alice Guo (OSS) wrote:
>
>
> > -----Original Message-----
> > From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> > Sent: Monday, August 22, 2022 10:04 PM
> > To: Marco Felsch <[email protected]>
> > Cc: Alice Guo (OSS) <[email protected]>; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > dl-linux-imx <[email protected]>; [email protected];
> > [email protected]
> > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > unlock sequence
> >
> > On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> > > On 22-08-22, Alice Guo (OSS) wrote:
> > > > > -----Original Message-----
> > > > > From: Marco Felsch <[email protected]>
> > > > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > Cc: [email protected]; [email protected];
> > > > > [email protected]; [email protected]; [email protected];
> > > > > [email protected];
> > > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > > [email protected]; [email protected]
> > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > barrier for unlock sequence
> > > > >
> > > > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > > > From: Jacky Bai <[email protected]>
> > > > > >
> > > > > > Add explict memory barrier for the wdog unlock sequence.
> > > > >
> > > > > Did you inspected any failures? It's not enough to say what you
> > > > > did, you need to specify the why as well.
> > > > >
> > > > > Regards,
> > > > > Marco
> > > >
> > > > Hi,
> > > >
> > > > Two 16-bit writes of unlocking the Watchdog should be completed within a
> > certain time. The first mb() is used to ensure that previous instructions are
> > completed.
> > > > The second mb() is used to ensure that the unlock sequence cannot be
> > affected by subsequent instructions. The reason will be added in the commit
> > log of v2.
> > >
> > > Hi,
> > >
> > > I know what memory barriers are. My question was, did you see any
> > > issues? Since the driver is used mainline and no one reported issues.
> > >
> > > Also just don't use the *_relaxed() versions is more common, than
> > > adding
> > > mb() calls around *_relaxed() versions.
> > >
> >
> > Agreed with both. The series is a bit short in explaining _why_ the changes are
> > made.
> >
> > Guenter
> >
> > > Regards,
> > > Marco
> > >
> > > >
>
> Hi Guenter and Marco,
>
> 1. did you see any issues?
> This WDOG Timer first appeared in i.MX7ULP, no one report issues
> probably because few people use i.MX7ULP. This issue was found when we
> did a stress test on it. When we reconfigure the WDOG Timer, there is
> a certain probability that it reset. The reason for the error is that
> when WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit writes
> (0xC520, 0xD928) to the CNT register within 16 bus clocks, and
> improper unlock sequence causes the WDOG to reset. Adding mb() is to
> guarantee that two 16-bit writes are finished within 16 bus clocks.

After this explanation the whole imx7ulp_wdt_init() seems a bit buggy
because writel_relaxed() as well as writel() are 32bit access functions.
So the very first thing to do is to enable the 32-bit mode.

Also this is a explanation worth to be added to the commit message ;)

> 2. Also just don't use the *_relaxed() versions is more common, than
> adding mb() calls around *_relaxed() versions. Memory barriers cannot
> be added between two 16-bit writes. I do not know the reason.

As written above, writel() as well as writel_relaxed() are not 16-bit
access functions.

So to me it looks as you need first to ensure that 32-bit access mode is
enabled. After that you can write drop the to writel_relaxed() functions
and instead just write:

writel(UNLOCK, wdt->base + WDOG_CNT);

Also why do we need to unlock the watchdog during imx7ulp_wdt_init()?
This is handled just fine during imx7ulp_wdt_enable() and during
imx7ulp_wdt_set_timeout(). So just drop those relaxed writes and
everything should be fine.

Regards,
Marco

2022-08-23 15:22:37

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog init

On Tue, Aug 23, 2022 at 05:46:55AM +0000, Alice Guo (OSS) wrote:
>
>
> > -----Original Message-----
> > From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> > Sent: Monday, August 22, 2022 10:06 PM
> > To: Alice Guo (OSS) <[email protected]>
> > Cc: [email protected]; [email protected];
> > [email protected]; [email protected]; [email protected];
> > dl-linux-imx <[email protected]>; [email protected];
> > [email protected]; [email protected]
> > Subject: Re: [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog
> > init
> >
> > On Tue, Aug 16, 2022 at 12:36:39PM +0800, Alice Guo (OSS) wrote:
> > > From: Ye Li <[email protected]>
> > >
> > > When bootloader has enabled the CMD32EN bit, switch to use 32bits
> > > unlock command to unlock the CS register. Using 32bits command will
> > > help on avoiding 16 bus cycle window violation for two 16 bits
> > > commands.
> > >
> > > Signed-off-by: Ye Li <[email protected]>
> > > Signed-off-by: Alice Guo <[email protected]>
> > > Reviewed-by: Jacky Bai <[email protected]>
> > > Acked-by: Jason Liu <[email protected]>
> > > ---
> > > drivers/watchdog/imx7ulp_wdt.c | 15 ++++++++++-----
> > > 1 file changed, 10 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > > b/drivers/watchdog/imx7ulp_wdt.c index b8ac0cb04d2f..a0f6b8cea78f
> > > 100644
> > > --- a/drivers/watchdog/imx7ulp_wdt.c
> > > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > > @@ -180,11 +180,16 @@ static int imx7ulp_wdt_init(void __iomem *base,
> > > unsigned int timeout)
> > >
> > > local_irq_disable();
> > >
> > > - mb();
> > > - /* unlock the wdog for reconfiguration */
> > > - writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > > - writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > > - mb();
> > > + val = readl(base + WDOG_CS);
> > > + if (val & WDOG_CS_CMD32EN) {
> > > + writel(UNLOCK, base + WDOG_CNT);
> > > + } else {
> > > + mb();
> > > + /* unlock the wdog for reconfiguration */
> > > + writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT);
> > > + writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT);
> > > + mb();
> >
> > Now this is intermixing writel() with writel_relaxed(), making the code all but
> > impossible to understand.
> >
> > Guenter
>
> Hi Guenter,
>
> Intermixing writel() with writel_relaxed() is unavoidable here. Because there cannot be a memory barrier between writing UNLOCK_SEQ0 and writing UNLOCK_SEQ1. This may be determined by hardware design.
>

If it is indeed impossible to configure the watchdog for 32-bit
access mode, that needs to be explained in the code and backed up,
for example with a reference to the documentation. Similar,
it needs to be documented in the code why writel() does not work
here and why mb() is needed.

Thanks,
Guenter

> Best Regards,
> Alice Guo
>
> > > + }
> > >
> > > ret = imx7ulp_wdt_wait(base, WDOG_CS_ULK);
> > > if (ret)
> > > --
> > > 2.17.1
> > >

2022-08-23 16:06:58

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On Tue, Aug 23, 2022 at 11:10:27AM +0200, Marco Felsch wrote:
> On 22-08-23, Alice Guo (OSS) wrote:
> >
> >
> > > -----Original Message-----
> > > From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> > > Sent: Monday, August 22, 2022 10:04 PM
> > > To: Marco Felsch <[email protected]>
> > > Cc: Alice Guo (OSS) <[email protected]>; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > dl-linux-imx <[email protected]>; [email protected];
> > > [email protected]
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > > unlock sequence
> > >
> > > On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> > > > On 22-08-22, Alice Guo (OSS) wrote:
> > > > > > -----Original Message-----
> > > > > > From: Marco Felsch <[email protected]>
> > > > > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > > Cc: [email protected]; [email protected];
> > > > > > [email protected]; [email protected]; [email protected];
> > > > > > [email protected];
> > > > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > > > [email protected]; [email protected]
> > > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > > barrier for unlock sequence
> > > > > >
> > > > > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > > > > From: Jacky Bai <[email protected]>
> > > > > > >
> > > > > > > Add explict memory barrier for the wdog unlock sequence.
> > > > > >
> > > > > > Did you inspected any failures? It's not enough to say what you
> > > > > > did, you need to specify the why as well.
> > > > > >
> > > > > > Regards,
> > > > > > Marco
> > > > >
> > > > > Hi,
> > > > >
> > > > > Two 16-bit writes of unlocking the Watchdog should be completed within a
> > > certain time. The first mb() is used to ensure that previous instructions are
> > > completed.
> > > > > The second mb() is used to ensure that the unlock sequence cannot be
> > > affected by subsequent instructions. The reason will be added in the commit
> > > log of v2.
> > > >
> > > > Hi,
> > > >
> > > > I know what memory barriers are. My question was, did you see any
> > > > issues? Since the driver is used mainline and no one reported issues.
> > > >
> > > > Also just don't use the *_relaxed() versions is more common, than
> > > > adding
> > > > mb() calls around *_relaxed() versions.
> > > >
> > >
> > > Agreed with both. The series is a bit short in explaining _why_ the changes are
> > > made.
> > >
> > > Guenter
> > >
> > > > Regards,
> > > > Marco
> > > >
> > > > >
> >
> > Hi Guenter and Marco,
> >
> > 1. did you see any issues?
> > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > probably because few people use i.MX7ULP. This issue was found when we
> > did a stress test on it. When we reconfigure the WDOG Timer, there is
> > a certain probability that it reset. The reason for the error is that
> > when WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit writes
> > (0xC520, 0xD928) to the CNT register within 16 bus clocks, and
> > improper unlock sequence causes the WDOG to reset. Adding mb() is to
> > guarantee that two 16-bit writes are finished within 16 bus clocks.
>
> After this explanation the whole imx7ulp_wdt_init() seems a bit buggy
> because writel_relaxed() as well as writel() are 32bit access functions.
> So the very first thing to do is to enable the 32-bit mode.
>
Agreed. This is much better than having extra code to deal with
both 16-bit and 32-bit access.

> Also this is a explanation worth to be added to the commit message ;)
>

Definitely. Also, the use of mb(), if it should indeed be needed,
would have to be explained in a code comment.

Thanks,
Guenter

> > 2. Also just don't use the *_relaxed() versions is more common, than
> > adding mb() calls around *_relaxed() versions. Memory barriers cannot
> > be added between two 16-bit writes. I do not know the reason.
>
> As written above, writel() as well as writel_relaxed() are not 16-bit
> access functions.
>
> So to me it looks as you need first to ensure that 32-bit access mode is
> enabled. After that you can write drop the to writel_relaxed() functions
> and instead just write:
>
> writel(UNLOCK, wdt->base + WDOG_CNT);
>
> Also why do we need to unlock the watchdog during imx7ulp_wdt_init()?
> This is handled just fine during imx7ulp_wdt_enable() and during
> imx7ulp_wdt_set_timeout(). So just drop those relaxed writes and
> everything should be fine.
>
> Regards,
> Marco

2022-08-24 07:27:45

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence



> -----Original Message-----
> From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> Sent: Tuesday, August 23, 2022 8:02 PM
> To: Marco Felsch <[email protected]>
> Cc: Alice Guo (OSS) <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> On Tue, Aug 23, 2022 at 11:10:27AM +0200, Marco Felsch wrote:
> > On 22-08-23, Alice Guo (OSS) wrote:
> > >
> > >
> > > > -----Original Message-----
> > > > From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> > > > Sent: Monday, August 22, 2022 10:04 PM
> > > > To: Marco Felsch <[email protected]>
> > > > Cc: Alice Guo (OSS) <[email protected]>;
> > > > [email protected]; [email protected];
> > > > [email protected]; [email protected];
> > > > [email protected];
> > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > [email protected]; [email protected]
> > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > barrier for unlock sequence
> > > >
> > > > On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> > > > > On 22-08-22, Alice Guo (OSS) wrote:
> > > > > > > -----Original Message-----
> > > > > > > From: Marco Felsch <[email protected]>
> > > > > > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > > > Cc: [email protected]; [email protected];
> > > > > > > [email protected]; [email protected];
> > > > > > > [email protected]; [email protected];
> > > > > > > [email protected]; dl-linux-imx
> > > > > > > <[email protected]>; [email protected];
> > > > > > > [email protected]
> > > > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict
> > > > > > > memory barrier for unlock sequence
> > > > > > >
> > > > > > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > > > > > From: Jacky Bai <[email protected]>
> > > > > > > >
> > > > > > > > Add explict memory barrier for the wdog unlock sequence.
> > > > > > >
> > > > > > > Did you inspected any failures? It's not enough to say what
> > > > > > > you did, you need to specify the why as well.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Marco
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > Two 16-bit writes of unlocking the Watchdog should be
> > > > > > completed within a
> > > > certain time. The first mb() is used to ensure that previous
> > > > instructions are completed.
> > > > > > The second mb() is used to ensure that the unlock sequence
> > > > > > cannot be
> > > > affected by subsequent instructions. The reason will be added in
> > > > the commit log of v2.
> > > > >
> > > > > Hi,
> > > > >
> > > > > I know what memory barriers are. My question was, did you see
> > > > > any issues? Since the driver is used mainline and no one reported
> issues.
> > > > >
> > > > > Also just don't use the *_relaxed() versions is more common,
> > > > > than adding
> > > > > mb() calls around *_relaxed() versions.
> > > > >
> > > >
> > > > Agreed with both. The series is a bit short in explaining _why_
> > > > the changes are made.
> > > >
> > > > Guenter
> > > >
> > > > > Regards,
> > > > > Marco
> > > > >
> > > > > >
> > >
> > > Hi Guenter and Marco,
> > >
> > > 1. did you see any issues?
> > > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > > probably because few people use i.MX7ULP. This issue was found when
> > > we did a stress test on it. When we reconfigure the WDOG Timer,
> > > there is a certain probability that it reset. The reason for the
> > > error is that when WDOG_CS[CMD32EN] is 0, the unlock sequence is two
> > > 16-bit writes (0xC520, 0xD928) to the CNT register within 16 bus
> > > clocks, and improper unlock sequence causes the WDOG to reset.
> > > Adding mb() is to guarantee that two 16-bit writes are finished within 16
> bus clocks.
> >
> > After this explanation the whole imx7ulp_wdt_init() seems a bit buggy
> > because writel_relaxed() as well as writel() are 32bit access functions.
> > So the very first thing to do is to enable the 32-bit mode.
> >
> Agreed. This is much better than having extra code to deal with both 16-bit
> and 32-bit access.
>
> > Also this is a explanation worth to be added to the commit message ;)
> >
>
> Definitely. Also, the use of mb(), if it should indeed be needed, would have to
> be explained in a code comment.
>
> Thanks,
> Guenter

Hi Marco and Guenter,

Thank you for your comments. I plan to enable support for 32-bit unlock command write words in bootloader. In this way, there is no need to distinguish whether the unlock command is a 32-bit command or a 16-bit command in driver.

Best Regards,
Alice Guo

> > > 2. Also just don't use the *_relaxed() versions is more common, than
> > > adding mb() calls around *_relaxed() versions. Memory barriers
> > > cannot be added between two 16-bit writes. I do not know the reason.
> >
> > As written above, writel() as well as writel_relaxed() are not 16-bit
> > access functions.
> >
> > So to me it looks as you need first to ensure that 32-bit access mode
> > is enabled. After that you can write drop the to writel_relaxed()
> > functions and instead just write:
> >
> > writel(UNLOCK, wdt->base + WDOG_CNT);
> >
> > Also why do we need to unlock the watchdog during imx7ulp_wdt_init()?
> > This is handled just fine during imx7ulp_wdt_enable() and during
> > imx7ulp_wdt_set_timeout(). So just drop those relaxed writes and
> > everything should be fine.
> >
> > Regards,
> > Marco

2022-08-24 08:12:01

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

Hi Alice,

On 22-08-24, Alice Guo (OSS) wrote:

...

> > > > Hi Guenter and Marco,
> > > >
> > > > 1. did you see any issues?
> > > > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > > > probably because few people use i.MX7ULP. This issue was found when
> > > > we did a stress test on it. When we reconfigure the WDOG Timer,
> > > > there is a certain probability that it reset. The reason for the
> > > > error is that when WDOG_CS[CMD32EN] is 0, the unlock sequence is two
> > > > 16-bit writes (0xC520, 0xD928) to the CNT register within 16 bus
> > > > clocks, and improper unlock sequence causes the WDOG to reset.
> > > > Adding mb() is to guarantee that two 16-bit writes are finished within 16
> > bus clocks.
> > >
> > > After this explanation the whole imx7ulp_wdt_init() seems a bit buggy
> > > because writel_relaxed() as well as writel() are 32bit access functions.
> > > So the very first thing to do is to enable the 32-bit mode.
> > >
> > Agreed. This is much better than having extra code to deal with both 16-bit
> > and 32-bit access.
> >
> > > Also this is a explanation worth to be added to the commit message ;)
> > >
> >
> > Definitely. Also, the use of mb(), if it should indeed be needed, would have to
> > be explained in a code comment.
> >
> > Thanks,
> > Guenter
>
> Hi Marco and Guenter,
>
> Thank you for your comments. I plan to enable support for 32-bit
> unlock command write words in bootloader. In this way, there is no
> need to distinguish whether the unlock command is a 32-bit command or
> a 16-bit command in driver.

Please don't move this into the bootloader, enabling it within the init
seq. is just fine. If you move it into the bootloader then you can't
ensure that the bit is set since there are plenty of bootloaders out
there.

As I said, just drop the "16bit" unlock sequence from the init function
because the unlock is handled just fine in all the watchdog_ops.

Regards,
Marco

2022-08-24 09:14:34

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

Hi Alice,

On 22-08-24, Alice Guo (OSS) wrote:
> > -----Original Message-----
> > From: Marco Felsch <[email protected]>
> > Sent: Wednesday, August 24, 2022 4:04 PM
> > To: Alice Guo (OSS) <[email protected]>
> > Cc: Guenter Roeck <[email protected]>; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > dl-linux-imx <[email protected]>; [email protected];
> > [email protected]
> > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > unlock sequence
> >
> > Hi Alice,
> >
> > On 22-08-24, Alice Guo (OSS) wrote:
> >
> > ...
> >
> > > > > > Hi Guenter and Marco,
> > > > > >
> > > > > > 1. did you see any issues?
> > > > > > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > > > > > probably because few people use i.MX7ULP. This issue was found
> > > > > > when we did a stress test on it. When we reconfigure the WDOG
> > > > > > Timer, there is a certain probability that it reset. The reason
> > > > > > for the error is that when WDOG_CS[CMD32EN] is 0, the unlock
> > > > > > sequence is two 16-bit writes (0xC520, 0xD928) to the CNT
> > > > > > register within 16 bus clocks, and improper unlock sequence causes the
> > WDOG to reset.
> > > > > > Adding mb() is to guarantee that two 16-bit writes are finished
> > > > > > within 16
> > > > bus clocks.
> > > > >
> > > > > After this explanation the whole imx7ulp_wdt_init() seems a bit
> > > > > buggy because writel_relaxed() as well as writel() are 32bit access
> > functions.
> > > > > So the very first thing to do is to enable the 32-bit mode.
> > > > >
> > > > Agreed. This is much better than having extra code to deal with both
> > > > 16-bit and 32-bit access.
> > > >
> > > > > Also this is a explanation worth to be added to the commit message
> > > > > ;)
> > > > >
> > > >
> > > > Definitely. Also, the use of mb(), if it should indeed be needed,
> > > > would have to be explained in a code comment.
> > > >
> > > > Thanks,
> > > > Guenter
> > >
> > > Hi Marco and Guenter,
> > >
> > > Thank you for your comments. I plan to enable support for 32-bit
> > > unlock command write words in bootloader. In this way, there is no
> > > need to distinguish whether the unlock command is a 32-bit command or
> > > a 16-bit command in driver.
> >
> > Please don't move this into the bootloader, enabling it within the init seq. is
> > just fine. If you move it into the bootloader then you can't ensure that the bit is
> > set since there are plenty of bootloaders out there.
> >
> > As I said, just drop the "16bit" unlock sequence from the init function because
> > the unlock is handled just fine in all the watchdog_ops.
> >
> > Regards,
> > Marco
>
> Hi Marco,
>
> Sorry, I did not tell you that all watchdog control bits, timeout
> value, and window value cannot be set until the watchdog is unlocked.

You don't have to according the RM:
8<----------------------------------------------------------------------
59.5.2 Disable Watchdog after Reset

All of watchdog registers are unlocked by reset. Therefore, unlock
sequence is unnecessary, but it needs to write all of watchdog registers
to make the new configuration take effect. The code snippet below shows
an example of disabling watchdog after reset.
8<----------------------------------------------------------------------

also the RM tells us:
8<----------------------------------------------------------------------
59.4.3.1 Configuring the Watchdog Once

The new configuration takes effect only after all registers except CNT
are written after reset. Otherwise, the WDOG uses the reset values by
default. If window mode is not used (CS[WIN] is 0), writing to WIN is
not required to make the new configuration take effect.
8<----------------------------------------------------------------------

> Support for 32-bit unlock command write words in enabled in
> imx7ulp_wdt_init now.

So.. after reading the IMX7ULP RM, which was not my intention, I found
out that most of the WDOG_CS regiter bits are write-once bits. This
means if you didn't set it within the bootloader you still in case
"59.4.3.1".

So the imx7ulp_wdt_init() function just needs to check if the
WDOG_CS_UPDATE bit was set. If it is not the case, then you need to
write the WDOG_CS register as currently done. If the bit is set, than
you need know that the bootloader did the job for you and you can exit
imx7ulp_wdt_init() early. In both cases the unlock is not required.

Can you please check/test if this is working for you?

Regards,
Marco

> Best Regards,
> Alice Guo
>
>
>
>

2022-08-24 09:30:14

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

> -----Original Message-----
> From: Marco Felsch <[email protected]>
> Sent: Wednesday, August 24, 2022 4:04 PM
> To: Alice Guo (OSS) <[email protected]>
> Cc: Guenter Roeck <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> Hi Alice,
>
> On 22-08-24, Alice Guo (OSS) wrote:
>
> ...
>
> > > > > Hi Guenter and Marco,
> > > > >
> > > > > 1. did you see any issues?
> > > > > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > > > > probably because few people use i.MX7ULP. This issue was found
> > > > > when we did a stress test on it. When we reconfigure the WDOG
> > > > > Timer, there is a certain probability that it reset. The reason
> > > > > for the error is that when WDOG_CS[CMD32EN] is 0, the unlock
> > > > > sequence is two 16-bit writes (0xC520, 0xD928) to the CNT
> > > > > register within 16 bus clocks, and improper unlock sequence causes the
> WDOG to reset.
> > > > > Adding mb() is to guarantee that two 16-bit writes are finished
> > > > > within 16
> > > bus clocks.
> > > >
> > > > After this explanation the whole imx7ulp_wdt_init() seems a bit
> > > > buggy because writel_relaxed() as well as writel() are 32bit access
> functions.
> > > > So the very first thing to do is to enable the 32-bit mode.
> > > >
> > > Agreed. This is much better than having extra code to deal with both
> > > 16-bit and 32-bit access.
> > >
> > > > Also this is a explanation worth to be added to the commit message
> > > > ;)
> > > >
> > >
> > > Definitely. Also, the use of mb(), if it should indeed be needed,
> > > would have to be explained in a code comment.
> > >
> > > Thanks,
> > > Guenter
> >
> > Hi Marco and Guenter,
> >
> > Thank you for your comments. I plan to enable support for 32-bit
> > unlock command write words in bootloader. In this way, there is no
> > need to distinguish whether the unlock command is a 32-bit command or
> > a 16-bit command in driver.
>
> Please don't move this into the bootloader, enabling it within the init seq. is
> just fine. If you move it into the bootloader then you can't ensure that the bit is
> set since there are plenty of bootloaders out there.
>
> As I said, just drop the "16bit" unlock sequence from the init function because
> the unlock is handled just fine in all the watchdog_ops.
>
> Regards,
> Marco

Hi Marco,

Sorry, I did not tell you that all watchdog control bits, timeout value, and window value cannot be set until the watchdog is unlocked. Support for 32-bit unlock command write words in enabled in imx7ulp_wdt_init now.

Best Regards,
Alice Guo



2022-08-24 10:46:06

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence


> -----Original Message-----
> From: Marco Felsch <[email protected]>
> Sent: Wednesday, August 24, 2022 5:06 PM
> To: Alice Guo (OSS) <[email protected]>
> Cc: Guenter Roeck <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> Hi Alice,
>
> On 22-08-24, Alice Guo (OSS) wrote:
> > > -----Original Message-----
> > > From: Marco Felsch <[email protected]>
> > > Sent: Wednesday, August 24, 2022 4:04 PM
> > > To: Alice Guo (OSS) <[email protected]>
> > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > dl-linux-imx <[email protected]>; [email protected];
> > > [email protected]
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > barrier for unlock sequence
> > >
> > > Hi Alice,
> > >
> > > On 22-08-24, Alice Guo (OSS) wrote:
> > >
> > > ...
> > >
> > > > > > > Hi Guenter and Marco,
> > > > > > >
> > > > > > > 1. did you see any issues?
> > > > > > > This WDOG Timer first appeared in i.MX7ULP, no one report
> > > > > > > issues probably because few people use i.MX7ULP. This issue
> > > > > > > was found when we did a stress test on it. When we
> > > > > > > reconfigure the WDOG Timer, there is a certain probability
> > > > > > > that it reset. The reason for the error is that when
> > > > > > > WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit
> > > > > > > writes (0xC520, 0xD928) to the CNT register within 16 bus
> > > > > > > clocks, and improper unlock sequence causes the
> > > WDOG to reset.
> > > > > > > Adding mb() is to guarantee that two 16-bit writes are
> > > > > > > finished within 16
> > > > > bus clocks.
> > > > > >
> > > > > > After this explanation the whole imx7ulp_wdt_init() seems a
> > > > > > bit buggy because writel_relaxed() as well as writel() are
> > > > > > 32bit access
> > > functions.
> > > > > > So the very first thing to do is to enable the 32-bit mode.
> > > > > >
> > > > > Agreed. This is much better than having extra code to deal with
> > > > > both 16-bit and 32-bit access.
> > > > >
> > > > > > Also this is a explanation worth to be added to the commit
> > > > > > message
> > > > > > ;)
> > > > > >
> > > > >
> > > > > Definitely. Also, the use of mb(), if it should indeed be
> > > > > needed, would have to be explained in a code comment.
> > > > >
> > > > > Thanks,
> > > > > Guenter
> > > >
> > > > Hi Marco and Guenter,
> > > >
> > > > Thank you for your comments. I plan to enable support for 32-bit
> > > > unlock command write words in bootloader. In this way, there is no
> > > > need to distinguish whether the unlock command is a 32-bit command
> > > > or a 16-bit command in driver.
> > >
> > > Please don't move this into the bootloader, enabling it within the
> > > init seq. is just fine. If you move it into the bootloader then you
> > > can't ensure that the bit is set since there are plenty of bootloaders out
> there.
> > >
> > > As I said, just drop the "16bit" unlock sequence from the init
> > > function because the unlock is handled just fine in all the watchdog_ops.
> > >
> > > Regards,
> > > Marco
> >
> > Hi Marco,
> >
> > Sorry, I did not tell you that all watchdog control bits, timeout
> > value, and window value cannot be set until the watchdog is unlocked.
>
> You don't have to according the RM:
> 8<----------------------------------------------------------------------
> 59.5.2 Disable Watchdog after Reset
>
> All of watchdog registers are unlocked by reset. Therefore, unlock sequence is
> unnecessary, but it needs to write all of watchdog registers to make the new
> configuration take effect. The code snippet below shows an example of
> disabling watchdog after reset.
> 8<----------------------------------------------------------------------
>
> also the RM tells us:
> 8<----------------------------------------------------------------------
> 59.4.3.1 Configuring the Watchdog Once
>
> The new configuration takes effect only after all registers except CNT are
> written after reset. Otherwise, the WDOG uses the reset values by default. If
> window mode is not used (CS[WIN] is 0), writing to WIN is not required to
> make the new configuration take effect.
> 8<----------------------------------------------------------------------
>
> > Support for 32-bit unlock command write words in enabled in
> > imx7ulp_wdt_init now.
>
> So.. after reading the IMX7ULP RM, which was not my intention, I found out
> that most of the WDOG_CS regiter bits are write-once bits. This means if you
> didn't set it within the bootloader you still in case "59.4.3.1".
>
> So the imx7ulp_wdt_init() function just needs to check if the
> WDOG_CS_UPDATE bit was set. If it is not the case, then you need to write the
> WDOG_CS register as currently done. If the bit is set, than you need know that
> the bootloader did the job for you and you can exit
> imx7ulp_wdt_init() early. In both cases the unlock is not required.
>
> Can you please check/test if this is working for you?
>
> Regards,
> Marco
>

Hi Marco,

Rom code has already configured the WDOG once, so we cannot use " Configuring the Watchdog Once".

Best Regards,
Alice Guo

2022-08-25 08:08:36

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On 22-08-24, Alice Guo (OSS) wrote:
>
> > -----Original Message-----
> > From: Marco Felsch <[email protected]>
> > Sent: Wednesday, August 24, 2022 5:06 PM
> > To: Alice Guo (OSS) <[email protected]>
> > Cc: Guenter Roeck <[email protected]>; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > dl-linux-imx <[email protected]>; [email protected];
> > [email protected]
> > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > unlock sequence
> >
> > Hi Alice,
> >
> > On 22-08-24, Alice Guo (OSS) wrote:
> > > > -----Original Message-----
> > > > From: Marco Felsch <[email protected]>
> > > > Sent: Wednesday, August 24, 2022 4:04 PM
> > > > To: Alice Guo (OSS) <[email protected]>
> > > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > > [email protected]; [email protected]; [email protected];
> > > > [email protected]; [email protected];
> > > > dl-linux-imx <[email protected]>; [email protected];
> > > > [email protected]
> > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > barrier for unlock sequence
> > > >
> > > > Hi Alice,
> > > >
> > > > On 22-08-24, Alice Guo (OSS) wrote:
> > > >
> > > > ...
> > > >
> > > > > > > > Hi Guenter and Marco,
> > > > > > > >
> > > > > > > > 1. did you see any issues?
> > > > > > > > This WDOG Timer first appeared in i.MX7ULP, no one report
> > > > > > > > issues probably because few people use i.MX7ULP. This issue
> > > > > > > > was found when we did a stress test on it. When we
> > > > > > > > reconfigure the WDOG Timer, there is a certain probability
> > > > > > > > that it reset. The reason for the error is that when
> > > > > > > > WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit
> > > > > > > > writes (0xC520, 0xD928) to the CNT register within 16 bus
> > > > > > > > clocks, and improper unlock sequence causes the
> > > > WDOG to reset.
> > > > > > > > Adding mb() is to guarantee that two 16-bit writes are
> > > > > > > > finished within 16
> > > > > > bus clocks.
> > > > > > >
> > > > > > > After this explanation the whole imx7ulp_wdt_init() seems a
> > > > > > > bit buggy because writel_relaxed() as well as writel() are
> > > > > > > 32bit access
> > > > functions.
> > > > > > > So the very first thing to do is to enable the 32-bit mode.
> > > > > > >
> > > > > > Agreed. This is much better than having extra code to deal with
> > > > > > both 16-bit and 32-bit access.
> > > > > >
> > > > > > > Also this is a explanation worth to be added to the commit
> > > > > > > message
> > > > > > > ;)
> > > > > > >
> > > > > >
> > > > > > Definitely. Also, the use of mb(), if it should indeed be
> > > > > > needed, would have to be explained in a code comment.
> > > > > >
> > > > > > Thanks,
> > > > > > Guenter
> > > > >
> > > > > Hi Marco and Guenter,
> > > > >
> > > > > Thank you for your comments. I plan to enable support for 32-bit
> > > > > unlock command write words in bootloader. In this way, there is no
> > > > > need to distinguish whether the unlock command is a 32-bit command
> > > > > or a 16-bit command in driver.
> > > >
> > > > Please don't move this into the bootloader, enabling it within the
> > > > init seq. is just fine. If you move it into the bootloader then you
> > > > can't ensure that the bit is set since there are plenty of bootloaders out
> > there.
> > > >
> > > > As I said, just drop the "16bit" unlock sequence from the init
> > > > function because the unlock is handled just fine in all the watchdog_ops.
> > > >
> > > > Regards,
> > > > Marco
> > >
> > > Hi Marco,
> > >
> > > Sorry, I did not tell you that all watchdog control bits, timeout
> > > value, and window value cannot be set until the watchdog is unlocked.
> >
> > You don't have to according the RM:
> > 8<----------------------------------------------------------------------
> > 59.5.2 Disable Watchdog after Reset
> >
> > All of watchdog registers are unlocked by reset. Therefore, unlock sequence is
> > unnecessary, but it needs to write all of watchdog registers to make the new
> > configuration take effect. The code snippet below shows an example of
> > disabling watchdog after reset.
> > 8<----------------------------------------------------------------------
> >
> > also the RM tells us:
> > 8<----------------------------------------------------------------------
> > 59.4.3.1 Configuring the Watchdog Once
> >
> > The new configuration takes effect only after all registers except CNT are
> > written after reset. Otherwise, the WDOG uses the reset values by default. If
> > window mode is not used (CS[WIN] is 0), writing to WIN is not required to
> > make the new configuration take effect.
> > 8<----------------------------------------------------------------------
> >
> > > Support for 32-bit unlock command write words in enabled in
> > > imx7ulp_wdt_init now.
> >
> > So.. after reading the IMX7ULP RM, which was not my intention, I found out
> > that most of the WDOG_CS regiter bits are write-once bits. This means if you
> > didn't set it within the bootloader you still in case "59.4.3.1".
> >
> > So the imx7ulp_wdt_init() function just needs to check if the
> > WDOG_CS_UPDATE bit was set. If it is not the case, then you need to write the
> > WDOG_CS register as currently done. If the bit is set, than you need know that
> > the bootloader did the job for you and you can exit
> > imx7ulp_wdt_init() early. In both cases the unlock is not required.
> >
> > Can you please check/test if this is working for you?
> >
> > Regards,
> > Marco
> >
>
> Hi Marco,
>
> Rom code has already configured the WDOG once, so we cannot use "
> Configuring the Watchdog Once".

What? How does the ROM code configure the WDOG? Also this would be worth a
comment within the code. Also still assume that this "16bit unlock" seq.
is useless since you writing 32bit anyway.

Regards,
Marco

2022-08-25 08:24:59

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence


> -----Original Message-----
> From: Marco Felsch <[email protected]>
> Sent: Thursday, August 25, 2022 3:50 PM
> To: Alice Guo (OSS) <[email protected]>
> Cc: Guenter Roeck <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> On 22-08-24, Alice Guo (OSS) wrote:
> >
> > > -----Original Message-----
> > > From: Marco Felsch <[email protected]>
> > > Sent: Wednesday, August 24, 2022 5:06 PM
> > > To: Alice Guo (OSS) <[email protected]>
> > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > dl-linux-imx <[email protected]>; [email protected];
> > > [email protected]
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > barrier for unlock sequence
> > >
> > > Hi Alice,
> > >
> > > On 22-08-24, Alice Guo (OSS) wrote:
> > > > > -----Original Message-----
> > > > > From: Marco Felsch <[email protected]>
> > > > > Sent: Wednesday, August 24, 2022 4:04 PM
> > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > > > [email protected]; [email protected];
> [email protected];
> > > > > [email protected];
> > > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > > [email protected]; [email protected]
> > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > barrier for unlock sequence
> > > > >
> > > > > Hi Alice,
> > > > >
> > > > > On 22-08-24, Alice Guo (OSS) wrote:
> > > > >
> > > > > ...
> > > > >
> > > > > > > > > Hi Guenter and Marco,
> > > > > > > > >
> > > > > > > > > 1. did you see any issues?
> > > > > > > > > This WDOG Timer first appeared in i.MX7ULP, no one
> > > > > > > > > report issues probably because few people use i.MX7ULP.
> > > > > > > > > This issue was found when we did a stress test on it.
> > > > > > > > > When we reconfigure the WDOG Timer, there is a certain
> > > > > > > > > probability that it reset. The reason for the error is
> > > > > > > > > that when WDOG_CS[CMD32EN] is 0, the unlock sequence is
> > > > > > > > > two 16-bit writes (0xC520, 0xD928) to the CNT register
> > > > > > > > > within 16 bus clocks, and improper unlock sequence
> > > > > > > > > causes the
> > > > > WDOG to reset.
> > > > > > > > > Adding mb() is to guarantee that two 16-bit writes are
> > > > > > > > > finished within 16
> > > > > > > bus clocks.
> > > > > > > >
> > > > > > > > After this explanation the whole imx7ulp_wdt_init() seems
> > > > > > > > a bit buggy because writel_relaxed() as well as writel()
> > > > > > > > are 32bit access
> > > > > functions.
> > > > > > > > So the very first thing to do is to enable the 32-bit mode.
> > > > > > > >
> > > > > > > Agreed. This is much better than having extra code to deal
> > > > > > > with both 16-bit and 32-bit access.
> > > > > > >
> > > > > > > > Also this is a explanation worth to be added to the commit
> > > > > > > > message
> > > > > > > > ;)
> > > > > > > >
> > > > > > >
> > > > > > > Definitely. Also, the use of mb(), if it should indeed be
> > > > > > > needed, would have to be explained in a code comment.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Guenter
> > > > > >
> > > > > > Hi Marco and Guenter,
> > > > > >
> > > > > > Thank you for your comments. I plan to enable support for
> > > > > > 32-bit unlock command write words in bootloader. In this way,
> > > > > > there is no need to distinguish whether the unlock command is
> > > > > > a 32-bit command or a 16-bit command in driver.
> > > > >
> > > > > Please don't move this into the bootloader, enabling it within
> > > > > the init seq. is just fine. If you move it into the bootloader
> > > > > then you can't ensure that the bit is set since there are plenty
> > > > > of bootloaders out
> > > there.
> > > > >
> > > > > As I said, just drop the "16bit" unlock sequence from the init
> > > > > function because the unlock is handled just fine in all the
> watchdog_ops.
> > > > >
> > > > > Regards,
> > > > > Marco
> > > >
> > > > Hi Marco,
> > > >
> > > > Sorry, I did not tell you that all watchdog control bits, timeout
> > > > value, and window value cannot be set until the watchdog is unlocked.
> > >
> > > You don't have to according the RM:
> > > 8<------------------------------------------------------------------
> > > ----
> > > 59.5.2 Disable Watchdog after Reset
> > >
> > > All of watchdog registers are unlocked by reset. Therefore, unlock
> > > sequence is unnecessary, but it needs to write all of watchdog
> > > registers to make the new configuration take effect. The code
> > > snippet below shows an example of disabling watchdog after reset.
> > > 8<------------------------------------------------------------------
> > > ----
> > >
> > > also the RM tells us:
> > > 8<------------------------------------------------------------------
> > > ----
> > > 59.4.3.1 Configuring the Watchdog Once
> > >
> > > The new configuration takes effect only after all registers except
> > > CNT are written after reset. Otherwise, the WDOG uses the reset
> > > values by default. If window mode is not used (CS[WIN] is 0),
> > > writing to WIN is not required to make the new configuration take effect.
> > > 8<------------------------------------------------------------------
> > > ----
> > >
> > > > Support for 32-bit unlock command write words in enabled in
> > > > imx7ulp_wdt_init now.
> > >
> > > So.. after reading the IMX7ULP RM, which was not my intention, I
> > > found out that most of the WDOG_CS regiter bits are write-once bits.
> > > This means if you didn't set it within the bootloader you still in case
> "59.4.3.1".
> > >
> > > So the imx7ulp_wdt_init() function just needs to check if the
> > > WDOG_CS_UPDATE bit was set. If it is not the case, then you need to
> > > write the WDOG_CS register as currently done. If the bit is set,
> > > than you need know that the bootloader did the job for you and you
> > > can exit
> > > imx7ulp_wdt_init() early. In both cases the unlock is not required.
> > >
> > > Can you please check/test if this is working for you?
> > >
> > > Regards,
> > > Marco
> > >
> >
> > Hi Marco,
> >
> > Rom code has already configured the WDOG once, so we cannot use "
> > Configuring the Watchdog Once".
>
> What? How does the ROM code configure the WDOG? Also this would be
> worth a comment within the code. Also still assume that this "16bit unlock"
> seq.
> is useless since you writing 32bit anyway.
>
> Regards,
> Marco

Hi Marco,

The ROM code of i.MX7ULP configures the WDOG to support 16-bit unlock command. I plan to add a comment to explain it in code, and keep "mb(); writel_relaxed; writel_relaxed; mb()" unchanged.

Best Regards,
Alice Guo








2022-08-25 09:38:53

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence

On 22-08-25, Alice Guo (OSS) wrote:
>
> > -----Original Message-----
> > From: Marco Felsch <[email protected]>
> > Sent: Thursday, August 25, 2022 3:50 PM
> > To: Alice Guo (OSS) <[email protected]>
> > Cc: Guenter Roeck <[email protected]>; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > dl-linux-imx <[email protected]>; [email protected];
> > [email protected]
> > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > unlock sequence
> >
> > On 22-08-24, Alice Guo (OSS) wrote:
> > >
> > > > -----Original Message-----
> > > > From: Marco Felsch <[email protected]>
> > > > Sent: Wednesday, August 24, 2022 5:06 PM
> > > > To: Alice Guo (OSS) <[email protected]>
> > > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > > [email protected]; [email protected]; [email protected];
> > > > [email protected]; [email protected];
> > > > dl-linux-imx <[email protected]>; [email protected];
> > > > [email protected]
> > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > barrier for unlock sequence
> > > >
> > > > Hi Alice,
> > > >
> > > > On 22-08-24, Alice Guo (OSS) wrote:
> > > > > > -----Original Message-----
> > > > > > From: Marco Felsch <[email protected]>
> > > > > > Sent: Wednesday, August 24, 2022 4:04 PM
> > > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > > > > [email protected]; [email protected];
> > [email protected];
> > > > > > [email protected];
> > > > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > > > [email protected]; [email protected]
> > > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > > barrier for unlock sequence
> > > > > >
> > > > > > Hi Alice,
> > > > > >
> > > > > > On 22-08-24, Alice Guo (OSS) wrote:
> > > > > >
> > > > > > ...
> > > > > >
> > > > > > > > > > Hi Guenter and Marco,
> > > > > > > > > >
> > > > > > > > > > 1. did you see any issues?
> > > > > > > > > > This WDOG Timer first appeared in i.MX7ULP, no one
> > > > > > > > > > report issues probably because few people use i.MX7ULP.
> > > > > > > > > > This issue was found when we did a stress test on it.
> > > > > > > > > > When we reconfigure the WDOG Timer, there is a certain
> > > > > > > > > > probability that it reset. The reason for the error is
> > > > > > > > > > that when WDOG_CS[CMD32EN] is 0, the unlock sequence is
> > > > > > > > > > two 16-bit writes (0xC520, 0xD928) to the CNT register
> > > > > > > > > > within 16 bus clocks, and improper unlock sequence
> > > > > > > > > > causes the
> > > > > > WDOG to reset.
> > > > > > > > > > Adding mb() is to guarantee that two 16-bit writes are
> > > > > > > > > > finished within 16
> > > > > > > > bus clocks.
> > > > > > > > >
> > > > > > > > > After this explanation the whole imx7ulp_wdt_init() seems
> > > > > > > > > a bit buggy because writel_relaxed() as well as writel()
> > > > > > > > > are 32bit access
> > > > > > functions.
> > > > > > > > > So the very first thing to do is to enable the 32-bit mode.
> > > > > > > > >
> > > > > > > > Agreed. This is much better than having extra code to deal
> > > > > > > > with both 16-bit and 32-bit access.
> > > > > > > >
> > > > > > > > > Also this is a explanation worth to be added to the commit
> > > > > > > > > message
> > > > > > > > > ;)
> > > > > > > > >
> > > > > > > >
> > > > > > > > Definitely. Also, the use of mb(), if it should indeed be
> > > > > > > > needed, would have to be explained in a code comment.
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Guenter
> > > > > > >
> > > > > > > Hi Marco and Guenter,
> > > > > > >
> > > > > > > Thank you for your comments. I plan to enable support for
> > > > > > > 32-bit unlock command write words in bootloader. In this way,
> > > > > > > there is no need to distinguish whether the unlock command is
> > > > > > > a 32-bit command or a 16-bit command in driver.
> > > > > >
> > > > > > Please don't move this into the bootloader, enabling it within
> > > > > > the init seq. is just fine. If you move it into the bootloader
> > > > > > then you can't ensure that the bit is set since there are plenty
> > > > > > of bootloaders out
> > > > there.
> > > > > >
> > > > > > As I said, just drop the "16bit" unlock sequence from the init
> > > > > > function because the unlock is handled just fine in all the
> > watchdog_ops.
> > > > > >
> > > > > > Regards,
> > > > > > Marco
> > > > >
> > > > > Hi Marco,
> > > > >
> > > > > Sorry, I did not tell you that all watchdog control bits, timeout
> > > > > value, and window value cannot be set until the watchdog is unlocked.
> > > >
> > > > You don't have to according the RM:
> > > > 8<------------------------------------------------------------------
> > > > ----
> > > > 59.5.2 Disable Watchdog after Reset
> > > >
> > > > All of watchdog registers are unlocked by reset. Therefore, unlock
> > > > sequence is unnecessary, but it needs to write all of watchdog
> > > > registers to make the new configuration take effect. The code
> > > > snippet below shows an example of disabling watchdog after reset.
> > > > 8<------------------------------------------------------------------
> > > > ----
> > > >
> > > > also the RM tells us:
> > > > 8<------------------------------------------------------------------
> > > > ----
> > > > 59.4.3.1 Configuring the Watchdog Once
> > > >
> > > > The new configuration takes effect only after all registers except
> > > > CNT are written after reset. Otherwise, the WDOG uses the reset
> > > > values by default. If window mode is not used (CS[WIN] is 0),
> > > > writing to WIN is not required to make the new configuration take effect.
> > > > 8<------------------------------------------------------------------
> > > > ----
> > > >
> > > > > Support for 32-bit unlock command write words in enabled in
> > > > > imx7ulp_wdt_init now.
> > > >
> > > > So.. after reading the IMX7ULP RM, which was not my intention, I
> > > > found out that most of the WDOG_CS regiter bits are write-once bits.
> > > > This means if you didn't set it within the bootloader you still in case
> > "59.4.3.1".
> > > >
> > > > So the imx7ulp_wdt_init() function just needs to check if the
> > > > WDOG_CS_UPDATE bit was set. If it is not the case, then you need to
> > > > write the WDOG_CS register as currently done. If the bit is set,
> > > > than you need know that the bootloader did the job for you and you
> > > > can exit
> > > > imx7ulp_wdt_init() early. In both cases the unlock is not required.
> > > >
> > > > Can you please check/test if this is working for you?
> > > >
> > > > Regards,
> > > > Marco
> > > >
> > >
> > > Hi Marco,
> > >
> > > Rom code has already configured the WDOG once, so we cannot use "
> > > Configuring the Watchdog Once".
> >
> > What? How does the ROM code configure the WDOG? Also this would be
> > worth a comment within the code. Also still assume that this "16bit unlock"
> > seq.
> > is useless since you writing 32bit anyway.
> >
> > Regards,
> > Marco
>
> Hi Marco,
>
> The ROM code of i.MX7ULP configures the WDOG to support 16-bit unlock
> command. I plan to add a comment to explain it in code, and keep
> "mb(); writel_relaxed; writel_relaxed; mb()" unchanged.

As said, the writel_relaxed() is also 32bit writes. Please just use the
correct APIs for the stuff you wanna do. In your case, if you want 16bit
access functions you need to use writew() function and you can drop the
mb(). But after reading the RM again, I think you can go with writel()
since 32bit writes are okay, but you need to pass the two 16bit unlock
commands. For that you just need to ensure that the timing is correct,
as noted in the RM.

Also I read that the WDOG1 is only programmed in serial downloader mode
to reset the device if no activity was found on the serial/usb bus. Also
this only happen if the fuse for it was burned, but the RM says also:
"The watchdog is enabled by default after reset.". Can you please read
the Watchdog status register and post it here?

Also after after reading the RM I found the ULK bit "This read-only bit
indicates whether WDOG is unlocked or not." If this bit is 0 the device
is locked and we need a unlock command else we can just write the config
to the device. The unlock command can than be: two writel() commands
which are adding the barriers for free.

Regards,
Marco


> Best Regards,
> Alice Guo
>
>
>
>
>
>
>
>
>

2022-08-25 10:24:22

by Alice Guo (OSS)

[permalink] [raw]
Subject: RE: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence


> -----Original Message-----
> From: Marco Felsch <[email protected]>
> Sent: Thursday, August 25, 2022 5:02 PM
> To: Alice Guo (OSS) <[email protected]>
> Cc: Guenter Roeck <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> dl-linux-imx <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> unlock sequence
>
> On 22-08-25, Alice Guo (OSS) wrote:
> >
> > > -----Original Message-----
> > > From: Marco Felsch <[email protected]>
> > > Sent: Thursday, August 25, 2022 3:50 PM
> > > To: Alice Guo (OSS) <[email protected]>
> > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > dl-linux-imx <[email protected]>; [email protected];
> > > [email protected]
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > barrier for unlock sequence
> > >
> > > On 22-08-24, Alice Guo (OSS) wrote:
> > > >
> > > > > -----Original Message-----
> > > > > From: Marco Felsch <[email protected]>
> > > > > Sent: Wednesday, August 24, 2022 5:06 PM
> > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > Cc: Guenter Roeck <[email protected]>; [email protected];
> > > > > [email protected]; [email protected];
> [email protected];
> > > > > [email protected];
> > > > > [email protected]; dl-linux-imx <[email protected]>;
> > > > > [email protected]; [email protected]
> > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > barrier for unlock sequence
> > > > >
> > > > > Hi Alice,
> > > > >
> > > > > On 22-08-24, Alice Guo (OSS) wrote:
> > > > > > > -----Original Message-----
> > > > > > > From: Marco Felsch <[email protected]>
> > > > > > > Sent: Wednesday, August 24, 2022 4:04 PM
> > > > > > > To: Alice Guo (OSS) <[email protected]>
> > > > > > > Cc: Guenter Roeck <[email protected]>;
> > > > > > > [email protected]; [email protected];
> > > > > > > [email protected];
> > > [email protected];
> > > > > > > [email protected];
> > > > > > > [email protected]; dl-linux-imx
> > > > > > > <[email protected]>; [email protected];
> > > > > > > [email protected]
> > > > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict
> > > > > > > memory barrier for unlock sequence
> > > > > > >
> > > > > > > Hi Alice,
> > > > > > >
> > > > > > > On 22-08-24, Alice Guo (OSS) wrote:
> > > > > > >
> > > > > > > ...
> > > > > > >
> > > > > > > > > > > Hi Guenter and Marco,
> > > > > > > > > > >
> > > > > > > > > > > 1. did you see any issues?
> > > > > > > > > > > This WDOG Timer first appeared in i.MX7ULP, no one
> > > > > > > > > > > report issues probably because few people use i.MX7ULP.
> > > > > > > > > > > This issue was found when we did a stress test on it.
> > > > > > > > > > > When we reconfigure the WDOG Timer, there is a
> > > > > > > > > > > certain probability that it reset. The reason for
> > > > > > > > > > > the error is that when WDOG_CS[CMD32EN] is 0, the
> > > > > > > > > > > unlock sequence is two 16-bit writes (0xC520,
> > > > > > > > > > > 0xD928) to the CNT register within 16 bus clocks,
> > > > > > > > > > > and improper unlock sequence causes the
> > > > > > > WDOG to reset.
> > > > > > > > > > > Adding mb() is to guarantee that two 16-bit writes
> > > > > > > > > > > are finished within 16
> > > > > > > > > bus clocks.
> > > > > > > > > >
> > > > > > > > > > After this explanation the whole imx7ulp_wdt_init()
> > > > > > > > > > seems a bit buggy because writel_relaxed() as well as
> > > > > > > > > > writel() are 32bit access
> > > > > > > functions.
> > > > > > > > > > So the very first thing to do is to enable the 32-bit mode.
> > > > > > > > > >
> > > > > > > > > Agreed. This is much better than having extra code to
> > > > > > > > > deal with both 16-bit and 32-bit access.
> > > > > > > > >
> > > > > > > > > > Also this is a explanation worth to be added to the
> > > > > > > > > > commit message
> > > > > > > > > > ;)
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > > Definitely. Also, the use of mb(), if it should indeed
> > > > > > > > > be needed, would have to be explained in a code comment.
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > > Guenter
> > > > > > > >
> > > > > > > > Hi Marco and Guenter,
> > > > > > > >
> > > > > > > > Thank you for your comments. I plan to enable support for
> > > > > > > > 32-bit unlock command write words in bootloader. In this
> > > > > > > > way, there is no need to distinguish whether the unlock
> > > > > > > > command is a 32-bit command or a 16-bit command in driver.
> > > > > > >
> > > > > > > Please don't move this into the bootloader, enabling it
> > > > > > > within the init seq. is just fine. If you move it into the
> > > > > > > bootloader then you can't ensure that the bit is set since
> > > > > > > there are plenty of bootloaders out
> > > > > there.
> > > > > > >
> > > > > > > As I said, just drop the "16bit" unlock sequence from the
> > > > > > > init function because the unlock is handled just fine in all
> > > > > > > the
> > > watchdog_ops.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Marco
> > > > > >
> > > > > > Hi Marco,
> > > > > >
> > > > > > Sorry, I did not tell you that all watchdog control bits,
> > > > > > timeout value, and window value cannot be set until the watchdog is
> unlocked.
> > > > >
> > > > > You don't have to according the RM:
> > > > > 8<--------------------------------------------------------------
> > > > > ----
> > > > > ----
> > > > > 59.5.2 Disable Watchdog after Reset
> > > > >
> > > > > All of watchdog registers are unlocked by reset. Therefore,
> > > > > unlock sequence is unnecessary, but it needs to write all of
> > > > > watchdog registers to make the new configuration take effect.
> > > > > The code snippet below shows an example of disabling watchdog after
> reset.
> > > > > 8<--------------------------------------------------------------
> > > > > ----
> > > > > ----
> > > > >
> > > > > also the RM tells us:
> > > > > 8<--------------------------------------------------------------
> > > > > ----
> > > > > ----
> > > > > 59.4.3.1 Configuring the Watchdog Once
> > > > >
> > > > > The new configuration takes effect only after all registers
> > > > > except CNT are written after reset. Otherwise, the WDOG uses the
> > > > > reset values by default. If window mode is not used (CS[WIN] is
> > > > > 0), writing to WIN is not required to make the new configuration take
> effect.
> > > > > 8<--------------------------------------------------------------
> > > > > ----
> > > > > ----
> > > > >
> > > > > > Support for 32-bit unlock command write words in enabled in
> > > > > > imx7ulp_wdt_init now.
> > > > >
> > > > > So.. after reading the IMX7ULP RM, which was not my intention, I
> > > > > found out that most of the WDOG_CS regiter bits are write-once bits.
> > > > > This means if you didn't set it within the bootloader you still
> > > > > in case
> > > "59.4.3.1".
> > > > >
> > > > > So the imx7ulp_wdt_init() function just needs to check if the
> > > > > WDOG_CS_UPDATE bit was set. If it is not the case, then you need
> > > > > to write the WDOG_CS register as currently done. If the bit is
> > > > > set, than you need know that the bootloader did the job for you
> > > > > and you can exit
> > > > > imx7ulp_wdt_init() early. In both cases the unlock is not required.
> > > > >
> > > > > Can you please check/test if this is working for you?
> > > > >
> > > > > Regards,
> > > > > Marco
> > > > >
> > > >
> > > > Hi Marco,
> > > >
> > > > Rom code has already configured the WDOG once, so we cannot use "
> > > > Configuring the Watchdog Once".
> > >
> > > What? How does the ROM code configure the WDOG? Also this would be
> > > worth a comment within the code. Also still assume that this "16bit
> unlock"
> > > seq.
> > > is useless since you writing 32bit anyway.
> > >
> > > Regards,
> > > Marco
> >
> > Hi Marco,
> >
> > The ROM code of i.MX7ULP configures the WDOG to support 16-bit unlock
> > command. I plan to add a comment to explain it in code, and keep
> > "mb(); writel_relaxed; writel_relaxed; mb()" unchanged.
>
> As said, the writel_relaxed() is also 32bit writes. Please just use the correct APIs
> for the stuff you wanna do. In your case, if you want 16bit access functions you
> need to use writew() function and you can drop the mb(). But after reading the
> RM again, I think you can go with writel() since 32bit writes are okay, but you
> need to pass the two 16bit unlock commands. For that you just need to ensure
> that the timing is correct, as noted in the RM.
>
> Also I read that the WDOG1 is only programmed in serial downloader mode to
> reset the device if no activity was found on the serial/usb bus. Also this only
> happen if the fuse for it was burned, but the RM says also:
> "The watchdog is enabled by default after reset.". Can you please read the
> Watchdog status register and post it here?
>
> Also after after reading the RM I found the ULK bit "This read-only bit indicates
> whether WDOG is unlocked or not." If this bit is 0 the device is locked and we
> need a unlock command else we can just write the config to the device. The
> unlock command can than be: two writel() commands which are adding the
> barriers for free.
>
> Regards,
> Marco

Hi Marco,

1. Two 16-bit writes(0xC520, 0xD928) to the CNT register must be finished within 16 bus clocks.
The CNT register is still a 32-bit register, so it is right to use writel_relaxed().

2. After test, we found that memory barriers cannot be added between two 16-bit writes.
writel() cannot be used.

3. Software must make updates within 128 bus clocks after unlocking and before WDOG closing unlock window.
The ULK bit cannot be used to indicate that WDOG can be configured.

Best Regards,
Alice Guo