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