1 // SPDX-License-Identifier: GPL-2.0
5 * $#-way unrolled RAID6 gen/xor functions for s390
6 * based on the vector facility
8 * Copyright IBM Corp. 2016
9 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
11 * This file is postprocessed using unroll.awk.
14 #include <linux/raid/pq.h>
15 #include <asm/fpu/api.h>
17 asm(".include \"asm/vx-insn.h\"\n");
21 static inline void LOAD_CONST(void)
23 asm volatile("VREPIB %v24,7");
24 asm volatile("VREPIB %v25,0x1d");
28 * The SHLBYTE() operation shifts each of the 16 bytes in
29 * vector register y left by 1 bit and stores the result in
32 static inline void SHLBYTE(int x, int y)
34 asm volatile ("VAB %0,%1,%1" : : "i" (x), "i" (y));
38 * For each of the 16 bytes in the vector register y the MASK()
39 * operation returns 0xFF if the high bit of the byte is 1,
40 * or 0x00 if the high bit is 0. The result is stored in vector
43 static inline void MASK(int x, int y)
45 asm volatile ("VESRAVB %0,%1,24" : : "i" (x), "i" (y));
48 static inline void AND(int x, int y, int z)
50 asm volatile ("VN %0,%1,%2" : : "i" (x), "i" (y), "i" (z));
53 static inline void XOR(int x, int y, int z)
55 asm volatile ("VX %0,%1,%2" : : "i" (x), "i" (y), "i" (z));
58 static inline void LOAD_DATA(int x, u8 *ptr)
60 typedef struct { u8 _[16 * $#]; } addrtype;
61 register addrtype *__ptr asm("1") = (addrtype *) ptr;
63 asm volatile ("VLM %2,%3,0,%r1"
64 : : "m" (*__ptr), "a" (__ptr), "i" (x),
68 static inline void STORE_DATA(int x, u8 *ptr)
70 typedef struct { u8 _[16 * $#]; } addrtype;
71 register addrtype *__ptr asm("1") = (addrtype *) ptr;
73 asm volatile ("VSTM %2,%3,0,1"
74 : "=m" (*__ptr) : "a" (__ptr), "i" (x),
78 static inline void COPY_VEC(int x, int y)
80 asm volatile ("VLR %0,%1" : : "i" (x), "i" (y));
83 static void raid6_s390vx$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
85 struct kernel_fpu vxstate;
89 kernel_fpu_begin(&vxstate, KERNEL_VXR);
93 z0 = disks - 3; /* Highest data disk */
94 p = dptr[z0 + 1]; /* XOR parity */
95 q = dptr[z0 + 2]; /* RS syndrome */
97 for (d = 0; d < bytes; d += $#*NSIZE) {
98 LOAD_DATA(0,&dptr[z0][d]);
100 for (z = z0 - 1; z >= 0; z--) {
104 XOR(8+$$,8+$$,16+$$);
105 LOAD_DATA(16,&dptr[z][d]);
106 XOR(0+$$,0+$$,16+$$);
107 XOR(8+$$,8+$$,16+$$);
112 kernel_fpu_end(&vxstate, KERNEL_VXR);
115 static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop,
116 size_t bytes, void **ptrs)
118 struct kernel_fpu vxstate;
123 z0 = stop; /* P/Q right side optimization */
124 p = dptr[disks - 2]; /* XOR parity */
125 q = dptr[disks - 1]; /* RS syndrome */
127 kernel_fpu_begin(&vxstate, KERNEL_VXR);
130 for (d = 0; d < bytes; d += $#*NSIZE) {
132 LOAD_DATA(0,&dptr[z0][d]);
134 for (z = z0 - 1; z >= start; z--) {
138 XOR(8+$$,8+$$,16+$$);
139 LOAD_DATA(16,&dptr[z][d]);
140 XOR(0+$$,0+$$,16+$$);
141 XOR(8+$$,8+$$,16+$$);
143 /* P/Q left side optimization */
144 for (z = start - 1; z >= 0; z--) {
148 XOR(8+$$,8+$$,16+$$);
151 XOR(16+$$,16+$$,0+$$);
152 STORE_DATA(16,&p[d]);
154 XOR(16+$$,16+$$,8+$$);
155 STORE_DATA(16,&q[d]);
157 kernel_fpu_end(&vxstate, KERNEL_VXR);
160 static int raid6_s390vx$#_valid(void)
162 return MACHINE_HAS_VX;
165 const struct raid6_calls raid6_s390vx$# = {
166 raid6_s390vx$#_gen_syndrome,
167 raid6_s390vx$#_xor_syndrome,
168 raid6_s390vx$#_valid,