1b10749d8SEric Biggers // SPDX-License-Identifier: GPL-2.0-or-later
2b10749d8SEric Biggers /*
3b10749d8SEric Biggers * CRC64 using [V]PCLMULQDQ instructions
4b10749d8SEric Biggers *
5b10749d8SEric Biggers * Copyright 2025 Google LLC
6b10749d8SEric Biggers */
7b10749d8SEric Biggers
8b10749d8SEric Biggers #include "crc-pclmul-template.h"
9b10749d8SEric Biggers
10b10749d8SEric Biggers static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq);
11b10749d8SEric Biggers
12b10749d8SEric Biggers DECLARE_CRC_PCLMUL_FUNCS(crc64_msb, u64);
13b10749d8SEric Biggers DECLARE_CRC_PCLMUL_FUNCS(crc64_lsb, u64);
14b10749d8SEric Biggers
crc64_be_arch(u64 crc,const u8 * p,size_t len)15b10749d8SEric Biggers static inline u64 crc64_be_arch(u64 crc, const u8 *p, size_t len)
16b10749d8SEric Biggers {
17b10749d8SEric Biggers CRC_PCLMUL(crc, p, len, crc64_msb, crc64_msb_0x42f0e1eba9ea3693_consts,
18b10749d8SEric Biggers have_pclmulqdq);
19b10749d8SEric Biggers return crc64_be_generic(crc, p, len);
20b10749d8SEric Biggers }
21b10749d8SEric Biggers
crc64_nvme_arch(u64 crc,const u8 * p,size_t len)22b10749d8SEric Biggers static inline u64 crc64_nvme_arch(u64 crc, const u8 *p, size_t len)
23b10749d8SEric Biggers {
24b10749d8SEric Biggers CRC_PCLMUL(crc, p, len, crc64_lsb, crc64_lsb_0x9a6c9329ac4bc9b5_consts,
25b10749d8SEric Biggers have_pclmulqdq);
26b10749d8SEric Biggers return crc64_nvme_generic(crc, p, len);
27b10749d8SEric Biggers }
28b10749d8SEric Biggers
29b10749d8SEric Biggers #define crc64_mod_init_arch crc64_mod_init_arch
crc64_mod_init_arch(void)30b10749d8SEric Biggers static inline void crc64_mod_init_arch(void)
31b10749d8SEric Biggers {
32b10749d8SEric Biggers if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) {
33b10749d8SEric Biggers static_branch_enable(&have_pclmulqdq);
34*110628e5SEric Biggers if (have_vpclmul()) {
35*110628e5SEric Biggers if (have_avx512()) {
36*110628e5SEric Biggers static_call_update(crc64_msb_pclmul,
37*110628e5SEric Biggers crc64_msb_vpclmul_avx512);
38*110628e5SEric Biggers static_call_update(crc64_lsb_pclmul,
39*110628e5SEric Biggers crc64_lsb_vpclmul_avx512);
40*110628e5SEric Biggers } else {
41*110628e5SEric Biggers static_call_update(crc64_msb_pclmul,
42*110628e5SEric Biggers crc64_msb_vpclmul_avx2);
43*110628e5SEric Biggers static_call_update(crc64_lsb_pclmul,
44*110628e5SEric Biggers crc64_lsb_vpclmul_avx2);
45*110628e5SEric Biggers }
46*110628e5SEric Biggers }
47b10749d8SEric Biggers }
48b10749d8SEric Biggers }
49