s390vx.uc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #include <linux/raid/pq.h>
  14. #include <asm/fpu/api.h>
  15. asm(".include \"asm/vx-insn.h\"\n");
  16. #define NSIZE 16
  17. static inline void LOAD_CONST(void)
  18. {
  19. asm volatile("VREPIB %v24,7");
  20. asm volatile("VREPIB %v25,0x1d");
  21. }
  22. /*
  23. * The SHLBYTE() operation shifts each of the 16 bytes in
  24. * vector register y left by 1 bit and stores the result in
  25. * vector register x.
  26. */
  27. static inline void SHLBYTE(int x, int y)
  28. {
  29. asm volatile ("VAB %0,%1,%1" : : "i" (x), "i" (y));
  30. }
  31. /*
  32. * For each of the 16 bytes in the vector register y the MASK()
  33. * operation returns 0xFF if the high bit of the byte is 1,
  34. * or 0x00 if the high bit is 0. The result is stored in vector
  35. * register x.
  36. */
  37. static inline void MASK(int x, int y)
  38. {
  39. asm volatile ("VESRAVB %0,%1,24" : : "i" (x), "i" (y));
  40. }
  41. static inline void AND(int x, int y, int z)
  42. {
  43. asm volatile ("VN %0,%1,%2" : : "i" (x), "i" (y), "i" (z));
  44. }
  45. static inline void XOR(int x, int y, int z)
  46. {
  47. asm volatile ("VX %0,%1,%2" : : "i" (x), "i" (y), "i" (z));
  48. }
  49. static inline void LOAD_DATA(int x, u8 *ptr)
  50. {
  51. typedef struct { u8 _[16 * $#]; } addrtype;
  52. register addrtype *__ptr asm("1") = (addrtype *) ptr;
  53. asm volatile ("VLM %2,%3,0,%1"
  54. : : "m" (*__ptr), "a" (__ptr), "i" (x),
  55. "i" (x + $# - 1));
  56. }
  57. static inline void STORE_DATA(int x, u8 *ptr)
  58. {
  59. typedef struct { u8 _[16 * $#]; } addrtype;
  60. register addrtype *__ptr asm("1") = (addrtype *) ptr;
  61. asm volatile ("VSTM %2,%3,0,1"
  62. : "=m" (*__ptr) : "a" (__ptr), "i" (x),
  63. "i" (x + $# - 1));
  64. }
  65. static inline void COPY_VEC(int x, int y)
  66. {
  67. asm volatile ("VLR %0,%1" : : "i" (x), "i" (y));
  68. }
  69. static void raid6_s390vx$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
  70. {
  71. struct kernel_fpu vxstate;
  72. u8 **dptr, *p, *q;
  73. int d, z, z0;
  74. kernel_fpu_begin(&vxstate, KERNEL_VXR);
  75. LOAD_CONST();
  76. dptr = (u8 **) ptrs;
  77. z0 = disks - 3; /* Highest data disk */
  78. p = dptr[z0 + 1]; /* XOR parity */
  79. q = dptr[z0 + 2]; /* RS syndrome */
  80. for (d = 0; d < bytes; d += $#*NSIZE) {
  81. LOAD_DATA(0,&dptr[z0][d]);
  82. COPY_VEC(8+$$,0+$$);
  83. for (z = z0 - 1; z >= 0; z--) {
  84. MASK(16+$$,8+$$);
  85. AND(16+$$,16+$$,25);
  86. SHLBYTE(8+$$,8+$$);
  87. XOR(8+$$,8+$$,16+$$);
  88. LOAD_DATA(16,&dptr[z][d]);
  89. XOR(0+$$,0+$$,16+$$);
  90. XOR(8+$$,8+$$,16+$$);
  91. }
  92. STORE_DATA(0,&p[d]);
  93. STORE_DATA(8,&q[d]);
  94. }
  95. kernel_fpu_end(&vxstate, KERNEL_VXR);
  96. }
  97. static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop,
  98. size_t bytes, void **ptrs)
  99. {
  100. struct kernel_fpu vxstate;
  101. u8 **dptr, *p, *q;
  102. int d, z, z0;
  103. dptr = (u8 **) ptrs;
  104. z0 = stop; /* P/Q right side optimization */
  105. p = dptr[disks - 2]; /* XOR parity */
  106. q = dptr[disks - 1]; /* RS syndrome */
  107. kernel_fpu_begin(&vxstate, KERNEL_VXR);
  108. LOAD_CONST();
  109. for (d = 0; d < bytes; d += $#*NSIZE) {
  110. /* P/Q data pages */
  111. LOAD_DATA(0,&dptr[z0][d]);
  112. COPY_VEC(8+$$,0+$$);
  113. for (z = z0 - 1; z >= start; z--) {
  114. MASK(16+$$,8+$$);
  115. AND(16+$$,16+$$,25);
  116. SHLBYTE(8+$$,8+$$);
  117. XOR(8+$$,8+$$,16+$$);
  118. LOAD_DATA(16,&dptr[z][d]);
  119. XOR(0+$$,0+$$,16+$$);
  120. XOR(8+$$,8+$$,16+$$);
  121. }
  122. /* P/Q left side optimization */
  123. for (z = start - 1; z >= 0; z--) {
  124. MASK(16+$$,8+$$);
  125. AND(16+$$,16+$$,25);
  126. SHLBYTE(8+$$,8+$$);
  127. XOR(8+$$,8+$$,16+$$);
  128. }
  129. LOAD_DATA(16,&p[d]);
  130. XOR(16+$$,16+$$,0+$$);
  131. STORE_DATA(16,&p[d]);
  132. LOAD_DATA(16,&q[d]);
  133. XOR(16+$$,16+$$,8+$$);
  134. STORE_DATA(16,&q[d]);
  135. }
  136. kernel_fpu_end(&vxstate, KERNEL_VXR);
  137. }
  138. static int raid6_s390vx$#_valid(void)
  139. {
  140. return MACHINE_HAS_VX;
  141. }
  142. const struct raid6_calls raid6_s390vx$# = {
  143. raid6_s390vx$#_gen_syndrome,
  144. raid6_s390vx$#_xor_syndrome,
  145. raid6_s390vx$#_valid,
  146. "vx128x$#",
  147. 1
  148. };