Skip to content

Commit da4fd65

Browse files
author
Eric Biggers
committed
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>
1 parent b10d2d2 commit da4fd65

4 files changed

Lines changed: 7 additions & 30 deletions

File tree

arch/mips/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,6 @@ config CPU_MIPSR5
20242024
config CPU_MIPSR6
20252025
bool
20262026
default y if CPU_MIPS32_R6 || CPU_MIPS64_R6
2027-
select ARCH_HAS_CRC32
20282027
select CPU_HAS_RIXI
20292028
select CPU_HAS_DIEI if !CPU_DIEI_BROKEN
20302029
select HAVE_ARCH_BITREVERSE

arch/mips/lib/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ lib-$(CONFIG_GENERIC_CSUM) := $(filter-out csum_partial.o, $(lib-y))
1616
obj-$(CONFIG_CPU_GENERIC_DUMP_TLB) += dump_tlb.o
1717
obj-$(CONFIG_CPU_R3000) += r3k_dump_tlb.o
1818

19-
obj-$(CONFIG_CRC32_ARCH) += crc32-mips.o
20-
2119
# libgcc-style stuff needed in the kernel
2220
obj-y += bswapsi.o bswapdi.o multi3.o

lib/crc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ config CRC32_ARCH
6969
default y if ARM && KERNEL_MODE_NEON
7070
default y if ARM64
7171
default y if LOONGARCH
72+
default y if MIPS && CPU_MIPSR6
7273

7374
config CRC64
7475
tristate
Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
*/
1010

1111
#include <linux/cpufeature.h>
12-
#include <linux/crc32.h>
13-
#include <linux/init.h>
14-
#include <linux/kernel.h>
15-
#include <linux/module.h>
1612
#include <asm/mipsregs.h>
1713
#include <linux/unaligned.h>
1814

@@ -64,7 +60,7 @@ do { \
6460

6561
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32);
6662

67-
u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
63+
static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
6864
{
6965
if (!static_branch_likely(&have_crc32))
7066
return crc32_le_base(crc, p, len);
@@ -106,9 +102,8 @@ u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
106102

107103
return crc;
108104
}
109-
EXPORT_SYMBOL(crc32_le_arch);
110105

111-
u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
106+
static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
112107
{
113108
if (!static_branch_likely(&have_crc32))
114109
return crc32c_base(crc, p, len);
@@ -149,35 +144,19 @@ u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
149144
}
150145
return crc;
151146
}
152-
EXPORT_SYMBOL(crc32c_arch);
153147

154-
u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
155-
{
156-
return crc32_be_base(crc, p, len);
157-
}
158-
EXPORT_SYMBOL(crc32_be_arch);
148+
#define crc32_be_arch crc32_be_base /* not implemented on this arch */
159149

160-
static int __init crc32_mips_init(void)
150+
#define crc32_mod_init_arch crc32_mod_init_arch
151+
static inline void crc32_mod_init_arch(void)
161152
{
162153
if (cpu_have_feature(cpu_feature(MIPS_CRC32)))
163154
static_branch_enable(&have_crc32);
164-
return 0;
165155
}
166-
subsys_initcall(crc32_mips_init);
167156

168-
static void __exit crc32_mips_exit(void)
169-
{
170-
}
171-
module_exit(crc32_mips_exit);
172-
173-
u32 crc32_optimizations(void)
157+
static inline u32 crc32_optimizations_arch(void)
174158
{
175159
if (static_key_enabled(&have_crc32))
176160
return CRC32_LE_OPTIMIZATION | CRC32C_OPTIMIZATION;
177161
return 0;
178162
}
179-
EXPORT_SYMBOL(crc32_optimizations);
180-
181-
MODULE_AUTHOR("Marcin Nowakowski <marcin.nowakowski@mips.com");
182-
MODULE_DESCRIPTION("CRC32 and CRC32C using optional MIPS instructions");
183-
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)