2023-02-20 10:51:06

by Meenakshi Aggarwal

[permalink] [raw]
Subject: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced

From: Horia Geanta <[email protected]>

Issues:
- Job ring device is busy when do kexec reboot
- Failed to flush job ring when do system suspend-resume

Fix:
Flush the job ring to stop the running jobs.

Signed-off-by: Horia Geanta <[email protected]>
Signed-off-by: Franck LENORMAND <[email protected]>
---
drivers/crypto/caam/jr.c | 53 +++++++++++++++++++++++++++++++++-------
1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 724fdec18bf9..8745fe3cb575 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -72,19 +72,27 @@ static void caam_jr_crypto_engine_exit(void *data)
crypto_engine_exit(jrpriv->engine);
}

-static int caam_reset_hw_jr(struct device *dev)
+/*
+ * Put the CAAM in quiesce, ie stop
+ *
+ * Must be called with itr disabled
+ */
+static int caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
{
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
unsigned int timeout = 100000;

- /*
- * mask interrupts since we are going to poll
- * for reset completion status
- */
- clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
+ /* Check the current status */
+ if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS)
+ goto wait_quiesce_completion;

- /* initiate flush (required prior to reset) */
- wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
+ /* Reset the field */
+ clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
+
+ /* initiate flush / park (required prior to reset) */
+ wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
+
+wait_quiesce_completion:
while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) ==
JRINT_ERR_HALT_INPROGRESS) && --timeout)
cpu_relax();
@@ -95,8 +103,35 @@ static int caam_reset_hw_jr(struct device *dev)
return -EIO;
}

+ return 0;
+}
+
+/*
+ * Flush the job ring, so the jobs running will be stopped, jobs queued will be
+ * invalidated and the CAAM will no longer fetch fron input ring.
+ *
+ * Must be called with itr disabled
+ */
+static int caam_jr_flush(struct device *dev)
+{
+ return caam_jr_stop_processing(dev, JRCR_RESET);
+}
+
+static int caam_reset_hw_jr(struct device *dev)
+{
+ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
+ unsigned int timeout = 100000;
+ int err;
+ /*
+ * mask interrupts since we are going to poll
+ * for reset completion status
+ */
+ clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
+ err = caam_jr_flush(dev);
+ if (err)
+ return err;
+
/* initiate reset */
- timeout = 100000;
wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --timeout)
cpu_relax();
--
2.25.1



2023-02-21 05:41:21

by Meenakshi Aggarwal

[permalink] [raw]
Subject: [PATCH] drivers: crypto: caam: jr: add .shutdown hook

From: Gaurav Jain <[email protected]>

add .shutdown hook in caam_jr driver to support kexec boot

Signed-off-by: Gaurav Jain <[email protected]>
---
drivers/crypto/caam/jr.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 8745fe3cb575..a2a99d09b4ad 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -198,6 +198,11 @@ static int caam_jr_remove(struct platform_device *pdev)
return ret;
}

+static void caam_jr_platform_shutdown(struct platform_device *pdev)
+{
+ caam_jr_remove(pdev);
+}
+
/* Main per-ring interrupt handler */
static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
{
@@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
},
.probe = caam_jr_probe,
.remove = caam_jr_remove,
+ .shutdown = caam_jr_platform_shutdown,
};

static int __init jr_driver_init(void)
--
2.25.1


2023-02-21 05:42:48

by Meenakshi Aggarwal

[permalink] [raw]
Subject: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced

From: Horia Geanta <[email protected]>

Issues:
- Job ring device is busy when do kexec reboot
- Failed to flush job ring when do system suspend-resume

Fix:
Flush the job ring to stop the running jobs.

Signed-off-by: Horia Geanta <[email protected]>
Signed-off-by: Franck LENORMAND <[email protected]>
---
drivers/crypto/caam/jr.c | 53 +++++++++++++++++++++++++++++++++-------
1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 724fdec18bf9..8745fe3cb575 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -72,19 +72,27 @@ static void caam_jr_crypto_engine_exit(void *data)
crypto_engine_exit(jrpriv->engine);
}

-static int caam_reset_hw_jr(struct device *dev)
+/*
+ * Put the CAAM in quiesce, ie stop
+ *
+ * Must be called with itr disabled
+ */
+static int caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
{
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
unsigned int timeout = 100000;

- /*
- * mask interrupts since we are going to poll
- * for reset completion status
- */
- clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
+ /* Check the current status */
+ if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS)
+ goto wait_quiesce_completion;

- /* initiate flush (required prior to reset) */
- wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
+ /* Reset the field */
+ clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
+
+ /* initiate flush / park (required prior to reset) */
+ wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
+
+wait_quiesce_completion:
while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) ==
JRINT_ERR_HALT_INPROGRESS) && --timeout)
cpu_relax();
@@ -95,8 +103,35 @@ static int caam_reset_hw_jr(struct device *dev)
return -EIO;
}

+ return 0;
+}
+
+/*
+ * Flush the job ring, so the jobs running will be stopped, jobs queued will be
+ * invalidated and the CAAM will no longer fetch fron input ring.
+ *
+ * Must be called with itr disabled
+ */
+static int caam_jr_flush(struct device *dev)
+{
+ return caam_jr_stop_processing(dev, JRCR_RESET);
+}
+
+static int caam_reset_hw_jr(struct device *dev)
+{
+ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
+ unsigned int timeout = 100000;
+ int err;
+ /*
+ * mask interrupts since we are going to poll
+ * for reset completion status
+ */
+ clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
+ err = caam_jr_flush(dev);
+ if (err)
+ return err;
+
/* initiate reset */
- timeout = 100000;
wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --timeout)
cpu_relax();
--
2.25.1


2023-02-21 17:32:22

by Vijay Balakrishna

[permalink] [raw]
Subject: Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook



On 2/20/2023 9:40 PM, [email protected] wrote:
> From: Gaurav Jain <[email protected]>
>
> add .shutdown hook in caam_jr driver to support kexec boot
>
> Signed-off-by: Gaurav Jain <[email protected]>

Tested-by: Vijay Balakrishna <[email protected]>

Thanks,
Vijay

> ---
> drivers/crypto/caam/jr.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index 8745fe3cb575..a2a99d09b4ad 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -198,6 +198,11 @@ static int caam_jr_remove(struct platform_device *pdev)
> return ret;
> }
>
> +static void caam_jr_platform_shutdown(struct platform_device *pdev)
> +{
> + caam_jr_remove(pdev);
> +}
> +
> /* Main per-ring interrupt handler */
> static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
> {
> @@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
> },
> .probe = caam_jr_probe,
> .remove = caam_jr_remove,
> + .shutdown = caam_jr_platform_shutdown,
> };
>
> static int __init jr_driver_init(void)

2023-02-21 17:33:27

by Vijay Balakrishna

[permalink] [raw]
Subject: Re: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced



On 2/20/2023 9:42 PM, [email protected] wrote:
> From: Horia Geanta <[email protected]>
>
> Issues:
> - Job ring device is busy when do kexec reboot
> - Failed to flush job ring when do system suspend-resume
>
> Fix:
> Flush the job ring to stop the running jobs.
>
> Signed-off-by: Horia Geanta <[email protected]>
> Signed-off-by: Franck LENORMAND <[email protected]>

Tested-by: Vijay Balakrishna <[email protected]>

Thanks,
Vijay


> ---
> drivers/crypto/caam/jr.c | 53 +++++++++++++++++++++++++++++++++-------
> 1 file changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index 724fdec18bf9..8745fe3cb575 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -72,19 +72,27 @@ static void caam_jr_crypto_engine_exit(void *data)
> crypto_engine_exit(jrpriv->engine);
> }
>
> -static int caam_reset_hw_jr(struct device *dev)
> +/*
> + * Put the CAAM in quiesce, ie stop
> + *
> + * Must be called with itr disabled
> + */
> +static int caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
> {
> struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> unsigned int timeout = 100000;
>
> - /*
> - * mask interrupts since we are going to poll
> - * for reset completion status
> - */
> - clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
> + /* Check the current status */
> + if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS)
> + goto wait_quiesce_completion;
>
> - /* initiate flush (required prior to reset) */
> - wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
> + /* Reset the field */
> + clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
> +
> + /* initiate flush / park (required prior to reset) */
> + wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
> +
> +wait_quiesce_completion:
> while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) ==
> JRINT_ERR_HALT_INPROGRESS) && --timeout)
> cpu_relax();
> @@ -95,8 +103,35 @@ static int caam_reset_hw_jr(struct device *dev)
> return -EIO;
> }
>
> + return 0;
> +}
> +
> +/*
> + * Flush the job ring, so the jobs running will be stopped, jobs queued will be
> + * invalidated and the CAAM will no longer fetch fron input ring.
> + *
> + * Must be called with itr disabled
> + */
> +static int caam_jr_flush(struct device *dev)
> +{
> + return caam_jr_stop_processing(dev, JRCR_RESET);
> +}
> +
> +static int caam_reset_hw_jr(struct device *dev)
> +{
> + struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> + unsigned int timeout = 100000;
> + int err;
> + /*
> + * mask interrupts since we are going to poll
> + * for reset completion status
> + */
> + clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
> + err = caam_jr_flush(dev);
> + if (err)
> + return err;
> +
> /* initiate reset */
> - timeout = 100000;
> wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
> while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --timeout)
> cpu_relax();

2023-02-27 07:32:48

by Pankaj Gupta

[permalink] [raw]
Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced

Change the year in the License header.

After changing, you can add the reviewed by me.
Reviewed-By: Pankaj Gupta <[email protected]>

> -----Original Message-----
> From: Vijay Balakrishna <[email protected]>
> Sent: Tuesday, February 21, 2023 11:03 PM
> To: Meenakshi Aggarwal <[email protected]>; Horia Geanta
> <[email protected]>; Varun Sethi <[email protected]>; Pankaj Gupta
> <[email protected]>; Gaurav Jain <[email protected]>;
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; Franck Lenormand
> <[email protected]>
> Cc: [email protected]
> Subject: [EXT] Re: [PATCH] drivers: crypto: caam: jr: Allow quiesce when
> quiesced
>
> Caution: EXT Email
>
> On 2/20/2023 9:42 PM, [email protected] wrote:
> > From: Horia Geanta <[email protected]>
> >
> > Issues:
> > - Job ring device is busy when do kexec reboot
> > - Failed to flush job ring when do system suspend-resume
> >
> > Fix:
> > Flush the job ring to stop the running jobs.
> >
> > Signed-off-by: Horia Geanta <[email protected]>
> > Signed-off-by: Franck LENORMAND <[email protected]>
>
> Tested-by: Vijay Balakrishna <[email protected]>
>
> Thanks,
> Vijay
>
>
> > ---
> > drivers/crypto/caam/jr.c | 53 +++++++++++++++++++++++++++++++++-
> ------
> > 1 file changed, 44 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index
> > 724fdec18bf9..8745fe3cb575 100644
> > --- a/drivers/crypto/caam/jr.c
> > +++ b/drivers/crypto/caam/jr.c
> > @@ -72,19 +72,27 @@ static void caam_jr_crypto_engine_exit(void *data)
> > crypto_engine_exit(jrpriv->engine);
> > }
> >
> > -static int caam_reset_hw_jr(struct device *dev)
> > +/*
> > + * Put the CAAM in quiesce, ie stop
> > + *
> > + * Must be called with itr disabled
> > + */
> > +static int caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
> > {
> > struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> > unsigned int timeout = 100000;
> >
> > - /*
> > - * mask interrupts since we are going to poll
> > - * for reset completion status
> > - */
> > - clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
> > + /* Check the current status */
> > + if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS)
> > + goto wait_quiesce_completion;
> >
> > - /* initiate flush (required prior to reset) */
> > - wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
> > + /* Reset the field */
> > + clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
> > +
> > + /* initiate flush / park (required prior to reset) */
> > + wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
> > +
> > +wait_quiesce_completion:
> > while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK)
> ==
> > JRINT_ERR_HALT_INPROGRESS) && --timeout)
> > cpu_relax();
> > @@ -95,8 +103,35 @@ static int caam_reset_hw_jr(struct device *dev)
> > return -EIO;
> > }
> >
> > + return 0;
> > +}
> > +
> > +/*
> > + * Flush the job ring, so the jobs running will be stopped, jobs
> > +queued will be
> > + * invalidated and the CAAM will no longer fetch fron input ring.
> > + *
> > + * Must be called with itr disabled
> > + */
> > +static int caam_jr_flush(struct device *dev) {
> > + return caam_jr_stop_processing(dev, JRCR_RESET); }
> > +
> > +static int caam_reset_hw_jr(struct device *dev) {
> > + struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> > + unsigned int timeout = 100000;
> > + int err;
> > + /*
> > + * mask interrupts since we are going to poll
> > + * for reset completion status
> > + */
> > + clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
> > + err = caam_jr_flush(dev);
> > + if (err)
> > + return err;
> > +
> > /* initiate reset */
> > - timeout = 100000;
> > wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
> > while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --
> timeout)
> > cpu_relax();

2023-02-27 07:33:06

by Pankaj Gupta

[permalink] [raw]
Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook

Change the year in the License header.

After changing, you can add the reviewed by me.
Reviewed-By: Pankaj Gupta <[email protected]>

> -----Original Message-----
> From: Vijay Balakrishna <[email protected]>
> Sent: Tuesday, February 21, 2023 11:02 PM
> To: Meenakshi Aggarwal <[email protected]>; Horia Geanta
> <[email protected]>; Varun Sethi <[email protected]>; Pankaj Gupta
> <[email protected]>; Gaurav Jain <[email protected]>;
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; Franck Lenormand
> <[email protected]>
> Cc: [email protected]
> Subject: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook
>
> Caution: EXT Email
>
> On 2/20/2023 9:40 PM, [email protected] wrote:
> > From: Gaurav Jain <[email protected]>
> >
> > add .shutdown hook in caam_jr driver to support kexec boot
> >
> > Signed-off-by: Gaurav Jain <[email protected]>
>
> Tested-by: Vijay Balakrishna <[email protected]>
>
> Thanks,
> Vijay
>
> > ---
> > drivers/crypto/caam/jr.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index
> > 8745fe3cb575..a2a99d09b4ad 100644
> > --- a/drivers/crypto/caam/jr.c
> > +++ b/drivers/crypto/caam/jr.c
> > @@ -198,6 +198,11 @@ static int caam_jr_remove(struct platform_device
> *pdev)
> > return ret;
> > }
> >
> > +static void caam_jr_platform_shutdown(struct platform_device *pdev) {
> > + caam_jr_remove(pdev);
> > +}
> > +
> > /* Main per-ring interrupt handler */
> > static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
> > {
> > @@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
> > },
> > .probe = caam_jr_probe,
> > .remove = caam_jr_remove,
> > + .shutdown = caam_jr_platform_shutdown,
> > };
> >
> > static int __init jr_driver_init(void)

2023-02-28 18:38:31

by Meenakshi Aggarwal

[permalink] [raw]
Subject: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced

From: Horia Geanta <[email protected]>

Issues:
- Job ring device is busy when do kexec reboot
- Failed to flush job ring when do system suspend-resume

Fix:
Flush the job ring to stop the running jobs.

Signed-off-by: Horia Geanta <[email protected]>
Signed-off-by: Franck LENORMAND <[email protected]>
Reviewed-by: Pankaj Gupta <[email protected]>
---
drivers/crypto/caam/jr.c | 55 ++++++++++++++++++++++++++++++++--------
1 file changed, 45 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 724fdec18bf9..eb3b9a7e9a35 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -4,7 +4,7 @@
* JobR backend functionality
*
* Copyright 2008-2012 Freescale Semiconductor, Inc.
- * Copyright 2019 NXP
+ * Copyright 2019, 2023 NXP
*/

#include <linux/of_irq.h>
@@ -72,19 +72,27 @@ static void caam_jr_crypto_engine_exit(void *data)
crypto_engine_exit(jrpriv->engine);
}

-static int caam_reset_hw_jr(struct device *dev)
+/*
+ * Put the CAAM in quiesce, ie stop
+ *
+ * Must be called with itr disabled
+ */
+static int caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
{
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
unsigned int timeout = 100000;

- /*
- * mask interrupts since we are going to poll
- * for reset completion status
- */
- clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
+ /* Check the current status */
+ if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS)
+ goto wait_quiesce_completion;

- /* initiate flush (required prior to reset) */
- wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
+ /* Reset the field */
+ clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
+
+ /* initiate flush / park (required prior to reset) */
+ wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
+
+wait_quiesce_completion:
while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) ==
JRINT_ERR_HALT_INPROGRESS) && --timeout)
cpu_relax();
@@ -95,8 +103,35 @@ static int caam_reset_hw_jr(struct device *dev)
return -EIO;
}

+ return 0;
+}
+
+/*
+ * Flush the job ring, so the jobs running will be stopped, jobs queued will be
+ * invalidated and the CAAM will no longer fetch fron input ring.
+ *
+ * Must be called with itr disabled
+ */
+static int caam_jr_flush(struct device *dev)
+{
+ return caam_jr_stop_processing(dev, JRCR_RESET);
+}
+
+static int caam_reset_hw_jr(struct device *dev)
+{
+ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
+ unsigned int timeout = 100000;
+ int err;
+ /*
+ * mask interrupts since we are going to poll
+ * for reset completion status
+ */
+ clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
+ err = caam_jr_flush(dev);
+ if (err)
+ return err;
+
/* initiate reset */
- timeout = 100000;
wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --timeout)
cpu_relax();
--
2.25.1


2023-03-01 05:39:33

by Meenakshi Aggarwal

[permalink] [raw]
Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook

Copyright updated in another patch and sent v2, both patches are modifying same file so no need to make any changes in this patch.

> -----Original Message-----
> From: Pankaj Gupta <[email protected]>
> Sent: Monday, February 27, 2023 1:03 PM
> To: Vijay Balakrishna <[email protected]>; Meenakshi Aggarwal
> <[email protected]>; Horia Geanta <[email protected]>;
> Varun Sethi <[email protected]>; Gaurav Jain <[email protected]>;
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; Franck Lenormand
> <[email protected]>
> Cc: [email protected]
> Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook
>
> Change the year in the License header.
>
> After changing, you can add the reviewed by me.
> Reviewed-By: Pankaj Gupta <[email protected]>
>
> > -----Original Message-----
> > From: Vijay Balakrishna <[email protected]>
> > Sent: Tuesday, February 21, 2023 11:02 PM
> > To: Meenakshi Aggarwal <[email protected]>; Horia Geanta
> > <[email protected]>; Varun Sethi <[email protected]>; Pankaj Gupta
> > <[email protected]>; Gaurav Jain <[email protected]>;
> > [email protected]; [email protected]; linux-
> > [email protected]; [email protected]; Franck Lenormand
> > <[email protected]>
> > Cc: [email protected]
> > Subject: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown
> > hook
> >
> > Caution: EXT Email
> >
> > On 2/20/2023 9:40 PM, [email protected] wrote:
> > > From: Gaurav Jain <[email protected]>
> > >
> > > add .shutdown hook in caam_jr driver to support kexec boot
> > >
> > > Signed-off-by: Gaurav Jain <[email protected]>
> >
> > Tested-by: Vijay Balakrishna <[email protected]>
> >
> > Thanks,
> > Vijay
> >
> > > ---
> > > drivers/crypto/caam/jr.c | 6 ++++++
> > > 1 file changed, 6 insertions(+)
> > >
> > > diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> > > index 8745fe3cb575..a2a99d09b4ad 100644
> > > --- a/drivers/crypto/caam/jr.c
> > > +++ b/drivers/crypto/caam/jr.c
> > > @@ -198,6 +198,11 @@ static int caam_jr_remove(struct
> > > platform_device
> > *pdev)
> > > return ret;
> > > }
> > >
> > > +static void caam_jr_platform_shutdown(struct platform_device *pdev) {
> > > + caam_jr_remove(pdev);
> > > +}
> > > +
> > > /* Main per-ring interrupt handler */
> > > static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
> > > {
> > > @@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
> > > },
> > > .probe = caam_jr_probe,
> > > .remove = caam_jr_remove,
> > > + .shutdown = caam_jr_platform_shutdown,
> > > };
> > >
> > > static int __init jr_driver_init(void)

2023-03-10 10:36:32

by Meenakshi Aggarwal

[permalink] [raw]
Subject: RE: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced

Hi Herbert,

Please apply the patch if you have no comments.

Thanks,
Meenakshi

> -----Original Message-----
> From: [email protected] <[email protected]>
> Sent: Wednesday, March 1, 2023 12:08 AM
> To: Horia Geanta <[email protected]>; Varun Sethi <[email protected]>;
> Pankaj Gupta <[email protected]>; Gaurav Jain <[email protected]>;
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; Franck Lenormand
> <[email protected]>
> Cc: [email protected]; [email protected]
> Subject: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced
>
> From: Horia Geanta <[email protected]>
>
> Issues:
> - Job ring device is busy when do kexec reboot
> - Failed to flush job ring when do system suspend-resume
>
> Fix:
> Flush the job ring to stop the running jobs.
>
> Signed-off-by: Horia Geanta <[email protected]>
> Signed-off-by: Franck LENORMAND <[email protected]>
> Reviewed-by: Pankaj Gupta <[email protected]>
> ---
> drivers/crypto/caam/jr.c | 55 ++++++++++++++++++++++++++++++++--------
> 1 file changed, 45 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index
> 724fdec18bf9..eb3b9a7e9a35 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -4,7 +4,7 @@
> * JobR backend functionality
> *
> * Copyright 2008-2012 Freescale Semiconductor, Inc.
> - * Copyright 2019 NXP
> + * Copyright 2019, 2023 NXP
> */
>
> #include <linux/of_irq.h>
> @@ -72,19 +72,27 @@ static void caam_jr_crypto_engine_exit(void *data)
> crypto_engine_exit(jrpriv->engine);
> }
>
> -static int caam_reset_hw_jr(struct device *dev)
> +/*
> + * Put the CAAM in quiesce, ie stop
> + *
> + * Must be called with itr disabled
> + */
> +static int caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
> {
> struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> unsigned int timeout = 100000;
>
> - /*
> - * mask interrupts since we are going to poll
> - * for reset completion status
> - */
> - clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
> + /* Check the current status */
> + if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS)
> + goto wait_quiesce_completion;
>
> - /* initiate flush (required prior to reset) */
> - wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
> + /* Reset the field */
> + clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
> +
> + /* initiate flush / park (required prior to reset) */
> + wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
> +
> +wait_quiesce_completion:
> while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK)
> ==
> JRINT_ERR_HALT_INPROGRESS) && --timeout)
> cpu_relax();
> @@ -95,8 +103,35 @@ static int caam_reset_hw_jr(struct device *dev)
> return -EIO;
> }
>
> + return 0;
> +}
> +
> +/*
> + * Flush the job ring, so the jobs running will be stopped, jobs queued
> +will be
> + * invalidated and the CAAM will no longer fetch fron input ring.
> + *
> + * Must be called with itr disabled
> + */
> +static int caam_jr_flush(struct device *dev) {
> + return caam_jr_stop_processing(dev, JRCR_RESET); }
> +
> +static int caam_reset_hw_jr(struct device *dev) {
> + struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> + unsigned int timeout = 100000;
> + int err;
> + /*
> + * mask interrupts since we are going to poll
> + * for reset completion status
> + */
> + clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
> + err = caam_jr_flush(dev);
> + if (err)
> + return err;
> +
> /* initiate reset */
> - timeout = 100000;
> wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
> while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --timeout)
> cpu_relax();
> --
> 2.25.1


2023-03-10 10:39:41

by Meenakshi Aggarwal

[permalink] [raw]
Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook

Hi Herbert,

If you have no comments then please apply the patch

> -----Original Message-----
> From: Meenakshi Aggarwal <[email protected]>
> Sent: Wednesday, March 1, 2023 11:09 AM
> To: Pankaj Gupta <[email protected]>; Vijay Balakrishna
> <[email protected]>; Horia Geanta <[email protected]>; Varun
> Sethi <[email protected]>; Gaurav Jain <[email protected]>;
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; Franck Lenormand
> <[email protected]>
> Cc: [email protected]
> Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook
>
> Copyright updated in another patch and sent v2, both patches are modifying
> same file so no need to make any changes in this patch.
>
> > -----Original Message-----
> > From: Pankaj Gupta <[email protected]>
> > Sent: Monday, February 27, 2023 1:03 PM
> > To: Vijay Balakrishna <[email protected]>; Meenakshi Aggarwal
> > <[email protected]>; Horia Geanta <[email protected]>;
> > Varun Sethi <[email protected]>; Gaurav Jain <[email protected]>;
> > [email protected]; [email protected]; linux-
> > [email protected]; [email protected]; Franck Lenormand
> > <[email protected]>
> > Cc: [email protected]
> > Subject: RE: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add
> > .shutdown hook
> >
> > Change the year in the License header.
> >
> > After changing, you can add the reviewed by me.
> > Reviewed-By: Pankaj Gupta <[email protected]>
> >
> > > -----Original Message-----
> > > From: Vijay Balakrishna <[email protected]>
> > > Sent: Tuesday, February 21, 2023 11:02 PM
> > > To: Meenakshi Aggarwal <[email protected]>; Horia Geanta
> > > <[email protected]>; Varun Sethi <[email protected]>; Pankaj Gupta
> > > <[email protected]>; Gaurav Jain <[email protected]>;
> > > [email protected]; [email protected]; linux-
> > > [email protected]; [email protected]; Franck
> > > Lenormand <[email protected]>
> > > Cc: [email protected]
> > > Subject: [EXT] Re: [PATCH] drivers: crypto: caam: jr: add .shutdown
> > > hook
> > >
> > > Caution: EXT Email
> > >
> > > On 2/20/2023 9:40 PM, [email protected] wrote:
> > > > From: Gaurav Jain <[email protected]>
> > > >
> > > > add .shutdown hook in caam_jr driver to support kexec boot
> > > >
> > > > Signed-off-by: Gaurav Jain <[email protected]>
> > >
> > > Tested-by: Vijay Balakrishna <[email protected]>
> > >
> > > Thanks,
> > > Vijay
> > >
> > > > ---
> > > > drivers/crypto/caam/jr.c | 6 ++++++
> > > > 1 file changed, 6 insertions(+)
> > > >
> > > > diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> > > > index 8745fe3cb575..a2a99d09b4ad 100644
> > > > --- a/drivers/crypto/caam/jr.c
> > > > +++ b/drivers/crypto/caam/jr.c
> > > > @@ -198,6 +198,11 @@ static int caam_jr_remove(struct
> > > > platform_device
> > > *pdev)
> > > > return ret;
> > > > }
> > > >
> > > > +static void caam_jr_platform_shutdown(struct platform_device *pdev) {
> > > > + caam_jr_remove(pdev);
> > > > +}
> > > > +
> > > > /* Main per-ring interrupt handler */
> > > > static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
> > > > {
> > > > @@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
> > > > },
> > > > .probe = caam_jr_probe,
> > > > .remove = caam_jr_remove,
> > > > + .shutdown = caam_jr_platform_shutdown,
> > > > };
> > > >
> > > > static int __init jr_driver_init(void)

2023-03-10 10:53:46

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] drivers: crypto: caam: jr: add .shutdown hook

On Tue, Feb 21, 2023 at 11:10:47AM +0530, [email protected] wrote:
>
> @@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
> },
> .probe = caam_jr_probe,
> .remove = caam_jr_remove,
> + .shutdown = caam_jr_platform_shutdown,

Please make your new addition line up with the rest of the code.

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2023-03-10 11:32:24

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] drivers: crypto: caam: jr: Allow quiesce when quiesced

On Wed, Mar 01, 2023 at 12:07:58AM +0530, [email protected] wrote:
> From: Horia Geanta <[email protected]>
>
> Issues:
> - Job ring device is busy when do kexec reboot
> - Failed to flush job ring when do system suspend-resume
>
> Fix:
> Flush the job ring to stop the running jobs.
>
> Signed-off-by: Horia Geanta <[email protected]>
> Signed-off-by: Franck LENORMAND <[email protected]>
> Reviewed-by: Pankaj Gupta <[email protected]>
> ---
> drivers/crypto/caam/jr.c | 55 ++++++++++++++++++++++++++++++++--------
> 1 file changed, 45 insertions(+), 10 deletions(-)

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2023-03-11 08:26:13

by Meenakshi Aggarwal

[permalink] [raw]
Subject: [PATCH] drivers: crypto: caam: jr: add .shutdown hook

From: Gaurav Jain <[email protected]>

add .shutdown hook in caam_jr driver to support kexec boot

Signed-off-by: Gaurav Jain <[email protected]>
Tested-by: Vijay Balakrishna <[email protected]>
Reviewed-by: Pankaj Gupta <[email protected]>
---
drivers/crypto/caam/jr.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 724fdec18bf9..ca5b49ea3821 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -163,6 +163,11 @@ static int caam_jr_remove(struct platform_device *pdev)
return ret;
}

+static void caam_jr_platform_shutdown(struct platform_device *pdev)
+{
+ caam_jr_remove(pdev);
+}
+
/* Main per-ring interrupt handler */
static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
{
@@ -618,6 +623,7 @@ static struct platform_driver caam_jr_driver = {
},
.probe = caam_jr_probe,
.remove = caam_jr_remove,
+ .shutdown = caam_jr_platform_shutdown,
};

static int __init jr_driver_init(void)
--
2.25.1


2023-03-16 06:08:06

by Meenakshi Aggarwal

[permalink] [raw]
Subject: [PATCH v2] drivers: crypto: caam: jr: add .shutdown hook

From: Gaurav Jain <[email protected]>

add .shutdown hook in caam_jr driver to support kexec boot

Signed-off-by: Gaurav Jain <[email protected]>
Tested-by: Vijay Balakrishna <[email protected]>
Reviewed-by: Pankaj Gupta <[email protected]>
---

changes in v2:
- corrected alignment

drivers/crypto/caam/jr.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 8745fe3cb575..28aef9ba8eac 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -198,6 +198,11 @@ static int caam_jr_remove(struct platform_device *pdev)
return ret;
}

+static void caam_jr_platform_shutdown(struct platform_device *pdev)
+{
+ caam_jr_remove(pdev);
+}
+
/* Main per-ring interrupt handler */
static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
{
@@ -653,6 +658,7 @@ static struct platform_driver caam_jr_driver = {
},
.probe = caam_jr_probe,
.remove = caam_jr_remove,
+ .shutdown = caam_jr_platform_shutdown,
};

static int __init jr_driver_init(void)
--
2.25.1


2023-03-24 10:31:25

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v2] drivers: crypto: caam: jr: add .shutdown hook

On Thu, Mar 16, 2023 at 11:37:34AM +0530, [email protected] wrote:
> From: Gaurav Jain <[email protected]>
>
> add .shutdown hook in caam_jr driver to support kexec boot
>
> Signed-off-by: Gaurav Jain <[email protected]>
> Tested-by: Vijay Balakrishna <[email protected]>
> Reviewed-by: Pankaj Gupta <[email protected]>
> ---
>
> changes in v2:
> - corrected alignment
>
> drivers/crypto/caam/jr.c | 6 ++++++
> 1 file changed, 6 insertions(+)

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt