pq.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /* Algorithm list */
  87. extern const struct raid6_calls * const raid6_algos[];
  88. int raid6_select_algo(void);
  89. /* Return values from chk_syndrome */
  90. #define RAID6_OK 0
  91. #define RAID6_P_BAD 1
  92. #define RAID6_Q_BAD 2
  93. #define RAID6_PQ_BAD 3
  94. /* Galois field tables */
  95. extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
  96. extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
  97. extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
  98. extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
  99. /* Recovery routines */
  100. void raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
  101. void **ptrs);
  102. void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs);
  103. void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
  104. void **ptrs);
  105. /* Some definitions to allow code to be compiled for testing in userspace */
  106. #ifndef __KERNEL__
  107. # define jiffies raid6_jiffies()
  108. # define printk printf
  109. # define GFP_KERNEL 0
  110. # define __get_free_pages(x, y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), \
  111. PROT_READ|PROT_WRITE, \
  112. MAP_PRIVATE|MAP_ANONYMOUS,\
  113. 0, 0))
  114. # define free_pages(x, y) munmap((void *)(x), PAGE_SIZE << (y))
  115. static inline void cpu_relax(void)
  116. {
  117. /* Nothing */
  118. }
  119. #undef HZ
  120. #define HZ 1000
  121. static inline uint32_t raid6_jiffies(void)
  122. {
  123. struct timeval tv;
  124. gettimeofday(&tv, NULL);
  125. return tv.tv_sec*1000 + tv.tv_usec/1000;
  126. }
  127. #endif /* ! __KERNEL__ */
  128. #endif /* LINUX_RAID_RAID6_H */