summaryrefslogtreecommitdiff
path: root/drivers/crypto/hisilicon
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2023-06-30 21:27:13 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2023-06-30 21:27:13 -0700
commit5d95ff84e62be914b4a4dabfa814e4096b05b1b0 (patch)
treef2d79d562971025b29deab50bb06e3b865f185b3 /drivers/crypto/hisilicon
parentd85a143b69abb4d7544227e26d12c4c7735ab27d (diff)
parent486bfb05913ac9969a3a71a4dc48f17f31cb162d (diff)
Merge tag 'v6.5-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto updates from Herbert Xu: "API: - Add linear akcipher/sig API - Add tfm cloning (hmac, cmac) - Add statesize to crypto_ahash Algorithms: - Allow only odd e and restrict value in FIPS mode for RSA - Replace LFSR with SHA3-256 in jitter - Add interface for gathering of raw entropy in jitter Drivers: - Fix race on data_avail and actual data in hwrng/virtio - Add hash and HMAC support in starfive - Add RSA algo support in starfive - Add support for PCI device 0x156E in ccp" * tag 'v6.5-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (85 commits) crypto: akcipher - Do not copy dst if it is NULL crypto: sig - Fix verify call crypto: akcipher - Set request tfm on sync path crypto: sm2 - Provide sm2_compute_z_digest when sm2 is disabled hwrng: imx-rngc - switch to DEFINE_SIMPLE_DEV_PM_OPS hwrng: st - keep clock enabled while hwrng is registered hwrng: st - support compile-testing hwrng: imx-rngc - fix the timeout for init and self check KEYS: asymmetric: Use new crypto interface without scatterlists KEYS: asymmetric: Move sm2 code into x509_public_key KEYS: Add forward declaration in asymmetric-parser.h crypto: sig - Add interface for sign/verify crypto: akcipher - Add sync interface without SG lists crypto: cipher - On clone do crypto_mod_get() crypto: api - Add __crypto_alloc_tfmgfp crypto: api - Remove crypto_init_ops() crypto: rsa - allow only odd e and restrict value in FIPS mode crypto: geniv - Split geniv out of AEAD Kconfig option crypto: algboss - Add missing dependency on RNG2 crypto: starfive - Add RSA algo support ...
Diffstat (limited to 'drivers/crypto/hisilicon')
-rw-r--r--drivers/crypto/hisilicon/Kconfig7
-rw-r--r--drivers/crypto/hisilicon/Makefile2
-rw-r--r--drivers/crypto/hisilicon/trng/Makefile3
-rw-r--r--drivers/crypto/hisilicon/trng/trng-stb.c176
4 files changed, 1 insertions, 187 deletions
diff --git a/drivers/crypto/hisilicon/Kconfig b/drivers/crypto/hisilicon/Kconfig
index e8690c223584..4137a8bf131f 100644
--- a/drivers/crypto/hisilicon/Kconfig
+++ b/drivers/crypto/hisilicon/Kconfig
@@ -82,10 +82,3 @@ config CRYPTO_DEV_HISI_TRNG
select CRYPTO_RNG
help
Support for HiSilicon TRNG Driver.
-
-config CRYPTO_DEV_HISTB_TRNG
- tristate "Support for HiSTB TRNG Driver"
- depends on ARCH_HISI || COMPILE_TEST
- select HW_RANDOM
- help
- Support for HiSTB TRNG Driver.
diff --git a/drivers/crypto/hisilicon/Makefile b/drivers/crypto/hisilicon/Makefile
index fc51e0edec69..8595a5a5d228 100644
--- a/drivers/crypto/hisilicon/Makefile
+++ b/drivers/crypto/hisilicon/Makefile
@@ -5,4 +5,4 @@ obj-$(CONFIG_CRYPTO_DEV_HISI_SEC2) += sec2/
obj-$(CONFIG_CRYPTO_DEV_HISI_QM) += hisi_qm.o
hisi_qm-objs = qm.o sgl.o debugfs.o
obj-$(CONFIG_CRYPTO_DEV_HISI_ZIP) += zip/
-obj-y += trng/
+obj-$(CONFIG_CRYPTO_DEV_HISI_TRNG) += trng/
diff --git a/drivers/crypto/hisilicon/trng/Makefile b/drivers/crypto/hisilicon/trng/Makefile
index cf20b057c66b..d909079f351c 100644
--- a/drivers/crypto/hisilicon/trng/Makefile
+++ b/drivers/crypto/hisilicon/trng/Makefile
@@ -1,5 +1,2 @@
obj-$(CONFIG_CRYPTO_DEV_HISI_TRNG) += hisi-trng-v2.o
hisi-trng-v2-objs = trng.o
-
-obj-$(CONFIG_CRYPTO_DEV_HISTB_TRNG) += histb-trng.o
-histb-trng-objs += trng-stb.o
diff --git a/drivers/crypto/hisilicon/trng/trng-stb.c b/drivers/crypto/hisilicon/trng/trng-stb.c
deleted file mode 100644
index 29200a7d3d81..000000000000
--- a/drivers/crypto/hisilicon/trng/trng-stb.c
+++ /dev/null
@@ -1,176 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
-/*
- * Device driver for True RNG in HiSTB SoCs
- *
- * Copyright (c) 2023 David Yang
- */
-
-#include <crypto/internal/rng.h>
-#include <linux/device.h>
-#include <linux/err.h>
-#include <linux/hw_random.h>
-#include <linux/io.h>
-#include <linux/iopoll.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/of_device.h>
-
-#define HISTB_TRNG_CTRL 0x0
-#define RNG_SOURCE GENMASK(1, 0)
-#define DROP_ENABLE BIT(5)
-#define POST_PROCESS_ENABLE BIT(7)
-#define POST_PROCESS_DEPTH GENMASK(15, 8)
-#define HISTB_TRNG_NUMBER 0x4
-#define HISTB_TRNG_STAT 0x8
-#define DATA_COUNT GENMASK(2, 0) /* max 4 */
-
-struct histb_trng_priv {
- struct hwrng rng;
- void __iomem *base;
-};
-
-/*
- * Observed:
- * depth = 1 -> ~1ms
- * depth = 255 -> ~16ms
- */
-static int histb_trng_wait(void __iomem *base)
-{
- u32 val;
-
- return readl_relaxed_poll_timeout(base + HISTB_TRNG_STAT, val,
- val & DATA_COUNT, 1000, 30 * 1000);
-}
-
-static void histb_trng_init(void __iomem *base, unsigned int depth)
-{
- u32 val;
-
- val = readl_relaxed(base + HISTB_TRNG_CTRL);
-
- val &= ~RNG_SOURCE;
- val |= 2;
-
- val &= ~POST_PROCESS_DEPTH;
- val |= min(depth, 0xffu) << 8;
-
- val |= POST_PROCESS_ENABLE;
- val |= DROP_ENABLE;
-
- writel_relaxed(val, base + HISTB_TRNG_CTRL);
-}
-
-static int histb_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
-{
- struct histb_trng_priv *priv = container_of(rng, typeof(*priv), rng);
- void __iomem *base = priv->base;
-
- for (int i = 0; i < max; i += sizeof(u32)) {
- if (!(readl_relaxed(base + HISTB_TRNG_STAT) & DATA_COUNT)) {
- if (!wait)
- return i;
- if (histb_trng_wait(base)) {
- pr_err("failed to generate random number, generated %d\n",
- i);
- return i ? i : -ETIMEDOUT;
- }
- }
- *(u32 *) (data + i) = readl_relaxed(base + HISTB_TRNG_NUMBER);
- }
-
- return max;
-}
-
-static unsigned int histb_trng_get_depth(void __iomem *base)
-{
- return (readl_relaxed(base + HISTB_TRNG_CTRL) & POST_PROCESS_DEPTH) >> 8;
-}
-
-static ssize_t
-depth_show(struct device *dev, struct device_attribute *attr, char *buf)
-{
- struct histb_trng_priv *priv = dev_get_drvdata(dev);
- void __iomem *base = priv->base;
-
- return sprintf(buf, "%d\n", histb_trng_get_depth(base));
-}
-
-static ssize_t
-depth_store(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct histb_trng_priv *priv = dev_get_drvdata(dev);
- void __iomem *base = priv->base;
- unsigned int depth;
-
- if (kstrtouint(buf, 0, &depth))
- return -ERANGE;
-
- histb_trng_init(base, depth);
- return count;
-}
-
-static DEVICE_ATTR_RW(depth);
-
-static struct attribute *histb_trng_attrs[] = {
- &dev_attr_depth.attr,
- NULL,
-};
-
-ATTRIBUTE_GROUPS(histb_trng);
-
-static int histb_trng_probe(struct platform_device *pdev)
-{
- struct device *dev = &pdev->dev;
- struct histb_trng_priv *priv;
- void __iomem *base;
- int ret;
-
- priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
- if (!priv)
- return -ENOMEM;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return -ENOMEM;
-
- histb_trng_init(base, 144);
- if (histb_trng_wait(base)) {
- dev_err(dev, "cannot bring up device\n");
- return -ENODEV;
- }
-
- priv->base = base;
- priv->rng.name = pdev->name;
- priv->rng.read = histb_trng_read;
- ret = devm_hwrng_register(dev, &priv->rng);
- if (ret) {
- dev_err(dev, "failed to register hwrng: %d\n", ret);
- return ret;
- }
-
- platform_set_drvdata(pdev, priv);
- dev_set_drvdata(dev, priv);
- return 0;
-}
-
-static const struct of_device_id histb_trng_of_match[] = {
- { .compatible = "hisilicon,histb-trng", },
- { }
-};
-
-static struct platform_driver histb_trng_driver = {
- .probe = histb_trng_probe,
- .driver = {
- .name = "histb-trng",
- .of_match_table = histb_trng_of_match,
- .dev_groups = histb_trng_groups,
- },
-};
-
-module_platform_driver(histb_trng_driver);
-
-MODULE_DESCRIPTION("HiSTB True RNG");
-MODULE_LICENSE("Dual MIT/GPL");
-MODULE_AUTHOR("David Yang <mmyangfl@gmail.com>");