raid6.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * Bostom 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/module.h>
  18. #include <linux/stddef.h>
  19. #include <linux/compiler.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/mempool.h>
  24. #include <linux/list.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/raid/md.h>
  27. #include <linux/raid/raid5.h>
  28. typedef raid5_conf_t raid6_conf_t; /* Same configuration */
  29. /* Additional compute_parity mode -- updates the parity w/o LOCKING */
  30. #define UPDATE_PARITY 4
  31. /* We need a pre-zeroed page... if we don't want to use the kernel-provided
  32. one define it here */
  33. #if RAID6_USE_EMPTY_ZERO_PAGE
  34. # define raid6_empty_zero_page empty_zero_page
  35. #else
  36. extern const char raid6_empty_zero_page[PAGE_SIZE];
  37. #endif
  38. #else /* ! __KERNEL__ */
  39. /* Used for testing in user space */
  40. #include <errno.h>
  41. #include <inttypes.h>
  42. #include <limits.h>
  43. #include <stddef.h>
  44. #include <sys/mman.h>
  45. #include <sys/types.h>
  46. /* Not standard, but glibc defines it */
  47. #define BITS_PER_LONG __WORDSIZE
  48. typedef uint8_t u8;
  49. typedef uint16_t u16;
  50. typedef uint32_t u32;
  51. typedef uint64_t u64;
  52. #ifndef PAGE_SIZE
  53. # define PAGE_SIZE 4096
  54. #endif
  55. extern const char raid6_empty_zero_page[PAGE_SIZE];
  56. #define __init
  57. #define __exit
  58. #define __attribute_const__ __attribute__((const))
  59. #define noinline __attribute__((noinline))
  60. #define preempt_enable()
  61. #define preempt_disable()
  62. #define cpu_has_feature(x) 1
  63. #define enable_kernel_altivec()
  64. #define disable_kernel_altivec()
  65. #endif /* __KERNEL__ */
  66. /* Routine choices */
  67. struct raid6_calls {
  68. void (*gen_syndrome)(int, size_t, void **);
  69. int (*valid)(void); /* Returns 1 if this routine set is usable */
  70. const char *name; /* Name of this routine set */
  71. int prefer; /* Has special performance attribute */
  72. };
  73. /* Selected algorithm */
  74. extern struct raid6_calls raid6_call;
  75. /* Algorithm list */
  76. extern const struct raid6_calls * const raid6_algos[];
  77. int raid6_select_algo(void);
  78. /* Return values from chk_syndrome */
  79. #define RAID6_OK 0
  80. #define RAID6_P_BAD 1
  81. #define RAID6_Q_BAD 2
  82. #define RAID6_PQ_BAD 3
  83. /* Galois field tables */
  84. extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
  85. extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
  86. extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
  87. extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
  88. /* Recovery routines */
  89. void raid6_2data_recov(int disks, size_t bytes, int faila, int failb, void **ptrs);
  90. void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs);
  91. void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, void **ptrs);
  92. /* Some definitions to allow code to be compiled for testing in userspace */
  93. #ifndef __KERNEL__
  94. # define jiffies raid6_jiffies()
  95. # define printk printf
  96. # define GFP_KERNEL 0
  97. # define __get_free_pages(x,y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0))
  98. # define free_pages(x,y) munmap((void *)(x), (y)*PAGE_SIZE)
  99. static inline void cpu_relax(void)
  100. {
  101. /* Nothing */
  102. }
  103. #undef HZ
  104. #define HZ 1000
  105. static inline uint32_t raid6_jiffies(void)
  106. {
  107. struct timeval tv;
  108. gettimeofday(&tv, NULL);
  109. return tv.tv_sec*1000 + tv.tv_usec/1000;
  110. }
  111. #endif /* ! __KERNEL__ */
  112. #endif /* LINUX_RAID_RAID6_H */