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