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

lib/crc: loongarch: Migrate optimized CRC code into lib/crc/

Move the loongarch-optimized CRC code from arch/loongarch/lib/crc* into
its new location in lib/crc/loongarch/, 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-6-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+7 -30
-1
arch/loongarch/Kconfig
··· 15 15 select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE 16 16 select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI 17 17 select ARCH_HAS_CPU_FINALIZE_INIT 18 - select ARCH_HAS_CRC32 19 18 select ARCH_HAS_CURRENT_STACK_POINTER 20 19 select ARCH_HAS_DEBUG_VM_PGTABLE 21 20 select ARCH_HAS_FAST_MULTIPLIER
-2
arch/loongarch/lib/Makefile
··· 11 11 obj-$(CONFIG_CPU_HAS_LSX) += xor_simd.o xor_simd_glue.o 12 12 13 13 obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o 14 - 15 - obj-$(CONFIG_CRC32_ARCH) += crc32-loongarch.o
+6 -27
arch/loongarch/lib/crc32-loongarch.c lib/crc/loongarch/crc32.h
··· 10 10 */ 11 11 12 12 #include <asm/cpu-features.h> 13 - #include <linux/crc32.h> 14 - #include <linux/export.h> 15 - #include <linux/module.h> 16 13 #include <linux/unaligned.h> 17 14 18 15 #define _CRC32(crc, value, size, type) \ ··· 26 29 27 30 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); 28 31 29 - u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 32 + static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 30 33 { 31 34 if (!static_branch_likely(&have_crc32)) 32 35 return crc32_le_base(crc, p, len); ··· 61 64 62 65 return crc; 63 66 } 64 - EXPORT_SYMBOL(crc32_le_arch); 65 67 66 - u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 68 + static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 67 69 { 68 70 if (!static_branch_likely(&have_crc32)) 69 71 return crc32c_base(crc, p, len); ··· 97 101 98 102 return crc; 99 103 } 100 - EXPORT_SYMBOL(crc32c_arch); 101 104 102 - u32 crc32_be_arch(u32 crc, const u8 *p, size_t len) 103 - { 104 - return crc32_be_base(crc, p, len); 105 - } 106 - EXPORT_SYMBOL(crc32_be_arch); 105 + #define crc32_be_arch crc32_be_base /* not implemented on this arch */ 107 106 108 - static int __init crc32_loongarch_init(void) 107 + #define crc32_mod_init_arch crc32_mod_init_arch 108 + static inline void crc32_mod_init_arch(void) 109 109 { 110 110 if (cpu_has_crc32) 111 111 static_branch_enable(&have_crc32); 112 - return 0; 113 112 } 114 - subsys_initcall(crc32_loongarch_init); 115 113 116 - static void __exit crc32_loongarch_exit(void) 117 - { 118 - } 119 - module_exit(crc32_loongarch_exit); 120 - 121 - u32 crc32_optimizations(void) 114 + static inline u32 crc32_optimizations_arch(void) 122 115 { 123 116 if (static_key_enabled(&have_crc32)) 124 117 return CRC32_LE_OPTIMIZATION | CRC32C_OPTIMIZATION; 125 118 return 0; 126 119 } 127 - EXPORT_SYMBOL(crc32_optimizations); 128 - 129 - MODULE_AUTHOR("Min Zhou <zhoumin@loongson.cn>"); 130 - MODULE_AUTHOR("Huacai Chen <chenhuacai@loongson.cn>"); 131 - MODULE_DESCRIPTION("CRC32 and CRC32C using LoongArch crc* instructions"); 132 - MODULE_LICENSE("GPL v2");
+1
lib/crc/Kconfig
··· 68 68 depends on CRC32 && CRC_OPTIMIZATIONS 69 69 default y if ARM && KERNEL_MODE_NEON 70 70 default y if ARM64 71 + default y if LOONGARCH 71 72 72 73 config CRC64 73 74 tristate