1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 /* 2 /* 3 * raid6_vx$#.c 3 * raid6_vx$#.c 4 * 4 * 5 * $#-way unrolled RAID6 gen/xor functions for 5 * $#-way unrolled RAID6 gen/xor functions for s390 6 * based on the vector facility 6 * based on the vector facility 7 * 7 * 8 * Copyright IBM Corp. 2016 8 * Copyright IBM Corp. 2016 9 * Author(s): Martin Schwidefsky <schwidefsky@d 9 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 10 * 10 * 11 * This file is postprocessed using unroll.awk 11 * This file is postprocessed using unroll.awk. 12 */ 12 */ 13 13 14 #include <linux/raid/pq.h> 14 #include <linux/raid/pq.h> 15 #include <asm/fpu.h> !! 15 #include <asm/fpu/api.h> >> 16 #include <asm/vx-insn.h> 16 17 17 #define NSIZE 16 18 #define NSIZE 16 18 19 19 static __always_inline void LOAD_CONST(void) !! 20 static inline void LOAD_CONST(void) 20 { 21 { 21 fpu_vrepib(24, 0x07); !! 22 asm volatile("VREPIB %v24,7"); 22 fpu_vrepib(25, 0x1d); !! 23 asm volatile("VREPIB %v25,0x1d"); 23 } 24 } 24 25 25 /* 26 /* 26 * The SHLBYTE() operation shifts each of the 27 * The SHLBYTE() operation shifts each of the 16 bytes in 27 * vector register y left by 1 bit and stores 28 * vector register y left by 1 bit and stores the result in 28 * vector register x. 29 * vector register x. 29 */ 30 */ 30 #define SHLBYTE(x, y) fpu_vab(x, y, !! 31 static inline void SHLBYTE(int x, int y) >> 32 { >> 33 asm volatile ("VAB %0,%1,%1" : : "i" (x), "i" (y)); >> 34 } 31 35 32 /* 36 /* 33 * For each of the 16 bytes in the vector regi 37 * For each of the 16 bytes in the vector register y the MASK() 34 * operation returns 0xFF if the high bit of t 38 * operation returns 0xFF if the high bit of the byte is 1, 35 * or 0x00 if the high bit is 0. The result is 39 * or 0x00 if the high bit is 0. The result is stored in vector 36 * register x. 40 * register x. 37 */ 41 */ 38 #define MASK(x, y) fpu_vesravb(x, !! 42 static inline void MASK(int x, int y) >> 43 { >> 44 asm volatile ("VESRAVB %0,%1,24" : : "i" (x), "i" (y)); >> 45 } >> 46 >> 47 static inline void AND(int x, int y, int z) >> 48 { >> 49 asm volatile ("VN %0,%1,%2" : : "i" (x), "i" (y), "i" (z)); >> 50 } >> 51 >> 52 static inline void XOR(int x, int y, int z) >> 53 { >> 54 asm volatile ("VX %0,%1,%2" : : "i" (x), "i" (y), "i" (z)); >> 55 } 39 56 40 #define AND(x, y, z) fpu_vn(x, y, z !! 57 static inline void LOAD_DATA(int x, u8 *ptr) 41 #define XOR(x, y, z) fpu_vx(x, y, z !! 58 { 42 #define LOAD_DATA(x, ptr) fpu_vlm(x, x + !! 59 typedef struct { u8 _[16 * $#]; } addrtype; 43 #define STORE_DATA(x, ptr) fpu_vstm(x, x !! 60 register addrtype *__ptr asm("1") = (addrtype *) ptr; 44 #define COPY_VEC(x, y) fpu_vlr(x, y) !! 61 >> 62 asm volatile ("VLM %2,%3,0,%1" >> 63 : : "m" (*__ptr), "a" (__ptr), "i" (x), >> 64 "i" (x + $# - 1)); >> 65 } >> 66 >> 67 static inline void STORE_DATA(int x, u8 *ptr) >> 68 { >> 69 typedef struct { u8 _[16 * $#]; } addrtype; >> 70 register addrtype *__ptr asm("1") = (addrtype *) ptr; >> 71 >> 72 asm volatile ("VSTM %2,%3,0,1" >> 73 : "=m" (*__ptr) : "a" (__ptr), "i" (x), >> 74 "i" (x + $# - 1)); >> 75 } >> 76 >> 77 static inline void COPY_VEC(int x, int y) >> 78 { >> 79 asm volatile ("VLR %0,%1" : : "i" (x), "i" (y)); >> 80 } 45 81 46 static void raid6_s390vx$#_gen_syndrome(int di 82 static void raid6_s390vx$#_gen_syndrome(int disks, size_t bytes, void **ptrs) 47 { 83 { 48 DECLARE_KERNEL_FPU_ONSTACK32(vxstate); !! 84 struct kernel_fpu vxstate; 49 u8 **dptr, *p, *q; 85 u8 **dptr, *p, *q; 50 int d, z, z0; 86 int d, z, z0; 51 87 52 kernel_fpu_begin(&vxstate, KERNEL_VXR) 88 kernel_fpu_begin(&vxstate, KERNEL_VXR); 53 LOAD_CONST(); 89 LOAD_CONST(); 54 90 55 dptr = (u8 **) ptrs; 91 dptr = (u8 **) ptrs; 56 z0 = disks - 3; /* Highest dat 92 z0 = disks - 3; /* Highest data disk */ 57 p = dptr[z0 + 1]; /* XOR parity 93 p = dptr[z0 + 1]; /* XOR parity */ 58 q = dptr[z0 + 2]; /* RS syndrome 94 q = dptr[z0 + 2]; /* RS syndrome */ 59 95 60 for (d = 0; d < bytes; d += $#*NSIZE) 96 for (d = 0; d < bytes; d += $#*NSIZE) { 61 LOAD_DATA(0,&dptr[z0][d]); 97 LOAD_DATA(0,&dptr[z0][d]); 62 COPY_VEC(8+$$,0+$$); 98 COPY_VEC(8+$$,0+$$); 63 for (z = z0 - 1; z >= 0; z--) 99 for (z = z0 - 1; z >= 0; z--) { 64 MASK(16+$$,8+$$); 100 MASK(16+$$,8+$$); 65 AND(16+$$,16+$$,25); 101 AND(16+$$,16+$$,25); 66 SHLBYTE(8+$$,8+$$); 102 SHLBYTE(8+$$,8+$$); 67 XOR(8+$$,8+$$,16+$$); 103 XOR(8+$$,8+$$,16+$$); 68 LOAD_DATA(16,&dptr[z][ 104 LOAD_DATA(16,&dptr[z][d]); 69 XOR(0+$$,0+$$,16+$$); 105 XOR(0+$$,0+$$,16+$$); 70 XOR(8+$$,8+$$,16+$$); 106 XOR(8+$$,8+$$,16+$$); 71 } 107 } 72 STORE_DATA(0,&p[d]); 108 STORE_DATA(0,&p[d]); 73 STORE_DATA(8,&q[d]); 109 STORE_DATA(8,&q[d]); 74 } 110 } 75 kernel_fpu_end(&vxstate, KERNEL_VXR); 111 kernel_fpu_end(&vxstate, KERNEL_VXR); 76 } 112 } 77 113 78 static void raid6_s390vx$#_xor_syndrome(int di 114 static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop, 79 size_t 115 size_t bytes, void **ptrs) 80 { 116 { 81 DECLARE_KERNEL_FPU_ONSTACK32(vxstate); !! 117 struct kernel_fpu vxstate; 82 u8 **dptr, *p, *q; 118 u8 **dptr, *p, *q; 83 int d, z, z0; 119 int d, z, z0; 84 120 85 dptr = (u8 **) ptrs; 121 dptr = (u8 **) ptrs; 86 z0 = stop; /* P/Q right s 122 z0 = stop; /* P/Q right side optimization */ 87 p = dptr[disks - 2]; /* XOR parity 123 p = dptr[disks - 2]; /* XOR parity */ 88 q = dptr[disks - 1]; /* RS syndrome 124 q = dptr[disks - 1]; /* RS syndrome */ 89 125 90 kernel_fpu_begin(&vxstate, KERNEL_VXR) 126 kernel_fpu_begin(&vxstate, KERNEL_VXR); 91 LOAD_CONST(); 127 LOAD_CONST(); 92 128 93 for (d = 0; d < bytes; d += $#*NSIZE) 129 for (d = 0; d < bytes; d += $#*NSIZE) { 94 /* P/Q data pages */ 130 /* P/Q data pages */ 95 LOAD_DATA(0,&dptr[z0][d]); 131 LOAD_DATA(0,&dptr[z0][d]); 96 COPY_VEC(8+$$,0+$$); 132 COPY_VEC(8+$$,0+$$); 97 for (z = z0 - 1; z >= start; z 133 for (z = z0 - 1; z >= start; z--) { 98 MASK(16+$$,8+$$); 134 MASK(16+$$,8+$$); 99 AND(16+$$,16+$$,25); 135 AND(16+$$,16+$$,25); 100 SHLBYTE(8+$$,8+$$); 136 SHLBYTE(8+$$,8+$$); 101 XOR(8+$$,8+$$,16+$$); 137 XOR(8+$$,8+$$,16+$$); 102 LOAD_DATA(16,&dptr[z][ 138 LOAD_DATA(16,&dptr[z][d]); 103 XOR(0+$$,0+$$,16+$$); 139 XOR(0+$$,0+$$,16+$$); 104 XOR(8+$$,8+$$,16+$$); 140 XOR(8+$$,8+$$,16+$$); 105 } 141 } 106 /* P/Q left side optimization 142 /* P/Q left side optimization */ 107 for (z = start - 1; z >= 0; z- 143 for (z = start - 1; z >= 0; z--) { 108 MASK(16+$$,8+$$); 144 MASK(16+$$,8+$$); 109 AND(16+$$,16+$$,25); 145 AND(16+$$,16+$$,25); 110 SHLBYTE(8+$$,8+$$); 146 SHLBYTE(8+$$,8+$$); 111 XOR(8+$$,8+$$,16+$$); 147 XOR(8+$$,8+$$,16+$$); 112 } 148 } 113 LOAD_DATA(16,&p[d]); 149 LOAD_DATA(16,&p[d]); 114 XOR(16+$$,16+$$,0+$$); 150 XOR(16+$$,16+$$,0+$$); 115 STORE_DATA(16,&p[d]); 151 STORE_DATA(16,&p[d]); 116 LOAD_DATA(16,&q[d]); 152 LOAD_DATA(16,&q[d]); 117 XOR(16+$$,16+$$,8+$$); 153 XOR(16+$$,16+$$,8+$$); 118 STORE_DATA(16,&q[d]); 154 STORE_DATA(16,&q[d]); 119 } 155 } 120 kernel_fpu_end(&vxstate, KERNEL_VXR); 156 kernel_fpu_end(&vxstate, KERNEL_VXR); 121 } 157 } 122 158 123 static int raid6_s390vx$#_valid(void) 159 static int raid6_s390vx$#_valid(void) 124 { 160 { 125 return cpu_has_vx(); !! 161 return MACHINE_HAS_VX; 126 } 162 } 127 163 128 const struct raid6_calls raid6_s390vx$# = { 164 const struct raid6_calls raid6_s390vx$# = { 129 raid6_s390vx$#_gen_syndrome, 165 raid6_s390vx$#_gen_syndrome, 130 raid6_s390vx$#_xor_syndrome, 166 raid6_s390vx$#_xor_syndrome, 131 raid6_s390vx$#_valid, 167 raid6_s390vx$#_valid, 132 "vx128x$#", 168 "vx128x$#", 133 1 169 1 134 }; 170 };
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.