xref: /isa-l/include/raid.h (revision fa5b8baf84e6a18dbaad48a3fa0d1fa062ae2fe8)
1 /**********************************************************************
2   Copyright(c) 2011-2015 Intel Corporation All rights reserved.
3 
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in
11       the documentation and/or other materials provided with the
12       distribution.
13     * Neither the name of Intel Corporation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29 
30 #ifndef _RAID_H_
31 #define _RAID_H_
32 
33 /**
34  *  @file  raid.h
35  *  @brief Interface to RAID functions - XOR and P+Q calculation.
36  *
37  *  This file defines the interface to optimized XOR calculation (RAID5) or P+Q
38  *  dual parity (RAID6).  Operations are carried out on an array of pointers to
39  *  sources and output arrays.
40  */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* Multi-binary functions */
47 
48 /**
49  * @brief Generate XOR parity vector from N sources, runs appropriate version.
50  *
51  * This function determines what instruction sets are enabled and
52  * selects the appropriate version at runtime.
53  *
54  * @param vects   Number of source+dest vectors in array. Must be > 2.
55  * @param len     Length of each vector in bytes.
56  * @param array   Array of pointers to source and dest. For XOR the dest is
57  *                the last pointer. ie array[vects-1]. Src and dest
58  *                pointers must be aligned to 32B.
59  *
60  * @returns 0 pass, other fail
61  */
62 
63 int
64 xor_gen(int vects, int len, void **array);
65 
66 /**
67  * @brief Checks that array has XOR parity sum of 0 across all vectors, runs appropriate version.
68  *
69  * This function determines what instruction sets are enabled and
70  * selects the appropriate version at runtime.
71  *
72  * @param vects   Number of vectors in array. Must be > 1.
73  * @param len     Length of each vector in bytes.
74  * @param array   Array of pointers to vectors. Src and dest pointers
75  *                must be aligned to 16B.
76  *
77  * @returns 0 pass, other fail
78  */
79 
80 int
81 xor_check(int vects, int len, void **array);
82 
83 /**
84  * @brief Generate P+Q parity vectors from N sources, runs appropriate version.
85  *
86  * This function determines what instruction sets are enabled and
87  * selects the appropriate version at runtime.
88  *
89  * @param vects   Number of source+dest vectors in array. Must be > 3.
90  * @param len     Length of each vector in bytes. Must be 32B aligned.
91  * @param array   Array of pointers to source and dest. For P+Q the dest
92  *                is the last two pointers. ie array[vects-2],
93  *                array[vects-1].  P and Q parity vectors are
94  *                written to these last two pointers. Src and dest
95  *                pointers must be aligned to 32B.
96  *
97  * @returns 0 pass, other fail
98  */
99 
100 int
101 pq_gen(int vects, int len, void **array);
102 
103 /**
104  * @brief Checks that array of N sources, P and Q are consistent across all vectors, runs
105  * appropriate version.
106  *
107  * This function determines what instruction sets are enabled and
108  * selects the appropriate version at runtime.
109  *
110  * @param vects  Number of vectors in array including P&Q. Must be > 3.
111  * @param len    Length of each vector in bytes. Must be 16B aligned.
112  * @param array  Array of pointers to source and P, Q. P and Q parity
113  *               are assumed to be the last two pointers in the array.
114  *               All pointers must be aligned to 16B.
115  *
116  * @returns 0 pass, other fail
117  */
118 
119 int
120 pq_check(int vects, int len, void **array);
121 
122 /* Arch specific versions */
123 // x86 only
124 #if defined(__i386__) || defined(__x86_64__)
125 
126 /**
127  * @brief Generate XOR parity vector from N sources.
128  * @requires SSE4.1
129  *
130  * @param vects   Number of source+dest vectors in array. Must be > 2.
131  * @param len     Length of each vector in bytes.
132  * @param array   Array of pointers to source and dest. For XOR the dest is
133  *                the last pointer. ie array[vects-1]. Src and dest pointers
134  *                must be aligned to 16B.
135  *
136  * @returns 0 pass, other fail
137  */
138 
139 int
140 xor_gen_sse(int vects, int len, void **array);
141 
142 /**
143  * @brief Generate XOR parity vector from N sources.
144  * @requires AVX
145  *
146  * @param vects   Number of source+dest vectors in array. Must be > 2.
147  * @param len     Length of each vector in bytes.
148  * @param array   Array of pointers to source and dest. For XOR the dest is
149  *                the last pointer. ie array[vects-1]. Src and dest pointers
150  *                must be aligned to 32B.
151  *
152  * @returns 0 pass, other fail
153  */
154 
155 int
156 xor_gen_avx(int vects, int len, void **array);
157 
158 /**
159  * @brief Checks that array has XOR parity sum of 0 across all vectors.
160  * @requires SSE4.1
161  *
162  * @param vects   Number of vectors in array. Must be > 1.
163  * @param len     Length of each vector in bytes.
164  * @param array   Array of pointers to vectors. Src and dest pointers
165  *                must be aligned to 16B.
166  *
167  * @returns 0 pass, other fail
168  */
169 
170 int
171 xor_check_sse(int vects, int len, void **array);
172 
173 /**
174  * @brief Generate P+Q parity vectors from N sources.
175  * @requires SSE4.1
176  *
177  * @param vects   Number of source+dest vectors in array. Must be > 3.
178  * @param len     Length of each vector in bytes. Must be 16B aligned.
179  * @param array   Array of pointers to source and dest. For P+Q the dest
180  *                is the last two pointers. ie array[vects-2],
181  *                array[vects-1]. P and Q parity vectors are
182  *                written to these last two pointers. Src and dest
183  *                pointers must be aligned to 16B.
184  *
185  * @returns 0 pass, other fail
186  */
187 
188 int
189 pq_gen_sse(int vects, int len, void **array);
190 
191 /**
192  * @brief Generate P+Q parity vectors from N sources.
193  * @requires AVX
194  *
195  * @param vects   Number of source+dest vectors in array. Must be > 3.
196  * @param len     Length of each vector in bytes. Must be 16B aligned.
197  * @param array   Array of pointers to source and dest. For P+Q the dest
198  *                is the last two pointers. ie array[vects-2],
199  *                array[vects-1]. P and Q parity vectors are
200  *                written to these last two pointers. Src and dest
201  *                pointers must be aligned to 16B.
202  *
203  * @returns 0 pass, other fail
204  */
205 
206 int
207 pq_gen_avx(int vects, int len, void **array);
208 
209 /**
210  * @brief Generate P+Q parity vectors from N sources.
211  * @requires AVX2
212  *
213  * @param vects   Number of source+dest vectors in array. Must be > 3.
214  * @param len     Length of each vector in bytes. Must be 32B aligned.
215  * @param array   Array of pointers to source and dest. For P+Q the dest
216  *                is the last two pointers. ie array[vects-2],
217  *                array[vects-1]. P and Q parity vectors are
218  *                written to these last two pointers. Src and dest
219  *                pointers must be aligned to 32B.
220  *
221  * @returns 0 pass, other fail
222  */
223 
224 int
225 pq_gen_avx2(int vects, int len, void **array);
226 
227 /**
228  * @brief Checks that array of N sources, P and Q are consistent across all vectors.
229  * @requires SSE4.1
230  *
231  * @param vects  Number of vectors in array including P&Q. Must be > 3.
232  * @param len    Length of each vector in bytes. Must be 16B aligned.
233  * @param array  Array of pointers to source and P, Q. P and Q parity
234                  are assumed to be the last two pointers in the array.
235                  All pointers must be aligned to 16B.
236  * @returns 0 pass, other fail
237  */
238 
239 int
240 pq_check_sse(int vects, int len, void **array);
241 
242 #endif
243 
244 /**
245  * @brief Generate P+Q parity vectors from N sources, runs baseline version.
246  * @param vects   Number of source+dest vectors in array. Must be > 3.
247  * @param len     Length of each vector in bytes. Must be 16B aligned.
248  * @param array   Array of pointers to source and dest. For P+Q the dest
249  * 		  is the last two pointers. ie array[vects-2],
250  * 		  array[vects-1]. P and Q parity vectors are
251  * 		  written to these last two pointers. Src and dest pointers
252  * 		  must be aligned to 16B.
253  *
254  * @returns 0 pass, other fail
255  */
256 
257 int
258 pq_gen_base(int vects, int len, void **array);
259 
260 /**
261  * @brief Generate XOR parity vector from N sources, runs baseline version.
262  * @param vects   Number of source+dest vectors in array. Must be > 2.
263  * @param len     Length of each vector in bytes.
264  * @param array   Array of pointers to source and dest. For XOR the dest is
265  * 		  the last pointer. ie array[vects-1]. Src and dest pointers
266  * 		  must be aligned to 32B.
267  *
268  * @returns 0 pass, other fail
269  */
270 
271 int
272 xor_gen_base(int vects, int len, void **array);
273 
274 /**
275  * @brief Checks that array has XOR parity sum of 0 across all vectors, runs baseline version.
276  *
277  * @param vects   Number of vectors in array. Must be > 1.
278  * @param len     Length of each vector in bytes.
279  * @param array   Array of pointers to vectors. Src and dest pointers
280  *                must be aligned to 16B.
281  *
282  * @returns 0 pass, other fail
283  */
284 
285 int
286 xor_check_base(int vects, int len, void **array);
287 
288 /**
289  * @brief Checks that array of N sources, P and Q are consistent across all vectors, runs baseline
290  * version.
291  *
292  * @param vects  Number of vectors in array including P&Q. Must be > 3.
293  * @param len    Length of each vector in bytes. Must be 16B aligned.
294  * @param array  Array of pointers to source and P, Q. P and Q parity
295  *               are assumed to be the last two pointers in the array.
296  *               All pointers must be aligned to 16B.
297  *
298  * @returns 0 pass, other fail
299  */
300 
301 int
302 pq_check_base(int vects, int len, void **array);
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif //_RAID_H_
309