1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * MD5 accelerated using the sparc64 crypto opcodes
4 *
5 * Copyright (c) Alan Smithee.
6 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
7 * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
8 * Copyright (c) Mathias Krause <minipli@googlemail.com>
9 * Copyright (c) Cryptoapi developers.
10 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
11 */
12
13 #include <asm/elf.h>
14 #include <asm/opcodes.h>
15 #include <asm/pstate.h>
16
17 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_md5_opcodes);
18
19 asmlinkage void md5_sparc64_transform(struct md5_block_state *state,
20 const u8 *data, size_t nblocks);
21
md5_blocks(struct md5_block_state * state,const u8 * data,size_t nblocks)22 static void md5_blocks(struct md5_block_state *state,
23 const u8 *data, size_t nblocks)
24 {
25 if (static_branch_likely(&have_md5_opcodes)) {
26 cpu_to_le32_array(state->h, ARRAY_SIZE(state->h));
27 md5_sparc64_transform(state, data, nblocks);
28 le32_to_cpu_array(state->h, ARRAY_SIZE(state->h));
29 } else {
30 md5_blocks_generic(state, data, nblocks);
31 }
32 }
33
34 #define md5_mod_init_arch md5_mod_init_arch
md5_mod_init_arch(void)35 static void md5_mod_init_arch(void)
36 {
37 unsigned long cfr;
38
39 if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
40 return;
41
42 __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
43 if (!(cfr & CFR_MD5))
44 return;
45
46 static_branch_enable(&have_md5_opcodes);
47 pr_info("Using sparc64 md5 opcode optimized MD5 implementation\n");
48 }
49