1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LINUX_RAID_RAID6_H
14#define LINUX_RAID_RAID6_H
15
16#ifdef __KERNEL__
17
18
19#define RAID6_USE_EMPTY_ZERO_PAGE 0
20
21#include <linux/raid/md.h>
22#include <linux/raid/raid5.h>
23
24typedef raid5_conf_t raid6_conf_t;
25
26
27#define UPDATE_PARITY 4
28
29
30
31#if RAID6_USE_EMPTY_ZERO_PAGE
32# define raid6_empty_zero_page empty_zero_page
33#else
34extern const char raid6_empty_zero_page[PAGE_SIZE];
35#endif
36
37#else
38
39
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
47
48#define BITS_PER_LONG __WORDSIZE
49
50typedef uint8_t u8;
51typedef uint16_t u16;
52typedef uint32_t u32;
53typedef uint64_t u64;
54
55#ifndef PAGE_SIZE
56# define PAGE_SIZE 4096
57#endif
58extern const char raid6_empty_zero_page[PAGE_SIZE];
59
60#define __init
61#define __exit
62#define __attribute_const__ __attribute__((const))
63#define noinline __attribute__((noinline))
64
65#define preempt_enable()
66#define preempt_disable()
67#define cpu_has_feature(x) 1
68#define enable_kernel_altivec()
69#define disable_kernel_altivec()
70
71#endif
72
73
74struct raid6_calls {
75 void (*gen_syndrome)(int, size_t, void **);
76 int (*valid)(void);
77 const char *name;
78 int prefer;
79};
80
81
82extern struct raid6_calls raid6_call;
83
84
85extern const struct raid6_calls * const raid6_algos[];
86int raid6_select_algo(void);
87
88
89#define RAID6_OK 0
90#define RAID6_P_BAD 1
91#define RAID6_Q_BAD 2
92#define RAID6_PQ_BAD 3
93
94
95extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
96extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
97extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
98extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
99
100
101void raid6_2data_recov(int disks, size_t bytes, int faila, int failb, void **ptrs);
102void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs);
103void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, void **ptrs);
104
105
106#ifndef __KERNEL__
107
108# define jiffies raid6_jiffies()
109# define printk printf
110# define GFP_KERNEL 0
111# define __get_free_pages(x,y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0))
112# define free_pages(x,y) munmap((void *)(x), (y)*PAGE_SIZE)
113
114static inline void cpu_relax(void)
115{
116
117}
118
119#undef HZ
120#define HZ 1000
121static 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
128#endif
129
130#endif
131