1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * CRC-T10DIF using [V]PCLMULQDQ instructions 4 * 5 * Copyright 2024 Google LLC 6 */ 7 8 #include <linux/crc-t10dif.h> 9 #include <linux/module.h> 10 #include "crc-pclmul-template.h" 11 12 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_pclmulqdq); 13 14 DECLARE_CRC_PCLMUL_FUNCS(crc16_msb, u16); 15 16 u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len) 17 { 18 CRC_PCLMUL(crc, p, len, crc16_msb, crc16_msb_0x8bb7_consts, 19 have_pclmulqdq); 20 return crc_t10dif_generic(crc, p, len); 21 } 22 EXPORT_SYMBOL(crc_t10dif_arch); 23 24 static int __init crc_t10dif_x86_init(void) 25 { 26 if (boot_cpu_has(X86_FEATURE_PCLMULQDQ)) { 27 static_branch_enable(&have_pclmulqdq); 28 INIT_CRC_PCLMUL(crc16_msb); 29 } 30 return 0; 31 } 32 subsys_initcall(crc_t10dif_x86_init); 33 34 static void __exit crc_t10dif_x86_exit(void) 35 { 36 } 37 module_exit(crc_t10dif_x86_exit); 38 39 MODULE_DESCRIPTION("CRC-T10DIF using [V]PCLMULQDQ instructions"); 40 MODULE_LICENSE("GPL"); 41