From patchwork Wed Nov 20 15:28:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 179859 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp2255618ilf; Wed, 20 Nov 2019 07:28:47 -0800 (PST) X-Google-Smtp-Source: APXvYqw+0Q4xuzFQm4s6zG1zliPKCF3EuGMBRZkyzuyh6xSTJTLrsZVyVaSwdxu9zdxhXIIFyZTL X-Received: by 2002:a17:906:4a43:: with SMTP id a3mr5897053ejv.311.1574263727492; Wed, 20 Nov 2019 07:28:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574263727; cv=none; d=google.com; s=arc-20160816; b=Acm4LVYffl5pqWdtt2cbGRH5uYanAu92EkN0nlV6TOHKMfA7f8YgeNY5vQS17iFv91 2huoL191vSo68v68an/y92IUCmLTKB0Tou0nBl/gdGWO2vV1sKbc47vjqPdZN0CdEf39 +uWMkmtmQYav6Quu3QsqQ8r3QkkB+MGT3V5dlc83w3sX+WhH2p0U9jgKwSZEYEgbX63n sghtQYgzG7onGs9fRr2eCOXUYXtCPaRuzKRKD6KPdG3ovGShR/zs11mK3q8ZF+YhZSFh 4bNKmBfH1rySokFkrttBjMSNPyS8uC+Igj02iwmqKmcoVwGayiILZJybd3MWMBf6vZLo W4+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VocVwERuj9CPUxI4LlG88AIMpkiR3wTIlIVCNMEfFWI=; b=nnuIXySyAsnajF+FgYELx1ulNwU0biL5zVIw6cHusO/XRuQLVPWW/1D93SxDfvYmVv ezNBhKTgf6euPWZld2Ny+IcqjoRHCqpTKeRUSyTWuw92Ii3G06sQhOP78fUWqPVixdmc pv0lEOqz39/YHRtQ66cTmaEptCCws85nV1fb6LrckBqDCkDFq5WqaUAKJucO9ojuqayR vYPE1+6L9TKKVX+K0sFxOd0icEcv2UYDN6tGpMSKGt5jp8bk1mSLpUAZVdXF1umq3P4i ddywIEdhpQAMfJiZhpCWOTYSBzWfllo/jawgmR9icftEWZhE10f0n48vny/AJIt6AYSb qsPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XGKqvA+f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si16283076ejk.81.2019.11.20.07.28.47; Wed, 20 Nov 2019 07:28:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XGKqvA+f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731258AbfKTP2p (ORCPT + 26 others); Wed, 20 Nov 2019 10:28:45 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:32834 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731187AbfKTP2n (ORCPT ); Wed, 20 Nov 2019 10:28:43 -0500 Received: by mail-wr1-f67.google.com with SMTP id w9so330952wrr.0; Wed, 20 Nov 2019 07:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VocVwERuj9CPUxI4LlG88AIMpkiR3wTIlIVCNMEfFWI=; b=XGKqvA+ftxeRIcTzRVR4iuKmoi0AoZftMzZznXbgI5lelIgfWtxFTXOkD40mmkJ0Yf 3F22LKumE86iAiZTdZP9sXgCKJowSPQEsszkhBRjtK2jKvfNZs3OcEhztgLYz9fCFYp7 FnRHXFhQTryMUWMHjF0jTxnuAMZ2bstdrHVNWQ3W5lOFj9A9vvJaoqPze3uXdJv0ZmY2 mVwxXHdA1kLLCy3FUnm+bNMrbOJ1Y8j0zdYzuYaQfcsoEF6V9j30lKqT3qf7x386q9pE uxwFmMwjNZKgba0UBhp6ZUEYCnk6EbEO2y9/cY8a//79YUOfCNXm2QqjQ3wj+jqWzPZt Q58g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VocVwERuj9CPUxI4LlG88AIMpkiR3wTIlIVCNMEfFWI=; b=lVU6/Gh4mAzBdN5p24+cARWJIpUG0mv25m7hwt6z86dKiTDhD7YvRSdQxPZeKn+Hae TSoxf6NI0elbnh/Q/CiyVRyySnidjFGVrooqn8qwRL7b8OdQuYUhgNtjHbZpyjUNugoF +V/5X3j891RlWoRBSydWAUQ8fOjtCJ6Nc7CFJ6DSnYv46EsyIZVNAVh3n3bcetWtJPTJ 5QGUpg+id9SHlv0Dglz0vKYpyIansPHqadO6se67dJzJPz0MWcUnoZEr3cqzN6LWm4yZ NTf9Vvmx9H27GCcSHLxGaE8GIadjQldqL6wZRiDbbgV5cO74gVded2uHgbnlQglNoGFD AcEQ== X-Gm-Message-State: APjAAAW8yVTTQhs7Fsb7BdFRVquXNtPWlJlkkieC6omI9NfruJfzBIX6 hPaHHjOP6Ub18/wpYoGKvnM5FTft X-Received: by 2002:a5d:4b82:: with SMTP id b2mr4032387wrt.335.1574263721112; Wed, 20 Nov 2019 07:28:41 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id w4sm31797881wrs.1.2019.11.20.07.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2019 07:28:40 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, mark.rutland@arm.com, mripard@kernel.org, robh+dt@kernel.org, wens@csie.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v2 3/3] crypto: sun4i-ss: add the A33 variant of SS Date: Wed, 20 Nov 2019 16:28:33 +0100 Message-Id: <20191120152833.20443-4-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191120152833.20443-1-clabbe.montjoie@gmail.com> References: <20191120152833.20443-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Signed-off-by: Corentin Labbe --- .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++- .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++- drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) -- 2.23.0 diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c index 814cd12149a9..d35a05843c22 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,14 @@ #include "sun4i-ss.h" +static const struct ss_variant ss_a10_variant = { + .sha1_in_be = false, +}; + +static const struct ss_variant ss_a33_variant = { + .sha1_in_be = true, +}; + static struct sun4i_ss_alg_template ss_algs[] = { { .type = CRYPTO_ALG_TYPE_AHASH, .mode = SS_OP_MD5, @@ -323,6 +332,12 @@ static int sun4i_ss_probe(struct platform_device *pdev) return PTR_ERR(ss->base); } + ss->variant = of_device_get_match_data(&pdev->dev); + if (!ss->variant) { + dev_err(&pdev->dev, "Missing Security System variant\n"); + return -EINVAL; + } + ss->ssclk = devm_clk_get(&pdev->dev, "mod"); if (IS_ERR(ss->ssclk)) { err = PTR_ERR(ss->ssclk); @@ -484,7 +499,12 @@ static int sun4i_ss_remove(struct platform_device *pdev) } static const struct of_device_id a20ss_crypto_of_match_table[] = { - { .compatible = "allwinner,sun4i-a10-crypto" }, + { .compatible = "allwinner,sun4i-a10-crypto", + .data = &ss_a10_variant + }, + { .compatible = "allwinner,sun8i-a33-crypto", + .data = &ss_a33_variant + }, {} }; MODULE_DEVICE_TABLE(of, a20ss_crypto_of_match_table); diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c index 91cf58db3845..c791d6935c65 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c @@ -478,7 +478,10 @@ static int sun4i_hash(struct ahash_request *areq) /* Get the hash from the device */ if (op->mode == SS_OP_SHA1) { for (i = 0; i < 5; i++) { - v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4)); + if (ss->variant->sha1_in_be) + v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4)); + else + v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4)); memcpy(areq->result + i * 4, &v, 4); } } else { diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h index 60425ac75d90..2b4c6333eb67 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -131,7 +131,16 @@ #define SS_SEED_LEN 192 #define SS_DATA_LEN 160 +/* + * struct ss_variant - Describe SS hardware variant + * @sha1_in_be: The SHA1 digest is given by SS in BE, and so need to be inverted. + */ +struct ss_variant { + bool sha1_in_be; +}; + struct sun4i_ss_ctx { + const struct ss_variant *variant; void __iomem *base; int irq; struct clk *busclk;