Home | History | Annotate | Line # | Download | only in raidframe
rf_general.h revision 1.1
      1 /*	$NetBSD: rf_general.h,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: Mark Holland
      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 /*
     30  * rf_general.h -- some general-use definitions
     31  */
     32 
     33 /*
     34  * :
     35  * Log: rf_general.h,v
     36  * Revision 1.26  1996/08/09 16:44:57  jimz
     37  * sunos port
     38  *
     39  * Revision 1.25  1996/08/07  21:08:57  jimz
     40  * get NBPG defined for IRIX
     41  *
     42  * Revision 1.24  1996/08/06  22:02:06  jimz
     43  * include linux/user.h for linux to get NBPG
     44  *
     45  * Revision 1.23  1996/07/27  23:36:08  jimz
     46  * Solaris port of simulator
     47  *
     48  * Revision 1.22  1996/06/09  02:36:46  jimz
     49  * lots of little crufty cleanup- fixup whitespace
     50  * issues, comment #ifdefs, improve typing in some
     51  * places (esp size-related)
     52  *
     53  * Revision 1.21  1996/05/30  23:22:16  jimz
     54  * bugfixes of serialization, timing problems
     55  * more cleanup
     56  *
     57  * Revision 1.20  1996/05/27  18:56:37  jimz
     58  * more code cleanup
     59  * better typing
     60  * compiles in all 3 environments
     61  *
     62  * Revision 1.19  1996/05/24  22:17:04  jimz
     63  * continue code + namespace cleanup
     64  * typed a bunch of flags
     65  *
     66  * Revision 1.18  1996/05/23  21:46:35  jimz
     67  * checkpoint in code cleanup (release prep)
     68  * lots of types, function names have been fixed
     69  *
     70  * Revision 1.17  1996/05/23  00:33:23  jimz
     71  * code cleanup: move all debug decls to rf_options.c, all extern
     72  * debug decls to rf_options.h, all debug vars preceded by rf_
     73  *
     74  * Revision 1.16  1996/05/21  18:53:13  jimz
     75  * be sure that noop macros don't confuse conditionals and loops
     76  *
     77  * Revision 1.15  1996/05/18  19:51:34  jimz
     78  * major code cleanup- fix syntax, make some types consistent,
     79  * add prototypes, clean out dead code, et cetera
     80  *
     81  * Revision 1.14  1996/05/08  21:01:24  jimz
     82  * fixed up enum type names that were conflicting with other
     83  * enums and function names (ie, "panic")
     84  * future naming trends will be towards RF_ and rf_ for
     85  * everything raidframe-related
     86  *
     87  * Revision 1.13  1995/12/12  18:10:06  jimz
     88  * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
     89  * fix 80-column brain damage in comments
     90  *
     91  * Revision 1.12  1995/12/01  18:29:08  root
     92  * added copyright info
     93  *
     94  * Revision 1.11  1995/09/19  22:59:52  jimz
     95  * Add kernel macro RF_DKU_END_IO(). When DKUSAGE is not defined,
     96  * this is a no-op. When it is defined, it calls dku_end_io()
     97  * correctly given a raidframe unit number and a buf pointer.
     98  *
     99  * Revision 1.10  1995/07/03  18:13:56  holland
    100  * changed kernel defn of GETTIME
    101  *
    102  * Revision 1.9  1995/07/02  15:07:42  holland
    103  * bug fixes related to getting distributed sparing numbers
    104  *
    105  * Revision 1.8  1995/06/12  15:54:40  rachad
    106  * Added garbege collection for log structured storage
    107  *
    108  * Revision 1.7  1995/06/03  19:18:16  holland
    109  * changes related to kernelization: access traces
    110  * changes related to distributed sparing: some bug fixes
    111  *
    112  * Revision 1.6  1995/05/01  13:28:00  holland
    113  * parity range locks, locking disk requests, recon+parityscan in kernel, etc.
    114  *
    115  * Revision 1.5  1995/04/06  14:47:56  rachad
    116  * merge completed
    117  *
    118  * Revision 1.4  1995/03/15  20:45:23  holland
    119  * distr sparing changes.
    120  *
    121  * Revision 1.3  1995/02/03  22:31:36  holland
    122  * many changes related to kernelization
    123  *
    124  * Revision 1.2  1994/11/29  21:37:10  danner
    125  * Added divide by zero check.
    126  *
    127  */
    128 
    129 /*#define NOASSERT*/
    130 
    131 #ifndef _RF__RF_GENERAL_H_
    132 #define _RF__RF_GENERAL_H_
    133 
    134 #ifdef _KERNEL
    135 #define KERNEL
    136 #endif
    137 
    138 #if !defined(KERNEL) && !defined(NOASSERT)
    139 #include <assert.h>
    140 #endif /* !KERNEL && !NOASSERT */
    141 
    142 /* error reporting and handling */
    143 
    144 #ifndef KERNEL
    145 
    146 #define RF_ERRORMSG(s)            fprintf(stderr,(s))
    147 #define RF_ERRORMSG1(s,a)         fprintf(stderr,(s),(a))
    148 #define RF_ERRORMSG2(s,a,b)       fprintf(stderr,(s),(a),(b))
    149 #define RF_ERRORMSG3(s,a,b,c)     fprintf(stderr,(s),(a),(b),(c))
    150 #define RF_ERRORMSG4(s,a,b,c,d)   fprintf(stderr,(s),(a),(b),(c),(d))
    151 #define RF_ERRORMSG5(s,a,b,c,d,e) fprintf(stderr,(s),(a),(b),(c),(d),(e))
    152 #ifndef NOASSERT
    153 #define RF_ASSERT(x)   {assert(x);}
    154 #else /* !NOASSERT */
    155 #define RF_ASSERT(x)   {/*noop*/}
    156 #endif /* !NOASSERT */
    157 #define RF_PANIC()              {printf("YIKES!  Something terrible happened at line %d of file %s.  Use a debugger.\n",__LINE__,__FILE__); abort();}
    158 
    159 #else /* !KERNEL */
    160 #if defined(__NetBSD__) && defined(_KERNEL)
    161 #include<sys/systm.h> /* printf, sprintf, and friends */
    162 #endif
    163 #define RF_ERRORMSG(s)            printf((s))
    164 #define RF_ERRORMSG1(s,a)         printf((s),(a))
    165 #define RF_ERRORMSG2(s,a,b)       printf((s),(a),(b))
    166 #define RF_ERRORMSG3(s,a,b,c)     printf((s),(a),(b),(c))
    167 #define RF_ERRORMSG4(s,a,b,c,d)   printf((s),(a),(b),(c),(d))
    168 #define RF_ERRORMSG5(s,a,b,c,d,e) printf((s),(a),(b),(c),(d),(e))
    169 #define perror(x)
    170 extern char rf_panicbuf[];
    171 #define RF_PANIC() {sprintf(rf_panicbuf,"raidframe error at line %d file %s",__LINE__,__FILE__); panic(rf_panicbuf);}
    172 
    173 #ifdef RF_ASSERT
    174 #undef RF_ASSERT
    175 #endif /* RF_ASSERT */
    176 #ifndef NOASSERT
    177 #define RF_ASSERT(_x_) { \
    178   if (!(_x_)) { \
    179     sprintf(rf_panicbuf, \
    180         "raidframe error at line %d file %s (failed asserting %s)\n", \
    181         __LINE__, __FILE__, #_x_); \
    182     panic(rf_panicbuf); \
    183   } \
    184 }
    185 #else /* !NOASSERT */
    186 #define RF_ASSERT(x) {/*noop*/}
    187 #endif /* !NOASSERT */
    188 
    189 #endif  /* !KERNEL */
    190 
    191 /* random stuff */
    192 #define RF_MAX(a,b) (((a) > (b)) ? (a) : (b))
    193 #define RF_MIN(a,b) (((a) < (b)) ? (a) : (b))
    194 
    195 /* divide-by-zero check */
    196 #define RF_DB0_CHECK(a,b) ( ((b)==0) ? 0 : (a)/(b) )
    197 
    198 /* get time of day */
    199 #ifdef KERNEL
    200 #ifndef __NetBSD__
    201 extern struct timeval time;
    202 #endif /* !__NetBSD__ */
    203 #define RF_GETTIME(_t) microtime(&(_t))
    204 #else /* KERNEL */
    205 #define RF_GETTIME(_t) gettimeofday(&(_t), NULL);
    206 #endif /* KERNEL */
    207 
    208 /*
    209  * zero memory- not all bzero calls go through here, only
    210  * those which in the kernel may have a user address
    211  */
    212 #ifdef KERNEL
    213 #ifndef __NetBSD__
    214 #define RF_BZERO(_bp,_b,_l) if (IS_SYS_VA(_b)) bzero(_b,_l); else rf_BzeroWithRemap(_bp,_b,_l)
    215 #else
    216 
    217 #define RF_BZERO(_bp,_b,_l)  bzero(_b,_l)  /* XXX This is likely incorrect. GO*/
    218 #endif /* __NetBSD__ */
    219 #else /* KERNEL */
    220 #define RF_BZERO(_bp,_b,_l) bzero(_b,_l)
    221 #endif /* KERNEL */
    222 
    223 #ifdef sun
    224 #include <sys/param.h>
    225 #ifndef NBPG
    226 #define NBPG PAGESIZE
    227 #endif /* !NBPG */
    228 #endif /* sun */
    229 
    230 #ifdef IRIX
    231 #include <sys/tfp.h>
    232 #define NBPG _PAGESZ
    233 #endif /* IRIX */
    234 
    235 #ifdef LINUX
    236 #include <linux/user.h>
    237 #endif /* LINUX */
    238 
    239 #define RF_UL(x)           ((unsigned long) (x))
    240 #define RF_PGMASK          RF_UL(NBPG-1)
    241 #define RF_BLIP(x)         (NBPG - (RF_UL(x) & RF_PGMASK))    /* bytes left in page */
    242 #define RF_PAGE_ALIGNED(x) ((RF_UL(x) & RF_PGMASK) == 0)
    243 
    244 #ifdef KERNEL
    245 #ifndef __NetBSD__
    246 #include <dkusage.h>
    247 #endif
    248 #if DKUSAGE > 0
    249 #define RF_DKU_END_IO(_unit_,_bp_) { \
    250 	int s = splbio(); \
    251 	dku_end_io(DKU_RAIDFRAME_BUS, _unit_, 0, \
    252 			(((_bp_)->b_flags&(B_READ|B_WRITE) == B_READ) ? \
    253 		    CAM_DIR_IN : CAM_DIR_OUT), \
    254 			(_bp_)->b_bcount); \
    255 	splx(s); \
    256 }
    257 #else /* DKUSAGE > 0 */
    258 #define RF_DKU_END_IO(unit) { /* noop */ }
    259 #endif /* DKUSAGE > 0 */
    260 #endif /* KERNEL */
    261 
    262 #ifdef __STDC__
    263 #define RF_STRING(_str_) #_str_
    264 #else /* __STDC__ */
    265 #define RF_STRING(_str_) "_str_"
    266 #endif /* __STDC__ */
    267 
    268 #endif /* !_RF__RF_GENERAL_H_ */
    269