pq.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. int (*valid)(void); /* Returns 1 if this routine set is usable */
  63. const char *name; /* Name of this routine set */
  64. int prefer; /* Has special performance attribute */
  65. };
  66. /* Selected algorithm */
  67. extern struct raid6_calls raid6_call;
  68. /* Various routine sets */
  69. extern const struct raid6_calls raid6_intx1;
  70. extern const struct raid6_calls raid6_intx2;
  71. extern const struct raid6_calls raid6_intx4;
  72. extern const struct raid6_calls raid6_intx8;
  73. extern const struct raid6_calls raid6_intx16;
  74. extern const struct raid6_calls raid6_intx32;
  75. extern const struct raid6_calls raid6_mmxx1;
  76. extern const struct raid6_calls raid6_mmxx2;
  77. extern const struct raid6_calls raid6_sse1x1;
  78. extern const struct raid6_calls raid6_sse1x2;
  79. extern const struct raid6_calls raid6_sse2x1;
  80. extern const struct raid6_calls raid6_sse2x2;
  81. extern const struct raid6_calls raid6_sse2x4;
  82. extern const struct raid6_calls raid6_altivec1;
  83. extern const struct raid6_calls raid6_altivec2;
  84. extern const struct raid6_calls raid6_altivec4;
  85. extern const struct raid6_calls raid6_altivec8;
  86. struct raid6_recov_calls {
  87. void (*data2)(int, size_t, int, int, void **);
  88. void (*datap)(int, size_t, int, void **);
  89. int (*valid)(void);
  90. const char *name;
  91. int priority;
  92. };
  93. extern const struct raid6_recov_calls raid6_recov_intx1;
  94. extern const struct raid6_recov_calls raid6_recov_ssse3;
  95. /* Algorithm list */
  96. extern const struct raid6_calls * const raid6_algos[];
  97. extern const struct raid6_recov_calls *const raid6_recov_algos[];
  98. int raid6_select_algo(void);
  99. /* Return values from chk_syndrome */
  100. #define RAID6_OK 0
  101. #define RAID6_P_BAD 1
  102. #define RAID6_Q_BAD 2
  103. #define RAID6_PQ_BAD 3
  104. /* Galois field tables */
  105. extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
  106. extern const u8 raid6_vgfmul[256][32] __attribute__((aligned(256)));
  107. extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
  108. extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
  109. extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
  110. /* Recovery routines */
  111. extern void (*raid6_2data_recov)(int disks, size_t bytes, int faila, int failb,
  112. void **ptrs);
  113. extern void (*raid6_datap_recov)(int disks, size_t bytes, int faila,
  114. void **ptrs);
  115. void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
  116. void **ptrs);
  117. /* Some definitions to allow code to be compiled for testing in userspace */
  118. #ifndef __KERNEL__
  119. # define jiffies raid6_jiffies()
  120. # define printk printf
  121. # define GFP_KERNEL 0
  122. # define __get_free_pages(x, y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), \
  123. PROT_READ|PROT_WRITE, \
  124. MAP_PRIVATE|MAP_ANONYMOUS,\
  125. 0, 0))
  126. # define free_pages(x, y) munmap((void *)(x), PAGE_SIZE << (y))
  127. static inline void cpu_relax(void)
  128. {
  129. /* Nothing */
  130. }
  131. #undef HZ
  132. #define HZ 1000
  133. static inline uint32_t raid6_jiffies(void)
  134. {
  135. struct timeval tv;
  136. gettimeofday(&tv, NULL);
  137. return tv.tv_sec*1000 + tv.tv_usec/1000;
  138. }
  139. #endif /* ! __KERNEL__ */
  140. #endif /* LINUX_RAID_RAID6_H */