mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
Replace the static array of algorithms with a call to an architecture helper to register algorithms. This serves two purposes: it avoid having to register all algorithms in a single central place, and it removes the need for the priority field by just registering the algorithms that the architecture considers suitable for the currently running CPUs. [hch@lst.de: register avx512 after avx2] Link: https://lore.kernel.org/20260527074539.2292913-3-hch@lst.de Link: https://lore.kernel.org/20260518051804.462141-11-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Ard Biesheuvel <ardb@kernel.org> Tested-by: Ard Biesheuvel <ardb@kernel.org> # kunit only on arm64 Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alexandre Ghiti <alex@ghiti.fr> Cc: Arnd Bergmann <arnd@arndb.de> Cc: "Borislav Petkov (AMD)" <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chris Mason <clm@fb.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: David Sterba <dsterba@suse.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Li Nan <linan122@huawei.com> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Song Liu <song@kernel.org> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: WANG Xuerui <kernel@xen0n.name> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
97 lines
2.8 KiB
C
97 lines
2.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include <asm/cpufeature.h>
|
|
|
|
extern const struct raid6_calls raid6_mmxx1;
|
|
extern const struct raid6_calls raid6_mmxx2;
|
|
extern const struct raid6_calls raid6_sse1x1;
|
|
extern const struct raid6_calls raid6_sse1x2;
|
|
extern const struct raid6_calls raid6_sse2x1;
|
|
extern const struct raid6_calls raid6_sse2x2;
|
|
extern const struct raid6_calls raid6_sse2x4;
|
|
extern const struct raid6_calls raid6_avx2x1;
|
|
extern const struct raid6_calls raid6_avx2x2;
|
|
extern const struct raid6_calls raid6_avx2x4;
|
|
extern const struct raid6_calls raid6_avx512x1;
|
|
extern const struct raid6_calls raid6_avx512x2;
|
|
extern const struct raid6_calls raid6_avx512x4;
|
|
|
|
extern const struct raid6_recov_calls raid6_recov_ssse3;
|
|
extern const struct raid6_recov_calls raid6_recov_avx2;
|
|
extern const struct raid6_recov_calls raid6_recov_avx512;
|
|
|
|
static inline int raid6_has_avx512(void)
|
|
{
|
|
return boot_cpu_has(X86_FEATURE_AVX2) &&
|
|
boot_cpu_has(X86_FEATURE_AVX) &&
|
|
boot_cpu_has(X86_FEATURE_AVX512F) &&
|
|
boot_cpu_has(X86_FEATURE_AVX512BW) &&
|
|
boot_cpu_has(X86_FEATURE_AVX512VL) &&
|
|
boot_cpu_has(X86_FEATURE_AVX512DQ);
|
|
}
|
|
|
|
static inline bool raid6_has_avx2(void)
|
|
{
|
|
return boot_cpu_has(X86_FEATURE_AVX2) && boot_cpu_has(X86_FEATURE_AVX);
|
|
}
|
|
|
|
static inline bool raid6_has_ssse3(void)
|
|
{
|
|
return boot_cpu_has(X86_FEATURE_XMM) &&
|
|
boot_cpu_has(X86_FEATURE_XMM2) &&
|
|
boot_cpu_has(X86_FEATURE_SSSE3);
|
|
}
|
|
|
|
static inline bool raid6_has_sse2(void)
|
|
{
|
|
return boot_cpu_has(X86_FEATURE_MMX) &&
|
|
boot_cpu_has(X86_FEATURE_FXSR) &&
|
|
boot_cpu_has(X86_FEATURE_XMM) &&
|
|
boot_cpu_has(X86_FEATURE_XMM2);
|
|
}
|
|
|
|
static inline bool raid6_has_sse1_or_mmxext(void)
|
|
{
|
|
return boot_cpu_has(X86_FEATURE_MMX) &&
|
|
(boot_cpu_has(X86_FEATURE_XMM) ||
|
|
boot_cpu_has(X86_FEATURE_MMXEXT));
|
|
}
|
|
|
|
static __always_inline void __init arch_raid6_init(void)
|
|
{
|
|
if (raid6_has_avx2()) {
|
|
raid6_algo_add(&raid6_avx2x1);
|
|
raid6_algo_add(&raid6_avx2x2);
|
|
if (IS_ENABLED(CONFIG_X86_64))
|
|
raid6_algo_add(&raid6_avx2x4);
|
|
if (raid6_has_avx512()) {
|
|
raid6_algo_add(&raid6_avx512x1);
|
|
raid6_algo_add(&raid6_avx512x2);
|
|
if (IS_ENABLED(CONFIG_X86_64))
|
|
raid6_algo_add(&raid6_avx512x4);
|
|
}
|
|
} else if (IS_ENABLED(CONFIG_X86_64) || raid6_has_sse2()) {
|
|
/* x86_64 can assume SSE2 as baseline */
|
|
raid6_algo_add(&raid6_sse2x1);
|
|
raid6_algo_add(&raid6_sse2x2);
|
|
if (IS_ENABLED(CONFIG_X86_64))
|
|
raid6_algo_add(&raid6_sse2x4);
|
|
} else {
|
|
raid6_algo_add_default();
|
|
if (raid6_has_sse1_or_mmxext()) {
|
|
raid6_algo_add(&raid6_sse1x1);
|
|
raid6_algo_add(&raid6_sse1x2);
|
|
} else if (boot_cpu_has(X86_FEATURE_MMX)) {
|
|
raid6_algo_add(&raid6_mmxx1);
|
|
raid6_algo_add(&raid6_mmxx2);
|
|
}
|
|
}
|
|
|
|
if (raid6_has_avx512())
|
|
raid6_recov_algo_add(&raid6_recov_avx512);
|
|
else if (raid6_has_avx2())
|
|
raid6_recov_algo_add(&raid6_recov_avx2);
|
|
else if (raid6_has_ssse3())
|
|
raid6_recov_algo_add(&raid6_recov_ssse3);
|
|
}
|