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