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("#include <linux/export.h>\n");
60 printf("#include <linux/raid/pq.h>\n");
62 /* Compute multiplication table */
63 printf("\nconst u8 __attribute__((aligned(256)))\n"
64 "raid6_gfmul[256][256] =\n"
66 for (i
= 0; i
< 256; i
++) {
68 for (j
= 0; j
< 256; j
+= 8) {
70 for (k
= 0; k
< 8; k
++)
71 printf("0x%02x,%c", gfmul(i
, j
+ k
),
72 (k
== 7) ? '\n' : ' ');
77 printf("#ifdef __KERNEL__\n");
78 printf("EXPORT_SYMBOL(raid6_gfmul);\n");
81 /* Compute vector multiplication table */
82 printf("\nconst u8 __attribute__((aligned(256)))\n"
83 "raid6_vgfmul[256][32] =\n"
85 for (i
= 0; i
< 256; i
++) {
87 for (j
= 0; j
< 16; j
+= 8) {
89 for (k
= 0; k
< 8; k
++)
90 printf("0x%02x,%c", gfmul(i
, j
+ k
),
91 (k
== 7) ? '\n' : ' ');
93 for (j
= 0; j
< 16; j
+= 8) {
95 for (k
= 0; k
< 8; k
++)
96 printf("0x%02x,%c", gfmul(i
, (j
+ k
) << 4),
97 (k
== 7) ? '\n' : ' ');
102 printf("#ifdef __KERNEL__\n");
103 printf("EXPORT_SYMBOL(raid6_vgfmul);\n");
106 /* Compute power-of-2 table (exponent) */
108 printf("\nconst u8 __attribute__((aligned(256)))\n"
109 "raid6_gfexp[256] =\n" "{\n");
110 for (i
= 0; i
< 256; i
+= 8) {
112 for (j
= 0; j
< 8; j
++) {
114 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
117 v
= 0; /* For entry 255, not a real entry */
121 printf("#ifdef __KERNEL__\n");
122 printf("EXPORT_SYMBOL(raid6_gfexp);\n");
125 /* Compute log-of-2 table */
126 printf("\nconst u8 __attribute__((aligned(256)))\n"
127 "raid6_gflog[256] =\n" "{\n");
128 for (i
= 0; i
< 256; i
+= 8) {
130 for (j
= 0; j
< 8; j
++) {
132 for (k
= 0; k
< 256; k
++)
133 if (exptbl
[k
] == (i
+ j
)) {
137 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
141 printf("#ifdef __KERNEL__\n");
142 printf("EXPORT_SYMBOL(raid6_gflog);\n");
145 /* Compute inverse table x^-1 == x^254 */
146 printf("\nconst u8 __attribute__((aligned(256)))\n"
147 "raid6_gfinv[256] =\n" "{\n");
148 for (i
= 0; i
< 256; i
+= 8) {
150 for (j
= 0; j
< 8; j
++) {
151 invtbl
[i
+ j
] = v
= gfpow(i
+ j
, 254);
152 printf("0x%02x,%c", v
, (j
== 7) ? '\n' : ' ');
156 printf("#ifdef __KERNEL__\n");
157 printf("EXPORT_SYMBOL(raid6_gfinv);\n");
160 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
161 printf("\nconst u8 __attribute__((aligned(256)))\n"
162 "raid6_gfexi[256] =\n" "{\n");
163 for (i
= 0; i
< 256; i
+= 8) {
165 for (j
= 0; j
< 8; j
++)
166 printf("0x%02x,%c", invtbl
[exptbl
[i
+ j
] ^ 1],
167 (j
== 7) ? '\n' : ' ');
170 printf("#ifdef __KERNEL__\n");
171 printf("EXPORT_SYMBOL(raid6_gfexi);\n");