Skip to content

Commit 1e02e6f

Browse files
montjoieherbertx
authored andcommitted
crypto: sun4i-ss - add the A33 variant of SS
The A33 SS has a difference with all other SS, it give SHA1 digest directly in BE. So this patch adds variant support in sun4i-ss. Fixes: 6298e94 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Signed-off-by: Corentin Labbe <[email protected]> Acked-by: Maxime Ripard <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 6b3413f commit 1e02e6f

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/io.h>
1414
#include <linux/module.h>
1515
#include <linux/of.h>
16+
#include <linux/of_device.h>
1617
#include <linux/platform_device.h>
1718
#include <crypto/scatterwalk.h>
1819
#include <linux/scatterlist.h>
@@ -22,6 +23,14 @@
2223

2324
#include "sun4i-ss.h"
2425

26+
static const struct ss_variant ss_a10_variant = {
27+
.sha1_in_be = false,
28+
};
29+
30+
static const struct ss_variant ss_a33_variant = {
31+
.sha1_in_be = true,
32+
};
33+
2534
static struct sun4i_ss_alg_template ss_algs[] = {
2635
{ .type = CRYPTO_ALG_TYPE_AHASH,
2736
.mode = SS_OP_MD5,
@@ -323,6 +332,12 @@ static int sun4i_ss_probe(struct platform_device *pdev)
323332
return PTR_ERR(ss->base);
324333
}
325334

335+
ss->variant = of_device_get_match_data(&pdev->dev);
336+
if (!ss->variant) {
337+
dev_err(&pdev->dev, "Missing Security System variant\n");
338+
return -EINVAL;
339+
}
340+
326341
ss->ssclk = devm_clk_get(&pdev->dev, "mod");
327342
if (IS_ERR(ss->ssclk)) {
328343
err = PTR_ERR(ss->ssclk);
@@ -484,7 +499,12 @@ static int sun4i_ss_remove(struct platform_device *pdev)
484499
}
485500

486501
static const struct of_device_id a20ss_crypto_of_match_table[] = {
487-
{ .compatible = "allwinner,sun4i-a10-crypto" },
502+
{ .compatible = "allwinner,sun4i-a10-crypto",
503+
.data = &ss_a10_variant
504+
},
505+
{ .compatible = "allwinner,sun8i-a33-crypto",
506+
.data = &ss_a33_variant
507+
},
488508
{}
489509
};
490510
MODULE_DEVICE_TABLE(of, a20ss_crypto_of_match_table);

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ static int sun4i_hash(struct ahash_request *areq)
479479
/* Get the hash from the device */
480480
if (op->mode == SS_OP_SHA1) {
481481
for (i = 0; i < 5; i++) {
482-
v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
482+
if (ss->variant->sha1_in_be)
483+
v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
484+
else
485+
v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
483486
memcpy(areq->result + i * 4, &v, 4);
484487
}
485488
} else {

drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,16 @@
131131
#define SS_SEED_LEN 192
132132
#define SS_DATA_LEN 160
133133

134+
/*
135+
* struct ss_variant - Describe SS hardware variant
136+
* @sha1_in_be: The SHA1 digest is given by SS in BE, and so need to be inverted.
137+
*/
138+
struct ss_variant {
139+
bool sha1_in_be;
140+
};
141+
134142
struct sun4i_ss_ctx {
143+
const struct ss_variant *variant;
135144
void __iomem *base;
136145
int irq;
137146
struct clk *busclk;

0 commit comments

Comments
 (0)