blob: 98dcde88470e4c23b8fc204e46587be0243bfa32 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -*- 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
13#ifndef LINUX_RAID_RAID6_H
14#define LINUX_RAID_RAID6_H
15
16#ifdef __KERNEL__
17
18/* Set to 1 to use kernel-wide empty_zero_page */
19#define RAID6_USE_EMPTY_ZERO_PAGE 0
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/raid/md.h>
22#include <linux/raid/raid5.h>
23
24typedef raid5_conf_t raid6_conf_t; /* Same configuration */
25
26/* Additional compute_parity mode -- updates the parity w/o LOCKING */
27#define UPDATE_PARITY 4
28
29/* We need a pre-zeroed page... if we don't want to use the kernel-provided
30 one define it here */
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 /* ! __KERNEL__ */
38/* Used for testing in user space */
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/* Not standard, but glibc defines it */
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))
H. Peter Anvind7e70ba2005-09-16 19:27:29 -070063#define noinline __attribute__((noinline))
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#define preempt_enable()
66#define preempt_disable()
H. Peter Anvind7e70ba2005-09-16 19:27:29 -070067#define cpu_has_feature(x) 1
68#define enable_kernel_altivec()
69#define disable_kernel_altivec()
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#endif /* __KERNEL__ */
72
73/* Routine choices */
74struct raid6_calls {
75 void (*gen_syndrome)(int, size_t, void **);
76 int (*valid)(void); /* Returns 1 if this routine set is usable */
77 const char *name; /* Name of this routine set */
78 int prefer; /* Has special performance attribute */
79};
80
81/* Selected algorithm */
82extern struct raid6_calls raid6_call;
83
84/* Algorithm list */
85extern const struct raid6_calls * const raid6_algos[];
86int raid6_select_algo(void);
87
88/* Return values from chk_syndrome */
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/* Galois field tables */
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/* Recovery routines */
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/* Some definitions to allow code to be compiled for testing in userspace */
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 /* Nothing */
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 /* ! __KERNEL__ */
129
130#endif /* LINUX_RAID_RAID6_H */