]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/raidframe/rf_geniq.c
This commit was generated by cvs2svn to compensate for changes in r106907,
[FreeBSD/FreeBSD.git] / sys / dev / raidframe / rf_geniq.c
1 /*      $FreeBSD$ */
2 /*      $NetBSD: rf_geniq.c,v 1.3 1999/02/05 00:06:12 oster Exp $       */
3 /*
4  * Copyright (c) 1995 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Daniel Stodolsky
8  *
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.
14  *
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.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29
30 /* rf_geniq.c
31  *  code which implements Reed-Solomon encoding for RAID level 6
32  */
33
34
35 #define RF_UTILITY 1
36 #include <dev/raidframe/rf_pqdeg.h>
37
38 /*
39    five bit lfsr
40    poly - feedback connections
41
42    val  = value;
43 */
44 int 
45 lsfr_shift(val, poly)
46         unsigned val, poly;
47 {
48         unsigned new;
49         unsigned int i;
50         unsigned high = (val >> 4) & 1;
51         unsigned bit;
52
53         new = (poly & 1) ? high : 0;
54
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);
59                 else
60                         new = new | (bit << i);
61         }
62         return new;
63 }
64 /* generate Q matricies for the data */
65
66 RF_ua32_t rf_qfor[32];
67
68 void 
69 main()
70 {
71         unsigned int i, j, l, a, b;
72         unsigned int val;
73         unsigned int r;
74         unsigned int m, p, q;
75
76         RF_ua32_t k;
77
78         printf("/*\n");
79         printf(" * rf_invertq.h\n");
80         printf(" */\n");
81         printf("/*\n");
82         printf(" * GENERATED FILE -- DO NOT EDIT\n");
83         printf(" */\n");
84         printf("\n");
85         printf("#ifndef _RF__RF_INVERTQ_H_\n");
86         printf("#define _RF__RF_INVERTQ_H_\n");
87         printf("\n");
88         printf("/*\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");
92         printf(" */\n");
93         printf("/* #include \"rf_archs.h\" */\n");
94         printf("\n");
95         printf("#if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_RAID6 > 0)\n");
96         printf("\n");
97         printf("#define RF_Q_COLS 32\n");
98         printf("RF_ua32_t rf_rn = {\n");
99         k[0] = 1;
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]);
104         printf("};\n");
105
106         printf("RF_ua32_t rf_qfor[32] = {\n");
107         for (i = 0; i < 32; i++) {
108                 printf("/* i = %d */ { 0, ", i);
109                 rf_qfor[i][0] = 0;
110                 for (j = 1; j < 32; j++) {
111                         val = j;
112                         for (l = 0; l < i; l++)
113                                 val = lsfr_shift(val, 5);
114                         rf_qfor[i][j] = val;
115                         printf("%d, ", val);
116                 }
117                 printf("},\n");
118         }
119         printf("};\n");
120         printf("#define RF_Q_DATA_COL(col_num) rf_rn[col_num],rf_qfor[28-(col_num)]\n");
121
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);
133                         if (i == j)
134                                 for (l = 0; l < 1023; l++)
135                                         printf("0, ");
136                         else {
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
141                                                  * ^ rf_rn[i+1]] ^
142                                                  * qfor[(28-j)][b ^
143                                                  * rf_rn[j+1]] =  q. Solve by
144                                                  * guessing a. Then testing. */
145                                                 for (a = 0; a < 32; a++) {
146                                                         b = a ^ p;
147                                                         if ((rf_qfor[28 - i][a ^ k[i + 1]] ^ rf_qfor[28 - j][b ^ k[j + 1]]) == q)
148                                                                 break;
149                                                 }
150                                                 if (a == 32)
151                                                         printf("unable to solve %d %d %d %d\n", i, j, p, q);
152                                                 printf("%d,", a);
153                                         }
154                         }
155                         printf("},\n");
156                 }
157         }
158         printf("};\n");
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");
162         exit(0);
163 }