xref: /linux/lib/raid/xor/xor_impl.h (revision 440d6635b20037bc9ad46b20817d7b61cef0fc1b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _XOR_IMPL_H
3 #define _XOR_IMPL_H
4 
5 #include <linux/init.h>
6 #include <linux/minmax.h>
7 
8 struct xor_block_template {
9 	struct xor_block_template *next;
10 	const char *name;
11 	int speed;
12 	void (*xor_gen)(void *dest, void **srcs, unsigned int src_cnt,
13 			unsigned int bytes);
14 };
15 
16 #define __DO_XOR_BLOCKS(_name, _handle1, _handle2, _handle3, _handle4)	\
17 void								\
18 xor_gen_##_name(void *dest, void **srcs, unsigned int src_cnt,		\
19 		unsigned int bytes)					\
20 {									\
21 	unsigned int src_off = 0;					\
22 									\
23 	while (src_cnt > 0) {						\
24 		unsigned int this_cnt = min(src_cnt, 4);		\
25 									\
26 		if (this_cnt == 1)					\
27 			_handle1(bytes, dest, srcs[src_off]);		\
28 		else if (this_cnt == 2)					\
29 			_handle2(bytes, dest, srcs[src_off],		\
30 				srcs[src_off + 1]);			\
31 		else if (this_cnt == 3)					\
32 			_handle3(bytes, dest, srcs[src_off],		\
33 				srcs[src_off + 1], srcs[src_off + 2]);	\
34 		else							\
35 			_handle4(bytes, dest, srcs[src_off],		\
36 				srcs[src_off + 1], srcs[src_off + 2],	\
37 				srcs[src_off + 3]);			\
38 									\
39 		src_cnt -= this_cnt;					\
40 		src_off += this_cnt;					\
41 	}								\
42 }
43 
44 #define DO_XOR_BLOCKS(_name, _handle1, _handle2, _handle3, _handle4)	\
45 	static __DO_XOR_BLOCKS(_name, _handle1, _handle2, _handle3, _handle4)
46 
47 /* generic implementations */
48 extern struct xor_block_template xor_block_8regs;
49 extern struct xor_block_template xor_block_32regs;
50 extern struct xor_block_template xor_block_8regs_p;
51 extern struct xor_block_template xor_block_32regs_p;
52 
53 void __init xor_register(struct xor_block_template *tmpl);
54 void __init xor_force(struct xor_block_template *tmpl);
55 
56 #endif /* _XOR_IMPL_H */
57