raid6.h 3.6 KB

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