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

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

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

+7 -30
-1
arch/mips/Kconfig
··· 2024 2024 config CPU_MIPSR6 2025 2025 bool 2026 2026 default y if CPU_MIPS32_R6 || CPU_MIPS64_R6 2027 - select ARCH_HAS_CRC32 2028 2027 select CPU_HAS_RIXI 2029 2028 select CPU_HAS_DIEI if !CPU_DIEI_BROKEN 2030 2029 select HAVE_ARCH_BITREVERSE
-2
arch/mips/lib/Makefile
··· 16 16 obj-$(CONFIG_CPU_GENERIC_DUMP_TLB) += dump_tlb.o 17 17 obj-$(CONFIG_CPU_R3000) += r3k_dump_tlb.o 18 18 19 - obj-$(CONFIG_CRC32_ARCH) += crc32-mips.o 20 - 21 19 # libgcc-style stuff needed in the kernel 22 20 obj-y += bswapsi.o bswapdi.o multi3.o
+6 -27
arch/mips/lib/crc32-mips.c lib/crc/mips/crc32.h
··· 9 9 */ 10 10 11 11 #include <linux/cpufeature.h> 12 - #include <linux/crc32.h> 13 - #include <linux/init.h> 14 - #include <linux/kernel.h> 15 - #include <linux/module.h> 16 12 #include <asm/mipsregs.h> 17 13 #include <linux/unaligned.h> 18 14 ··· 60 64 61 65 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32); 62 66 63 - u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 67 + static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len) 64 68 { 65 69 if (!static_branch_likely(&have_crc32)) 66 70 return crc32_le_base(crc, p, len); ··· 102 106 103 107 return crc; 104 108 } 105 - EXPORT_SYMBOL(crc32_le_arch); 106 109 107 - u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 110 + static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len) 108 111 { 109 112 if (!static_branch_likely(&have_crc32)) 110 113 return crc32c_base(crc, p, len); ··· 144 149 } 145 150 return crc; 146 151 } 147 - EXPORT_SYMBOL(crc32c_arch); 148 152 149 - u32 crc32_be_arch(u32 crc, const u8 *p, size_t len) 150 - { 151 - return crc32_be_base(crc, p, len); 152 - } 153 - EXPORT_SYMBOL(crc32_be_arch); 153 + #define crc32_be_arch crc32_be_base /* not implemented on this arch */ 154 154 155 - static int __init crc32_mips_init(void) 155 + #define crc32_mod_init_arch crc32_mod_init_arch 156 + static inline void crc32_mod_init_arch(void) 156 157 { 157 158 if (cpu_have_feature(cpu_feature(MIPS_CRC32))) 158 159 static_branch_enable(&have_crc32); 159 - return 0; 160 160 } 161 - subsys_initcall(crc32_mips_init); 162 161 163 - static void __exit crc32_mips_exit(void) 164 - { 165 - } 166 - module_exit(crc32_mips_exit); 167 - 168 - u32 crc32_optimizations(void) 162 + static inline u32 crc32_optimizations_arch(void) 169 163 { 170 164 if (static_key_enabled(&have_crc32)) 171 165 return CRC32_LE_OPTIMIZATION | CRC32C_OPTIMIZATION; 172 166 return 0; 173 167 } 174 - EXPORT_SYMBOL(crc32_optimizations); 175 - 176 - MODULE_AUTHOR("Marcin Nowakowski <marcin.nowakowski@mips.com"); 177 - MODULE_DESCRIPTION("CRC32 and CRC32C using optional MIPS instructions"); 178 - MODULE_LICENSE("GPL v2");
+1
lib/crc/Kconfig
··· 69 69 default y if ARM && KERNEL_MODE_NEON 70 70 default y if ARM64 71 71 default y if LOONGARCH 72 + default y if MIPS && CPU_MIPSR6 72 73 73 74 config CRC64 74 75 tristate