1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
6 * ----------------------------------------------------------------------- */
11 * Make RAID-6 tables. This is a host user space program to be run at
21 static uint8_t gfmul(uint8_t a
, uint8_t b
)
28 a
= (a
<< 1) ^ (a
& 0x80 ? 0x1d : 0);
35 static uint8_t gfpow(uint8_t a
, int b
)
53 int main(int argc
, char *argv
[])
57 uint8_t exptbl
[256], invtbl
[256];
59 printf("#ifdef __KERNEL__\n");
60 printf("#include <linux/export.h>\n");
62 printf("#include <linux/raid/pq.h>\n");
64 /* Compute multiplication table */
65 printf("\nconst u8 __attribute__((aligned(256)))\n"
66 "raid6_gfmul[256][256] =\n"
68 for (i
= 0; i
< 256; i
++) {
70 for (j
= 0; j
< 256; j
+= 8) {
72 for (k
= 0; k
< 8; k
++)
73 printf("0x%02x,%c", gfmul(i
, j
+ k
),
74 (k
== 7) ? '\n' : ' ');
79 printf("#ifdef __KERNEL__\n");
80 printf("EXPORT_SYMBOL(raid6_gfmul);\n");
83 /* Compute vector multiplication table */
84 printf("\nconst u8 __attribute__((aligned(256)))\n"
85 "raid6_vgfmul[256][32] =\n"
87 for (i
= 0; i
< 256; i
++) {
89 for (j
= 0; j
< 16; j
+= 8) {
91 for (k
= 0; k
< 8; k
++)
92 printf("0x%02x,%c", gfmul(i
, j
+ k
),
93 (k
== 7) ? '\n' : ' ');
95 for (j
= 0; j
< 16; j
+= 8) {
97 for (k
= 0; k
< 8; k
++)
98 printf("0x%02x,%c", gfmul(i
, (j
+ k
) << 4),
99 (k
== 7) ? '\n' : ' ');
104 printf("#ifdef __KERNEL__\n");
105 printf("EXPORT_SYMBOL(raid6_vgfmul);\n");
108 /* Compute power-of-2 table (exponent) */
110 printf("\nconst u8 __attribute__((aligned(256)))\n"
111 "raid6_gfexp[256] =\n" "{\n");
112 for (i
= 0; i
< 256; i
+= 8) {
114 for (j
= 0; j
< 8; j
++) {
116 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
119 v
= 0; /* For entry 255, not a real entry */
123 printf("#ifdef __KERNEL__\n");
124 printf("EXPORT_SYMBOL(raid6_gfexp);\n");
127 /* Compute log-of-2 table */
128 printf("\nconst u8 __attribute__((aligned(256)))\n"
129 "raid6_gflog[256] =\n" "{\n");
130 for (i
= 0; i
< 256; i
+= 8) {
132 for (j
= 0; j
< 8; j
++) {
134 for (k
= 0; k
< 256; k
++)
135 if (exptbl
[k
] == (i
+ j
)) {
139 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
143 printf("#ifdef __KERNEL__\n");
144 printf("EXPORT_SYMBOL(raid6_gflog);\n");
147 /* Compute inverse table x^-1 == x^254 */
148 printf("\nconst u8 __attribute__((aligned(256)))\n"
149 "raid6_gfinv[256] =\n" "{\n");
150 for (i
= 0; i
< 256; i
+= 8) {
152 for (j
= 0; j
< 8; j
++) {
153 invtbl
[i
+ j
] = v
= gfpow(i
+ j
, 254);
154 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
158 printf("#ifdef __KERNEL__\n");
159 printf("EXPORT_SYMBOL(raid6_gfinv);\n");
162 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
163 printf("\nconst u8 __attribute__((aligned(256)))\n"
164 "raid6_gfexi[256] =\n" "{\n");
165 for (i
= 0; i
< 256; i
+= 8) {
167 for (j
= 0; j
< 8; j
++)
168 printf("0x%02x,%c", invtbl
[exptbl
[i
+ j
] ^ 1],
169 (j
== 7) ? '\n' : ' ');
172 printf("#ifdef __KERNEL__\n");
173 printf("EXPORT_SYMBOL(raid6_gfexi);\n");