forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/arch/x86/crypto/crc32c-intel_glue.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.
34 * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE)
....@@ -9,30 +10,17 @@
910 * Copyright (C) 2008 Intel Corporation
1011 * Authors: Austin Zhang <austin_zhang@linux.intel.com>
1112 * Kent Liu <kent.liu@intel.com>
12
- *
13
- * This program is free software; you can redistribute it and/or modify it
14
- * under the terms and conditions of the GNU General Public License,
15
- * version 2, as published by the Free Software Foundation.
16
- *
17
- * This program is distributed in the hope it will be useful, but WITHOUT
18
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20
- * more details.
21
- *
22
- * You should have received a copy of the GNU General Public License along with
23
- * this program; if not, write to the Free Software Foundation, Inc.,
24
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
25
- *
2613 */
2714 #include <linux/init.h>
2815 #include <linux/module.h>
2916 #include <linux/string.h>
3017 #include <linux/kernel.h>
3118 #include <crypto/internal/hash.h>
19
+#include <crypto/internal/simd.h>
3220
3321 #include <asm/cpufeatures.h>
3422 #include <asm/cpu_device_id.h>
35
-#include <asm/fpu/internal.h>
23
+#include <asm/simd.h>
3624
3725 #define CHKSUM_BLOCK_SIZE 1
3826 #define CHKSUM_DIGEST_SIZE 4
....@@ -40,9 +28,9 @@
4028 #define SCALE_F sizeof(unsigned long)
4129
4230 #ifdef CONFIG_X86_64
43
-#define REX_PRE "0x48, "
31
+#define CRC32_INST "crc32q %1, %q0"
4432 #else
45
-#define REX_PRE
33
+#define CRC32_INST "crc32l %1, %0"
4634 #endif
4735
4836 #ifdef CONFIG_X86_64
....@@ -60,11 +48,8 @@
6048 static u32 crc32c_intel_le_hw_byte(u32 crc, unsigned char const *data, size_t length)
6149 {
6250 while (length--) {
63
- __asm__ __volatile__(
64
- ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
65
- :"=S"(crc)
66
- :"0"(crc), "c"(*data)
67
- );
51
+ asm("crc32b %1, %0"
52
+ : "+r" (crc) : "rm" (*data));
6853 data++;
6954 }
7055
....@@ -78,11 +63,8 @@
7863 unsigned long *ptmp = (unsigned long *)p;
7964
8065 while (iquotient--) {
81
- __asm__ __volatile__(
82
- ".byte 0xf2, " REX_PRE "0xf, 0x38, 0xf1, 0xf1;"
83
- :"=S"(crc)
84
- :"0"(crc), "c"(*ptmp)
85
- );
66
+ asm(CRC32_INST
67
+ : "+r" (crc) : "rm" (*ptmp));
8668 ptmp++;
8769 }
8870
....@@ -103,10 +85,8 @@
10385 {
10486 u32 *mctx = crypto_shash_ctx(hash);
10587
106
- if (keylen != sizeof(u32)) {
107
- crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
88
+ if (keylen != sizeof(u32))
10889 return -EINVAL;
109
- }
11090 *mctx = le32_to_cpup((__le32 *)key);
11191 return 0;
11292 }
....@@ -177,7 +157,7 @@
177157 * use faster PCL version if datasize is large enough to
178158 * overcome kernel fpu state save/restore overhead
179159 */
180
- if (len >= CRC32C_PCL_BREAKEVEN && irq_fpu_usable()) {
160
+ if (len >= CRC32C_PCL_BREAKEVEN && crypto_simd_usable()) {
181161 kernel_fpu_begin();
182162 *crcp = crc_pcl(data, len, *crcp);
183163 kernel_fpu_end();
....@@ -189,7 +169,7 @@
189169 static int __crc32c_pcl_intel_finup(u32 *crcp, const u8 *data, unsigned int len,
190170 u8 *out)
191171 {
192
- if (len >= CRC32C_PCL_BREAKEVEN && irq_fpu_usable()) {
172
+ if (len >= CRC32C_PCL_BREAKEVEN && crypto_simd_usable()) {
193173 kernel_fpu_begin();
194174 *(__le32 *)out = ~cpu_to_le32(crc_pcl(data, len, *crcp));
195175 kernel_fpu_end();
....@@ -235,7 +215,7 @@
235215 };
236216
237217 static const struct x86_cpu_id crc32c_cpu_id[] = {
238
- X86_FEATURE_MATCH(X86_FEATURE_XMM4_2),
218
+ X86_MATCH_FEATURE(X86_FEATURE_XMM4_2, NULL),
239219 {}
240220 };
241221 MODULE_DEVICE_TABLE(x86cpu, crc32c_cpu_id);