1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * CRC-T10DIF using PCLMULQDQ instructions 4 * 5 * Copyright 2024 Google LLC 6 */ 7 8 #include <asm/cpufeatures.h> 9 #include <asm/simd.h> 10 #include <crypto/internal/simd.h> 11 #include <linux/crc-t10dif.h> 12 #include <linux/module.h> 13 14 static DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); 15 16 asmlinkage u16 crc_t10dif_pcl(u16 init_crc, const u8 *buf, size_t len); 17 18 u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len) 19 { 20 if (len >= 16 && 21 static_key_enabled(&have_pclmulqdq) && crypto_simd_usable()) { 22 kernel_fpu_begin(); 23 crc = crc_t10dif_pcl(crc, p, len); 24 kernel_fpu_end(); 25 return crc; 26 } 27 return crc_t10dif_generic(crc, p, len); 28 } 29 EXPORT_SYMBOL(crc_t10dif_arch); 30 31 static int __init crc_t10dif_x86_init(void) 32 { 33 if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) 34 static_branch_enable(&have_pclmulqdq); 35 return 0; 36 } 37 arch_initcall(crc_t10dif_x86_init); 38 39 static void __exit crc_t10dif_x86_exit(void) 40 { 41 } 42 module_exit(crc_t10dif_x86_exit); 43 44 bool crc_t10dif_is_optimized(void) 45 { 46 return static_key_enabled(&have_pclmulqdq); 47 } 48 EXPORT_SYMBOL(crc_t10dif_is_optimized); 49 50 MODULE_DESCRIPTION("CRC-T10DIF using PCLMULQDQ instructions"); 51 MODULE_LICENSE("GPL"); 52