1b10749d8SEric Biggers // SPDX-License-Identifier: GPL-2.0-or-later
2b10749d8SEric Biggers /*
3b10749d8SEric Biggers * CRC-T10DIF using [V]PCLMULQDQ instructions
4b10749d8SEric Biggers *
5b10749d8SEric Biggers * Copyright 2024 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(crc16_msb, u16);
13b10749d8SEric Biggers
crc_t10dif_arch(u16 crc,const u8 * p,size_t len)14b10749d8SEric Biggers static inline u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len)
15b10749d8SEric Biggers {
16b10749d8SEric Biggers CRC_PCLMUL(crc, p, len, crc16_msb, crc16_msb_0x8bb7_consts,
17b10749d8SEric Biggers have_pclmulqdq);
18b10749d8SEric Biggers return crc_t10dif_generic(crc, p, len);
19b10749d8SEric Biggers }
20b10749d8SEric Biggers
21b10749d8SEric Biggers #define crc_t10dif_mod_init_arch crc_t10dif_mod_init_arch
crc_t10dif_mod_init_arch(void)22b10749d8SEric Biggers static inline void crc_t10dif_mod_init_arch(void)
23b10749d8SEric Biggers {
24b10749d8SEric Biggers if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) {
25b10749d8SEric Biggers static_branch_enable(&have_pclmulqdq);
26*110628e5SEric Biggers if (have_vpclmul()) {
27*110628e5SEric Biggers if (have_avx512())
28*110628e5SEric Biggers static_call_update(crc16_msb_pclmul,
29*110628e5SEric Biggers crc16_msb_vpclmul_avx512);
30*110628e5SEric Biggers else
31*110628e5SEric Biggers static_call_update(crc16_msb_pclmul,
32*110628e5SEric Biggers crc16_msb_vpclmul_avx2);
33*110628e5SEric Biggers }
34b10749d8SEric Biggers }
35b10749d8SEric Biggers }
36