pq.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* -*- linux-c -*- ------------------------------------------------------- *
  3. *
  4. * Copyright 2003 H. Peter Anvin - All Rights Reserved
  5. *
  6. * ----------------------------------------------------------------------- */
  7. #ifndef LINUX_RAID_RAID6_H
  8. #define LINUX_RAID_RAID6_H
  9. #ifdef __KERNEL__
  10. /* Set to 1 to use kernel-wide empty_zero_page */
  11. #define RAID6_USE_EMPTY_ZERO_PAGE 0
  12. #include <linux/blkdev.h>
  13. /* We need a pre-zeroed page... if we don't want to use the kernel-provided
  14. one define it here */
  15. #if RAID6_USE_EMPTY_ZERO_PAGE
  16. # define raid6_empty_zero_page empty_zero_page
  17. #else
  18. extern const char raid6_empty_zero_page[PAGE_SIZE];
  19. #endif
  20. #else /* ! __KERNEL__ */
  21. /* Used for testing in user space */
  22. #include <errno.h>
  23. #include <inttypes.h>
  24. #include <stddef.h>
  25. #include <string.h>
  26. #include <sys/mman.h>
  27. #include <sys/time.h>
  28. #include <sys/types.h>
  29. /* Not standard, but glibc defines it */
  30. #define BITS_PER_LONG __WORDSIZE
  31. typedef uint8_t u8;
  32. typedef uint16_t u16;
  33. typedef uint32_t u32;
  34. typedef uint64_t u64;
  35. #ifndef PAGE_SIZE
  36. # define PAGE_SIZE 4096
  37. #endif
  38. #ifndef PAGE_SHIFT
  39. # define PAGE_SHIFT 12
  40. #endif
  41. extern const char raid6_empty_zero_page[PAGE_SIZE];
  42. #define __init
  43. #define __exit
  44. #ifndef __attribute_const__
  45. # define __attribute_const__ __attribute__((const))
  46. #endif
  47. #define noinline __attribute__((noinline))
  48. #define preempt_enable()
  49. #define preempt_disable()
  50. #define cpu_has_feature(x) 1
  51. #define enable_kernel_altivec()
  52. #define disable_kernel_altivec()
  53. #undef EXPORT_SYMBOL
  54. #define EXPORT_SYMBOL(sym)
  55. #undef EXPORT_SYMBOL_GPL
  56. #define EXPORT_SYMBOL_GPL(sym)
  57. #define MODULE_LICENSE(licence)
  58. #define MODULE_DESCRIPTION(desc)
  59. #define subsys_initcall(x)
  60. #define module_exit(x)
  61. #define IS_ENABLED(x) (x)
  62. #define CONFIG_RAID6_PQ_BENCHMARK 1
  63. #endif /* __KERNEL__ */
  64. /* Routine choices */
  65. struct raid6_calls {
  66. void (*gen_syndrome)(int, size_t, void **);
  67. void (*xor_syndrome)(int, int, int, size_t, void **);
  68. int (*valid)(void); /* Returns 1 if this routine set is usable */
  69. const char *name; /* Name of this routine set */
  70. int prefer; /* Has special performance attribute */
  71. };
  72. /* Selected algorithm */
  73. extern struct raid6_calls raid6_call;
  74. /* Various routine sets */
  75. extern const struct raid6_calls raid6_intx1;
  76. extern const struct raid6_calls raid6_intx2;
  77. extern const struct raid6_calls raid6_intx4;
  78. extern const struct raid6_calls raid6_intx8;
  79. extern const struct raid6_calls raid6_intx16;
  80. extern const struct raid6_calls raid6_intx32;
  81. extern const struct raid6_calls raid6_mmxx1;
  82. extern const struct raid6_calls raid6_mmxx2;
  83. extern const struct raid6_calls raid6_sse1x1;
  84. extern const struct raid6_calls raid6_sse1x2;
  85. extern const struct raid6_calls raid6_sse2x1;
  86. extern const struct raid6_calls raid6_sse2x2;
  87. extern const struct raid6_calls raid6_sse2x4;
  88. extern const struct raid6_calls raid6_altivec1;
  89. extern const struct raid6_calls raid6_altivec2;
  90. extern const struct raid6_calls raid6_altivec4;
  91. extern const struct raid6_calls raid6_altivec8;
  92. extern const struct raid6_calls raid6_avx2x1;
  93. extern const struct raid6_calls raid6_avx2x2;
  94. extern const struct raid6_calls raid6_avx2x4;
  95. extern const struct raid6_calls raid6_avx512x1;
  96. extern const struct raid6_calls raid6_avx512x2;
  97. extern const struct raid6_calls raid6_avx512x4;
  98. extern const struct raid6_calls raid6_s390vx8;
  99. extern const struct raid6_calls raid6_vpermxor1;
  100. extern const struct raid6_calls raid6_vpermxor2;
  101. extern const struct raid6_calls raid6_vpermxor4;
  102. extern const struct raid6_calls raid6_vpermxor8;
  103. struct raid6_recov_calls {
  104. void (*data2)(int, size_t, int, int, void **);
  105. void (*datap)(int, size_t, int, void **);
  106. int (*valid)(void);
  107. const char *name;
  108. int priority;
  109. };
  110. extern const struct raid6_recov_calls raid6_recov_intx1;
  111. extern const struct raid6_recov_calls raid6_recov_ssse3;
  112. extern const struct raid6_recov_calls raid6_recov_avx2;
  113. extern const struct raid6_recov_calls raid6_recov_avx512;
  114. extern const struct raid6_recov_calls raid6_recov_s390xc;
  115. extern const struct raid6_recov_calls raid6_recov_neon;
  116. extern const struct raid6_calls raid6_neonx1;
  117. extern const struct raid6_calls raid6_neonx2;
  118. extern const struct raid6_calls raid6_neonx4;
  119. extern const struct raid6_calls raid6_neonx8;
  120. /* Algorithm list */
  121. extern const struct raid6_calls * const raid6_algos[];
  122. extern const struct raid6_recov_calls *const raid6_recov_algos[];
  123. int raid6_select_algo(void);
  124. /* Return values from chk_syndrome */
  125. #define RAID6_OK 0
  126. #define RAID6_P_BAD 1
  127. #define RAID6_Q_BAD 2
  128. #define RAID6_PQ_BAD 3
  129. /* Galois field tables */
  130. extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
  131. extern const u8 raid6_vgfmul[256][32] __attribute__((aligned(256)));
  132. extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
  133. extern const u8 raid6_gflog[256] __attribute__((aligned(256)));
  134. extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
  135. extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
  136. /* Recovery routines */
  137. extern void (*raid6_2data_recov)(int disks, size_t bytes, int faila, int failb,
  138. void **ptrs);
  139. extern void (*raid6_datap_recov)(int disks, size_t bytes, int faila,
  140. void **ptrs);
  141. void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
  142. void **ptrs);
  143. /* Some definitions to allow code to be compiled for testing in userspace */
  144. #ifndef __KERNEL__
  145. # define jiffies raid6_jiffies()
  146. # define printk printf
  147. # define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
  148. # define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__)
  149. # define GFP_KERNEL 0
  150. # define __get_free_pages(x, y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), \
  151. PROT_READ|PROT_WRITE, \
  152. MAP_PRIVATE|MAP_ANONYMOUS,\
  153. 0, 0))
  154. # define free_pages(x, y) munmap((void *)(x), PAGE_SIZE << (y))
  155. static inline void cpu_relax(void)
  156. {
  157. /* Nothing */
  158. }
  159. #undef HZ
  160. #define HZ 1000
  161. static inline uint32_t raid6_jiffies(void)
  162. {
  163. struct timeval tv;
  164. gettimeofday(&tv, NULL);
  165. return tv.tv_sec*1000 + tv.tv_usec/1000;
  166. }
  167. #endif /* ! __KERNEL__ */
  168. #endif /* LINUX_RAID_RAID6_H */