1 // SPDX-License-Identifier: GPL-2.0
3 * RAID-6 data recovery in dual failure mode based on the XC instruction.
5 * Copyright IBM Corp. 2016
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
9 #include <linux/export.h>
10 #include <linux/raid/pq.h>
12 static inline void xor_block(u8 *p1, u8 *p2)
14 typedef struct { u8 _[256]; } addrtype;
17 " xc 0(256,%[p1]),0(%[p2])\n"
18 : "+m" (*(addrtype *) p1) : "m" (*(addrtype *) p2),
19 [p1] "a" (p1), [p2] "a" (p2) : "cc");
22 /* Recover two failed data blocks. */
23 static void raid6_2data_recov_s390xc(int disks, size_t bytes, int faila,
24 int failb, void **ptrs)
27 const u8 *pbmul; /* P multiplier table for B data */
28 const u8 *qmul; /* Q multiplier table (for both) */
31 p = (u8 *)ptrs[disks-2];
32 q = (u8 *)ptrs[disks-1];
34 /* Compute syndrome with zero for the missing data pages
35 Use the dead data pages as temporary storage for
36 delta p and delta q */
37 dp = (u8 *)ptrs[faila];
38 ptrs[faila] = (void *)raid6_empty_zero_page;
40 dq = (u8 *)ptrs[failb];
41 ptrs[failb] = (void *)raid6_empty_zero_page;
44 raid6_call.gen_syndrome(disks, bytes, ptrs);
46 /* Restore pointer table */
52 /* Now, pick the proper data tables */
53 pbmul = raid6_gfmul[raid6_gfexi[failb-faila]];
54 qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]]];
60 for (i = 0; i < 256; i++)
61 dq[i] = pbmul[dp[i]] ^ qmul[dq[i]];
71 /* Recover failure of one data block plus the P block */
72 static void raid6_datap_recov_s390xc(int disks, size_t bytes, int faila,
76 const u8 *qmul; /* Q multiplier table */
79 p = (u8 *)ptrs[disks-2];
80 q = (u8 *)ptrs[disks-1];
82 /* Compute syndrome with zero for the missing data page
83 Use the dead data page as temporary storage for delta q */
84 dq = (u8 *)ptrs[faila];
85 ptrs[faila] = (void *)raid6_empty_zero_page;
88 raid6_call.gen_syndrome(disks, bytes, ptrs);
90 /* Restore pointer table */
94 /* Now, pick the proper data tables */
95 qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]]];
100 for (i = 0; i < 256; i++)
111 const struct raid6_recov_calls raid6_recov_s390xc = {
112 .data2 = raid6_2data_recov_s390xc,
113 .datap = raid6_datap_recov_s390xc,