1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27d11965dSArd Biesheuvel /*
37d11965dSArd Biesheuvel * linux/lib/raid6/neon.c - RAID6 syndrome calculation using ARM NEON intrinsics
47d11965dSArd Biesheuvel *
57d11965dSArd Biesheuvel * Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
67d11965dSArd Biesheuvel */
77d11965dSArd Biesheuvel
87d11965dSArd Biesheuvel #include <linux/raid/pq.h>
97d11965dSArd Biesheuvel
107d11965dSArd Biesheuvel #ifdef __KERNEL__
117d11965dSArd Biesheuvel #include <asm/neon.h>
127d11965dSArd Biesheuvel #else
137d11965dSArd Biesheuvel #define kernel_neon_begin()
147d11965dSArd Biesheuvel #define kernel_neon_end()
157d11965dSArd Biesheuvel #define cpu_has_neon() (1)
167d11965dSArd Biesheuvel #endif
177d11965dSArd Biesheuvel
187d11965dSArd Biesheuvel /*
197d11965dSArd Biesheuvel * There are 2 reasons these wrappers are kept in a separate compilation unit
207d11965dSArd Biesheuvel * from the actual implementations in neonN.c (generated from neon.uc by
217d11965dSArd Biesheuvel * unroll.awk):
227d11965dSArd Biesheuvel * - the actual implementations use NEON intrinsics, and the GCC support header
237d11965dSArd Biesheuvel * (arm_neon.h) is not fully compatible (type wise) with the kernel;
247d11965dSArd Biesheuvel * - the neonN.c files are compiled with -mfpu=neon and optimization enabled,
257d11965dSArd Biesheuvel * and we have to make sure that we never use *any* NEON/VFP instructions
267d11965dSArd Biesheuvel * outside a kernel_neon_begin()/kernel_neon_end() pair.
277d11965dSArd Biesheuvel */
287d11965dSArd Biesheuvel
297d11965dSArd Biesheuvel #define RAID6_NEON_WRAPPER(_n) \
307d11965dSArd Biesheuvel static void raid6_neon ## _n ## _gen_syndrome(int disks, \
317d11965dSArd Biesheuvel size_t bytes, void **ptrs) \
327d11965dSArd Biesheuvel { \
337d11965dSArd Biesheuvel void raid6_neon ## _n ## _gen_syndrome_real(int, \
347d11965dSArd Biesheuvel unsigned long, void**); \
357d11965dSArd Biesheuvel kernel_neon_begin(); \
367d11965dSArd Biesheuvel raid6_neon ## _n ## _gen_syndrome_real(disks, \
377d11965dSArd Biesheuvel (unsigned long)bytes, ptrs); \
387d11965dSArd Biesheuvel kernel_neon_end(); \
397d11965dSArd Biesheuvel } \
400e833e69SArd Biesheuvel static void raid6_neon ## _n ## _xor_syndrome(int disks, \
410e833e69SArd Biesheuvel int start, int stop, \
420e833e69SArd Biesheuvel size_t bytes, void **ptrs) \
430e833e69SArd Biesheuvel { \
440e833e69SArd Biesheuvel void raid6_neon ## _n ## _xor_syndrome_real(int, \
450e833e69SArd Biesheuvel int, int, unsigned long, void**); \
460e833e69SArd Biesheuvel kernel_neon_begin(); \
470e833e69SArd Biesheuvel raid6_neon ## _n ## _xor_syndrome_real(disks, \
480e833e69SArd Biesheuvel start, stop, (unsigned long)bytes, ptrs); \
490e833e69SArd Biesheuvel kernel_neon_end(); \
500e833e69SArd Biesheuvel } \
517d11965dSArd Biesheuvel struct raid6_calls const raid6_neonx ## _n = { \
527d11965dSArd Biesheuvel raid6_neon ## _n ## _gen_syndrome, \
530e833e69SArd Biesheuvel raid6_neon ## _n ## _xor_syndrome, \
547d11965dSArd Biesheuvel raid6_have_neon, \
557d11965dSArd Biesheuvel "neonx" #_n, \
567d11965dSArd Biesheuvel 0 \
577d11965dSArd Biesheuvel }
587d11965dSArd Biesheuvel
raid6_have_neon(void)597d11965dSArd Biesheuvel static int raid6_have_neon(void)
607d11965dSArd Biesheuvel {
617d11965dSArd Biesheuvel return cpu_has_neon();
627d11965dSArd Biesheuvel }
637d11965dSArd Biesheuvel
647d11965dSArd Biesheuvel RAID6_NEON_WRAPPER(1);
657d11965dSArd Biesheuvel RAID6_NEON_WRAPPER(2);
667d11965dSArd Biesheuvel RAID6_NEON_WRAPPER(4);
677d11965dSArd Biesheuvel RAID6_NEON_WRAPPER(8);
68