xref: /linux/lib/raid/raid6/arm/neon.c (revision 35472bc6f31b64e58d1fe560340aa4f1684b8d6d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/lib/raid6/neon.c - RAID6 syndrome calculation using ARM NEON intrinsics
4  *
5  * Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
6  */
7 
8 #include <linux/raid/pq.h>
9 #include <asm/simd.h>
10 
11 /*
12  * There are 2 reasons these wrappers are kept in a separate compilation unit
13  * from the actual implementations in neonN.c (generated from neon.uc by
14  * unroll.awk):
15  * - the actual implementations use NEON intrinsics, and the GCC support header
16  *   (arm_neon.h) is not fully compatible (type wise) with the kernel;
17  * - the neonN.c files are compiled with -mfpu=neon and optimization enabled,
18  *   and we have to make sure that we never use *any* NEON/VFP instructions
19  *   outside a kernel_neon_begin()/kernel_neon_end() pair.
20  */
21 
22 #define RAID6_NEON_WRAPPER(_n)						\
23 	static void raid6_neon ## _n ## _gen_syndrome(int disks,	\
24 					size_t bytes, void **ptrs)	\
25 	{								\
26 		void raid6_neon ## _n  ## _gen_syndrome_real(int,	\
27 						unsigned long, void**);	\
28 		scoped_ksimd()						\
29 			raid6_neon ## _n ## _gen_syndrome_real(disks,	\
30 					(unsigned long)bytes, ptrs);	\
31 	}								\
32 	static void raid6_neon ## _n ## _xor_syndrome(int disks,	\
33 					int start, int stop, 		\
34 					size_t bytes, void **ptrs)	\
35 	{								\
36 		void raid6_neon ## _n  ## _xor_syndrome_real(int,	\
37 				int, int, unsigned long, void**);	\
38 		scoped_ksimd()						\
39 			raid6_neon ## _n ## _xor_syndrome_real(disks,	\
40 				start, stop, (unsigned long)bytes, ptrs);\
41 	}								\
42 	struct raid6_calls const raid6_neonx ## _n = {			\
43 		.gen_syndrome	= raid6_neon ## _n ## _gen_syndrome,	\
44 		.xor_syndrome	= raid6_neon ## _n ## _xor_syndrome,	\
45 		.valid		= raid6_have_neon,			\
46 		.name		= "neonx" #_n,				\
47 	}
48 
49 static int raid6_have_neon(void)
50 {
51 	return cpu_has_neon();
52 }
53 
54 RAID6_NEON_WRAPPER(1);
55 RAID6_NEON_WRAPPER(2);
56 RAID6_NEON_WRAPPER(4);
57 RAID6_NEON_WRAPPER(8);
58