2 /* $NetBSD: rf_geniq.c,v 1.3 1999/02/05 00:06:12 oster Exp $ */
4 * Copyright (c) 1995 Carnegie-Mellon University.
7 * Author: Daniel Stodolsky
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
31 * code which implements Reed-Solomon encoding for RAID level 6
36 #include <dev/raidframe/rf_pqdeg.h>
40 poly - feedback connections
50 unsigned high = (val >> 4) & 1;
53 new = (poly & 1) ? high : 0;
55 for (i = 1; i <= 4; i++) {
56 bit = (val >> (i - 1)) & 1;
57 if (poly & (1 << i)) /* there is a feedback connection */
58 new = new | ((bit ^ high) << i);
60 new = new | (bit << i);
64 /* generate Q matricies for the data */
66 RF_ua32_t rf_qfor[32];
71 unsigned int i, j, l, a, b;
79 printf(" * rf_invertq.h\n");
82 printf(" * GENERATED FILE -- DO NOT EDIT\n");
85 printf("#ifndef _RF__RF_INVERTQ_H_\n");
86 printf("#define _RF__RF_INVERTQ_H_\n");
89 printf(" * rf_geniq.c must include rf_archs.h before including\n");
90 printf(" * this file (to get VPATH magic right with the way we\n");
91 printf(" * generate this file in kernel trees)\n");
93 printf("/* #include \"rf_archs.h\" */\n");
95 printf("#if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0)\n");
97 printf("#define RF_Q_COLS 32\n");
98 printf("RF_ua32_t rf_rn = {\n");
100 for (j = 0; j < 31; j++)
101 k[j + 1] = lsfr_shift(k[j], 5);
102 for (j = 0; j < 32; j++)
103 printf("%d, ", k[j]);
106 printf("RF_ua32_t rf_qfor[32] = {\n");
107 for (i = 0; i < 32; i++) {
108 printf("/* i = %d */ { 0, ", i);
110 for (j = 1; j < 32; j++) {
112 for (l = 0; l < i; l++)
113 val = lsfr_shift(val, 5);
120 printf("#define RF_Q_DATA_COL(col_num) rf_rn[col_num],rf_qfor[28-(col_num)]\n");
122 /* generate the inverse tables. (i,j,p,q) */
123 /* The table just stores a. Get b back from the parity */
124 printf("#ifdef KERNEL\n");
125 printf("RF_ua1024_t rf_qinv[1]; /* don't compile monster table into kernel */\n");
126 printf("#elif defined(NO_PQ)\n");
127 printf("RF_ua1024_t rf_qinv[29*29];\n");
128 printf("#else /* !KERNEL && NO_PQ */\n");
129 printf("RF_ua1024_t rf_qinv[29*29] = {\n");
130 for (i = 0; i < 29; i++) {
131 for (j = 0; j < 29; j++) {
132 printf("/* i %d, j %d */{ ", i, j);
134 for (l = 0; l < 1023; l++)
137 for (p = 0; p < 32; p++)
138 for (q = 0; q < 32; q++) {
139 /* What are a, b such that a ^
140 * b = p; and qfor[(28-i)][a
143 * rf_rn[j+1]] = q. Solve by
144 * guessing a. Then testing. */
145 for (a = 0; a < 32; a++) {
147 if ((rf_qfor[28 - i][a ^ k[i + 1]] ^ rf_qfor[28 - j][b ^ k[j + 1]]) == q)
151 printf("unable to solve %d %d %d %d\n", i, j, p, q);
159 printf("\n#endif /* (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0) */\n\n");
160 printf("#endif /* !KERNEL && NO_PQ */\n");
161 printf("#endif /* !_RF__RF_INVERTQ_H_ */\n");