1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * arm64-optimized SHA-512 block function 4 * 5 * Copyright 2025 Google LLC 6 */ 7 #include <asm/neon.h> 8 #include <asm/simd.h> 9 #include <linux/cpufeature.h> 10 11 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha512_insns); 12 13 asmlinkage void sha512_block_data_order(struct sha512_block_state *state, 14 const u8 *data, size_t nblocks); 15 asmlinkage size_t __sha512_ce_transform(struct sha512_block_state *state, 16 const u8 *data, size_t nblocks); 17 18 static void sha512_blocks(struct sha512_block_state *state, 19 const u8 *data, size_t nblocks) 20 { 21 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && 22 static_branch_likely(&have_sha512_insns) && 23 likely(may_use_simd())) { 24 do { 25 size_t rem; 26 27 kernel_neon_begin(); 28 rem = __sha512_ce_transform(state, data, nblocks); 29 kernel_neon_end(); 30 data += (nblocks - rem) * SHA512_BLOCK_SIZE; 31 nblocks = rem; 32 } while (nblocks); 33 } else { 34 sha512_block_data_order(state, data, nblocks); 35 } 36 } 37 38 #ifdef CONFIG_KERNEL_MODE_NEON 39 #define sha512_mod_init_arch sha512_mod_init_arch 40 static void sha512_mod_init_arch(void) 41 { 42 if (cpu_have_named_feature(SHA512)) 43 static_branch_enable(&have_sha512_insns); 44 } 45 #endif /* CONFIG_KERNEL_MODE_NEON */ 46