rf_geniq.c revision 1.1 1 1.1 oster /* $NetBSD: rf_geniq.c,v 1.1 1998/11/13 04:20:30 oster Exp $ */
2 1.1 oster /*
3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University.
4 1.1 oster * All rights reserved.
5 1.1 oster *
6 1.1 oster * Author: Daniel Stodolsky
7 1.1 oster *
8 1.1 oster * Permission to use, copy, modify and distribute this software and
9 1.1 oster * its documentation is hereby granted, provided that both the copyright
10 1.1 oster * notice and this permission notice appear in all copies of the
11 1.1 oster * software, derivative works or modified versions, and any portions
12 1.1 oster * thereof, and that both notices appear in supporting documentation.
13 1.1 oster *
14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.1 oster *
18 1.1 oster * Carnegie Mellon requests users of this software to return to
19 1.1 oster *
20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 oster * School of Computer Science
22 1.1 oster * Carnegie Mellon University
23 1.1 oster * Pittsburgh PA 15213-3890
24 1.1 oster *
25 1.1 oster * any improvements or extensions that they make and grant Carnegie the
26 1.1 oster * rights to redistribute these changes.
27 1.1 oster */
28 1.1 oster
29 1.1 oster /* rf_geniq.c
30 1.1 oster * code which implements Reed-Solomon encoding for RAID level 6
31 1.1 oster */
32 1.1 oster
33 1.1 oster /* :
34 1.1 oster * Log: rf_geniq.c,v
35 1.1 oster * Revision 1.12 1996/07/29 16:37:00 jimz
36 1.1 oster * remove archs.h include to avoid VPATH problems in kernel
37 1.1 oster * rf_invertq.c now must include archs.h before invertq.h
38 1.1 oster *
39 1.1 oster * Revision 1.11 1996/07/29 15:04:16 jimz
40 1.1 oster * correct rf_archs.h path for kernel
41 1.1 oster *
42 1.1 oster * Revision 1.10 1996/07/27 23:36:08 jimz
43 1.1 oster * Solaris port of simulator
44 1.1 oster *
45 1.1 oster * Revision 1.9 1996/07/18 22:57:14 jimz
46 1.1 oster * port simulator to AIX
47 1.1 oster *
48 1.1 oster * Revision 1.8 1996/07/15 17:22:18 jimz
49 1.1 oster * nit-pick code cleanup
50 1.1 oster * resolve stdlib problems on DEC OSF
51 1.1 oster *
52 1.1 oster * Revision 1.7 1996/06/09 02:36:46 jimz
53 1.1 oster * lots of little crufty cleanup- fixup whitespace
54 1.1 oster * issues, comment #ifdefs, improve typing in some
55 1.1 oster * places (esp size-related)
56 1.1 oster *
57 1.1 oster * Revision 1.6 1996/05/23 21:46:35 jimz
58 1.1 oster * checkpoint in code cleanup (release prep)
59 1.1 oster * lots of types, function names have been fixed
60 1.1 oster *
61 1.1 oster * Revision 1.5 1995/12/01 18:29:18 root
62 1.1 oster * added copyright info
63 1.1 oster *
64 1.1 oster */
65 1.1 oster
66 1.1 oster #define RF_UTILITY 1
67 1.1 oster #include "rf_pqdeg.h"
68 1.1 oster
69 1.1 oster /*
70 1.1 oster five bit lfsr
71 1.1 oster poly - feedback connections
72 1.1 oster
73 1.1 oster val = value;
74 1.1 oster */
75 1.1 oster int lsfr_shift(val,poly)
76 1.1 oster unsigned val, poly;
77 1.1 oster {
78 1.1 oster unsigned new;
79 1.1 oster unsigned int i;
80 1.1 oster unsigned high = (val >> 4) & 1;
81 1.1 oster unsigned bit;
82 1.1 oster
83 1.1 oster new = (poly & 1) ? high : 0;
84 1.1 oster
85 1.1 oster for (i=1; i <=4; i++)
86 1.1 oster {
87 1.1 oster bit = (val >> (i-1)) & 1;
88 1.1 oster if (poly & (1<<i)) /* there is a feedback connection */
89 1.1 oster new = new | ((bit ^ high)<<i);
90 1.1 oster else
91 1.1 oster new = new | (bit << i);
92 1.1 oster }
93 1.1 oster return new;
94 1.1 oster }
95 1.1 oster
96 1.1 oster /* generate Q matricies for the data */
97 1.1 oster
98 1.1 oster RF_ua32_t rf_qfor[32];
99 1.1 oster
100 1.1 oster void main()
101 1.1 oster {
102 1.1 oster unsigned int i,j,l,a,b;
103 1.1 oster unsigned int val;
104 1.1 oster unsigned int r;
105 1.1 oster unsigned int m,p,q;
106 1.1 oster
107 1.1 oster RF_ua32_t k;
108 1.1 oster
109 1.1 oster printf("/*\n");
110 1.1 oster printf(" * rf_invertq.h\n");
111 1.1 oster printf(" */\n");
112 1.1 oster printf("/*\n");
113 1.1 oster printf(" * GENERATED FILE -- DO NOT EDIT\n");
114 1.1 oster printf(" */\n");
115 1.1 oster printf("\n");
116 1.1 oster printf("#ifndef _RF__RF_INVERTQ_H_\n");
117 1.1 oster printf("#define _RF__RF_INVERTQ_H_\n");
118 1.1 oster printf("\n");
119 1.1 oster printf("/*\n");
120 1.1 oster printf(" * rf_geniq.c must include rf_archs.h before including\n");
121 1.1 oster printf(" * this file (to get VPATH magic right with the way we\n");
122 1.1 oster printf(" * generate this file in kernel trees)\n");
123 1.1 oster printf(" */\n");
124 1.1 oster printf("/* #include \"rf_archs.h\" */\n");
125 1.1 oster printf("\n");
126 1.1 oster printf("#if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0)\n");
127 1.1 oster printf("\n");
128 1.1 oster printf("#define RF_Q_COLS 32\n");
129 1.1 oster printf("RF_ua32_t rf_rn = {\n");
130 1.1 oster k[0] = 1;
131 1.1 oster for (j=0 ; j < 31; j++)
132 1.1 oster k[j+1] = lsfr_shift(k[j],5);
133 1.1 oster for (j=0; j < 32; j++)
134 1.1 oster printf("%d, ",k[j]);
135 1.1 oster printf("};\n");
136 1.1 oster
137 1.1 oster printf("RF_ua32_t rf_qfor[32] = {\n");
138 1.1 oster for (i=0; i < 32; i++)
139 1.1 oster {
140 1.1 oster printf("/* i = %d */ { 0, ",i);
141 1.1 oster rf_qfor[i][0] = 0;
142 1.1 oster for (j=1; j < 32; j++)
143 1.1 oster {
144 1.1 oster val = j;
145 1.1 oster for (l=0; l < i; l++)
146 1.1 oster val = lsfr_shift(val,5);
147 1.1 oster rf_qfor[i][j] = val;
148 1.1 oster printf("%d, ",val);
149 1.1 oster }
150 1.1 oster printf("},\n");
151 1.1 oster }
152 1.1 oster printf("};\n");
153 1.1 oster printf("#define RF_Q_DATA_COL(col_num) rf_rn[col_num],rf_qfor[28-(col_num)]\n");
154 1.1 oster
155 1.1 oster /* generate the inverse tables. (i,j,p,q) */
156 1.1 oster /* The table just stores a. Get b back from
157 1.1 oster the parity */
158 1.1 oster printf("#ifdef KERNEL\n");
159 1.1 oster printf("RF_ua1024_t rf_qinv[1]; /* don't compile monster table into kernel */\n");
160 1.1 oster printf("#elif defined(NO_PQ)\n");
161 1.1 oster printf("RF_ua1024_t rf_qinv[29*29];\n");
162 1.1 oster printf("#else /* !KERNEL && NO_PQ */\n");
163 1.1 oster printf("RF_ua1024_t rf_qinv[29*29] = {\n");
164 1.1 oster for (i=0; i < 29; i++)
165 1.1 oster {
166 1.1 oster for (j =0; j < 29; j++)
167 1.1 oster {
168 1.1 oster printf("/* i %d, j %d */{ ",i,j);
169 1.1 oster if (i==j)
170 1.1 oster for (l=0; l < 1023; l++) printf("0, ");
171 1.1 oster else
172 1.1 oster {
173 1.1 oster for (p=0; p < 32; p++)
174 1.1 oster for (q=0; q < 32; q++)
175 1.1 oster {
176 1.1 oster /* What are a, b such that
177 1.1 oster a ^ b = p; and
178 1.1 oster qfor[(28-i)][a ^ rf_rn[i+1]] ^ qfor[(28-j)][b ^ rf_rn[j+1]] = q.
179 1.1 oster Solve by guessing a. Then testing.
180 1.1 oster */
181 1.1 oster for ( a =0 ; a < 32; a++ )
182 1.1 oster {
183 1.1 oster b = a ^ p;
184 1.1 oster if ( (rf_qfor[28-i][a^ k[i+1]] ^ rf_qfor[28-j][b ^ k[j+1]]) == q )
185 1.1 oster break;
186 1.1 oster }
187 1.1 oster if (a == 32) printf("unable to solve %d %d %d %d\n",i,j,p,q);
188 1.1 oster printf("%d,",a);
189 1.1 oster }
190 1.1 oster }
191 1.1 oster printf("},\n");
192 1.1 oster }
193 1.1 oster }
194 1.1 oster printf("};\n");
195 1.1 oster printf("\n#endif /* (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0) */\n\n");
196 1.1 oster printf("#endif /* !KERNEL && NO_PQ */\n");
197 1.1 oster printf("#endif /* !_RF__RF_INVERTQ_H_ */\n");
198 1.1 oster exit(0);
199 1.1 oster }
200