Skip to content

Commit 9b2d720

Browse files
author
Eric Biggers
committed
lib/crc: sparc: Migrate optimized CRC code into lib/crc/
Move the sparc-optimized CRC code from arch/sparc/lib/crc* into its new location in lib/crc/sparc/, and wire it up in the new way. This new way of organizing the CRC code eliminates the need to artificially split the code for each CRC variant into separate arch and generic modules, enabling better inlining and dead code elimination. For more details, see "lib/crc: Prepare for arch-optimized code in subdirs of lib/crc/". Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com> Acked-by: Ingo Molnar <mingo@kernel.org> Acked-by: "Jason A. Donenfeld" <Jason@zx2c4.com> Link: https://lore.kernel.org/r/20250607200454.73587-11-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 2374bf2 commit 9b2d720

6 files changed

Lines changed: 10 additions & 37 deletions

File tree

arch/sparc/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ config SPARC64
110110
select HAVE_SETUP_PER_CPU_AREA
111111
select NEED_PER_CPU_EMBED_FIRST_CHUNK
112112
select NEED_PER_CPU_PAGE_FIRST_CHUNK
113-
select ARCH_HAS_CRC32
114113

115114
config ARCH_PROC_KCORE_TEXT
116115
def_bool y

arch/sparc/lib/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,3 @@ lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o
5454
obj-$(CONFIG_SPARC64) += iomap.o
5555
obj-$(CONFIG_SPARC32) += atomic32.o
5656
obj-$(CONFIG_SPARC64) += PeeCeeI.o
57-
obj-$(CONFIG_CRC32_ARCH) += crc32-sparc.o
58-
crc32-sparc-y := crc32.o crc32c_asm.o

lib/crc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ config CRC32_ARCH
7575
default y if PPC64 && ALTIVEC
7676
default y if RISCV && RISCV_ISA_ZBC
7777
default y if S390
78+
default y if SPARC64
7879

7980
config CRC64
8081
tristate

lib/crc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ crc32-$(CONFIG_ARM64) += arm64/crc32-core.o
2828
crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o
2929
crc32-$(CONFIG_RISCV) += riscv/crc32_lsb.o riscv/crc32_msb.o
3030
crc32-$(CONFIG_S390) += s390/crc32le-vx.o s390/crc32be-vx.o
31+
crc32-$(CONFIG_SPARC) += sparc/crc32c_asm.o
3132
endif
3233

3334
obj-$(CONFIG_CRC64) += crc64.o
Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,17 @@
88
* Kent Liu <kent.liu@intel.com>
99
*/
1010

11-
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12-
13-
#include <linux/init.h>
14-
#include <linux/module.h>
15-
#include <linux/kernel.h>
16-
#include <linux/crc32.h>
1711
#include <asm/pstate.h>
1812
#include <asm/elf.h>
1913

2014
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32c_opcode);
2115

22-
u32 crc32_le_arch(u32 crc, const u8 *data, size_t len)
23-
{
24-
return crc32_le_base(crc, data, len);
25-
}
26-
EXPORT_SYMBOL(crc32_le_arch);
16+
#define crc32_le_arch crc32_le_base /* not implemented on this arch */
17+
#define crc32_be_arch crc32_be_base /* not implemented on this arch */
2718

2819
void crc32c_sparc64(u32 *crcp, const u64 *data, size_t len);
2920

30-
u32 crc32c_arch(u32 crc, const u8 *data, size_t len)
21+
static inline u32 crc32c_arch(u32 crc, const u8 *data, size_t len)
3122
{
3223
size_t n = -(uintptr_t)data & 7;
3324

@@ -51,43 +42,26 @@ u32 crc32c_arch(u32 crc, const u8 *data, size_t len)
5142
crc = crc32c_base(crc, data, len);
5243
return crc;
5344
}
54-
EXPORT_SYMBOL(crc32c_arch);
55-
56-
u32 crc32_be_arch(u32 crc, const u8 *data, size_t len)
57-
{
58-
return crc32_be_base(crc, data, len);
59-
}
60-
EXPORT_SYMBOL(crc32_be_arch);
6145

62-
static int __init crc32_sparc_init(void)
46+
#define crc32_mod_init_arch crc32_mod_init_arch
47+
static inline void crc32_mod_init_arch(void)
6348
{
6449
unsigned long cfr;
6550

6651
if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
67-
return 0;
52+
return;
6853

6954
__asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
7055
if (!(cfr & CFR_CRC32C))
71-
return 0;
56+
return;
7257

7358
static_branch_enable(&have_crc32c_opcode);
7459
pr_info("Using sparc64 crc32c opcode optimized CRC32C implementation\n");
75-
return 0;
7660
}
77-
subsys_initcall(crc32_sparc_init);
7861

79-
static void __exit crc32_sparc_exit(void)
80-
{
81-
}
82-
module_exit(crc32_sparc_exit);
83-
84-
u32 crc32_optimizations(void)
62+
static inline u32 crc32_optimizations_arch(void)
8563
{
8664
if (static_key_enabled(&have_crc32c_opcode))
8765
return CRC32C_OPTIMIZATION;
8866
return 0;
8967
}
90-
EXPORT_SYMBOL(crc32_optimizations);
91-
92-
MODULE_LICENSE("GPL");
93-
MODULE_DESCRIPTION("CRC32c (Castagnoli), sparc64 crc32c opcode accelerated");

0 commit comments

Comments
 (0)