recov_s390xc.c 2.7 KB

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