recov_s390xc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * RAID-6 data recovery in dual failure mode based on the XC instruction.
  4. *
  5. * Copyright IBM Corp. 2016
  6. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. */
  8. #include <linux/export.h>
  9. #include <linux/raid/pq.h>
  10. static inline void xor_block(u8 *p1, u8 *p2)
  11. {
  12. typedef struct { u8 _[256]; } addrtype;
  13. asm volatile(
  14. " xc 0(256,%[p1]),0(%[p2])\n"
  15. : "+m" (*(addrtype *) p1) : "m" (*(addrtype *) p2),
  16. [p1] "a" (p1), [p2] "a" (p2) : "cc");
  17. }
  18. /* Recover two failed data blocks. */
  19. static void raid6_2data_recov_s390xc(int disks, size_t bytes, int faila,
  20. int failb, void **ptrs)
  21. {
  22. u8 *p, *q, *dp, *dq;
  23. const u8 *pbmul; /* P multiplier table for B data */
  24. const u8 *qmul; /* Q multiplier table (for both) */
  25. int i;
  26. p = (u8 *)ptrs[disks-2];
  27. q = (u8 *)ptrs[disks-1];
  28. /* Compute syndrome with zero for the missing data pages
  29. Use the dead data pages as temporary storage for
  30. delta p and delta q */
  31. dp = (u8 *)ptrs[faila];
  32. ptrs[faila] = (void *)raid6_empty_zero_page;
  33. ptrs[disks-2] = dp;
  34. dq = (u8 *)ptrs[failb];
  35. ptrs[failb] = (void *)raid6_empty_zero_page;
  36. ptrs[disks-1] = dq;
  37. raid6_call.gen_syndrome(disks, bytes, ptrs);
  38. /* Restore pointer table */
  39. ptrs[faila] = dp;
  40. ptrs[failb] = dq;
  41. ptrs[disks-2] = p;
  42. ptrs[disks-1] = q;
  43. /* Now, pick the proper data tables */
  44. pbmul = raid6_gfmul[raid6_gfexi[failb-faila]];
  45. qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]]];
  46. /* Now do it... */
  47. while (bytes) {
  48. xor_block(dp, p);
  49. xor_block(dq, q);
  50. for (i = 0; i < 256; i++)
  51. dq[i] = pbmul[dp[i]] ^ qmul[dq[i]];
  52. xor_block(dp, dq);
  53. p += 256;
  54. q += 256;
  55. dp += 256;
  56. dq += 256;
  57. bytes -= 256;
  58. }
  59. }
  60. /* Recover failure of one data block plus the P block */
  61. static void raid6_datap_recov_s390xc(int disks, size_t bytes, int faila,
  62. void **ptrs)
  63. {
  64. u8 *p, *q, *dq;
  65. const u8 *qmul; /* Q multiplier table */
  66. int i;
  67. p = (u8 *)ptrs[disks-2];
  68. q = (u8 *)ptrs[disks-1];
  69. /* Compute syndrome with zero for the missing data page
  70. Use the dead data page as temporary storage for delta q */
  71. dq = (u8 *)ptrs[faila];
  72. ptrs[faila] = (void *)raid6_empty_zero_page;
  73. ptrs[disks-1] = dq;
  74. raid6_call.gen_syndrome(disks, bytes, ptrs);
  75. /* Restore pointer table */
  76. ptrs[faila] = dq;
  77. ptrs[disks-1] = q;
  78. /* Now, pick the proper data tables */
  79. qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]]];
  80. /* Now do it... */
  81. while (bytes) {
  82. xor_block(dq, q);
  83. for (i = 0; i < 256; i++)
  84. dq[i] = qmul[dq[i]];
  85. xor_block(p, dq);
  86. p += 256;
  87. q += 256;
  88. dq += 256;
  89. bytes -= 256;
  90. }
  91. }
  92. const struct raid6_recov_calls raid6_recov_s390xc = {
  93. .data2 = raid6_2data_recov_s390xc,
  94. .datap = raid6_datap_recov_s390xc,
  95. .valid = NULL,
  96. .name = "s390xc",
  97. .priority = 1,
  98. };