rf_geniq.c revision 1.3 1 1.3 oster /* $NetBSD: rf_geniq.c,v 1.3 1999/02/05 00:06:12 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 #define RF_UTILITY 1
35 1.1 oster #include "rf_pqdeg.h"
36 1.1 oster
37 1.1 oster /*
38 1.1 oster five bit lfsr
39 1.1 oster poly - feedback connections
40 1.1 oster
41 1.1 oster val = value;
42 1.1 oster */
43 1.3 oster int
44 1.3 oster lsfr_shift(val, poly)
45 1.3 oster unsigned val, poly;
46 1.1 oster {
47 1.3 oster unsigned new;
48 1.3 oster unsigned int i;
49 1.3 oster unsigned high = (val >> 4) & 1;
50 1.3 oster unsigned bit;
51 1.3 oster
52 1.3 oster new = (poly & 1) ? high : 0;
53 1.3 oster
54 1.3 oster for (i = 1; i <= 4; i++) {
55 1.3 oster bit = (val >> (i - 1)) & 1;
56 1.3 oster if (poly & (1 << i)) /* there is a feedback connection */
57 1.3 oster new = new | ((bit ^ high) << i);
58 1.3 oster else
59 1.3 oster new = new | (bit << i);
60 1.3 oster }
61 1.3 oster return new;
62 1.1 oster }
63 1.1 oster /* generate Q matricies for the data */
64 1.1 oster
65 1.1 oster RF_ua32_t rf_qfor[32];
66 1.1 oster
67 1.3 oster void
68 1.3 oster main()
69 1.1 oster {
70 1.3 oster unsigned int i, j, l, a, b;
71 1.3 oster unsigned int val;
72 1.3 oster unsigned int r;
73 1.3 oster unsigned int m, p, q;
74 1.3 oster
75 1.3 oster RF_ua32_t k;
76 1.3 oster
77 1.3 oster printf("/*\n");
78 1.3 oster printf(" * rf_invertq.h\n");
79 1.3 oster printf(" */\n");
80 1.3 oster printf("/*\n");
81 1.3 oster printf(" * GENERATED FILE -- DO NOT EDIT\n");
82 1.3 oster printf(" */\n");
83 1.3 oster printf("\n");
84 1.3 oster printf("#ifndef _RF__RF_INVERTQ_H_\n");
85 1.3 oster printf("#define _RF__RF_INVERTQ_H_\n");
86 1.3 oster printf("\n");
87 1.3 oster printf("/*\n");
88 1.3 oster printf(" * rf_geniq.c must include rf_archs.h before including\n");
89 1.3 oster printf(" * this file (to get VPATH magic right with the way we\n");
90 1.3 oster printf(" * generate this file in kernel trees)\n");
91 1.3 oster printf(" */\n");
92 1.3 oster printf("/* #include \"rf_archs.h\" */\n");
93 1.3 oster printf("\n");
94 1.3 oster printf("#if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0)\n");
95 1.3 oster printf("\n");
96 1.3 oster printf("#define RF_Q_COLS 32\n");
97 1.3 oster printf("RF_ua32_t rf_rn = {\n");
98 1.3 oster k[0] = 1;
99 1.3 oster for (j = 0; j < 31; j++)
100 1.3 oster k[j + 1] = lsfr_shift(k[j], 5);
101 1.3 oster for (j = 0; j < 32; j++)
102 1.3 oster printf("%d, ", k[j]);
103 1.3 oster printf("};\n");
104 1.3 oster
105 1.3 oster printf("RF_ua32_t rf_qfor[32] = {\n");
106 1.3 oster for (i = 0; i < 32; i++) {
107 1.3 oster printf("/* i = %d */ { 0, ", i);
108 1.3 oster rf_qfor[i][0] = 0;
109 1.3 oster for (j = 1; j < 32; j++) {
110 1.3 oster val = j;
111 1.3 oster for (l = 0; l < i; l++)
112 1.3 oster val = lsfr_shift(val, 5);
113 1.3 oster rf_qfor[i][j] = val;
114 1.3 oster printf("%d, ", val);
115 1.3 oster }
116 1.3 oster printf("},\n");
117 1.1 oster }
118 1.3 oster printf("};\n");
119 1.3 oster printf("#define RF_Q_DATA_COL(col_num) rf_rn[col_num],rf_qfor[28-(col_num)]\n");
120 1.3 oster
121 1.3 oster /* generate the inverse tables. (i,j,p,q) */
122 1.3 oster /* The table just stores a. Get b back from the parity */
123 1.3 oster printf("#ifdef KERNEL\n");
124 1.3 oster printf("RF_ua1024_t rf_qinv[1]; /* don't compile monster table into kernel */\n");
125 1.3 oster printf("#elif defined(NO_PQ)\n");
126 1.3 oster printf("RF_ua1024_t rf_qinv[29*29];\n");
127 1.3 oster printf("#else /* !KERNEL && NO_PQ */\n");
128 1.3 oster printf("RF_ua1024_t rf_qinv[29*29] = {\n");
129 1.3 oster for (i = 0; i < 29; i++) {
130 1.3 oster for (j = 0; j < 29; j++) {
131 1.3 oster printf("/* i %d, j %d */{ ", i, j);
132 1.3 oster if (i == j)
133 1.3 oster for (l = 0; l < 1023; l++)
134 1.3 oster printf("0, ");
135 1.3 oster else {
136 1.3 oster for (p = 0; p < 32; p++)
137 1.3 oster for (q = 0; q < 32; q++) {
138 1.3 oster /* What are a, b such that a ^
139 1.3 oster * b = p; and qfor[(28-i)][a
140 1.3 oster * ^ rf_rn[i+1]] ^
141 1.3 oster * qfor[(28-j)][b ^
142 1.3 oster * rf_rn[j+1]] = q. Solve by
143 1.3 oster * guessing a. Then testing. */
144 1.3 oster for (a = 0; a < 32; a++) {
145 1.3 oster b = a ^ p;
146 1.3 oster if ((rf_qfor[28 - i][a ^ k[i + 1]] ^ rf_qfor[28 - j][b ^ k[j + 1]]) == q)
147 1.3 oster break;
148 1.3 oster }
149 1.3 oster if (a == 32)
150 1.3 oster printf("unable to solve %d %d %d %d\n", i, j, p, q);
151 1.3 oster printf("%d,", a);
152 1.3 oster }
153 1.3 oster }
154 1.3 oster printf("},\n");
155 1.3 oster }
156 1.1 oster }
157 1.3 oster printf("};\n");
158 1.3 oster printf("\n#endif /* (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0) */\n\n");
159 1.3 oster printf("#endif /* !KERNEL && NO_PQ */\n");
160 1.3 oster printf("#endif /* !_RF__RF_INVERTQ_H_ */\n");
161 1.3 oster exit(0);
162 1.1 oster }
163