Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+10 -37
-1
arch/sparc/Kconfig
··· 110 110 select HAVE_SETUP_PER_CPU_AREA 111 111 select NEED_PER_CPU_EMBED_FIRST_CHUNK 112 112 select NEED_PER_CPU_PAGE_FIRST_CHUNK 113 - select ARCH_HAS_CRC32 114 113 115 114 config ARCH_PROC_KCORE_TEXT 116 115 def_bool y
-2
arch/sparc/lib/Makefile
··· 54 54 obj-$(CONFIG_SPARC64) += iomap.o 55 55 obj-$(CONFIG_SPARC32) += atomic32.o 56 56 obj-$(CONFIG_SPARC64) += PeeCeeI.o 57 - obj-$(CONFIG_CRC32_ARCH) += crc32-sparc.o 58 - crc32-sparc-y := crc32.o crc32c_asm.o
+8 -34
arch/sparc/lib/crc32.c lib/crc/sparc/crc32.h
··· 8 8 * Kent Liu <kent.liu@intel.com> 9 9 */ 10 10 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> 17 11 #include <asm/pstate.h> 18 12 #include <asm/elf.h> 19 13 20 14 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32c_opcode); 21 15 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 */ 27 18 28 19 void crc32c_sparc64(u32 *crcp, const u64 *data, size_t len); 29 20 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) 31 22 { 32 23 size_t n = -(uintptr_t)data & 7; 33 24 ··· 42 51 crc = crc32c_base(crc, data, len); 43 52 return crc; 44 53 } 45 - EXPORT_SYMBOL(crc32c_arch); 46 54 47 - u32 crc32_be_arch(u32 crc, const u8 *data, size_t len) 48 - { 49 - return crc32_be_base(crc, data, len); 50 - } 51 - EXPORT_SYMBOL(crc32_be_arch); 52 - 53 - static int __init crc32_sparc_init(void) 55 + #define crc32_mod_init_arch crc32_mod_init_arch 56 + static inline void crc32_mod_init_arch(void) 54 57 { 55 58 unsigned long cfr; 56 59 57 60 if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO)) 58 - return 0; 61 + return; 59 62 60 63 __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr)); 61 64 if (!(cfr & CFR_CRC32C)) 62 - return 0; 65 + return; 63 66 64 67 static_branch_enable(&have_crc32c_opcode); 65 68 pr_info("Using sparc64 crc32c opcode optimized CRC32C implementation\n"); 66 - return 0; 67 69 } 68 - subsys_initcall(crc32_sparc_init); 69 70 70 - static void __exit crc32_sparc_exit(void) 71 - { 72 - } 73 - module_exit(crc32_sparc_exit); 74 - 75 - u32 crc32_optimizations(void) 71 + static inline u32 crc32_optimizations_arch(void) 76 72 { 77 73 if (static_key_enabled(&have_crc32c_opcode)) 78 74 return CRC32C_OPTIMIZATION; 79 75 return 0; 80 76 } 81 - EXPORT_SYMBOL(crc32_optimizations); 82 - 83 - MODULE_LICENSE("GPL"); 84 - MODULE_DESCRIPTION("CRC32c (Castagnoli), sparc64 crc32c opcode accelerated");
arch/sparc/lib/crc32c_asm.S lib/crc/sparc/crc32c_asm.S
+1
lib/crc/Kconfig
··· 75 75 default y if PPC64 && ALTIVEC 76 76 default y if RISCV && RISCV_ISA_ZBC 77 77 default y if S390 78 + default y if SPARC64 78 79 79 80 config CRC64 80 81 tristate
+1
lib/crc/Makefile
··· 28 28 crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o 29 29 crc32-$(CONFIG_RISCV) += riscv/crc32_lsb.o riscv/crc32_msb.o 30 30 crc32-$(CONFIG_S390) += s390/crc32le-vx.o s390/crc32be-vx.o 31 + crc32-$(CONFIG_SPARC) += sparc/crc32c_asm.o 31 32 endif 32 33 33 34 obj-$(CONFIG_CRC64) += crc64.o