1 /* $NetBSD: rf_geniq.c,v 1.5 2009/03/14 21:04:22 dsl Exp $ */
3 * Copyright (c) 1995 Carnegie-Mellon University.
6 * Author: Daniel Stodolsky
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
30 * code which implements Reed-Solomon encoding for RAID level 6
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: rf_geniq.c,v 1.5 2009/03/14 21:04:22 dsl Exp $");
42 poly - feedback connections
47 lsfr_shift(unsigned val
, unsigned poly
)
51 unsigned high
= (val
>> 4) & 1;
54 new = (poly
& 1) ? high
: 0;
56 for (i
= 1; i
<= 4; i
++) {
57 bit
= (val
>> (i
- 1)) & 1;
58 if (poly
& (1 << i
)) /* there is a feedback connection */
59 new = new | ((bit
^ high
) << i
);
61 new = new | (bit
<< i
);
65 /* generate Q matricies for the data */
67 RF_ua32_t rf_qfor
[32];
72 unsigned int i
, j
, l
, a
, b
;
80 printf(" * rf_invertq.h\n");
83 printf(" * GENERATED FILE -- DO NOT EDIT\n");
86 printf("#ifndef _RF__RF_INVERTQ_H_\n");
87 printf("#define _RF__RF_INVERTQ_H_\n");
90 printf(" * rf_geniq.c must include rf_archs.h before including\n");
91 printf(" * this file (to get VPATH magic right with the way we\n");
92 printf(" * generate this file in kernel trees)\n");
94 printf("/* #include \"rf_archs.h\" */\n");
96 printf("#if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0)\n");
98 printf("#define RF_Q_COLS 32\n");
99 printf("RF_ua32_t rf_rn = {\n");
101 for (j
= 0; j
< 31; j
++)
102 k
[j
+ 1] = lsfr_shift(k
[j
], 5);
103 for (j
= 0; j
< 32; j
++)
104 printf("%d, ", k
[j
]);
107 printf("RF_ua32_t rf_qfor[32] = {\n");
108 for (i
= 0; i
< 32; i
++) {
109 printf("/* i = %d */ { 0, ", i
);
111 for (j
= 1; j
< 32; j
++) {
113 for (l
= 0; l
< i
; l
++)
114 val
= lsfr_shift(val
, 5);
121 printf("#define RF_Q_DATA_COL(col_num) rf_rn[col_num],rf_qfor[28-(col_num)]\n");
123 /* generate the inverse tables. (i,j,p,q) */
124 /* The table just stores a. Get b back from the parity */
125 printf("#ifdef KERNEL\n");
126 printf("RF_ua1024_t rf_qinv[1]; /* don't compile monster table into kernel */\n");
127 printf("#elif defined(NO_PQ)\n");
128 printf("RF_ua1024_t rf_qinv[29*29];\n");
129 printf("#else /* !KERNEL && NO_PQ */\n");
130 printf("RF_ua1024_t rf_qinv[29*29] = {\n");
131 for (i
= 0; i
< 29; i
++) {
132 for (j
= 0; j
< 29; j
++) {
133 printf("/* i %d, j %d */{ ", i
, j
);
135 for (l
= 0; l
< 1023; l
++)
138 for (p
= 0; p
< 32; p
++)
139 for (q
= 0; q
< 32; q
++) {
140 /* What are a, b such that a ^
141 * b = p; and qfor[(28-i)][a
144 * rf_rn[j+1]] = q. Solve by
145 * guessing a. Then testing. */
146 for (a
= 0; a
< 32; a
++) {
148 if ((rf_qfor
[28 - i
][a
^ k
[i
+ 1]] ^ rf_qfor
[28 - j
][b
^ k
[j
+ 1]]) == q
)
152 printf("unable to solve %d %d %d %d\n", i
, j
, p
, q
);
160 printf("\n#endif /* (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0) */\n\n");
161 printf("#endif /* !KERNEL && NO_PQ */\n");
162 printf("#endif /* !_RF__RF_INVERTQ_H_ */\n");