13626738bSChristoph Hellwig// SPDX-License-Identifier: GPL-2.0 23626738bSChristoph Hellwig/* 33626738bSChristoph Hellwig * raid6_vx$#.c 43626738bSChristoph Hellwig * 53626738bSChristoph Hellwig * $#-way unrolled RAID6 gen/xor functions for s390 63626738bSChristoph Hellwig * based on the vector facility 73626738bSChristoph Hellwig * 83626738bSChristoph Hellwig * Copyright IBM Corp. 2016 93626738bSChristoph Hellwig * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 103626738bSChristoph Hellwig * 113626738bSChristoph Hellwig * This file is postprocessed using unroll.awk. 123626738bSChristoph Hellwig */ 133626738bSChristoph Hellwig 143626738bSChristoph Hellwig#include <linux/cpufeature.h> 153626738bSChristoph Hellwig#include <asm/fpu.h> 16*769d603fSChristoph Hellwig#include "algos.h" 173626738bSChristoph Hellwig 183626738bSChristoph Hellwig#define NSIZE 16 193626738bSChristoph Hellwig 203626738bSChristoph Hellwigstatic __always_inline void LOAD_CONST(void) 213626738bSChristoph Hellwig{ 223626738bSChristoph Hellwig fpu_vrepib(24, 0x07); 233626738bSChristoph Hellwig fpu_vrepib(25, 0x1d); 243626738bSChristoph Hellwig} 253626738bSChristoph Hellwig 263626738bSChristoph Hellwig/* 273626738bSChristoph Hellwig * The SHLBYTE() operation shifts each of the 16 bytes in 283626738bSChristoph Hellwig * vector register y left by 1 bit and stores the result in 293626738bSChristoph Hellwig * vector register x. 303626738bSChristoph Hellwig */ 313626738bSChristoph Hellwig#define SHLBYTE(x, y) fpu_vab(x, y, y) 323626738bSChristoph Hellwig 333626738bSChristoph Hellwig/* 343626738bSChristoph Hellwig * For each of the 16 bytes in the vector register y the MASK() 353626738bSChristoph Hellwig * operation returns 0xFF if the high bit of the byte is 1, 363626738bSChristoph Hellwig * or 0x00 if the high bit is 0. The result is stored in vector 373626738bSChristoph Hellwig * register x. 383626738bSChristoph Hellwig */ 393626738bSChristoph Hellwig#define MASK(x, y) fpu_vesravb(x, y, 24) 403626738bSChristoph Hellwig 413626738bSChristoph Hellwig#define AND(x, y, z) fpu_vn(x, y, z) 423626738bSChristoph Hellwig#define XOR(x, y, z) fpu_vx(x, y, z) 433626738bSChristoph Hellwig#define LOAD_DATA(x, ptr) fpu_vlm(x, x + $# - 1, ptr) 443626738bSChristoph Hellwig#define STORE_DATA(x, ptr) fpu_vstm(x, x + $# - 1, ptr) 453626738bSChristoph Hellwig#define COPY_VEC(x, y) fpu_vlr(x, y) 463626738bSChristoph Hellwig 473626738bSChristoph Hellwigstatic void raid6_s390vx$#_gen_syndrome(int disks, size_t bytes, void **ptrs) 483626738bSChristoph Hellwig{ 493626738bSChristoph Hellwig DECLARE_KERNEL_FPU_ONSTACK32(vxstate); 503626738bSChristoph Hellwig u8 **dptr, *p, *q; 513626738bSChristoph Hellwig int d, z, z0; 523626738bSChristoph Hellwig 533626738bSChristoph Hellwig kernel_fpu_begin(&vxstate, KERNEL_VXR); 543626738bSChristoph Hellwig LOAD_CONST(); 553626738bSChristoph Hellwig 563626738bSChristoph Hellwig dptr = (u8 **) ptrs; 573626738bSChristoph Hellwig z0 = disks - 3; /* Highest data disk */ 583626738bSChristoph Hellwig p = dptr[z0 + 1]; /* XOR parity */ 593626738bSChristoph Hellwig q = dptr[z0 + 2]; /* RS syndrome */ 603626738bSChristoph Hellwig 613626738bSChristoph Hellwig for (d = 0; d < bytes; d += $#*NSIZE) { 623626738bSChristoph Hellwig LOAD_DATA(0,&dptr[z0][d]); 633626738bSChristoph Hellwig COPY_VEC(8+$$,0+$$); 643626738bSChristoph Hellwig for (z = z0 - 1; z >= 0; z--) { 653626738bSChristoph Hellwig MASK(16+$$,8+$$); 663626738bSChristoph Hellwig AND(16+$$,16+$$,25); 673626738bSChristoph Hellwig SHLBYTE(8+$$,8+$$); 683626738bSChristoph Hellwig XOR(8+$$,8+$$,16+$$); 693626738bSChristoph Hellwig LOAD_DATA(16,&dptr[z][d]); 703626738bSChristoph Hellwig XOR(0+$$,0+$$,16+$$); 713626738bSChristoph Hellwig XOR(8+$$,8+$$,16+$$); 723626738bSChristoph Hellwig } 733626738bSChristoph Hellwig STORE_DATA(0,&p[d]); 743626738bSChristoph Hellwig STORE_DATA(8,&q[d]); 753626738bSChristoph Hellwig } 763626738bSChristoph Hellwig kernel_fpu_end(&vxstate, KERNEL_VXR); 773626738bSChristoph Hellwig} 783626738bSChristoph Hellwig 793626738bSChristoph Hellwigstatic void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop, 803626738bSChristoph Hellwig size_t bytes, void **ptrs) 813626738bSChristoph Hellwig{ 823626738bSChristoph Hellwig DECLARE_KERNEL_FPU_ONSTACK32(vxstate); 833626738bSChristoph Hellwig u8 **dptr, *p, *q; 843626738bSChristoph Hellwig int d, z, z0; 853626738bSChristoph Hellwig 863626738bSChristoph Hellwig dptr = (u8 **) ptrs; 873626738bSChristoph Hellwig z0 = stop; /* P/Q right side optimization */ 883626738bSChristoph Hellwig p = dptr[disks - 2]; /* XOR parity */ 893626738bSChristoph Hellwig q = dptr[disks - 1]; /* RS syndrome */ 903626738bSChristoph Hellwig 913626738bSChristoph Hellwig kernel_fpu_begin(&vxstate, KERNEL_VXR); 923626738bSChristoph Hellwig LOAD_CONST(); 933626738bSChristoph Hellwig 943626738bSChristoph Hellwig for (d = 0; d < bytes; d += $#*NSIZE) { 953626738bSChristoph Hellwig /* P/Q data pages */ 963626738bSChristoph Hellwig LOAD_DATA(0,&dptr[z0][d]); 973626738bSChristoph Hellwig COPY_VEC(8+$$,0+$$); 983626738bSChristoph Hellwig for (z = z0 - 1; z >= start; z--) { 993626738bSChristoph Hellwig MASK(16+$$,8+$$); 1003626738bSChristoph Hellwig AND(16+$$,16+$$,25); 1013626738bSChristoph Hellwig SHLBYTE(8+$$,8+$$); 1023626738bSChristoph Hellwig XOR(8+$$,8+$$,16+$$); 1033626738bSChristoph Hellwig LOAD_DATA(16,&dptr[z][d]); 1043626738bSChristoph Hellwig XOR(0+$$,0+$$,16+$$); 1053626738bSChristoph Hellwig XOR(8+$$,8+$$,16+$$); 1063626738bSChristoph Hellwig } 1073626738bSChristoph Hellwig /* P/Q left side optimization */ 1083626738bSChristoph Hellwig for (z = start - 1; z >= 0; z--) { 1093626738bSChristoph Hellwig MASK(16+$$,8+$$); 1103626738bSChristoph Hellwig AND(16+$$,16+$$,25); 1113626738bSChristoph Hellwig SHLBYTE(8+$$,8+$$); 1123626738bSChristoph Hellwig XOR(8+$$,8+$$,16+$$); 1133626738bSChristoph Hellwig } 1143626738bSChristoph Hellwig LOAD_DATA(16,&p[d]); 1153626738bSChristoph Hellwig XOR(16+$$,16+$$,0+$$); 1163626738bSChristoph Hellwig STORE_DATA(16,&p[d]); 1173626738bSChristoph Hellwig LOAD_DATA(16,&q[d]); 1183626738bSChristoph Hellwig XOR(16+$$,16+$$,8+$$); 1193626738bSChristoph Hellwig STORE_DATA(16,&q[d]); 1203626738bSChristoph Hellwig } 1213626738bSChristoph Hellwig kernel_fpu_end(&vxstate, KERNEL_VXR); 1223626738bSChristoph Hellwig} 1233626738bSChristoph Hellwig 1243626738bSChristoph Hellwigconst struct raid6_calls raid6_s390vx$# = { 1257e91f76aSChristoph Hellwig .gen_syndrome = raid6_s390vx$#_gen_syndrome, 1267e91f76aSChristoph Hellwig .xor_syndrome = raid6_s390vx$#_xor_syndrome, 1277e91f76aSChristoph Hellwig .name = "vx128x$#", 1283626738bSChristoph Hellwig}; 129