1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012 Intel Corporation
4 * Author: Jim Kukunas <james.t.kukunas@linux.intel.com>
9 #include <linux/raid/pq.h>
12 static int raid6_has_avx2(void)
14 return boot_cpu_has(X86_FEATURE_AVX2
) &&
15 boot_cpu_has(X86_FEATURE_AVX
);
18 static void raid6_2data_recov_avx2(int disks
, size_t bytes
, int faila
,
19 int failb
, void **ptrs
)
22 const u8
*pbmul
; /* P multiplier table for B data */
23 const u8
*qmul
; /* Q multiplier table (for both) */
26 p
= (u8
*)ptrs
[disks
-2];
27 q
= (u8
*)ptrs
[disks
-1];
29 /* Compute syndrome with zero for the missing data pages
30 Use the dead data pages as temporary storage for
31 delta p and delta q */
32 dp
= (u8
*)ptrs
[faila
];
33 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
35 dq
= (u8
*)ptrs
[failb
];
36 ptrs
[failb
] = (void *)raid6_empty_zero_page
;
39 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
41 /* Restore pointer table */
47 /* Now, pick the proper data tables */
48 pbmul
= raid6_vgfmul
[raid6_gfexi
[failb
-faila
]];
49 qmul
= raid6_vgfmul
[raid6_gfinv
[raid6_gfexp
[faila
] ^
55 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f
));
59 asm volatile("vmovdqa %0, %%ymm1" : : "m" (q
[0]));
60 asm volatile("vmovdqa %0, %%ymm9" : : "m" (q
[32]));
61 asm volatile("vmovdqa %0, %%ymm0" : : "m" (p
[0]));
62 asm volatile("vmovdqa %0, %%ymm8" : : "m" (p
[32]));
63 asm volatile("vpxor %0, %%ymm1, %%ymm1" : : "m" (dq
[0]));
64 asm volatile("vpxor %0, %%ymm9, %%ymm9" : : "m" (dq
[32]));
65 asm volatile("vpxor %0, %%ymm0, %%ymm0" : : "m" (dp
[0]));
66 asm volatile("vpxor %0, %%ymm8, %%ymm8" : : "m" (dp
[32]));
75 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (qmul
[0]));
76 asm volatile("vbroadcasti128 %0, %%ymm5" : : "m" (qmul
[16]));
78 asm volatile("vpsraw $4, %ymm1, %ymm3");
79 asm volatile("vpsraw $4, %ymm9, %ymm12");
80 asm volatile("vpand %ymm7, %ymm1, %ymm1");
81 asm volatile("vpand %ymm7, %ymm9, %ymm9");
82 asm volatile("vpand %ymm7, %ymm3, %ymm3");
83 asm volatile("vpand %ymm7, %ymm12, %ymm12");
84 asm volatile("vpshufb %ymm9, %ymm4, %ymm14");
85 asm volatile("vpshufb %ymm1, %ymm4, %ymm4");
86 asm volatile("vpshufb %ymm12, %ymm5, %ymm15");
87 asm volatile("vpshufb %ymm3, %ymm5, %ymm5");
88 asm volatile("vpxor %ymm14, %ymm15, %ymm15");
89 asm volatile("vpxor %ymm4, %ymm5, %ymm5");
96 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (pbmul
[0]));
97 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (pbmul
[16]));
98 asm volatile("vpsraw $4, %ymm0, %ymm2");
99 asm volatile("vpsraw $4, %ymm8, %ymm6");
100 asm volatile("vpand %ymm7, %ymm0, %ymm3");
101 asm volatile("vpand %ymm7, %ymm8, %ymm14");
102 asm volatile("vpand %ymm7, %ymm2, %ymm2");
103 asm volatile("vpand %ymm7, %ymm6, %ymm6");
104 asm volatile("vpshufb %ymm14, %ymm4, %ymm12");
105 asm volatile("vpshufb %ymm3, %ymm4, %ymm4");
106 asm volatile("vpshufb %ymm6, %ymm1, %ymm13");
107 asm volatile("vpshufb %ymm2, %ymm1, %ymm1");
108 asm volatile("vpxor %ymm4, %ymm1, %ymm1");
109 asm volatile("vpxor %ymm12, %ymm13, %ymm13");
115 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
116 asm volatile("vpxor %ymm15, %ymm13, %ymm13");
120 * 13 = db[32] = DQ[32]
122 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq
[0]));
123 asm volatile("vmovdqa %%ymm13,%0" : "=m" (dq
[32]));
124 asm volatile("vpxor %ymm1, %ymm0, %ymm0");
125 asm volatile("vpxor %ymm13, %ymm8, %ymm8");
127 asm volatile("vmovdqa %%ymm0, %0" : "=m" (dp
[0]));
128 asm volatile("vmovdqa %%ymm8, %0" : "=m" (dp
[32]));
136 asm volatile("vmovdqa %0, %%ymm1" : : "m" (*q
));
137 asm volatile("vmovdqa %0, %%ymm0" : : "m" (*p
));
138 asm volatile("vpxor %0, %%ymm1, %%ymm1" : : "m" (*dq
));
139 asm volatile("vpxor %0, %%ymm0, %%ymm0" : : "m" (*dp
));
141 /* 1 = dq ^ q; 0 = dp ^ p */
143 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (qmul
[0]));
144 asm volatile("vbroadcasti128 %0, %%ymm5" : : "m" (qmul
[16]));
150 asm volatile("vpsraw $4, %ymm1, %ymm3");
151 asm volatile("vpand %ymm7, %ymm1, %ymm1");
152 asm volatile("vpand %ymm7, %ymm3, %ymm3");
153 asm volatile("vpshufb %ymm1, %ymm4, %ymm4");
154 asm volatile("vpshufb %ymm3, %ymm5, %ymm5");
155 asm volatile("vpxor %ymm4, %ymm5, %ymm5");
159 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (pbmul
[0]));
160 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (pbmul
[16]));
162 asm volatile("vpsraw $4, %ymm0, %ymm2");
163 asm volatile("vpand %ymm7, %ymm0, %ymm3");
164 asm volatile("vpand %ymm7, %ymm2, %ymm2");
165 asm volatile("vpshufb %ymm3, %ymm4, %ymm4");
166 asm volatile("vpshufb %ymm2, %ymm1, %ymm1");
167 asm volatile("vpxor %ymm4, %ymm1, %ymm1");
170 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
172 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq
[0]));
174 asm volatile("vpxor %ymm1, %ymm0, %ymm0");
175 asm volatile("vmovdqa %%ymm0, %0" : "=m" (dp
[0]));
188 static void raid6_datap_recov_avx2(int disks
, size_t bytes
, int faila
,
192 const u8
*qmul
; /* Q multiplier table */
195 p
= (u8
*)ptrs
[disks
-2];
196 q
= (u8
*)ptrs
[disks
-1];
198 /* Compute syndrome with zero for the missing data page
199 Use the dead data page as temporary storage for delta q */
200 dq
= (u8
*)ptrs
[faila
];
201 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
204 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
206 /* Restore pointer table */
210 /* Now, pick the proper data tables */
211 qmul
= raid6_vgfmul
[raid6_gfinv
[raid6_gfexp
[faila
]]];
215 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f
));
219 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq
[0]));
220 asm volatile("vmovdqa %0, %%ymm8" : : "m" (dq
[32]));
221 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q
[0]));
222 asm volatile("vpxor %0, %%ymm8, %%ymm8" : : "m" (q
[32]));
228 asm volatile("vbroadcasti128 %0, %%ymm0" : : "m" (qmul
[0]));
229 asm volatile("vmovapd %ymm0, %ymm13");
230 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (qmul
[16]));
231 asm volatile("vmovapd %ymm1, %ymm14");
233 asm volatile("vpsraw $4, %ymm3, %ymm6");
234 asm volatile("vpsraw $4, %ymm8, %ymm12");
235 asm volatile("vpand %ymm7, %ymm3, %ymm3");
236 asm volatile("vpand %ymm7, %ymm8, %ymm8");
237 asm volatile("vpand %ymm7, %ymm6, %ymm6");
238 asm volatile("vpand %ymm7, %ymm12, %ymm12");
239 asm volatile("vpshufb %ymm3, %ymm0, %ymm0");
240 asm volatile("vpshufb %ymm8, %ymm13, %ymm13");
241 asm volatile("vpshufb %ymm6, %ymm1, %ymm1");
242 asm volatile("vpshufb %ymm12, %ymm14, %ymm14");
243 asm volatile("vpxor %ymm0, %ymm1, %ymm1");
244 asm volatile("vpxor %ymm13, %ymm14, %ymm14");
247 * 1 = qmul[q[0] ^ dq[0]]
248 * 14 = qmul[q[32] ^ dq[32]]
250 asm volatile("vmovdqa %0, %%ymm2" : : "m" (p
[0]));
251 asm volatile("vmovdqa %0, %%ymm12" : : "m" (p
[32]));
252 asm volatile("vpxor %ymm1, %ymm2, %ymm2");
253 asm volatile("vpxor %ymm14, %ymm12, %ymm12");
256 * 2 = p[0] ^ qmul[q[0] ^ dq[0]]
257 * 12 = p[32] ^ qmul[q[32] ^ dq[32]]
260 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq
[0]));
261 asm volatile("vmovdqa %%ymm14, %0" : "=m" (dq
[32]));
262 asm volatile("vmovdqa %%ymm2, %0" : "=m" (p
[0]));
263 asm volatile("vmovdqa %%ymm12,%0" : "=m" (p
[32]));
270 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq
[0]));
271 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q
[0]));
275 asm volatile("vbroadcasti128 %0, %%ymm0" : : "m" (qmul
[0]));
276 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (qmul
[16]));
278 asm volatile("vpsraw $4, %ymm3, %ymm6");
279 asm volatile("vpand %ymm7, %ymm3, %ymm3");
280 asm volatile("vpand %ymm7, %ymm6, %ymm6");
281 asm volatile("vpshufb %ymm3, %ymm0, %ymm0");
282 asm volatile("vpshufb %ymm6, %ymm1, %ymm1");
283 asm volatile("vpxor %ymm0, %ymm1, %ymm1");
285 /* 1 = qmul[q ^ dq] */
287 asm volatile("vmovdqa %0, %%ymm2" : : "m" (p
[0]));
288 asm volatile("vpxor %ymm1, %ymm2, %ymm2");
290 /* 2 = p ^ qmul[q ^ dq] */
292 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq
[0]));
293 asm volatile("vmovdqa %%ymm2, %0" : "=m" (p
[0]));
305 const struct raid6_recov_calls raid6_recov_avx2
= {
306 .data2
= raid6_2data_recov_avx2
,
307 .datap
= raid6_datap_recov_avx2
,
308 .valid
= raid6_has_avx2
,
318 #warning "your version of binutils lacks AVX2 support"