1// SPDX-License-Identifier: GPL-2.0 2/* 3 * raid6_vx$#.c 4 * 5 * $#-way unrolled RAID6 gen/xor functions for s390 6 * based on the vector facility 7 * 8 * Copyright IBM Corp. 2016 9 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 10 * 11 * This file is postprocessed using unroll.awk. 12 */ 13 14#include <linux/cpufeature.h> 15#include <linux/raid/pq.h> 16#include <asm/fpu.h> 17 18#define NSIZE 16 19 20static __always_inline void LOAD_CONST(void) 21{ 22 fpu_vrepib(24, 0x07); 23 fpu_vrepib(25, 0x1d); 24} 25 26/* 27 * The SHLBYTE() operation shifts each of the 16 bytes in 28 * vector register y left by 1 bit and stores the result in 29 * vector register x. 30 */ 31#define SHLBYTE(x, y) fpu_vab(x, y, y) 32 33/* 34 * For each of the 16 bytes in the vector register y the MASK() 35 * operation returns 0xFF if the high bit of the byte is 1, 36 * or 0x00 if the high bit is 0. The result is stored in vector 37 * register x. 38 */ 39#define MASK(x, y) fpu_vesravb(x, y, 24) 40 41#define AND(x, y, z) fpu_vn(x, y, z) 42#define XOR(x, y, z) fpu_vx(x, y, z) 43#define LOAD_DATA(x, ptr) fpu_vlm(x, x + $# - 1, ptr) 44#define STORE_DATA(x, ptr) fpu_vstm(x, x + $# - 1, ptr) 45#define COPY_VEC(x, y) fpu_vlr(x, y) 46 47static void raid6_s390vx$#_gen_syndrome(int disks, size_t bytes, void **ptrs) 48{ 49 DECLARE_KERNEL_FPU_ONSTACK32(vxstate); 50 u8 **dptr, *p, *q; 51 int d, z, z0; 52 53 kernel_fpu_begin(&vxstate, KERNEL_VXR); 54 LOAD_CONST(); 55 56 dptr = (u8 **) ptrs; 57 z0 = disks - 3; /* Highest data disk */ 58 p = dptr[z0 + 1]; /* XOR parity */ 59 q = dptr[z0 + 2]; /* RS syndrome */ 60 61 for (d = 0; d < bytes; d += $#*NSIZE) { 62 LOAD_DATA(0,&dptr[z0][d]); 63 COPY_VEC(8+$$,0+$$); 64 for (z = z0 - 1; z >= 0; z--) { 65 MASK(16+$$,8+$$); 66 AND(16+$$,16+$$,25); 67 SHLBYTE(8+$$,8+$$); 68 XOR(8+$$,8+$$,16+$$); 69 LOAD_DATA(16,&dptr[z][d]); 70 XOR(0+$$,0+$$,16+$$); 71 XOR(8+$$,8+$$,16+$$); 72 } 73 STORE_DATA(0,&p[d]); 74 STORE_DATA(8,&q[d]); 75 } 76 kernel_fpu_end(&vxstate, KERNEL_VXR); 77} 78 79static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop, 80 size_t bytes, void **ptrs) 81{ 82 DECLARE_KERNEL_FPU_ONSTACK32(vxstate); 83 u8 **dptr, *p, *q; 84 int d, z, z0; 85 86 dptr = (u8 **) ptrs; 87 z0 = stop; /* P/Q right side optimization */ 88 p = dptr[disks - 2]; /* XOR parity */ 89 q = dptr[disks - 1]; /* RS syndrome */ 90 91 kernel_fpu_begin(&vxstate, KERNEL_VXR); 92 LOAD_CONST(); 93 94 for (d = 0; d < bytes; d += $#*NSIZE) { 95 /* P/Q data pages */ 96 LOAD_DATA(0,&dptr[z0][d]); 97 COPY_VEC(8+$$,0+$$); 98 for (z = z0 - 1; z >= start; z--) { 99 MASK(16+$$,8+$$); 100 AND(16+$$,16+$$,25); 101 SHLBYTE(8+$$,8+$$); 102 XOR(8+$$,8+$$,16+$$); 103 LOAD_DATA(16,&dptr[z][d]); 104 XOR(0+$$,0+$$,16+$$); 105 XOR(8+$$,8+$$,16+$$); 106 } 107 /* P/Q left side optimization */ 108 for (z = start - 1; z >= 0; z--) { 109 MASK(16+$$,8+$$); 110 AND(16+$$,16+$$,25); 111 SHLBYTE(8+$$,8+$$); 112 XOR(8+$$,8+$$,16+$$); 113 } 114 LOAD_DATA(16,&p[d]); 115 XOR(16+$$,16+$$,0+$$); 116 STORE_DATA(16,&p[d]); 117 LOAD_DATA(16,&q[d]); 118 XOR(16+$$,16+$$,8+$$); 119 STORE_DATA(16,&q[d]); 120 } 121 kernel_fpu_end(&vxstate, KERNEL_VXR); 122} 123 124static int raid6_s390vx$#_valid(void) 125{ 126 return cpu_has_vx(); 127} 128 129const struct raid6_calls raid6_s390vx$# = { 130 raid6_s390vx$#_gen_syndrome, 131 raid6_s390vx$#_xor_syndrome, 132 raid6_s390vx$#_valid, 133 "vx128x$#", 134 1 135}; 136