| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* SHA-512 accelerated using the sparc64 sha512 opcodes |
| 4 |
* |
| 5 |
* Copyright (c) Jean-Luc Cooke <[email protected]> |
| 6 |
* Copyright (c) Andrew McDonald <[email protected]> |
| 7 |
* Copyright (c) 2003 Kyle McMartin <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <asm/elf.h> |
| 11 |
#include <asm/opcodes.h> |
| 12 |
#include <asm/pstate.h> |
| 13 |
|
| 14 |
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha512_opcodes); |
| 15 |
|
| 16 |
asmlinkage void sha512_sparc64_transform(struct sha512_block_state *state, |
| 17 |
const u8 *data, size_t nblocks); |
| 18 |
|
| 19 |
static void sha512_blocks(struct sha512_block_state *state, |
| 20 |
const u8 *data, size_t nblocks) |
| 21 |
{ |
| 22 |
if (static_branch_likely(&have_sha512_opcodes)) |
| 23 |
sha512_sparc64_transform(state, data, nblocks); |
| 24 |
else |
| 25 |
sha512_blocks_generic(state, data, nblocks); |
| 26 |
} |
| 27 |
|
| 28 |
#define sha512_mod_init_arch sha512_mod_init_arch |
| 29 |
static void sha512_mod_init_arch(void) |
| 30 |
{ |
| 31 |
unsigned long cfr; |
| 32 |
|
| 33 |
if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO)) |
| 34 |
return; |
| 35 |
|
| 36 |
__asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr)); |
| 37 |
if (!(cfr & CFR_SHA512)) |
| 38 |
return; |
| 39 |
|
| 40 |
static_branch_enable(&have_sha512_opcodes); |
| 41 |
pr_info("Using sparc64 sha512 opcode optimized SHA-512/SHA-384 implementation\n"); |
| 42 |
} |