From patchwork Thu Nov 14 14:48:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 179446 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp11156790ilf; Thu, 14 Nov 2019 06:48:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzJyYGeMJdzYeAL870COtIbar00u1E0L5nth2XBoRnwBG0NXzrJFt2kbnwIWBI3+uEQErnO X-Received: by 2002:aa7:cb53:: with SMTP id w19mr1704478edt.50.1573742923499; Thu, 14 Nov 2019 06:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573742923; cv=none; d=google.com; s=arc-20160816; b=XH6WRviKg9vc8XJcHBH19YlzPwk41vfb7U4NYKpAhnXFr0dOq4SS5WfFnykh1k6QaW Wl2/gGj7v3z3tRwuwGZyvns4zxugK8lhrghCYwOqF+8/O8zcSNR5tS361nXlkpnazrIn StmxS6erz1dt+n4NL765lgVDORHB6jzNsT20OzUo4S5mhTccAnJujTOKmxqYBEbEKuC9 gTG8yfNuiTY6iDLMFlKnlJXhwfwvDE1bXj2BGIHhRIeHPJNtq7iPCCX3Zq+f4FO1tUTW X5NLWuLmRT9IwCtx1ML66cs7NBBV1pQk8uuVIKBmz6+qdGOqzMXHi31H8vYC9UC1D3sK a+1A== 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=osQPobpkOPnRC9LXPzS0ICaLsSaTgnPD7uH0HuL7bsg=; b=NTY4eYN30I15LT+iZeQXCi4aKC/LWdDtZ1neIXH1NWTOfiC3oDRbYwJESz/SnBenub Ywvl3pbY22ScnxCMTLmfXXtVlRofXTMYkHpBHJ0zkSDNy4f+pyiRpbXCMccbSE0hqeWD 7kZ0HqymNJ8VUQrDfZC+KRq3dGB8WD3bbcf1y1JhcijaduylVafEAeXj4TgWvUh6bRF+ dv7I7kP+uIE01Wacox6TqbC9UuIrRx7AHvLX5kyS1GwpbSfdGEmxA002z6pRnSzubKSV P+9HrDIi4gC2uH55Cs3HOfu6T2zawSyoUSrAdPhQBN/+iIQrEWfniSYL7ELH5sYvaPJS eYvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gFm9i5+Q; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 v2si4166292ede.61.2019.11.14.06.48.43; Thu, 14 Nov 2019 06:48:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=gFm9i5+Q; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1726992AbfKNOsi (ORCPT + 8 others); Thu, 14 Nov 2019 09:48:38 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55346 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726852AbfKNOsh (ORCPT ); Thu, 14 Nov 2019 09:48:37 -0500 Received: by mail-wm1-f65.google.com with SMTP id b11so5954810wmb.5; Thu, 14 Nov 2019 06:48:35 -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=osQPobpkOPnRC9LXPzS0ICaLsSaTgnPD7uH0HuL7bsg=; b=gFm9i5+Q4erupPrQYD6hQx0NKLe5zgJP0SlHfMTD5BEfvWIDz3mr2NfUsaFysX/mnR Oc4VITBDZYrIqiwZ34l3GoJ/SqxuSi+xhAK8kgFJmXlsxxGL3QiVtJhpK45COXk1LvRm 2KyIpi8iT9VNeB0r6mhX9TLucAi1QK5L0nS2KlhrhL6b8xNI59NenZqwa07IsRxULGW/ x7PSuPd6cU3YImqIKoFRnSEw9S9DsPhMdM5VhNqkw+GATxDqeY5X9fYIwCS+uFBWA1ir W7eJGT/xmmMTWz/j3hv0t/Hs8b3/UWpk2/K29up+DWHC2flGpj+wXH/UNnWQ8csAAm6q jnKQ== 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=osQPobpkOPnRC9LXPzS0ICaLsSaTgnPD7uH0HuL7bsg=; b=nXhGpzfppKAs31As9HgYo8GThiUdvamGQmp9ZaklR7vh7ZrE19HxY+XjAnjJhJanEb n4T9Quql8UaY70Xkdj82QeOSvkco/BGDdbkk72Q0z2ZcZFRKeuymvpurX+xsEZcyCFAh q0npBWO9+fgR1aWELkC75bN/6nn2T9Vw4fwOp679smX9Hibfm8y0QSUzMY3ji8Qoy0fP BAb0wV8SrVU3pAUJ0/5CKNl1cvm9NcnO7hUOFWf2KO9nf6RhQVu8uah/7ECkW9flLRnv Bnzz0Ca9tiQ4XJcnkKx/9OpaT6ntgxA05K0VSAVyWvq01YUt3A7zco90aSjp8m3PYhC6 imfA== X-Gm-Message-State: APjAAAWH0YqRZKVzxYG+LyFoTv8Az96Mwp4X5A/Cqosy3CotTGIsKjFZ xp1UVgqyr12LsKYACdbJJyQ= X-Received: by 2002:a7b:ce08:: with SMTP id m8mr8188339wmc.68.1573742914630; Thu, 14 Nov 2019 06:48:34 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id v9sm7153223wrs.95.2019.11.14.06.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2019 06:48:34 -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 3/3] crypto: sun4i-ss: add the A33 variant of SecuritySystem Date: Thu, 14 Nov 2019 15:48:12 +0100 Message-Id: <20191114144812.22747-4-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191114144812.22747-1-clabbe.montjoie@gmail.com> References: <20191114144812.22747-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The A33 SecuritySystem 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;