1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
5 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2 or (at your
7 * option) any later version; incorporated herein by reference.
9 * ----------------------------------------------------------------------- */
14 * Make RAID-6 tables. This is a host user space program to be run at
24 static uint8_t gfmul(uint8_t a
, uint8_t b
)
31 a
= (a
<< 1) ^ (a
& 0x80 ? 0x1d : 0);
38 static uint8_t gfpow(uint8_t a
, int b
)
56 int main(int argc
, char *argv
[])
60 uint8_t exptbl
[256], invtbl
[256];
62 printf("#include <linux/raid/pq.h>\n");
63 printf("#include <linux/export.h>\n");
65 /* Compute multiplication table */
66 printf("\nconst u8 __attribute__((aligned(256)))\n"
67 "raid6_gfmul[256][256] =\n"
69 for (i
= 0; i
< 256; i
++) {
71 for (j
= 0; j
< 256; j
+= 8) {
73 for (k
= 0; k
< 8; k
++)
74 printf("0x%02x,%c", gfmul(i
, j
+ k
),
75 (k
== 7) ? '\n' : ' ');
80 printf("#ifdef __KERNEL__\n");
81 printf("EXPORT_SYMBOL(raid6_gfmul);\n");
84 /* Compute power-of-2 table (exponent) */
86 printf("\nconst u8 __attribute__((aligned(256)))\n"
87 "raid6_gfexp[256] =\n" "{\n");
88 for (i
= 0; i
< 256; i
+= 8) {
90 for (j
= 0; j
< 8; j
++) {
92 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
95 v
= 0; /* For entry 255, not a real entry */
99 printf("#ifdef __KERNEL__\n");
100 printf("EXPORT_SYMBOL(raid6_gfexp);\n");
103 /* Compute inverse table x^-1 == x^254 */
104 printf("\nconst u8 __attribute__((aligned(256)))\n"
105 "raid6_gfinv[256] =\n" "{\n");
106 for (i
= 0; i
< 256; i
+= 8) {
108 for (j
= 0; j
< 8; j
++) {
109 invtbl
[i
+ j
] = v
= gfpow(i
+ j
, 254);
110 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
114 printf("#ifdef __KERNEL__\n");
115 printf("EXPORT_SYMBOL(raid6_gfinv);\n");
118 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
119 printf("\nconst u8 __attribute__((aligned(256)))\n"
120 "raid6_gfexi[256] =\n" "{\n");
121 for (i
= 0; i
< 256; i
+= 8) {
123 for (j
= 0; j
< 8; j
++)
124 printf("0x%02x,%c", invtbl
[exptbl
[i
+ j
] ^ 1],
125 (j
== 7) ? '\n' : ' ');
128 printf("#ifdef __KERNEL__\n");
129 printf("EXPORT_SYMBOL(raid6_gfexi);\n");