2019-05-21 01:08:13 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* -*- linux-c -*- ------------------------------------------------------- *
|
|
|
|
*
|
|
|
|
* Copyright 2003 H. Peter Anvin - All Rights Reserved
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#ifndef LINUX_RAID_RAID6_H
|
|
|
|
#define LINUX_RAID_RAID6_H
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
/* Set to 1 to use kernel-wide empty_zero_page */
|
|
|
|
#define RAID6_USE_EMPTY_ZERO_PAGE 0
|
2009-03-31 11:33:13 +08:00
|
|
|
#include <linux/blkdev.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We need a pre-zeroed page... if we don't want to use the kernel-provided
|
|
|
|
one define it here */
|
|
|
|
#if RAID6_USE_EMPTY_ZERO_PAGE
|
|
|
|
# define raid6_empty_zero_page empty_zero_page
|
|
|
|
#else
|
|
|
|
extern const char raid6_empty_zero_page[PAGE_SIZE];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* ! __KERNEL__ */
|
|
|
|
/* Used for testing in user space */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/mman.h>
|
2018-11-13 07:22:16 +08:00
|
|
|
#include <sys/time.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
/* Not standard, but glibc defines it */
|
|
|
|
#define BITS_PER_LONG __WORDSIZE
|
|
|
|
|
|
|
|
typedef uint8_t u8;
|
|
|
|
typedef uint16_t u16;
|
|
|
|
typedef uint32_t u32;
|
|
|
|
typedef uint64_t u64;
|
|
|
|
|
|
|
|
#ifndef PAGE_SIZE
|
|
|
|
# define PAGE_SIZE 4096
|
|
|
|
#endif
|
|
|
|
extern const char raid6_empty_zero_page[PAGE_SIZE];
|
|
|
|
|
|
|
|
#define __init
|
|
|
|
#define __exit
|
2018-11-13 07:22:17 +08:00
|
|
|
#ifndef __attribute_const__
|
|
|
|
# define __attribute_const__ __attribute__((const))
|
|
|
|
#endif
|
2005-09-17 10:27:29 +08:00
|
|
|
#define noinline __attribute__((noinline))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define preempt_enable()
|
|
|
|
#define preempt_disable()
|
2005-09-17 10:27:29 +08:00
|
|
|
#define cpu_has_feature(x) 1
|
|
|
|
#define enable_kernel_altivec()
|
|
|
|
#define disable_kernel_altivec()
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 12:09:39 +08:00
|
|
|
#define EXPORT_SYMBOL(sym)
|
2010-08-12 04:38:24 +08:00
|
|
|
#define EXPORT_SYMBOL_GPL(sym)
|
2009-03-31 12:09:39 +08:00
|
|
|
#define MODULE_LICENSE(licence)
|
2010-08-12 04:38:24 +08:00
|
|
|
#define MODULE_DESCRIPTION(desc)
|
2009-03-31 12:09:39 +08:00
|
|
|
#define subsys_initcall(x)
|
|
|
|
#define module_exit(x)
|
2018-11-13 07:26:52 +08:00
|
|
|
|
|
|
|
#define IS_ENABLED(x) (x)
|
|
|
|
#define CONFIG_RAID6_PQ_BENCHMARK 1
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
/* Routine choices */
|
|
|
|
struct raid6_calls {
|
|
|
|
void (*gen_syndrome)(int, size_t, void **);
|
2014-12-15 09:57:04 +08:00
|
|
|
void (*xor_syndrome)(int, int, int, size_t, void **);
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*valid)(void); /* Returns 1 if this routine set is usable */
|
|
|
|
const char *name; /* Name of this routine set */
|
|
|
|
int prefer; /* Has special performance attribute */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Selected algorithm */
|
|
|
|
extern struct raid6_calls raid6_call;
|
|
|
|
|
2009-12-14 09:49:47 +08:00
|
|
|
/* Various routine sets */
|
|
|
|
extern const struct raid6_calls raid6_intx1;
|
|
|
|
extern const struct raid6_calls raid6_intx2;
|
|
|
|
extern const struct raid6_calls raid6_intx4;
|
|
|
|
extern const struct raid6_calls raid6_intx8;
|
|
|
|
extern const struct raid6_calls raid6_intx16;
|
|
|
|
extern const struct raid6_calls raid6_intx32;
|
|
|
|
extern const struct raid6_calls raid6_mmxx1;
|
|
|
|
extern const struct raid6_calls raid6_mmxx2;
|
|
|
|
extern const struct raid6_calls raid6_sse1x1;
|
|
|
|
extern const struct raid6_calls raid6_sse1x2;
|
|
|
|
extern const struct raid6_calls raid6_sse2x1;
|
|
|
|
extern const struct raid6_calls raid6_sse2x2;
|
|
|
|
extern const struct raid6_calls raid6_sse2x4;
|
|
|
|
extern const struct raid6_calls raid6_altivec1;
|
|
|
|
extern const struct raid6_calls raid6_altivec2;
|
|
|
|
extern const struct raid6_calls raid6_altivec4;
|
|
|
|
extern const struct raid6_calls raid6_altivec8;
|
2012-12-01 05:10:39 +08:00
|
|
|
extern const struct raid6_calls raid6_avx2x1;
|
|
|
|
extern const struct raid6_calls raid6_avx2x2;
|
|
|
|
extern const struct raid6_calls raid6_avx2x4;
|
2016-08-13 09:03:19 +08:00
|
|
|
extern const struct raid6_calls raid6_avx512x1;
|
|
|
|
extern const struct raid6_calls raid6_avx512x2;
|
|
|
|
extern const struct raid6_calls raid6_avx512x4;
|
2016-08-23 19:30:24 +08:00
|
|
|
extern const struct raid6_calls raid6_s390vx8;
|
2017-08-04 11:42:32 +08:00
|
|
|
extern const struct raid6_calls raid6_vpermxor1;
|
|
|
|
extern const struct raid6_calls raid6_vpermxor2;
|
|
|
|
extern const struct raid6_calls raid6_vpermxor4;
|
|
|
|
extern const struct raid6_calls raid6_vpermxor8;
|
2009-12-14 09:49:47 +08:00
|
|
|
|
2012-05-22 11:54:18 +08:00
|
|
|
struct raid6_recov_calls {
|
|
|
|
void (*data2)(int, size_t, int, int, void **);
|
|
|
|
void (*datap)(int, size_t, int, void **);
|
|
|
|
int (*valid)(void);
|
|
|
|
const char *name;
|
|
|
|
int priority;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct raid6_recov_calls raid6_recov_intx1;
|
|
|
|
extern const struct raid6_recov_calls raid6_recov_ssse3;
|
2012-11-09 05:47:44 +08:00
|
|
|
extern const struct raid6_recov_calls raid6_recov_avx2;
|
2016-08-13 09:03:20 +08:00
|
|
|
extern const struct raid6_recov_calls raid6_recov_avx512;
|
2016-08-31 15:27:35 +08:00
|
|
|
extern const struct raid6_recov_calls raid6_recov_s390xc;
|
2017-07-14 01:16:01 +08:00
|
|
|
extern const struct raid6_recov_calls raid6_recov_neon;
|
2012-05-22 11:54:18 +08:00
|
|
|
|
2013-05-16 23:20:32 +08:00
|
|
|
extern const struct raid6_calls raid6_neonx1;
|
|
|
|
extern const struct raid6_calls raid6_neonx2;
|
|
|
|
extern const struct raid6_calls raid6_neonx4;
|
|
|
|
extern const struct raid6_calls raid6_neonx8;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Algorithm list */
|
|
|
|
extern const struct raid6_calls * const raid6_algos[];
|
2012-05-22 11:54:18 +08:00
|
|
|
extern const struct raid6_recov_calls *const raid6_recov_algos[];
|
2005-04-17 06:20:36 +08:00
|
|
|
int raid6_select_algo(void);
|
|
|
|
|
|
|
|
/* Return values from chk_syndrome */
|
|
|
|
#define RAID6_OK 0
|
|
|
|
#define RAID6_P_BAD 1
|
|
|
|
#define RAID6_Q_BAD 2
|
|
|
|
#define RAID6_PQ_BAD 3
|
|
|
|
|
|
|
|
/* Galois field tables */
|
|
|
|
extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256)));
|
2012-05-22 11:54:18 +08:00
|
|
|
extern const u8 raid6_vgfmul[256][32] __attribute__((aligned(256)));
|
2005-04-17 06:20:36 +08:00
|
|
|
extern const u8 raid6_gfexp[256] __attribute__((aligned(256)));
|
2017-05-15 13:04:52 +08:00
|
|
|
extern const u8 raid6_gflog[256] __attribute__((aligned(256)));
|
2005-04-17 06:20:36 +08:00
|
|
|
extern const u8 raid6_gfinv[256] __attribute__((aligned(256)));
|
|
|
|
extern const u8 raid6_gfexi[256] __attribute__((aligned(256)));
|
|
|
|
|
|
|
|
/* Recovery routines */
|
2012-05-22 11:54:18 +08:00
|
|
|
extern void (*raid6_2data_recov)(int disks, size_t bytes, int faila, int failb,
|
2009-03-31 12:09:39 +08:00
|
|
|
void **ptrs);
|
2012-05-22 11:54:18 +08:00
|
|
|
extern void (*raid6_datap_recov)(int disks, size_t bytes, int faila,
|
|
|
|
void **ptrs);
|
2009-03-31 12:09:39 +08:00
|
|
|
void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
|
|
|
|
void **ptrs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Some definitions to allow code to be compiled for testing in userspace */
|
|
|
|
#ifndef __KERNEL__
|
|
|
|
|
|
|
|
# define jiffies raid6_jiffies()
|
|
|
|
# define printk printf
|
2016-01-22 06:02:39 +08:00
|
|
|
# define pr_err(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
|
|
|
|
# define pr_info(format, ...) fprintf(stdout, format, ## __VA_ARGS__)
|
2005-04-17 06:20:36 +08:00
|
|
|
# define GFP_KERNEL 0
|
2009-03-31 12:09:39 +08:00
|
|
|
# define __get_free_pages(x, y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), \
|
|
|
|
PROT_READ|PROT_WRITE, \
|
|
|
|
MAP_PRIVATE|MAP_ANONYMOUS,\
|
|
|
|
0, 0))
|
2011-12-23 07:17:51 +08:00
|
|
|
# define free_pages(x, y) munmap((void *)(x), PAGE_SIZE << (y))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static inline void cpu_relax(void)
|
|
|
|
{
|
|
|
|
/* Nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef HZ
|
|
|
|
#define HZ 1000
|
|
|
|
static inline uint32_t raid6_jiffies(void)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_sec*1000 + tv.tv_usec/1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* LINUX_RAID_RAID6_H */
|