pq.h 5.8 KB

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