linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622
@ 2017-06-12 15:56 sean.wang at mediatek.com
  2017-06-12 15:56 ` [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings sean.wang at mediatek.com
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: sean.wang at mediatek.com @ 2017-06-12 15:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Sean Wang <sean.wang@mediatek.com>

Changes since v1:
- update the bindings with the specific "mediatek,mt7622-rng"
  instead of the generic one as "mediatek,generic-rng"

The series add support of hardware RNG on MediaTek MT7622 and
, runtime PM support and add me as the maintainer for the existing
and following chipset.

Sean Wang (3):
  dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator
    bindings
  hwrng: mtk - add runtime PM support
  MAINTAINERS: add entry for MediaTek Random Number Generator

 Documentation/devicetree/bindings/rng/mtk-rng.txt |  4 ++-
 MAINTAINERS                                       |  5 +++
 drivers/char/hw_random/mtk-rng.c                  | 42 +++++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

-- 
1.9.1

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

* [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings
  2017-06-12 15:56 [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 sean.wang at mediatek.com
@ 2017-06-12 15:56 ` sean.wang at mediatek.com
  2017-06-13  9:39   ` Matthias Brugger
  2017-06-18 14:04   ` Rob Herring
  2017-06-12 15:56 ` [PATCH v2 2/3] hwrng: mtk - add runtime PM support sean.wang at mediatek.com
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: sean.wang at mediatek.com @ 2017-06-12 15:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Sean Wang <sean.wang@mediatek.com>

Document the bindings used by MediaTek MT7622 SoC hardware random number
generator.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 Documentation/devicetree/bindings/rng/mtk-rng.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/rng/mtk-rng.txt b/Documentation/devicetree/bindings/rng/mtk-rng.txt
index a6d62a2..366b99b 100644
--- a/Documentation/devicetree/bindings/rng/mtk-rng.txt
+++ b/Documentation/devicetree/bindings/rng/mtk-rng.txt
@@ -2,7 +2,9 @@ Device-Tree bindings for Mediatek random number generator
 found in Mediatek SoC family
 
 Required properties:
-- compatible	    : Should be "mediatek,mt7623-rng"
+- compatible	    : Should be
+			"mediatek,mt7622-rng", 	"mediatek,mt7623-rng" : for MT7622
+			"mediatek,mt7623-rng" : for MT7623
 - clocks	    : list of clock specifiers, corresponding to
 		      entries in clock-names property;
 - clock-names	    : Should contain "rng" entries;
-- 
1.9.1

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

* [PATCH v2 2/3] hwrng: mtk - add runtime PM support
  2017-06-12 15:56 [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 sean.wang at mediatek.com
  2017-06-12 15:56 ` [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings sean.wang at mediatek.com
@ 2017-06-12 15:56 ` sean.wang at mediatek.com
  2017-06-12 15:56 ` [PATCH v2 3/3] MAINTAINERS: add entry for MediaTek Random Number Generator sean.wang at mediatek.com
  2017-06-20  3:40 ` [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 Herbert Xu
  3 siblings, 0 replies; 10+ messages in thread
From: sean.wang at mediatek.com @ 2017-06-12 15:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Sean Wang <sean.wang@mediatek.com>

Add runtime PM support.  There will be the benefit on SoCs where the
clock to the RNG used can be shutdown.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/char/hw_random/mtk-rng.c | 42 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
index df8eb54..8da7bcf 100644
--- a/drivers/char/hw_random/mtk-rng.c
+++ b/drivers/char/hw_random/mtk-rng.c
@@ -25,6 +25,10 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+
+/* Runtime PM autosuspend timeout: */
+#define RNG_AUTOSUSPEND_TIMEOUT		100
 
 #define USEC_POLL			2
 #define TIMEOUT_POLL			20
@@ -90,6 +94,8 @@ static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
 	struct mtk_rng *priv = to_mtk_rng(rng);
 	int retval = 0;
 
+	pm_runtime_get_sync((struct device *)priv->rng.priv);
+
 	while (max >= sizeof(u32)) {
 		if (!mtk_rng_wait_ready(rng, wait))
 			break;
@@ -100,6 +106,9 @@ static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
 		max -= sizeof(u32);
 	}
 
+	pm_runtime_mark_last_busy((struct device *)priv->rng.priv);
+	pm_runtime_put_sync_autosuspend((struct device *)priv->rng.priv);
+
 	return retval || !wait ? retval : -EIO;
 }
 
@@ -120,9 +129,12 @@ static int mtk_rng_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	priv->rng.name = pdev->name;
+#ifndef CONFIG_PM
 	priv->rng.init = mtk_rng_init;
 	priv->rng.cleanup = mtk_rng_cleanup;
+#endif
 	priv->rng.read = mtk_rng_read;
+	priv->rng.priv = (unsigned long)&pdev->dev;
 
 	priv->clk = devm_clk_get(&pdev->dev, "rng");
 	if (IS_ERR(priv->clk)) {
@@ -142,11 +154,40 @@ static int mtk_rng_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	dev_set_drvdata(&pdev->dev, priv);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, RNG_AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
 	dev_info(&pdev->dev, "registered RNG driver\n");
 
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int mtk_rng_runtime_suspend(struct device *dev)
+{
+	struct mtk_rng *priv = dev_get_drvdata(dev);
+
+	mtk_rng_cleanup(&priv->rng);
+
+	return 0;
+}
+
+static int mtk_rng_runtime_resume(struct device *dev)
+{
+	struct mtk_rng *priv = dev_get_drvdata(dev);
+
+	return mtk_rng_init(&priv->rng);
+}
+
+static UNIVERSAL_DEV_PM_OPS(mtk_rng_pm_ops, mtk_rng_runtime_suspend,
+			    mtk_rng_runtime_resume, NULL);
+#define MTK_RNG_PM_OPS (&mtk_rng_pm_ops)
+#else	/* CONFIG_PM */
+#define MTK_RNG_PM_OPS NULL
+#endif	/* CONFIG_PM */
+
 static const struct of_device_id mtk_rng_match[] = {
 	{ .compatible = "mediatek,mt7623-rng" },
 	{},
@@ -157,6 +198,7 @@ static int mtk_rng_probe(struct platform_device *pdev)
 	.probe          = mtk_rng_probe,
 	.driver = {
 		.name = MTK_RNG_DEV,
+		.pm = MTK_RNG_PM_OPS,
 		.of_match_table = mtk_rng_match,
 	},
 };
-- 
1.9.1

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

* [PATCH v2 3/3] MAINTAINERS: add entry for MediaTek Random Number Generator
  2017-06-12 15:56 [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 sean.wang at mediatek.com
  2017-06-12 15:56 ` [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings sean.wang at mediatek.com
  2017-06-12 15:56 ` [PATCH v2 2/3] hwrng: mtk - add runtime PM support sean.wang at mediatek.com
@ 2017-06-12 15:56 ` sean.wang at mediatek.com
  2017-06-20  3:40 ` [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 Herbert Xu
  3 siblings, 0 replies; 10+ messages in thread
From: sean.wang at mediatek.com @ 2017-06-12 15:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Sean Wang <sean.wang@mediatek.com>

I work for MediaTek on maintaining the MediaTek RNG driver
for the existing SoCs and adding support for the following
SoCs.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index cf86519..da473d0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8262,6 +8262,11 @@ L:	linux-wireless at vger.kernel.org
 S:	Maintained
 F:	drivers/net/wireless/mediatek/mt7601u/
 
+MEDIATEK RANDOM NUMBER GENERATOR SUPPORT
+M:      Sean Wang <sean.wang@mediatek.com>
+S:      Maintained
+F:      drivers/char/hw_random/mtk-rng.c
+
 MEGACHIPS STDPXXXX-GE-B850V3-FW LVDS/DP++ BRIDGES
 M:	Peter Senna Tschudin <peter.senna@collabora.com>
 M:	Martin Donnelly <martin.donnelly@ge.com>
-- 
1.9.1

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

* [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings
  2017-06-12 15:56 ` [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings sean.wang at mediatek.com
@ 2017-06-13  9:39   ` Matthias Brugger
  2017-06-18 14:04   ` Rob Herring
  1 sibling, 0 replies; 10+ messages in thread
From: Matthias Brugger @ 2017-06-13  9:39 UTC (permalink / raw)
  To: linux-arm-kernel



On 12/06/17 17:56, sean.wang at mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Document the bindings used by MediaTek MT7622 SoC hardware random number
> generator.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>   Documentation/devicetree/bindings/rng/mtk-rng.txt | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> diff --git a/Documentation/devicetree/bindings/rng/mtk-rng.txt b/Documentation/devicetree/bindings/rng/mtk-rng.txt
> index a6d62a2..366b99b 100644
> --- a/Documentation/devicetree/bindings/rng/mtk-rng.txt
> +++ b/Documentation/devicetree/bindings/rng/mtk-rng.txt
> @@ -2,7 +2,9 @@ Device-Tree bindings for Mediatek random number generator
>   found in Mediatek SoC family
>   
>   Required properties:
> -- compatible	    : Should be "mediatek,mt7623-rng"
> +- compatible	    : Should be
> +			"mediatek,mt7622-rng", 	"mediatek,mt7623-rng" : for MT7622
> +			"mediatek,mt7623-rng" : for MT7623
>   - clocks	    : list of clock specifiers, corresponding to
>   		      entries in clock-names property;
>   - clock-names	    : Should contain "rng" entries;
> 

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

* [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings
  2017-06-12 15:56 ` [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings sean.wang at mediatek.com
  2017-06-13  9:39   ` Matthias Brugger
@ 2017-06-18 14:04   ` Rob Herring
  1 sibling, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-06-18 14:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jun 12, 2017 at 11:56:54PM +0800, sean.wang at mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Document the bindings used by MediaTek MT7622 SoC hardware random number
> generator.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  Documentation/devicetree/bindings/rng/mtk-rng.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Acked-by: Rob Herring <robh@kernel.org>

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

* [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622
  2017-06-12 15:56 [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 sean.wang at mediatek.com
                   ` (2 preceding siblings ...)
  2017-06-12 15:56 ` [PATCH v2 3/3] MAINTAINERS: add entry for MediaTek Random Number Generator sean.wang at mediatek.com
@ 2017-06-20  3:40 ` Herbert Xu
  2017-06-20 14:21   ` Sean Wang
  3 siblings, 1 reply; 10+ messages in thread
From: Herbert Xu @ 2017-06-20  3:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jun 12, 2017 at 11:56:53PM +0800, sean.wang at mediatek.com wrote:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Changes since v1:
> - update the bindings with the specific "mediatek,mt7622-rng"
>   instead of the generic one as "mediatek,generic-rng"
> 
> The series add support of hardware RNG on MediaTek MT7622 and
> , runtime PM support and add me as the maintainer for the existing
> and following chipset.
> 
> Sean Wang (3):
>   dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator
>     bindings
>   hwrng: mtk - add runtime PM support
>   MAINTAINERS: add entry for MediaTek Random Number Generator

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622
  2017-06-20  3:40 ` [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 Herbert Xu
@ 2017-06-20 14:21   ` Sean Wang
  2017-06-20 14:59     ` Torsten Duwe
  0 siblings, 1 reply; 10+ messages in thread
From: Sean Wang @ 2017-06-20 14:21 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Herbert,

thanks for effort reviewing on those patches.

By the way, also loop in Torsten

Could you kindly guide me how to determine appropriate 
rng->ops.quality value used by the driver?

There is less clues since the value is not being set in
most drivers. But good value decided would allow feeding
fresh entropy data with the hwrng so i would like add it
in the next patch.

I have tested with rngtest on mtk-cir and the result is got as
the below log shown.  If the rngtest always gives the result for
success rate over 99.8%, can I set the rng->ops.quality 998?

rngtest: starting FIPS tests...
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 998
rngtest: FIPS 140-2 failures: 2
rngtest: FIPS 140-2(2001-10-10) Monobit: 1
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 1
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=715.902; avg=3846.234;
max=3906250.000)Kibits/s
rngtest: FIPS tests speed: (min=35.453; avg=37.862; max=38.300)Mibits/s
rngtest: Program run time: 5591758 microseconds

rngtest: starting FIPS tests...
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 1000
rngtest: FIPS 140-2 failures: 0
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 0
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=715.588; avg=4424.787;
max=4882812.500)Kibits/s
rngtest: FIPS tests speed: (min=35.785; avg=37.859; max=38.223)Mibits/s
rngtest: Program run time: 4947950 microseconds



On Tue, 2017-06-20 at 11:40 +0800, Herbert Xu wrote:
> On Mon, Jun 12, 2017 at 11:56:53PM +0800, sean.wang at mediatek.com wrote:
> > From: Sean Wang <sean.wang@mediatek.com>
> > 
> > Changes since v1:
> > - update the bindings with the specific "mediatek,mt7622-rng"
> >   instead of the generic one as "mediatek,generic-rng"
> > 
> > The series add support of hardware RNG on MediaTek MT7622 and
> > , runtime PM support and add me as the maintainer for the existing
> > and following chipset.
> > 
> > Sean Wang (3):
> >   dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator
> >     bindings
> >   hwrng: mtk - add runtime PM support
> >   MAINTAINERS: add entry for MediaTek Random Number Generator
> 
> All applied.  Thanks.

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

* [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622
  2017-06-20 14:21   ` Sean Wang
@ 2017-06-20 14:59     ` Torsten Duwe
  2017-06-20 16:08       ` Sean Wang
  0 siblings, 1 reply; 10+ messages in thread
From: Torsten Duwe @ 2017-06-20 14:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jun 20, 2017 at 10:21:17PM +0800, Sean Wang wrote:
> Hi Herbert,
> 
> thanks for effort reviewing on those patches.
> 
> By the way, also loop in Torsten
> 
> Could you kindly guide me how to determine appropriate 
> rng->ops.quality value used by the driver?
> 
> I have tested with rngtest on mtk-cir and the result is got as
> the below log shown.  If the rngtest always gives the result for
> success rate over 99.8%, can I set the rng->ops.quality 998?
> 
> rngtest: starting FIPS tests...
> rngtest: bits received from input: 20000032
> rngtest: FIPS 140-2 successes: 998
> rngtest: FIPS 140-2 failures: 2

No! You'd have to determine the failure threshold of the test and
apply some math to find a lower boundary of your RNG's entropy.

What the quality is for: your RNG produces bits, but not all of them
are completely independent of each other i.e. not completely random.
So you simply lower the quality rating to express the net entropy
contained in the data stream.

	Torsten

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

* [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622
  2017-06-20 14:59     ` Torsten Duwe
@ 2017-06-20 16:08       ` Sean Wang
  0 siblings, 0 replies; 10+ messages in thread
From: Sean Wang @ 2017-06-20 16:08 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 2017-06-20 at 16:59 +0200, Torsten Duwe wrote:
> On Tue, Jun 20, 2017 at 10:21:17PM +0800, Sean Wang wrote:
> > Hi Herbert,
> > 
> > thanks for effort reviewing on those patches.
> > 
> > By the way, also loop in Torsten
> > 
> > Could you kindly guide me how to determine appropriate 
> > rng->ops.quality value used by the driver?
> > 
> > I have tested with rngtest on mtk-cir and the result is got as
> > the below log shown.  If the rngtest always gives the result for
> > success rate over 99.8%, can I set the rng->ops.quality 998?
> > 
> > rngtest: starting FIPS tests...
> > rngtest: bits received from input: 20000032
> > rngtest: FIPS 140-2 successes: 998
> > rngtest: FIPS 140-2 failures: 2
> 
> No! You'd have to determine the failure threshold of the test and
> apply some math to find a lower boundary of your RNG's entropy.
> 
> What the quality is for: your RNG produces bits, but not all of them
> are completely independent of each other i.e. not completely random.
> So you simply lower the quality rating to express the net entropy
> contained in the data stream.
> 
> 	Torsten
> 


Hi Torsten,

Understood, appreciate your quick and clear explanation.
 
For the math, is there existing any well-known or recommended
open source software assisting identify the lower boundary of
RNG entropy? I think the logic should be common for all RNGs.

thanks again

	Sean


	Sean

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

end of thread, other threads:[~2017-06-20 16:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 15:56 [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 sean.wang at mediatek.com
2017-06-12 15:56 ` [PATCH v2 1/3] dt-bindings: rng: add MediaTek MT7622 Hardware Random Generator bindings sean.wang at mediatek.com
2017-06-13  9:39   ` Matthias Brugger
2017-06-18 14:04   ` Rob Herring
2017-06-12 15:56 ` [PATCH v2 2/3] hwrng: mtk - add runtime PM support sean.wang at mediatek.com
2017-06-12 15:56 ` [PATCH v2 3/3] MAINTAINERS: add entry for MediaTek Random Number Generator sean.wang at mediatek.com
2017-06-20  3:40 ` [PATCH v2 0/3] add support of hardware random generator on MediaTek MT7622 Herbert Xu
2017-06-20 14:21   ` Sean Wang
2017-06-20 14:59     ` Torsten Duwe
2017-06-20 16:08       ` Sean Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).