From nobody Thu Dec 25 01:34:28 2025 Received: from mx1.zhaoxin.com (MX1.ZHAOXIN.COM [210.0.225.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92E384E1BC for ; Tue, 23 Jan 2024 02:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.0.225.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705976950; cv=none; b=pM7DQTOuUQXF4Nt7ZFIvVkIIjfn2WlUzYydJibagwf4SRLBRE1IVQDc1iD08Lx/lMjEgcFHAGetWrstju0XbcvBki3oMo9+4lVinqyRbbSikkxWLePANT8Ypwym/5/U1VzURoirNlShYBhEjJAGKW1gJ8xs9cXT8QV2iW+ga2t8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705976950; c=relaxed/simple; bh=8jR/wyg20Cbwp1wNyTE4dL3FSTw1OLFz7/S0CpcZm/0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qYlW4aUHZTUhz0vDoro+0itgXKTeN37Ykg9yrz3fHFOF3Y6MD+bEJbjGPaq4b3551dO/nDO5XMQhvOfZKr0fOecfmM8ZSfpvm3SwlZ3SbD/VMwIfut68Ez8GnHsme1wZn1NkNye3h6XerMxnbYJOirKJh9mwizeQRqQoTVyZrV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=210.0.225.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1705976937-086e230f27288d0001-xx1T2L Received: from ZXSHMBX1.zhaoxin.com (ZXSHMBX1.zhaoxin.com [10.28.252.163]) by mx1.zhaoxin.com with ESMTP id qsqivOYb0MXRPciq (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 23 Jan 2024 10:28:57 +0800 (CST) X-Barracuda-Envelope-From: TonyWWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 23 Jan 2024 10:28:56 +0800 Received: from localhost.localdomain (10.32.65.162) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 23 Jan 2024 10:28:54 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 From: Tony W Wang-oc X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: , , , , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v2 1/3] crypto: padlock-sha: Matches CPU with Family with 6 explicitly Date: Tue, 23 Jan 2024 10:28:50 +0800 X-ASG-Orig-Subj: [PATCH v2 1/3] crypto: padlock-sha: Matches CPU with Family with 6 explicitly Message-ID: <20240123022852.2475-2-TonyWWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240123022852.2475-1-TonyWWang-oc@zhaoxin.com> References: <20240123022852.2475-1-TonyWWang-oc@zhaoxin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX1.zhaoxin.com[10.28.252.163] X-Barracuda-Start-Time: 1705976937 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.35:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 786 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.119808 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Content-Type: text/plain; charset="utf-8" Updates the supporting qualification for packlock-sha driver, making it support CPUs whose vendor ID is Centaur and Famliy is 6. Signed-off-by: Tony W Wang-oc --- drivers/crypto/padlock-sha.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c index 6865c7f1fc1a..2e82c5e77f7a 100644 --- a/drivers/crypto/padlock-sha.c +++ b/drivers/crypto/padlock-sha.c @@ -491,7 +491,7 @@ static struct shash_alg sha256_alg_nano =3D { }; =20 static const struct x86_cpu_id padlock_sha_ids[] =3D { - X86_MATCH_FEATURE(X86_FEATURE_PHE, NULL), + X86_MATCH_VENDOR_FAM_FEATURE(CENTAUR, 6, X86_FEATURE_PHE, NULL), {} }; MODULE_DEVICE_TABLE(x86cpu, padlock_sha_ids); --=20 2.25.1 From nobody Thu Dec 25 01:34:28 2025 Received: from mx1.zhaoxin.com (MX1.ZHAOXIN.COM [210.0.225.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A376B4EB21 for ; Tue, 23 Jan 2024 02:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.0.225.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705976951; cv=none; b=YBe53Yp3C27bO3KaN3wCShVVf8ugITAW+fRhML2MhGMnjm9BNaVuJ2A5T8DC6T4maNoHQMrVRFR+MUuBMQDJCEd0ndjfyrlRQY09nQSr4B+AR3o3GBgESTA2H/d/nCcg4JnwbKxLfrvtapsMdhtF81SVwDRZyjd0KPOGzNP8HAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705976951; c=relaxed/simple; bh=BNwz8nogyl4n1yMnhodPp9Q+F0gYYUhsajY5U+RhqWE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SQRyAHpCpDcm3TZGwiU18bK4m3VxTBu6NdbPVrjNZ9sxPLUyssXUQv+AfQcDDURJnI15mAZQG9loMy2wyqLz5HYuG/Ljmqq6fVFjAweqkgcrgk6OQc4lJFqp0e6AU+aq+N2sh0H9wqvLKtxjIIbpYfYQFcny945/KS5Baf0PxKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=210.0.225.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1705976939-086e230f26288d0001-xx1T2L Received: from ZXSHMBX2.zhaoxin.com (ZXSHMBX2.zhaoxin.com [10.28.252.164]) by mx1.zhaoxin.com with ESMTP id cdEzdbBKdWckdm3l (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 23 Jan 2024 10:28:59 +0800 (CST) X-Barracuda-Envelope-From: TonyWWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX2.zhaoxin.com (10.28.252.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 23 Jan 2024 10:28:58 +0800 Received: from localhost.localdomain (10.32.65.162) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 23 Jan 2024 10:28:56 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 From: Tony W Wang-oc X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: , , , , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v2 2/3] x86/cpufeatures: Add CPU feature flags for Zhaoxin Hash Engine Date: Tue, 23 Jan 2024 10:28:51 +0800 X-ASG-Orig-Subj: [PATCH v2 2/3] x86/cpufeatures: Add CPU feature flags for Zhaoxin Hash Engine Message-ID: <20240123022852.2475-3-TonyWWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240123022852.2475-1-TonyWWang-oc@zhaoxin.com> References: <20240123022852.2475-1-TonyWWang-oc@zhaoxin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX2.zhaoxin.com[10.28.252.164] X-Barracuda-Start-Time: 1705976939 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.35:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 2994 X-Barracuda-BRTS-Status: 0 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.119808 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Content-Type: text/plain; charset="utf-8" Zhaoxin CPUs have implemented the SHA(Secure Hash Algorithm) as its instrucions. Add two CPU feature flags indicated by CPUID.(EAX=3DC0000001,ECX=3D0):EDX bit 25/26 which will be used by Zhaoxin SHA driver. Signed-off-by: Tony W Wang-oc --- arch/x86/include/asm/cpufeatures.h | 4 +++- tools/arch/x86/include/asm/cpufeatures.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 29cb275a219d..28b0e62dbdf5 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -145,7 +145,7 @@ #define X86_FEATURE_RDRAND ( 4*32+30) /* RDRAND instruction */ #define X86_FEATURE_HYPERVISOR ( 4*32+31) /* Running on a hypervisor */ =20 -/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 = */ +/* VIA/Cyrix/Centaur/Zhaoxin-defined CPU features, CPUID level 0xC0000001,= word 5 */ #define X86_FEATURE_XSTORE ( 5*32+ 2) /* "rng" RNG present (xstore) */ #define X86_FEATURE_XSTORE_EN ( 5*32+ 3) /* "rng_en" RNG enabled */ #define X86_FEATURE_XCRYPT ( 5*32+ 6) /* "ace" on-CPU crypto (xcrypt) */ @@ -156,6 +156,8 @@ #define X86_FEATURE_PHE_EN ( 5*32+11) /* PHE enabled */ #define X86_FEATURE_PMM ( 5*32+12) /* PadLock Montgomery Multiplier */ #define X86_FEATURE_PMM_EN ( 5*32+13) /* PMM enabled */ +#define X86_FEATURE_PHE2 ( 5*32+25) /* "phe2" Zhaoxin Hash Engine */ +#define X86_FEATURE_PHE2_EN ( 5*32+26) /* "phe2_en" PHE2 enabled */ =20 /* More extended AMD flags: CPUID level 0x80000001, ECX, word 6 */ #define X86_FEATURE_LAHF_LM ( 6*32+ 0) /* LAHF/SAHF in long mode */ diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/incl= ude/asm/cpufeatures.h index f4542d2718f4..21caba9d070b 100644 --- a/tools/arch/x86/include/asm/cpufeatures.h +++ b/tools/arch/x86/include/asm/cpufeatures.h @@ -145,7 +145,7 @@ #define X86_FEATURE_RDRAND ( 4*32+30) /* RDRAND instruction */ #define X86_FEATURE_HYPERVISOR ( 4*32+31) /* Running on a hypervisor */ =20 -/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 = */ +/* VIA/Cyrix/Centaur/Zhaoxin-defined CPU features, CPUID level 0xC0000001,= word 5 */ #define X86_FEATURE_XSTORE ( 5*32+ 2) /* "rng" RNG present (xstore) */ #define X86_FEATURE_XSTORE_EN ( 5*32+ 3) /* "rng_en" RNG enabled */ #define X86_FEATURE_XCRYPT ( 5*32+ 6) /* "ace" on-CPU crypto (xcrypt) */ @@ -156,6 +156,8 @@ #define X86_FEATURE_PHE_EN ( 5*32+11) /* PHE enabled */ #define X86_FEATURE_PMM ( 5*32+12) /* PadLock Montgomery Multiplier */ #define X86_FEATURE_PMM_EN ( 5*32+13) /* PMM enabled */ +#define X86_FEATURE_PHE2 ( 5*32+25) /* "phe2" Zhaoxin Hash Engine */ +#define X86_FEATURE_PHE2_EN ( 5*32+26) /* "phe2_en" PHE2 enabled */ =20 /* More extended AMD flags: CPUID level 0x80000001, ECX, word 6 */ #define X86_FEATURE_LAHF_LM ( 6*32+ 0) /* LAHF/SAHF in long mode */ --=20 2.25.1 From nobody Thu Dec 25 01:34:28 2025 Received: from mx2.zhaoxin.com (mx2.zhaoxin.com [203.110.167.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB37C29408 for ; Tue, 23 Jan 2024 02:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.110.167.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705976947; cv=none; b=S8Eh54ATCIXh12/wONW08XKsqU8+MT/pshRGZbITXFntAhmFJEYIJz8Lbkr9HW+cHNSjmk2GCNEj9CAecDtjA8Rvx6xLJ0m0tn0r7yombkHm5G6cu1sDmSvYvn8MlnhDje2zVuqzTEcGUq+ujHlc0bUmYze37bpkzz2vaHORLiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705976947; c=relaxed/simple; bh=aKNudZURXkE0eh5I39W+olvacmX+u5O7V8geqBn7LkI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nrAO5IOfhHaX5myFUDgMkb+WZU8uQeiPE1GcW7WNIiBQkdrYc3WYNgy/1bVFrDd+U6ln3XcaKwSrRlDqwQe4UFRIP/TH1rq2esyPv5kJT3sE/8ZU4G9+UIW/cQEX9PI2A3J1gRfZQA0ocCUvHLBTE8tLLtSYpUiougNaMP49y9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=203.110.167.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1705976941-1eb14e0c7e27290001-xx1T2L Received: from ZXSHMBX1.zhaoxin.com (ZXSHMBX1.zhaoxin.com [10.28.252.163]) by mx2.zhaoxin.com with ESMTP id TupZt8Zh9ZMPwTOL (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 23 Jan 2024 10:29:01 +0800 (CST) X-Barracuda-Envelope-From: TonyWWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 23 Jan 2024 10:29:01 +0800 Received: from localhost.localdomain (10.32.65.162) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 23 Jan 2024 10:28:58 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 From: Tony W Wang-oc X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: , , , , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v2 3/3] crypto: Zhaoxin: Hardware Engine Driver for SHA1/256/384/512 Date: Tue, 23 Jan 2024 10:28:52 +0800 X-ASG-Orig-Subj: [PATCH v2 3/3] crypto: Zhaoxin: Hardware Engine Driver for SHA1/256/384/512 Message-ID: <20240123022852.2475-4-TonyWWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240123022852.2475-1-TonyWWang-oc@zhaoxin.com> References: <20240123022852.2475-1-TonyWWang-oc@zhaoxin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX1.zhaoxin.com[10.28.252.163] X-Barracuda-Start-Time: 1705976941 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.36:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 18963 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.119809 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Content-Type: text/plain; charset="utf-8" Zhaoxin CPUs have implemented the SHA(Secure Hash Algorithm) as its CPU instructions, including SHA1, SHA256, SHA384 and SHA512, which conform to the Secure Hash Algorithms specified by FIPS 180-3. With the help of implementation of SHA in hardware instead of software, can develop applications with higher performance, more security and more flexibility. Below table gives a summary of test using the driver tcrypt with different crypt algorithm drivers on Zhaoxin KH-40000 platform: --------------------------------------------------------------------------- tcrypt driver 16* 64 256 1024 2048 4096 8192 --------------------------------------------------------------------------- zhaoxin** 442.80 1309.21 3257.53 5221.56 5813.45 6136.39 6264.50= *** 403:SHA1 generic** 341.44 813.27 1458.98 1818.03 1896.60 1940.71 1939.06 ratio 1.30 1.61 2.23 2.87 3.07 3.16 3.23 --------------------------------------------------------------------------- zhaoxin 451.70 1313.65 2958.71 4658.55 5109.16 5359.08 5459.13 404:SHA256 generic 202.62 463.55 845.01 1070.50 1117.51 1144.79 1155.68 ratio 2.23 2.83 3.50 4.35 4.57 4.68 4.72 --------------------------------------------------------------------------- zhaoxin 350.90 1406.42 3166.16 5736.39 6627.77 7182.01 7429.18 405:SHA384 generic 161.76 654.88 979.06 1350.56 1423.08 1496.57 1513.12 ratio 2.17 2.15 3.23 4.25 4.66 4.80 4.91 --------------------------------------------------------------------------- zhaoxin 334.49 1394.71 3159.93 5728.86 6625.33 7169.23 7407.80 406:SHA512 generic 161.80 653.84 979.42 1351.41 1444.14 1495.35 1518.43 ratio 2.07 2.13 3.23 4.24 4.59 4.79 4.88 --------------------------------------------------------------------------- *: The length of each data block to be processed by one complete SHA sequence, namely one INIT, multi UPDATEs and one FINAL. **: Crypt algorithm driver used by tcrypt, "zhaoxin" represents zhaoxin-sha while "generic" represents the generic software SHA driver. ***: The speed of each crypt algorithm driver processing different length of data blocks, unit is Mb/s. The ratio in the table implies the performance of SHA implemented by zhaoxin-sha driver is much higher than the ones implemented by the generic software driver of sha1/sha256/sha384/sha512. Signed-off-by: Tony W Wang-oc --- MAINTAINERS | 6 + drivers/crypto/Kconfig | 16 ++ drivers/crypto/Makefile | 1 + drivers/crypto/zhaoxin-sha.c | 500 +++++++++++++++++++++++++++++++++++ drivers/crypto/zhaoxin-sha.h | 17 ++ 5 files changed, 540 insertions(+) create mode 100644 drivers/crypto/zhaoxin-sha.c create mode 100644 drivers/crypto/zhaoxin-sha.h diff --git a/MAINTAINERS b/MAINTAINERS index ddc5e1049921..7d2bb64ea196 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -24329,6 +24329,12 @@ L: linux-kernel@vger.kernel.org S: Maintained F: arch/x86/kernel/cpu/zhaoxin.c =20 +ZHAOXIN SHA SUPPORT +M: +M: +S: Maintained +F: drivers/crypto/zhaoxin-sha.c + ZONEFS FILESYSTEM M: Damien Le Moal M: Naohiro Aota diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 0991f026cb07..97716b90e180 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -799,4 +799,20 @@ config CRYPTO_DEV_SA2UL source "drivers/crypto/aspeed/Kconfig" source "drivers/crypto/starfive/Kconfig" =20 +config CRYPTO_DEV_ZHAOXIN_SHA + tristate "Support for Zhaoxin SHA1/SHA256/SHA384/SHA512 algorithms" + depends on X86 && !UML + select CRYPTO_HASH + select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA384 + select CRYPTO_SHA512 + help + Use Zhaoxin HW engine for SHA1/SHA256/SHA384/SHA512 algorithms. + + Available in ZX-C+ and newer processors. + + If unsure say M. The compiled module will be + called zhaoxin-sha. + endif # CRYPTO_HW diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile index d859d6a5f3a4..b77c02d6dab7 100644 --- a/drivers/crypto/Makefile +++ b/drivers/crypto/Makefile @@ -51,3 +51,4 @@ obj-y +=3D hisilicon/ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) +=3D amlogic/ obj-y +=3D intel/ obj-y +=3D starfive/ +obj-$(CONFIG_CRYPTO_DEV_ZHAOXIN_SHA) +=3D zhaoxin-sha.o diff --git a/drivers/crypto/zhaoxin-sha.c b/drivers/crypto/zhaoxin-sha.c new file mode 100644 index 000000000000..17242239edf2 --- /dev/null +++ b/drivers/crypto/zhaoxin-sha.c @@ -0,0 +1,500 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Cryptographic API. + * + * Support for Zhaoxin hardware crypto engine. + * + * Copyright (c) 2023 George Xue + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "zhaoxin-sha.h" + +static inline void zhaoxin_output_block(uint32_t *src, uint32_t *dst, size= _t count) +{ + while (count--) + *dst++ =3D swab32(*src++); +} + +static int zhaoxin_sha1_init(struct shash_desc *desc) +{ + struct sha1_state *sctx =3D shash_desc_ctx(desc); + + *sctx =3D (struct sha1_state){ + .state =3D { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, + }; + + return 0; +} + +static int zhaoxin_sha1_update(struct shash_desc *desc, const u8 *data, un= signed int len) +{ + struct sha1_state *sctx =3D shash_desc_ctx(desc); + unsigned int partial, done; + const u8 *src; + u8 buf[SHA1_BLOCK_SIZE * 2]; + u8 *dst =3D &buf[0]; + + partial =3D sctx->count & (SHA1_BLOCK_SIZE - 1); + sctx->count +=3D len; + done =3D 0; + src =3D data; + memcpy(dst, sctx->state, SHA1_DIGEST_SIZE); + + if ((partial + len) >=3D SHA1_BLOCK_SIZE) { + + /* Append the bytes in state's buffer to a block to handle */ + if (partial) { + done =3D -partial; + memcpy(sctx->buffer + partial, data, done + SHA1_BLOCK_SIZE); + src =3D sctx->buffer; + + asm volatile (".byte 0xf3,0x0f,0xa6,0xc8" + : "+S"(src), "+D"(dst) + : "a"(-1L), "c"(1UL)); + + done +=3D SHA1_BLOCK_SIZE; + src =3D data + done; + } + + /* Process the left bytes from the input data */ + if (len - done >=3D SHA1_BLOCK_SIZE) { + asm volatile (".byte 0xf3,0x0f,0xa6,0xc8" + : "+S"(src), "+D"(dst) + : "a"(-1L), + "c"((unsigned long)((len - done) / SHA1_BLOCK_SIZE))); + + done +=3D ((len - done) - (len - done) % SHA1_BLOCK_SIZE); + src =3D data + done; + } + partial =3D 0; + } + memcpy(sctx->state, dst, SHA1_DIGEST_SIZE); + memcpy(sctx->buffer + partial, src, len - done); + + return 0; +} + +static int zhaoxin_sha1_final(struct shash_desc *desc, u8 *out) +{ + struct sha1_state *state =3D shash_desc_ctx(desc); + unsigned int partial, padlen; + __be64 bits; + static const u8 padding[SHA1_BLOCK_SIZE] =3D {SHA_PADDING_BYTE, }; + const int bit_offset =3D SHA1_BLOCK_SIZE - sizeof(__be64); + + bits =3D cpu_to_be64(state->count << 3); + + /* Padding */ + partial =3D state->count & (SHA1_BLOCK_SIZE - 1); + padlen =3D (partial < bit_offset) ? (bit_offset - partial) : + ((SHA1_BLOCK_SIZE + bit_offset) - partial); + zhaoxin_sha1_update(desc, padding, padlen); + + /* Append length field bytes */ + zhaoxin_sha1_update(desc, (const u8 *)&bits, sizeof(bits)); + + /* Swap to output */ + zhaoxin_output_block(state->state, (uint32_t *)out, SHA1_DIGEST_SIZE/size= of(uint32_t)); + + return 0; +} + +static int zhaoxin_sha256_init(struct shash_desc *desc) +{ + struct sha256_state *sctx =3D shash_desc_ctx(desc); + + *sctx =3D (struct sha256_state){ + .state =3D { SHA256_H0, SHA256_H1, SHA256_H2, SHA256_H3, + SHA256_H4, SHA256_H5, SHA256_H6, SHA256_H7}, + }; + + return 0; +} + +static int zhaoxin_sha256_update(struct shash_desc *desc, const u8 *data, + unsigned int len) +{ + struct sha256_state *sctx =3D shash_desc_ctx(desc); + unsigned int partial, done; + const u8 *src; + u8 buf[SHA256_BLOCK_SIZE*2]; + u8 *dst =3D &buf[0]; + + partial =3D sctx->count & (SHA256_BLOCK_SIZE - 1); + sctx->count +=3D len; + done =3D 0; + src =3D data; + memcpy(dst, sctx->state, SHA256_DIGEST_SIZE); + + if ((partial + len) >=3D SHA256_BLOCK_SIZE) { + + /* Append the bytes in state's buffer to a block to handle */ + if (partial) { + done =3D -partial; + memcpy(sctx->buf + partial, data, done + SHA256_BLOCK_SIZE); + src =3D sctx->buf; + + asm volatile (".byte 0xf3,0x0f,0xa6,0xd0" + : "+S"(src), "+D"(dst) + : "a"(-1L), "c"(1UL)); + + done +=3D SHA256_BLOCK_SIZE; + src =3D data + done; + } + + /* Process the left bytes from input data*/ + if (len - done >=3D SHA256_BLOCK_SIZE) { + asm volatile (".byte 0xf3,0x0f,0xa6,0xd0" + : "+S"(src), "+D"(dst) + : "a"(-1L), + "c"((unsigned long)((len - done) / SHA256_BLOCK_SIZE))); + + done +=3D ((len - done) - (len - done) % SHA256_BLOCK_SIZE); + src =3D data + done; + } + partial =3D 0; + } + memcpy(sctx->state, dst, SHA256_DIGEST_SIZE); + memcpy(sctx->buf + partial, src, len - done); + + return 0; +} + +static int zhaoxin_sha256_final(struct shash_desc *desc, u8 *out) +{ + struct sha256_state *state =3D shash_desc_ctx(desc); + unsigned int partial, padlen; + __be64 bits; + static const u8 padding[SHA256_BLOCK_SIZE] =3D {SHA_PADDING_BYTE, }; + const int bit_offset =3D SHA256_BLOCK_SIZE - sizeof(__be64); + + bits =3D cpu_to_be64(state->count << 3); + + /* Padding */ + partial =3D state->count & (SHA256_BLOCK_SIZE - 1); + padlen =3D (partial < bit_offset) ? (bit_offset - partial) : + ((SHA256_BLOCK_SIZE + bit_offset) - partial); + zhaoxin_sha256_update(desc, padding, padlen); + + /* Append length field bytes */ + zhaoxin_sha256_update(desc, (const u8 *)&bits, sizeof(bits)); + + /* Swap to output */ + zhaoxin_output_block(state->state, (uint32_t *)out, SHA256_DIGEST_SIZE/si= zeof(uint32_t)); + + return 0; +} + +static inline void zhaoxin_output_block_512(uint64_t *src, + uint64_t *dst, size_t count) +{ + while (count--) + *dst++ =3D swab64(*src++); +} + +static int zhaoxin_sha384_init(struct shash_desc *desc) +{ + struct sha512_state *sctx =3D shash_desc_ctx(desc); + + *sctx =3D (struct sha512_state){ + .state =3D { SHA384_H0, SHA384_H1, SHA384_H2, SHA384_H3, + SHA384_H4, SHA384_H5, SHA384_H6, SHA384_H7}, + .count =3D {0, 0}, + }; + + return 0; +} + +static int zhaoxin_sha512_init(struct shash_desc *desc) +{ + struct sha512_state *sctx =3D shash_desc_ctx(desc); + + *sctx =3D (struct sha512_state){ + .state =3D { SHA512_H0, SHA512_H1, SHA512_H2, SHA512_H3, + SHA512_H4, SHA512_H5, SHA512_H6, SHA512_H7}, + .count =3D {0, 0}, + }; + + return 0; +} + +static int zhaoxin_sha512_update(struct shash_desc *desc, const u8 *data, + unsigned int len) +{ + struct sha512_state *sctx =3D shash_desc_ctx(desc); + unsigned int partial, done; + const u8 *src; + u8 buf[SHA512_BLOCK_SIZE]; + u8 *dst =3D &buf[0]; + + partial =3D sctx->count[0] % SHA512_BLOCK_SIZE; + + sctx->count[0] +=3D len; + if (sctx->count[0] < len) + sctx->count[1]++; + + done =3D 0; + src =3D data; + memcpy(dst, sctx->state, SHA512_DIGEST_SIZE); + + if ((partial + len) >=3D SHA512_BLOCK_SIZE) { + /* Append the bytes in state's buffer to a block to handle */ + if (partial) { + + done =3D -partial; + memcpy(sctx->buf + partial, data, done + SHA512_BLOCK_SIZE); + + src =3D sctx->buf; + + asm volatile (".byte 0xf3,0x0f,0xa6,0xe0" + : "+S"(src), "+D"(dst) + : "c"(1UL)); + + done +=3D SHA512_BLOCK_SIZE; + src =3D data + done; + } + + /* Process the left bytes from input data*/ + if (len - done >=3D SHA512_BLOCK_SIZE) { + asm volatile (".byte 0xf3,0x0f,0xa6,0xe0" + : "+S"(src), "+D"(dst) + : "c"((unsigned long)((len - done) / SHA512_BLOCK_SIZE))); + + done +=3D ((len - done) - (len - done) % SHA512_BLOCK_SIZE); + src =3D data + done; + } + partial =3D 0; + } + + memcpy(sctx->state, dst, SHA512_DIGEST_SIZE); + memcpy(sctx->buf + partial, src, len - done); + + return 0; +} + +static int zhaoxin_sha512_final(struct shash_desc *desc, u8 *out) +{ + const int bit_offset =3D SHA512_BLOCK_SIZE - sizeof(__be64[2]); + struct sha512_state *state =3D shash_desc_ctx(desc); + unsigned int partial =3D state->count[0] % SHA512_BLOCK_SIZE, padlen; + __be64 bits2[2]; + + // Both SHA384 and SHA512 may be supported. + int dgst_size =3D crypto_shash_digestsize(desc->tfm); + + static u8 padding[SHA512_BLOCK_SIZE]; + + memset(padding, 0, SHA512_BLOCK_SIZE); + padding[0] =3D SHA_PADDING_BYTE; + + // Convert byte count in little endian to bit count in big endian. + bits2[0] =3D cpu_to_be64(state->count[1] << 3 | state->count[0] >> 61); + bits2[1] =3D cpu_to_be64(state->count[0] << 3); + + padlen =3D (partial < bit_offset) ? (bit_offset - partial) : + ((SHA512_BLOCK_SIZE + bit_offset) - partial); + + zhaoxin_sha512_update(desc, padding, padlen); + + /* Append length field bytes */ + zhaoxin_sha512_update(desc, (const u8 *)bits2, sizeof(__be64[2])); + + /* Swap to output */ + zhaoxin_output_block_512(state->state, (uint64_t *)out, dgst_size/sizeof(= uint64_t)); + + return 0; +} + +static int zhaoxin_sha_export(struct shash_desc *desc, + void *out) +{ + int statesize =3D crypto_shash_statesize(desc->tfm); + void *sctx =3D shash_desc_ctx(desc); + + memcpy(out, sctx, statesize); + return 0; +} + +static int zhaoxin_sha_import(struct shash_desc *desc, + const void *in) +{ + int statesize =3D crypto_shash_statesize(desc->tfm); + void *sctx =3D shash_desc_ctx(desc); + + memcpy(sctx, in, statesize); + return 0; +} + +static struct shash_alg sha1_alg =3D { + .digestsize =3D SHA1_DIGEST_SIZE, + .init =3D zhaoxin_sha1_init, + .update =3D zhaoxin_sha1_update, + .final =3D zhaoxin_sha1_final, + .export =3D zhaoxin_sha_export, + .import =3D zhaoxin_sha_import, + .descsize =3D sizeof(struct sha1_state), + .statesize =3D sizeof(struct sha1_state), + .base =3D { + .cra_name =3D "sha1", + .cra_driver_name =3D "sha1-zhaoxin", + .cra_priority =3D ZHAOXIN_SHA_CRA_PRIORITY, + .cra_blocksize =3D SHA1_BLOCK_SIZE, + .cra_module =3D THIS_MODULE, + } +}; + +static struct shash_alg sha256_alg =3D { + .digestsize =3D SHA256_DIGEST_SIZE, + .init =3D zhaoxin_sha256_init, + .update =3D zhaoxin_sha256_update, + .final =3D zhaoxin_sha256_final, + .export =3D zhaoxin_sha_export, + .import =3D zhaoxin_sha_import, + .descsize =3D sizeof(struct sha256_state), + .statesize =3D sizeof(struct sha256_state), + .base =3D { + .cra_name =3D "sha256", + .cra_driver_name =3D "sha256-zhaoxin", + .cra_priority =3D ZHAOXIN_SHA_CRA_PRIORITY, + .cra_blocksize =3D SHA256_BLOCK_SIZE, + .cra_module =3D THIS_MODULE, + } +}; + +static struct shash_alg sha384_alg =3D { + .digestsize =3D SHA384_DIGEST_SIZE, + .init =3D zhaoxin_sha384_init, + .update =3D zhaoxin_sha512_update, + .final =3D zhaoxin_sha512_final, + .export =3D zhaoxin_sha_export, + .import =3D zhaoxin_sha_import, + .descsize =3D sizeof(struct sha512_state), + .statesize =3D sizeof(struct sha512_state), + .base =3D { + .cra_name =3D "sha384", + .cra_driver_name =3D "sha384-zhaoxin", + .cra_priority =3D ZHAOXIN_SHA_CRA_PRIORITY, + .cra_blocksize =3D SHA384_BLOCK_SIZE, + .cra_module =3D THIS_MODULE, + } +}; + +static struct shash_alg sha512_alg =3D { + .digestsize =3D SHA512_DIGEST_SIZE, + .init =3D zhaoxin_sha512_init, + .update =3D zhaoxin_sha512_update, + .final =3D zhaoxin_sha512_final, + .export =3D zhaoxin_sha_export, + .import =3D zhaoxin_sha_import, + .descsize =3D sizeof(struct sha512_state), + .statesize =3D sizeof(struct sha512_state), + .base =3D { + .cra_name =3D "sha512", + .cra_driver_name =3D "sha512-zhaoxin", + .cra_priority =3D ZHAOXIN_SHA_CRA_PRIORITY, + .cra_blocksize =3D SHA512_BLOCK_SIZE, + .cra_module =3D THIS_MODULE, + } +}; + + +static const struct x86_cpu_id zhaoxin_sha_ids[] =3D { + X86_MATCH_VENDOR_FAM_FEATURE(ZHAOXIN, 6, X86_FEATURE_PHE, NULL), + X86_MATCH_VENDOR_FAM_FEATURE(ZHAOXIN, 7, X86_FEATURE_PHE, NULL), + X86_MATCH_VENDOR_FAM_FEATURE(CENTAUR, 7, X86_FEATURE_PHE, NULL), + {} +}; +MODULE_DEVICE_TABLE(x86cpu, zhaoxin_sha_ids); + +static int __init zhaoxin_sha_init(void) +{ + int rc =3D -ENODEV; + + struct shash_alg *sha1; + struct shash_alg *sha256; + struct shash_alg *sha384; + struct shash_alg *sha512; + + if (!x86_match_cpu(zhaoxin_sha_ids) || !boot_cpu_has(X86_FEATURE_PHE_EN)) + return -ENODEV; + + sha1 =3D &sha1_alg; + sha256 =3D &sha256_alg; + + rc =3D crypto_register_shash(sha1); + if (rc) + goto out; + + rc =3D crypto_register_shash(sha256); + if (rc) + goto out_unreg1; + + if (boot_cpu_has(X86_FEATURE_PHE2_EN)) { + + sha384 =3D &sha384_alg; + sha512 =3D &sha512_alg; + + rc =3D crypto_register_shash(sha384); + if (rc) + goto out_unreg2; + + rc =3D crypto_register_shash(sha512); + if (rc) + goto out_unreg3; + + pr_notice("Using Zhaoxin Hardware Engine for SHA1/SHA256/SHA384/SHA512 a= lgorithms.\n"); + } else + pr_notice("Using Zhaoxin Hardware Engine for SHA1/SHA256 algorithms.\n"); + + + return 0; + +out_unreg3: + if (boot_cpu_has(X86_FEATURE_PHE2_EN)) + crypto_unregister_shash(sha384); + +out_unreg2: + crypto_unregister_shash(sha256); +out_unreg1: + crypto_unregister_shash(sha1); + +out: + pr_err("Zhaoxin Hardware Engine for SHA1/SHA256/SHA384/SHA512 initializat= ion failed.\n"); + return rc; +} + +static void __exit zhaoxin_sha_fini(void) +{ + crypto_unregister_shash(&sha1_alg); + crypto_unregister_shash(&sha256_alg); + + if (boot_cpu_has(X86_FEATURE_PHE2_EN)) { + crypto_unregister_shash(&sha384_alg); + crypto_unregister_shash(&sha512_alg); + } + +} + +module_init(zhaoxin_sha_init); +module_exit(zhaoxin_sha_fini); + +MODULE_DESCRIPTION("Zhaoxin Hardware SHA1/SHA256/SHA384/SHA512 algorithms = support."); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("George Xue"); + +MODULE_ALIAS_CRYPTO("sha1-zhaoxin"); +MODULE_ALIAS_CRYPTO("sha256-zhaoxin"); +MODULE_ALIAS_CRYPTO("sha384-zhaoxin"); +MODULE_ALIAS_CRYPTO("sha512-zhaoxin"); + diff --git a/drivers/crypto/zhaoxin-sha.h b/drivers/crypto/zhaoxin-sha.h new file mode 100644 index 000000000000..699659018d19 --- /dev/null +++ b/drivers/crypto/zhaoxin-sha.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Driver for Zhaoxin Sha + * + * Copyright (c) 2023 George Xue + */ + +#ifndef _ZHAOXIN_SHA_H +#define _ZHAOXIN_SHA_H + +#define ZHAOXIN_SHA_CRA_PRIORITY 300 +#define ZHAOXIN_SHA_COMPOSITE_PRIORITY 400 + +#define SHA_PADDING_BYTE 0x80 + +#endif /* _ZHAOXIN_SHA_H */ + --=20 2.25.1