]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/crc: sparc: Migrate optimized CRC code into lib/crc/
authorEric Biggers <ebiggers@kernel.org>
Sat, 7 Jun 2025 20:04:52 +0000 (13:04 -0700)
committerEric Biggers <ebiggers@kernel.org>
Mon, 30 Jun 2025 16:31:57 +0000 (09:31 -0700)
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>
arch/sparc/Kconfig
arch/sparc/lib/Makefile
lib/crc/Kconfig
lib/crc/Makefile
lib/crc/sparc/crc32.h [moved from arch/sparc/lib/crc32.c with 60% similarity]
lib/crc/sparc/crc32c_asm.S [moved from arch/sparc/lib/crc32c_asm.S with 100% similarity]

index 0f88123925a4f9f95b1b8336ff80798dacd243f5..dcfdb7f1dae9763b58646a910d252135d8139014 100644 (file)
@@ -110,7 +110,6 @@ config SPARC64
        select HAVE_SETUP_PER_CPU_AREA
        select NEED_PER_CPU_EMBED_FIRST_CHUNK
        select NEED_PER_CPU_PAGE_FIRST_CHUNK
-       select ARCH_HAS_CRC32
 
 config ARCH_PROC_KCORE_TEXT
        def_bool y
index 5cf9781d68b40e0fa61d5885ef2f563b7c2d9c1e..2d6c3c535273480981f08d379a6501eb3960de8f 100644 (file)
@@ -54,5 +54,3 @@ lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o
 obj-$(CONFIG_SPARC64) += iomap.o
 obj-$(CONFIG_SPARC32) += atomic32.o
 obj-$(CONFIG_SPARC64) += PeeCeeI.o
-obj-$(CONFIG_CRC32_ARCH) += crc32-sparc.o
-crc32-sparc-y := crc32.o crc32c_asm.o
index c8d540a6b04a0563e87097706597e17dc89f8aff..0eacefdccc2861c4637551037a8d137d71078b30 100644 (file)
@@ -75,6 +75,7 @@ config CRC32_ARCH
        default y if PPC64 && ALTIVEC
        default y if RISCV && RISCV_ISA_ZBC
        default y if S390
+       default y if SPARC64
 
 config CRC64
        tristate
index bec58266251f8555c5461368659cf09031c9894b..81e176db0947c6d5429e52da7354831b2cb92847 100644 (file)
@@ -28,6 +28,7 @@ crc32-$(CONFIG_ARM64) += arm64/crc32-core.o
 crc32-$(CONFIG_PPC) += powerpc/crc32c-vpmsum_asm.o
 crc32-$(CONFIG_RISCV) += riscv/crc32_lsb.o riscv/crc32_msb.o
 crc32-$(CONFIG_S390) += s390/crc32le-vx.o s390/crc32be-vx.o
+crc32-$(CONFIG_SPARC) += sparc/crc32c_asm.o
 endif
 
 obj-$(CONFIG_CRC64) += crc64.o
similarity index 60%
rename from arch/sparc/lib/crc32.c
rename to lib/crc/sparc/crc32.h
index 40d4720a42a1b4be3cc893be01a586588ce33135..60f2765ac01573ee024030c1dd9a832973d9c151 100644 (file)
@@ -8,26 +8,17 @@
  *          Kent Liu <kent.liu@intel.com>
  */
 
-#define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
-
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/crc32.h>
 #include <asm/pstate.h>
 #include <asm/elf.h>
 
 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32c_opcode);
 
-u32 crc32_le_arch(u32 crc, const u8 *data, size_t len)
-{
-       return crc32_le_base(crc, data, len);
-}
-EXPORT_SYMBOL(crc32_le_arch);
+#define crc32_le_arch crc32_le_base /* not implemented on this arch */
+#define crc32_be_arch crc32_be_base /* not implemented on this arch */
 
 void crc32c_sparc64(u32 *crcp, const u64 *data, size_t len);
 
-u32 crc32c_arch(u32 crc, const u8 *data, size_t len)
+static inline u32 crc32c_arch(u32 crc, const u8 *data, size_t len)
 {
        size_t n = -(uintptr_t)data & 7;
 
@@ -51,43 +42,26 @@ u32 crc32c_arch(u32 crc, const u8 *data, size_t len)
                crc = crc32c_base(crc, data, len);
        return crc;
 }
-EXPORT_SYMBOL(crc32c_arch);
-
-u32 crc32_be_arch(u32 crc, const u8 *data, size_t len)
-{
-       return crc32_be_base(crc, data, len);
-}
-EXPORT_SYMBOL(crc32_be_arch);
 
-static int __init crc32_sparc_init(void)
+#define crc32_mod_init_arch crc32_mod_init_arch
+static inline void crc32_mod_init_arch(void)
 {
        unsigned long cfr;
 
        if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
-               return 0;
+               return;
 
        __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
        if (!(cfr & CFR_CRC32C))
-               return 0;
+               return;
 
        static_branch_enable(&have_crc32c_opcode);
        pr_info("Using sparc64 crc32c opcode optimized CRC32C implementation\n");
-       return 0;
 }
-subsys_initcall(crc32_sparc_init);
 
-static void __exit crc32_sparc_exit(void)
-{
-}
-module_exit(crc32_sparc_exit);
-
-u32 crc32_optimizations(void)
+static inline u32 crc32_optimizations_arch(void)
 {
        if (static_key_enabled(&have_crc32c_opcode))
                return CRC32C_OPTIMIZATION;
        return 0;
 }
-EXPORT_SYMBOL(crc32_optimizations);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("CRC32c (Castagnoli), sparc64 crc32c opcode accelerated");