xref: /linux/lib/raid/raid6/s390/recov_s390xc.c (revision 2e05544060b9fef5d4d0e0172944e6956c55080f)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * RAID-6 data recovery in dual failure mode based on the XC instruction.
4  *
5  * Copyright IBM Corp. 2016
6  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7  */
8 
9 #include <linux/mm.h>
10 #include <linux/raid/pq.h>
11 #include "algos.h"
12 
13 static inline void xor_block(u8 *p1, u8 *p2)
14 {
15 	typedef struct { u8 _[256]; } addrtype;
16 
17 	asm volatile(
18 		"	xc	0(256,%[p1]),0(%[p2])\n"
19 		: "+m" (*(addrtype *) p1) : "m" (*(addrtype *) p2),
20 		  [p1] "a" (p1), [p2] "a" (p2) : "cc");
21 }
22 
23 /* Recover two failed data blocks. */
24 static void raid6_2data_recov_s390xc(int disks, size_t bytes, int faila,
25 		int failb, void **ptrs)
26 {
27 	u8 *p, *q, *dp, *dq;
28 	const u8 *pbmul;	/* P multiplier table for B data */
29 	const u8 *qmul;		/* Q multiplier table (for both) */
30 	int i;
31 
32 	p = (u8 *)ptrs[disks-2];
33 	q = (u8 *)ptrs[disks-1];
34 
35 	/* Compute syndrome with zero for the missing data pages
36 	   Use the dead data pages as temporary storage for
37 	   delta p and delta q */
38 	dp = (u8 *)ptrs[faila];
39 	ptrs[faila] = page_address(ZERO_PAGE(0));
40 	ptrs[disks-2] = dp;
41 	dq = (u8 *)ptrs[failb];
42 	ptrs[failb] = page_address(ZERO_PAGE(0));
43 	ptrs[disks-1] = dq;
44 
45 	raid6_gen_syndrome(disks, bytes, ptrs);
46 
47 	/* Restore pointer table */
48 	ptrs[faila]   = dp;
49 	ptrs[failb]   = dq;
50 	ptrs[disks-2] = p;
51 	ptrs[disks-1] = q;
52 
53 	/* Now, pick the proper data tables */
54 	pbmul = raid6_gfmul[raid6_gfexi[failb-faila]];
55 	qmul  = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]]];
56 
57 	/* Now do it... */
58 	while (bytes) {
59 		xor_block(dp, p);
60 		xor_block(dq, q);
61 		for (i = 0; i < 256; i++)
62 			dq[i] = pbmul[dp[i]] ^ qmul[dq[i]];
63 		xor_block(dp, dq);
64 		p += 256;
65 		q += 256;
66 		dp += 256;
67 		dq += 256;
68 		bytes -= 256;
69 	}
70 }
71 
72 /* Recover failure of one data block plus the P block */
73 static void raid6_datap_recov_s390xc(int disks, size_t bytes, int faila,
74 		void **ptrs)
75 {
76 	u8 *p, *q, *dq;
77 	const u8 *qmul;		/* Q multiplier table */
78 	int i;
79 
80 	p = (u8 *)ptrs[disks-2];
81 	q = (u8 *)ptrs[disks-1];
82 
83 	/* Compute syndrome with zero for the missing data page
84 	   Use the dead data page as temporary storage for delta q */
85 	dq = (u8 *)ptrs[faila];
86 	ptrs[faila] = page_address(ZERO_PAGE(0));
87 	ptrs[disks-1] = dq;
88 
89 	raid6_gen_syndrome(disks, bytes, ptrs);
90 
91 	/* Restore pointer table */
92 	ptrs[faila]   = dq;
93 	ptrs[disks-1] = q;
94 
95 	/* Now, pick the proper data tables */
96 	qmul  = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]]];
97 
98 	/* Now do it... */
99 	while (bytes) {
100 		xor_block(dq, q);
101 		for (i = 0; i < 256; i++)
102 			dq[i] = qmul[dq[i]];
103 		xor_block(p, dq);
104 		p += 256;
105 		q += 256;
106 		dq += 256;
107 		bytes -= 256;
108 	}
109 }
110 
111 
112 const struct raid6_recov_calls raid6_recov_s390xc = {
113 	.data2 = raid6_2data_recov_s390xc,
114 	.datap = raid6_datap_recov_s390xc,
115 	.name = "s390xc",
116 };
117