0001
0002
0003
0004
0005
0006
0007
0008 #ifndef LINUX_RAID_RAID6_H
0009 #define LINUX_RAID_RAID6_H
0010
0011 #ifdef __KERNEL__
0012
0013
0014 #define RAID6_USE_EMPTY_ZERO_PAGE 0
0015 #include <linux/blkdev.h>
0016
0017
0018
0019 #if RAID6_USE_EMPTY_ZERO_PAGE
0020 # define raid6_empty_zero_page empty_zero_page
0021 #else
0022 extern const char raid6_empty_zero_page[PAGE_SIZE];
0023 #endif
0024
0025 #else
0026
0027
0028 #include <errno.h>
0029 #include <inttypes.h>
0030 #include <stddef.h>
0031 #include <string.h>
0032 #include <sys/mman.h>
0033 #include <sys/time.h>
0034 #include <sys/types.h>
0035
0036
0037 #define BITS_PER_LONG __WORDSIZE
0038
0039 typedef uint8_t u8;
0040 typedef uint16_t u16;
0041 typedef uint32_t u32;
0042 typedef uint64_t u64;
0043
0044 #ifndef PAGE_SIZE
0045 # define PAGE_SIZE 4096
0046 #endif
0047 #ifndef PAGE_SHIFT
0048 # define PAGE_SHIFT 12
0049 #endif
0050 extern const char raid6_empty_zero_page[PAGE_SIZE];
0051
0052 #define __init
0053 #define __exit
0054 #ifndef __attribute_const__
0055 # define __attribute_const__ __attribute__((const))
0056 #endif
0057 #define noinline __attribute__((noinline))
0058
0059 #define preempt_enable()
0060 #define preempt_disable()
0061 #define cpu_has_feature(x) 1
0062 #define enable_kernel_altivec()
0063 #define disable_kernel_altivec()
0064
0065 #undef EXPORT_SYMBOL
0066 #define EXPORT_SYMBOL(sym)
0067 #undef EXPORT_SYMBOL_GPL
0068 #define EXPORT_SYMBOL_GPL(sym)
0069 #define MODULE_LICENSE(licence)
0070 #define MODULE_DESCRIPTION(desc)
0071 #define subsys_initcall(x)
0072 #define module_exit(x)
0073
0074 #define IS_ENABLED(x) (x)
0075 #define CONFIG_RAID6_PQ_BENCHMARK 1
0076 #endif
0077
0078
0079 struct raid6_calls {
0080 void (*gen_syndrome)(int, size_t, void **);
0081 void (*xor_syndrome)(int, int, int, size_t, void **);
0082 int (*valid)(void);
0083 const char *name;
0084 int priority;
0085 };
0086
0087
0088 extern struct raid6_calls raid6_call;
0089
0090
0091 extern const struct raid6_calls raid6_intx1;
0092 extern const struct raid6_calls raid6_intx2;
0093 extern const struct raid6_calls raid6_intx4;
0094 extern const struct raid6_calls raid6_intx8;
0095 extern const struct raid6_calls raid6_intx16;
0096 extern const struct raid6_calls raid6_intx32;
0097 extern const struct raid6_calls raid6_mmxx1;
0098 extern const struct raid6_calls raid6_mmxx2;
0099 extern const struct raid6_calls raid6_sse1x1;
0100 extern const struct raid6_calls raid6_sse1x2;
0101 extern const struct raid6_calls raid6_sse2x1;
0102 extern const struct raid6_calls raid6_sse2x2;
0103 extern const struct raid6_calls raid6_sse2x4;
0104 extern const struct raid6_calls raid6_altivec1;
0105 extern const struct raid6_calls raid6_altivec2;
0106 extern const struct raid6_calls raid6_altivec4;
0107 extern const struct raid6_calls raid6_altivec8;
0108 extern const struct raid6_calls raid6_avx2x1;
0109 extern const struct raid6_calls raid6_avx2x2;
0110 extern const struct raid6_calls raid6_avx2x4;
0111 extern const struct raid6_calls raid6_avx512x1;
0112 extern const struct raid6_calls raid6_avx512x2;
0113 extern const struct raid6_calls raid6_avx512x4;
0114 extern const struct raid6_calls raid6_s390vx8;
0115 extern const struct raid6_calls raid6_vpermxor1;
0116 extern const struct raid6_calls raid6_vpermxor2;
0117 extern const struct raid6_calls raid6_vpermxor4;
0118 extern const struct raid6_calls raid6_vpermxor8;
0119
0120 struct raid6_recov_calls {
0121 void (*data2)(int, size_t, int, int, void **);
0122 void (*datap)(int, size_t, int, void **);
0123 int (*valid)(void);
0124 const char *name;
0125 int priority;
0126 };
0127
0128 extern const struct raid6_recov_calls raid6_recov_intx1;
0129 extern const struct raid6_recov_calls raid6_recov_ssse3;
0130 extern const struct raid6_recov_calls raid6_recov_avx2;
0131 extern const struct raid6_recov_calls raid6_recov_avx512;
0132 extern const struct raid6_recov_calls raid6_recov_s390xc;
0133 extern const struct raid6_recov_calls raid6_recov_neon;
0134
0135 extern const struct raid6_calls raid6_neonx1;
0136 extern const struct raid6_calls raid6_neonx2;
0137 extern const struct raid6_calls raid6_neonx4;
0138 extern const struct raid6_calls raid6_neonx8;
0139
0140
0141 extern const struct raid6_calls * const raid6_algos[];
0142 extern const struct raid6_recov_calls *const raid6_recov_algos[];
0143 int raid6_select_algo(void);
0144
0145
0146 #define RAID6_OK 0
0147 #define RAID6_P_BAD 1
0148 #define RAID6_Q_BAD 2
0149 #define RAID6_PQ_BAD 3
0150
0151
0152 extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
0153 extern const u8 raid6_vgfmul[256][32] __attribute__((aligned(256)));
0154 extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
0155 extern const u8 raid6_gflog[256] __attribute__((aligned(256)));
0156 extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
0157 extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
0158
0159
0160 extern void (*raid6_2data_recov)(int disks, size_t bytes, int faila, int failb,
0161 void **ptrs);
0162 extern void (*raid6_datap_recov)(int disks, size_t bytes, int faila,
0163 void **ptrs);
0164 void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
0165 void **ptrs);
0166
0167
0168 #ifndef __KERNEL__
0169
0170 # define jiffies raid6_jiffies()
0171 # define printk printf
0172 # define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
0173 # define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__)
0174 # define GFP_KERNEL 0
0175 # define __get_free_pages(x, y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), \
0176 PROT_READ|PROT_WRITE, \
0177 MAP_PRIVATE|MAP_ANONYMOUS,\
0178 0, 0))
0179 # define free_pages(x, y) munmap((void *)(x), PAGE_SIZE << (y))
0180
0181 static inline void cpu_relax(void)
0182 {
0183
0184 }
0185
0186 #undef HZ
0187 #define HZ 1000
0188 static inline uint32_t raid6_jiffies(void)
0189 {
0190 struct timeval tv;
0191 gettimeofday(&tv, NULL);
0192 return tv.tv_sec*1000 + tv.tv_usec/1000;
0193 }
0194
0195 #endif
0196
0197 #endif