1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012 Intel Corporation
4 * Author: Jim Kukunas <james.t.kukunas@linux.intel.com>
7 #include <linux/raid/pq.h>
10 static int raid6_has_avx2(void)
12 return boot_cpu_has(X86_FEATURE_AVX2) &&
13 boot_cpu_has(X86_FEATURE_AVX);
16 static void raid6_2data_recov_avx2(int disks, size_t bytes, int faila,
17 int failb, void **ptrs)
20 const u8 *pbmul; /* P multiplier table for B data */
21 const u8 *qmul; /* Q multiplier table (for both) */
24 p = (u8 *)ptrs[disks-2];
25 q = (u8 *)ptrs[disks-1];
27 /* Compute syndrome with zero for the missing data pages
28 Use the dead data pages as temporary storage for
29 delta p and delta q */
30 dp = (u8 *)ptrs[faila];
31 ptrs[faila] = (void *)raid6_empty_zero_page;
33 dq = (u8 *)ptrs[failb];
34 ptrs[failb] = (void *)raid6_empty_zero_page;
37 raid6_call.gen_syndrome(disks, bytes, ptrs);
39 /* Restore pointer table */
45 /* Now, pick the proper data tables */
46 pbmul = raid6_vgfmul[raid6_gfexi[failb-faila]];
47 qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila] ^
53 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f));
57 asm volatile("vmovdqa %0, %%ymm1" : : "m" (q[0]));
58 asm volatile("vmovdqa %0, %%ymm9" : : "m" (q[32]));
59 asm volatile("vmovdqa %0, %%ymm0" : : "m" (p[0]));
60 asm volatile("vmovdqa %0, %%ymm8" : : "m" (p[32]));
61 asm volatile("vpxor %0, %%ymm1, %%ymm1" : : "m" (dq[0]));
62 asm volatile("vpxor %0, %%ymm9, %%ymm9" : : "m" (dq[32]));
63 asm volatile("vpxor %0, %%ymm0, %%ymm0" : : "m" (dp[0]));
64 asm volatile("vpxor %0, %%ymm8, %%ymm8" : : "m" (dp[32]));
73 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (qmul[0]));
74 asm volatile("vbroadcasti128 %0, %%ymm5" : : "m" (qmul[16]));
76 asm volatile("vpsraw $4, %ymm1, %ymm3");
77 asm volatile("vpsraw $4, %ymm9, %ymm12");
78 asm volatile("vpand %ymm7, %ymm1, %ymm1");
79 asm volatile("vpand %ymm7, %ymm9, %ymm9");
80 asm volatile("vpand %ymm7, %ymm3, %ymm3");
81 asm volatile("vpand %ymm7, %ymm12, %ymm12");
82 asm volatile("vpshufb %ymm9, %ymm4, %ymm14");
83 asm volatile("vpshufb %ymm1, %ymm4, %ymm4");
84 asm volatile("vpshufb %ymm12, %ymm5, %ymm15");
85 asm volatile("vpshufb %ymm3, %ymm5, %ymm5");
86 asm volatile("vpxor %ymm14, %ymm15, %ymm15");
87 asm volatile("vpxor %ymm4, %ymm5, %ymm5");
94 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (pbmul[0]));
95 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (pbmul[16]));
96 asm volatile("vpsraw $4, %ymm0, %ymm2");
97 asm volatile("vpsraw $4, %ymm8, %ymm6");
98 asm volatile("vpand %ymm7, %ymm0, %ymm3");
99 asm volatile("vpand %ymm7, %ymm8, %ymm14");
100 asm volatile("vpand %ymm7, %ymm2, %ymm2");
101 asm volatile("vpand %ymm7, %ymm6, %ymm6");
102 asm volatile("vpshufb %ymm14, %ymm4, %ymm12");
103 asm volatile("vpshufb %ymm3, %ymm4, %ymm4");
104 asm volatile("vpshufb %ymm6, %ymm1, %ymm13");
105 asm volatile("vpshufb %ymm2, %ymm1, %ymm1");
106 asm volatile("vpxor %ymm4, %ymm1, %ymm1");
107 asm volatile("vpxor %ymm12, %ymm13, %ymm13");
113 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
114 asm volatile("vpxor %ymm15, %ymm13, %ymm13");
118 * 13 = db[32] = DQ[32]
120 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
121 asm volatile("vmovdqa %%ymm13,%0" : "=m" (dq[32]));
122 asm volatile("vpxor %ymm1, %ymm0, %ymm0");
123 asm volatile("vpxor %ymm13, %ymm8, %ymm8");
125 asm volatile("vmovdqa %%ymm0, %0" : "=m" (dp[0]));
126 asm volatile("vmovdqa %%ymm8, %0" : "=m" (dp[32]));
134 asm volatile("vmovdqa %0, %%ymm1" : : "m" (*q));
135 asm volatile("vmovdqa %0, %%ymm0" : : "m" (*p));
136 asm volatile("vpxor %0, %%ymm1, %%ymm1" : : "m" (*dq));
137 asm volatile("vpxor %0, %%ymm0, %%ymm0" : : "m" (*dp));
139 /* 1 = dq ^ q; 0 = dp ^ p */
141 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (qmul[0]));
142 asm volatile("vbroadcasti128 %0, %%ymm5" : : "m" (qmul[16]));
148 asm volatile("vpsraw $4, %ymm1, %ymm3");
149 asm volatile("vpand %ymm7, %ymm1, %ymm1");
150 asm volatile("vpand %ymm7, %ymm3, %ymm3");
151 asm volatile("vpshufb %ymm1, %ymm4, %ymm4");
152 asm volatile("vpshufb %ymm3, %ymm5, %ymm5");
153 asm volatile("vpxor %ymm4, %ymm5, %ymm5");
157 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (pbmul[0]));
158 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (pbmul[16]));
160 asm volatile("vpsraw $4, %ymm0, %ymm2");
161 asm volatile("vpand %ymm7, %ymm0, %ymm3");
162 asm volatile("vpand %ymm7, %ymm2, %ymm2");
163 asm volatile("vpshufb %ymm3, %ymm4, %ymm4");
164 asm volatile("vpshufb %ymm2, %ymm1, %ymm1");
165 asm volatile("vpxor %ymm4, %ymm1, %ymm1");
168 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
170 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
172 asm volatile("vpxor %ymm1, %ymm0, %ymm0");
173 asm volatile("vmovdqa %%ymm0, %0" : "=m" (dp[0]));
186 static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila,
190 const u8 *qmul; /* Q multiplier table */
193 p = (u8 *)ptrs[disks-2];
194 q = (u8 *)ptrs[disks-1];
196 /* Compute syndrome with zero for the missing data page
197 Use the dead data page as temporary storage for delta q */
198 dq = (u8 *)ptrs[faila];
199 ptrs[faila] = (void *)raid6_empty_zero_page;
202 raid6_call.gen_syndrome(disks, bytes, ptrs);
204 /* Restore pointer table */
208 /* Now, pick the proper data tables */
209 qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila]]];
213 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f));
217 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq[0]));
218 asm volatile("vmovdqa %0, %%ymm8" : : "m" (dq[32]));
219 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q[0]));
220 asm volatile("vpxor %0, %%ymm8, %%ymm8" : : "m" (q[32]));
226 asm volatile("vbroadcasti128 %0, %%ymm0" : : "m" (qmul[0]));
227 asm volatile("vmovapd %ymm0, %ymm13");
228 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (qmul[16]));
229 asm volatile("vmovapd %ymm1, %ymm14");
231 asm volatile("vpsraw $4, %ymm3, %ymm6");
232 asm volatile("vpsraw $4, %ymm8, %ymm12");
233 asm volatile("vpand %ymm7, %ymm3, %ymm3");
234 asm volatile("vpand %ymm7, %ymm8, %ymm8");
235 asm volatile("vpand %ymm7, %ymm6, %ymm6");
236 asm volatile("vpand %ymm7, %ymm12, %ymm12");
237 asm volatile("vpshufb %ymm3, %ymm0, %ymm0");
238 asm volatile("vpshufb %ymm8, %ymm13, %ymm13");
239 asm volatile("vpshufb %ymm6, %ymm1, %ymm1");
240 asm volatile("vpshufb %ymm12, %ymm14, %ymm14");
241 asm volatile("vpxor %ymm0, %ymm1, %ymm1");
242 asm volatile("vpxor %ymm13, %ymm14, %ymm14");
245 * 1 = qmul[q[0] ^ dq[0]]
246 * 14 = qmul[q[32] ^ dq[32]]
248 asm volatile("vmovdqa %0, %%ymm2" : : "m" (p[0]));
249 asm volatile("vmovdqa %0, %%ymm12" : : "m" (p[32]));
250 asm volatile("vpxor %ymm1, %ymm2, %ymm2");
251 asm volatile("vpxor %ymm14, %ymm12, %ymm12");
254 * 2 = p[0] ^ qmul[q[0] ^ dq[0]]
255 * 12 = p[32] ^ qmul[q[32] ^ dq[32]]
258 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
259 asm volatile("vmovdqa %%ymm14, %0" : "=m" (dq[32]));
260 asm volatile("vmovdqa %%ymm2, %0" : "=m" (p[0]));
261 asm volatile("vmovdqa %%ymm12,%0" : "=m" (p[32]));
268 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq[0]));
269 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q[0]));
273 asm volatile("vbroadcasti128 %0, %%ymm0" : : "m" (qmul[0]));
274 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (qmul[16]));
276 asm volatile("vpsraw $4, %ymm3, %ymm6");
277 asm volatile("vpand %ymm7, %ymm3, %ymm3");
278 asm volatile("vpand %ymm7, %ymm6, %ymm6");
279 asm volatile("vpshufb %ymm3, %ymm0, %ymm0");
280 asm volatile("vpshufb %ymm6, %ymm1, %ymm1");
281 asm volatile("vpxor %ymm0, %ymm1, %ymm1");
283 /* 1 = qmul[q ^ dq] */
285 asm volatile("vmovdqa %0, %%ymm2" : : "m" (p[0]));
286 asm volatile("vpxor %ymm1, %ymm2, %ymm2");
288 /* 2 = p ^ qmul[q ^ dq] */
290 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
291 asm volatile("vmovdqa %%ymm2, %0" : "=m" (p[0]));
303 const struct raid6_recov_calls raid6_recov_avx2 = {
304 .data2 = raid6_2data_recov_avx2,
305 .datap = raid6_datap_recov_avx2,
306 .valid = raid6_has_avx2,