| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* SHA-256 (RISC-V accelerated) |
| 4 |
* |
| 5 |
* Copyright (C) 2022 VRULL GmbH |
| 6 |
* Author: Heiko Stuebner <[email protected]> |
| 7 |
* |
| 8 |
* Copyright (C) 2023 SiFive, Inc. |
| 9 |
* Author: Jerry Shih <[email protected]> |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <asm/simd.h> |
| 13 |
#include <asm/vector.h> |
| 14 |
|
| 15 |
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions); |
| 16 |
|
| 17 |
asmlinkage void |
| 18 |
sha256_transform_zvknha_or_zvknhb_zvkb(struct sha256_block_state *state, |
| 19 |
const u8 *data, size_t nblocks); |
| 20 |
|
| 21 |
static void sha256_blocks(struct sha256_block_state *state, |
| 22 |
const u8 *data, size_t nblocks) |
| 23 |
{ |
| 24 |
if (static_branch_likely(&have_extensions) && likely(may_use_simd())) { |
| 25 |
kernel_vector_begin(); |
| 26 |
sha256_transform_zvknha_or_zvknhb_zvkb(state, data, nblocks); |
| 27 |
kernel_vector_end(); |
| 28 |
} else { |
| 29 |
sha256_blocks_generic(state, data, nblocks); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
#define sha256_mod_init_arch sha256_mod_init_arch |
| 34 |
static void sha256_mod_init_arch(void) |
| 35 |
{ |
| 36 |
/* Both zvknha and zvknhb provide the SHA-256 instructions. */ |
| 37 |
if ((riscv_isa_extension_available(NULL, ZVKNHA) || |
| 38 |
riscv_isa_extension_available(NULL, ZVKNHB)) && |
| 39 |
riscv_isa_extension_available(NULL, ZVKB) && |
| 40 |
riscv_vector_vlen() >= 128) |
| 41 |
static_branch_enable(&have_extensions); |
| 42 |
} |