iPXE
etherfabric.h
Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * GPL net driver for Level 5 Etherfabric network cards
00004  *
00005  * Written by Michael Brown <mbrown@fensystems.co.uk>
00006  *
00007  * Copyright Fen Systems Ltd. 2005
00008  * Copyright Level 5 Networks Inc. 2005
00009  *
00010  * This software may be used and distributed according to the terms of
00011  * the GNU General Public License (GPL), incorporated herein by
00012  * reference.  Drivers based on or derived from this code fall under
00013  * the GPL and must retain the authorship, copyright and license
00014  * notice.  This file is not a complete program and may only be used
00015  * when the entire operating system is licensed under the GPL.
00016  *
00017  **************************************************************************
00018  */
00019 
00020 FILE_LICENCE ( GPL_ANY );
00021 
00022 #ifndef EFAB_BITFIELD_H
00023 #define EFAB_BITFIELD_H
00024 
00025 /** @file
00026  *
00027  * Etherfabric bitfield access
00028  *
00029  * Etherfabric NICs make extensive use of bitfields up to 128 bits
00030  * wide.  Since there is no native 128-bit datatype on most systems,
00031  * and since 64-bit datatypes are inefficient on 32-bit systems and
00032  * vice versa, we wrap accesses in a way that uses the most efficient
00033  * datatype.
00034  *
00035  * The NICs are PCI devices and therefore little-endian.  Since most
00036  * of the quantities that we deal with are DMAed to/from host memory,
00037  * we define our datatypes (efab_oword_t, efab_qword_t and
00038  * efab_dword_t) to be little-endian.
00039  *
00040  * In the less common case of using PIO for individual register
00041  * writes, we construct the little-endian datatype in host memory and
00042  * then use non-swapping equivalents of writel/writeq, rather than
00043  * constructing a native-endian datatype and relying on the implicit
00044  * byte-swapping done by writel/writeq.  (We use a similar strategy
00045  * for register reads.)
00046  */
00047 
00048 /** Dummy field low bit number */
00049 #define EFAB_DUMMY_FIELD_LBN 0
00050 /** Dummy field width */
00051 #define EFAB_DUMMY_FIELD_WIDTH 0
00052 /** Dword 0 low bit number */
00053 #define EFAB_DWORD_0_LBN 0
00054 /** Dword 0 width */
00055 #define EFAB_DWORD_0_WIDTH 32
00056 /** Dword 1 low bit number */
00057 #define EFAB_DWORD_1_LBN 32
00058 /** Dword 1 width */
00059 #define EFAB_DWORD_1_WIDTH 32
00060 /** Dword 2 low bit number */
00061 #define EFAB_DWORD_2_LBN 64
00062 /** Dword 2 width */
00063 #define EFAB_DWORD_2_WIDTH 32
00064 /** Dword 3 low bit number */
00065 #define EFAB_DWORD_3_LBN 96
00066 /** Dword 3 width */
00067 #define EFAB_DWORD_3_WIDTH 32
00068 
00069 /** Specified attribute (e.g. LBN) of the specified field */
00070 #define EFAB_VAL(field,attribute) field ## _ ## attribute
00071 /** Low bit number of the specified field */
00072 #define EFAB_LOW_BIT( field ) EFAB_VAL ( field, LBN )
00073 /** Bit width of the specified field */
00074 #define EFAB_WIDTH( field ) EFAB_VAL ( field, WIDTH )
00075 /** High bit number of the specified field */
00076 #define EFAB_HIGH_BIT(field) ( EFAB_LOW_BIT(field) + EFAB_WIDTH(field) - 1 )
00077 /** Mask equal in width to the specified field.
00078  *
00079  * For example, a field with width 5 would have a mask of 0x1f.
00080  *
00081  * The maximum width mask that can be generated is 64 bits.
00082  */
00083 #define EFAB_MASK64( field )                                            \
00084         ( EFAB_WIDTH(field) == 64 ? ~( ( uint64_t ) 0 ) :               \
00085           ( ( ( ( ( uint64_t ) 1 ) << EFAB_WIDTH(field) ) ) - 1 ) )
00086 
00087 /** Mask equal in width to the specified field.
00088  *
00089  * For example, a field with width 5 would have a mask of 0x1f.
00090  *
00091  * The maximum width mask that can be generated is 32 bits.  Use
00092  * EFAB_MASK64 for higher width fields.
00093  */
00094 #define EFAB_MASK32( field )                                            \
00095         ( EFAB_WIDTH(field) == 32 ? ~( ( uint32_t ) 0 ) :               \
00096           ( ( ( ( ( uint32_t ) 1 ) << EFAB_WIDTH(field) ) ) - 1 ) )
00097 
00098 /** A doubleword (i.e. 4 byte) datatype
00099  *
00100  * This datatype is defined to be little-endian.
00101  */
00102 typedef union efab_dword {
00103         uint32_t u32[1];
00104         uint32_t opaque; /* For bitwise operations between two efab_dwords */
00105 } efab_dword_t;
00106 
00107 /** A quadword (i.e. 8 byte) datatype
00108  *
00109  * This datatype is defined to be little-endian.
00110  */
00111 typedef union efab_qword {
00112         uint64_t u64[1];
00113         uint32_t u32[2];
00114         efab_dword_t dword[2];
00115 } efab_qword_t;
00116 
00117 /**
00118  * An octword (eight-word, i.e. 16 byte) datatype
00119  *
00120  * This datatype is defined to be little-endian.
00121  */
00122 typedef union efab_oword {
00123         uint64_t u64[2];
00124         efab_qword_t qword[2];
00125         uint32_t u32[4];
00126         efab_dword_t dword[4];
00127 } efab_oword_t;
00128 
00129 /** Format string for printing an efab_dword_t */
00130 #define EFAB_DWORD_FMT "%08x"
00131 
00132 /** Format string for printing an efab_qword_t */
00133 #define EFAB_QWORD_FMT "%08x:%08x"
00134 
00135 /** Format string for printing an efab_oword_t */
00136 #define EFAB_OWORD_FMT "%08x:%08x:%08x:%08x"
00137 
00138 /** printk parameters for printing an efab_dword_t */
00139 #define EFAB_DWORD_VAL(dword)                                   \
00140         ( ( unsigned int ) le32_to_cpu ( (dword).u32[0] ) )
00141 
00142 /** printk parameters for printing an efab_qword_t */
00143 #define EFAB_QWORD_VAL(qword)                                   \
00144         ( ( unsigned int ) le32_to_cpu ( (qword).u32[1] ) ),    \
00145         ( ( unsigned int ) le32_to_cpu ( (qword).u32[0] ) )
00146 
00147 /** printk parameters for printing an efab_oword_t */
00148 #define EFAB_OWORD_VAL(oword)                                   \
00149         ( ( unsigned int ) le32_to_cpu ( (oword).u32[3] ) ),    \
00150         ( ( unsigned int ) le32_to_cpu ( (oword).u32[2] ) ),    \
00151         ( ( unsigned int ) le32_to_cpu ( (oword).u32[1] ) ),    \
00152         ( ( unsigned int ) le32_to_cpu ( (oword).u32[0] ) )
00153 
00154 /**
00155  * Extract bit field portion [low,high) from the native-endian element
00156  * which contains bits [min,max).
00157  *
00158  * For example, suppose "element" represents the high 32 bits of a
00159  * 64-bit value, and we wish to extract the bits belonging to the bit
00160  * field occupying bits 28-45 of this 64-bit value.
00161  *
00162  * Then EFAB_EXTRACT ( element, 32, 63, 28, 45 ) would give
00163  *
00164  *   ( element ) << 4
00165  *
00166  * The result will contain the relevant bits filled in in the range
00167  * [0,high-low), with garbage in bits [high-low+1,...).
00168  */
00169 #define EFAB_EXTRACT_NATIVE( native_element, min ,max ,low ,high )      \
00170         ( ( ( low > max ) || ( high < min ) ) ? 0 :                     \
00171           ( ( low > min ) ?                                             \
00172             ( (native_element) >> ( low - min ) ) :                     \
00173             ( (native_element) << ( min - low ) ) ) )
00174 
00175 /**
00176  * Extract bit field portion [low,high) from the 64-bit little-endian
00177  * element which contains bits [min,max)
00178  */
00179 #define EFAB_EXTRACT64( element, min, max, low, high )                  \
00180         EFAB_EXTRACT_NATIVE ( le64_to_cpu(element), min, max, low, high )
00181 
00182 /**
00183  * Extract bit field portion [low,high) from the 32-bit little-endian
00184  * element which contains bits [min,max)
00185  */
00186 #define EFAB_EXTRACT32( element, min, max, low, high )                  \
00187         EFAB_EXTRACT_NATIVE ( le32_to_cpu(element), min, max, low, high )
00188 
00189 #define EFAB_EXTRACT_OWORD64( oword, low, high )                        \
00190         ( EFAB_EXTRACT64 ( (oword).u64[0],   0,  63, low, high ) |      \
00191           EFAB_EXTRACT64 ( (oword).u64[1],  64, 127, low, high ) )
00192 
00193 #define EFAB_EXTRACT_QWORD64( qword, low, high )                        \
00194         ( EFAB_EXTRACT64 ( (qword).u64[0],   0,  63, low, high ) )
00195 
00196 #define EFAB_EXTRACT_OWORD32( oword, low, high )                        \
00197         ( EFAB_EXTRACT32 ( (oword).u32[0],   0,  31, low, high ) |      \
00198           EFAB_EXTRACT32 ( (oword).u32[1],  32,  63, low, high ) |      \
00199           EFAB_EXTRACT32 ( (oword).u32[2],  64,  95, low, high ) |      \
00200           EFAB_EXTRACT32 ( (oword).u32[3],  96, 127, low, high ) )
00201 
00202 #define EFAB_EXTRACT_QWORD32( qword, low, high )                        \
00203         ( EFAB_EXTRACT32 ( (qword).u32[0],   0,  31, low, high ) |      \
00204           EFAB_EXTRACT32 ( (qword).u32[1],  32,  63, low, high ) )
00205 
00206 #define EFAB_EXTRACT_DWORD( dword, low, high )                          \
00207         ( EFAB_EXTRACT32 ( (dword).u32[0],   0,  31, low, high ) )
00208 
00209 #define EFAB_OWORD_FIELD64( oword, field )                              \
00210         ( EFAB_EXTRACT_OWORD64 ( oword, EFAB_LOW_BIT ( field ),         \
00211                                  EFAB_HIGH_BIT ( field ) ) &            \
00212           EFAB_MASK64 ( field ) )
00213 
00214 #define EFAB_QWORD_FIELD64( qword, field )                              \
00215         ( EFAB_EXTRACT_QWORD64 ( qword, EFAB_LOW_BIT ( field ),         \
00216                                  EFAB_HIGH_BIT ( field ) ) &            \
00217           EFAB_MASK64 ( field ) )
00218 
00219 #define EFAB_OWORD_FIELD32( oword, field )                              \
00220         ( EFAB_EXTRACT_OWORD32 ( oword, EFAB_LOW_BIT ( field ),         \
00221                                  EFAB_HIGH_BIT ( field ) ) &            \
00222           EFAB_MASK32 ( field ) )
00223 
00224 #define EFAB_QWORD_FIELD32( qword, field )                              \
00225         ( EFAB_EXTRACT_QWORD32 ( qword, EFAB_LOW_BIT ( field ),         \
00226                                  EFAB_HIGH_BIT ( field ) ) &            \
00227           EFAB_MASK32 ( field ) )
00228 
00229 #define EFAB_DWORD_FIELD( dword, field )                                \
00230         ( EFAB_EXTRACT_DWORD ( dword, EFAB_LOW_BIT ( field ),           \
00231                                EFAB_HIGH_BIT ( field ) ) &              \
00232           EFAB_MASK32 ( field ) )
00233 
00234 #define EFAB_OWORD_IS_ZERO64( oword )                                   \
00235         ( ! ( (oword).u64[0] || (oword).u64[1] ) )
00236 
00237 #define EFAB_QWORD_IS_ZERO64( qword )                                   \
00238         ( ! ( (qword).u64[0] ) )
00239 
00240 #define EFAB_OWORD_IS_ZERO32( oword )                                   \
00241         ( ! ( (oword).u32[0] || (oword).u32[1] ||                       \
00242               (oword).u32[2] || (oword).u32[3] ) )
00243 
00244 #define EFAB_QWORD_IS_ZERO32( qword )                                   \
00245         ( ! ( (qword).u32[0] || (qword).u32[1] ) )
00246 
00247 #define EFAB_DWORD_IS_ZERO( dword )                                     \
00248         ( ! ( (dword).u32[0] ) )
00249 
00250 #define EFAB_OWORD_IS_ALL_ONES64( oword )                               \
00251         ( ( (oword).u64[0] & (oword).u64[1] ) == ~( ( uint64_t ) 0 ) )
00252 
00253 #define EFAB_QWORD_IS_ALL_ONES64( qword )                               \
00254         ( (qword).u64[0] == ~( ( uint64_t ) 0 ) )
00255 
00256 #define EFAB_OWORD_IS_ALL_ONES32( oword )                               \
00257         ( ( (oword).u32[0] & (oword).u32[1] &                           \
00258             (oword).u32[2] & (oword).u32[3] ) == ~( ( uint32_t ) 0 ) )
00259 
00260 #define EFAB_QWORD_IS_ALL_ONES32( qword )                               \
00261         ( ( (qword).u32[0] & (qword).u32[1] ) == ~( ( uint32_t ) 0 ) )
00262 
00263 #define EFAB_DWORD_IS_ALL_ONES( dword )                                 \
00264         ( (dword).u32[0] == ~( ( uint32_t ) 0 ) )
00265 
00266 #if ( BITS_PER_LONG == 64 )
00267 #define EFAB_OWORD_FIELD        EFAB_OWORD_FIELD64
00268 #define EFAB_QWORD_FIELD        EFAB_QWORD_FIELD64
00269 #define EFAB_OWORD_IS_ZERO      EFAB_OWORD_IS_ZERO64
00270 #define EFAB_QWORD_IS_ZERO      EFAB_QWORD_IS_ZERO64
00271 #define EFAB_OWORD_IS_ALL_ONES  EFAB_OWORD_IS_ALL_ONES64
00272 #define EFAB_QWORD_IS_ALL_ONES  EFAB_QWORD_IS_ALL_ONES64
00273 #else
00274 #define EFAB_OWORD_FIELD        EFAB_OWORD_FIELD32
00275 #define EFAB_QWORD_FIELD        EFAB_QWORD_FIELD32
00276 #define EFAB_OWORD_IS_ZERO      EFAB_OWORD_IS_ZERO32
00277 #define EFAB_QWORD_IS_ZERO      EFAB_QWORD_IS_ZERO32
00278 #define EFAB_OWORD_IS_ALL_ONES  EFAB_OWORD_IS_ALL_ONES32
00279 #define EFAB_QWORD_IS_ALL_ONES  EFAB_QWORD_IS_ALL_ONES32
00280 #endif
00281 
00282 /**
00283  * Construct bit field portion
00284  *
00285  * Creates the portion of the bit field [low,high) that lies within
00286  * the range [min,max).
00287  */
00288 #define EFAB_INSERT_NATIVE64( min, max, low, high, value )      \
00289         ( ( ( low > max ) || ( high < min ) ) ? 0 :             \
00290           ( ( low > min ) ?                                     \
00291             ( ( ( uint64_t ) (value) ) << ( low - min ) ) :     \
00292             ( ( ( uint64_t ) (value) ) >> ( min - low ) ) ) )
00293 
00294 #define EFAB_INSERT_NATIVE32( min, max, low, high, value )      \
00295         ( ( ( low > max ) || ( high < min ) ) ? 0 :             \
00296           ( ( low > min ) ?                                     \
00297             ( ( ( uint32_t ) (value) ) << ( low - min ) ) :     \
00298             ( ( ( uint32_t ) (value) ) >> ( min - low ) ) ) )
00299 
00300 #define EFAB_INSERT_NATIVE( min, max, low, high, value )        \
00301         ( ( ( ( max - min ) >= 32 ) ||                          \
00302             ( ( high - low ) >= 32 ) )                          \
00303           ? EFAB_INSERT_NATIVE64 ( min, max, low, high, value ) \
00304           : EFAB_INSERT_NATIVE32 ( min, max, low, high, value ) )
00305 
00306 /**
00307  * Construct bit field portion
00308  *
00309  * Creates the portion of the named bit field that lies within the
00310  * range [min,max).
00311  */
00312 #define EFAB_INSERT_FIELD_NATIVE( min, max, field, value )      \
00313         EFAB_INSERT_NATIVE ( min, max, EFAB_LOW_BIT ( field ),  \
00314                              EFAB_HIGH_BIT ( field ), value )
00315 
00316 /**
00317  * Construct bit field
00318  *
00319  * Creates the portion of the named bit fields that lie within the
00320  * range [min,max).
00321  */
00322 #define EFAB_INSERT_FIELDS_NATIVE( min, max,                            \
00323                                    field1, value1,                      \
00324                                    field2, value2,                      \
00325                                    field3, value3,                      \
00326                                    field4, value4,                      \
00327                                    field5, value5,                      \
00328                                    field6, value6,                      \
00329                                    field7, value7,                      \
00330                                    field8, value8,                      \
00331                                    field9, value9,                      \
00332                                    field10, value10 )                   \
00333         ( EFAB_INSERT_FIELD_NATIVE ( min, max, field1, value1 ) |       \
00334           EFAB_INSERT_FIELD_NATIVE ( min, max, field2, value2 ) |       \
00335           EFAB_INSERT_FIELD_NATIVE ( min, max, field3, value3 ) |       \
00336           EFAB_INSERT_FIELD_NATIVE ( min, max, field4, value4 ) |       \
00337           EFAB_INSERT_FIELD_NATIVE ( min, max, field5, value5 ) |       \
00338           EFAB_INSERT_FIELD_NATIVE ( min, max, field6, value6 ) |       \
00339           EFAB_INSERT_FIELD_NATIVE ( min, max, field7, value7 ) |       \
00340           EFAB_INSERT_FIELD_NATIVE ( min, max, field8, value8 ) |       \
00341           EFAB_INSERT_FIELD_NATIVE ( min, max, field9, value9 ) |       \
00342           EFAB_INSERT_FIELD_NATIVE ( min, max, field10, value10 ) )
00343 
00344 #define EFAB_INSERT_FIELDS64( ... )                                     \
00345         cpu_to_le64 ( EFAB_INSERT_FIELDS_NATIVE ( __VA_ARGS__ ) )
00346 
00347 #define EFAB_INSERT_FIELDS32( ... )                                     \
00348         cpu_to_le32 ( EFAB_INSERT_FIELDS_NATIVE ( __VA_ARGS__ ) )
00349 
00350 #define EFAB_POPULATE_OWORD64( oword, ... ) do {                        \
00351         (oword).u64[0] = EFAB_INSERT_FIELDS64 (   0,  63, __VA_ARGS__ );\
00352         (oword).u64[1] = EFAB_INSERT_FIELDS64 (  64, 127, __VA_ARGS__ );\
00353         } while ( 0 )
00354 
00355 #define EFAB_POPULATE_QWORD64( qword, ... ) do {                        \
00356         (qword).u64[0] = EFAB_INSERT_FIELDS64 (   0,  63, __VA_ARGS__ );\
00357         } while ( 0 )
00358 
00359 #define EFAB_POPULATE_OWORD32( oword, ... ) do {                        \
00360         (oword).u32[0] = EFAB_INSERT_FIELDS32 (   0,  31, __VA_ARGS__ );\
00361         (oword).u32[1] = EFAB_INSERT_FIELDS32 (  32,  63, __VA_ARGS__ );\
00362         (oword).u32[2] = EFAB_INSERT_FIELDS32 (  64,  95, __VA_ARGS__ );\
00363         (oword).u32[3] = EFAB_INSERT_FIELDS32 (  96, 127, __VA_ARGS__ );\
00364         } while ( 0 )
00365 
00366 #define EFAB_POPULATE_QWORD32( qword, ... ) do {                        \
00367         (qword).u32[0] = EFAB_INSERT_FIELDS32 (   0,  31, __VA_ARGS__ );\
00368         (qword).u32[1] = EFAB_INSERT_FIELDS32 (  32,  63, __VA_ARGS__ );\
00369         } while ( 0 )
00370 
00371 #define EFAB_POPULATE_DWORD( dword, ... ) do {                          \
00372         (dword).u32[0] = EFAB_INSERT_FIELDS32 (   0,  31, __VA_ARGS__ );\
00373         } while ( 0 )
00374 
00375 #if ( BITS_PER_LONG == 64 )
00376 #define EFAB_POPULATE_OWORD EFAB_POPULATE_OWORD64
00377 #define EFAB_POPULATE_QWORD EFAB_POPULATE_QWORD64
00378 #else
00379 #define EFAB_POPULATE_OWORD EFAB_POPULATE_OWORD32
00380 #define EFAB_POPULATE_QWORD EFAB_POPULATE_QWORD32
00381 #endif
00382 
00383 /* Populate an octword field with various numbers of arguments */
00384 #define EFAB_POPULATE_OWORD_10 EFAB_POPULATE_OWORD
00385 #define EFAB_POPULATE_OWORD_9( oword, ... ) \
00386         EFAB_POPULATE_OWORD_10 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00387 #define EFAB_POPULATE_OWORD_8( oword, ... ) \
00388         EFAB_POPULATE_OWORD_9 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00389 #define EFAB_POPULATE_OWORD_7( oword, ... ) \
00390         EFAB_POPULATE_OWORD_8 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00391 #define EFAB_POPULATE_OWORD_6( oword, ... ) \
00392         EFAB_POPULATE_OWORD_7 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00393 #define EFAB_POPULATE_OWORD_5( oword, ... ) \
00394         EFAB_POPULATE_OWORD_6 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00395 #define EFAB_POPULATE_OWORD_4( oword, ... ) \
00396         EFAB_POPULATE_OWORD_5 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00397 #define EFAB_POPULATE_OWORD_3( oword, ... ) \
00398         EFAB_POPULATE_OWORD_4 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00399 #define EFAB_POPULATE_OWORD_2( oword, ... ) \
00400         EFAB_POPULATE_OWORD_3 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00401 #define EFAB_POPULATE_OWORD_1( oword, ... ) \
00402         EFAB_POPULATE_OWORD_2 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00403 #define EFAB_ZERO_OWORD( oword ) \
00404         EFAB_POPULATE_OWORD_1 ( oword, EFAB_DUMMY_FIELD, 0 )
00405 #define EFAB_SET_OWORD( oword ) \
00406         EFAB_POPULATE_OWORD_4 ( oword, \
00407                                 EFAB_DWORD_0, 0xffffffff, \
00408                                 EFAB_DWORD_1, 0xffffffff, \
00409                                 EFAB_DWORD_2, 0xffffffff, \
00410                                 EFAB_DWORD_3, 0xffffffff )
00411 
00412 /* Populate a quadword field with various numbers of arguments */
00413 #define EFAB_POPULATE_QWORD_10 EFAB_POPULATE_QWORD
00414 #define EFAB_POPULATE_QWORD_9( qword, ... ) \
00415         EFAB_POPULATE_QWORD_10 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00416 #define EFAB_POPULATE_QWORD_8( qword, ... ) \
00417         EFAB_POPULATE_QWORD_9 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00418 #define EFAB_POPULATE_QWORD_7( qword, ... ) \
00419         EFAB_POPULATE_QWORD_8 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00420 #define EFAB_POPULATE_QWORD_6( qword, ... ) \
00421         EFAB_POPULATE_QWORD_7 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00422 #define EFAB_POPULATE_QWORD_5( qword, ... ) \
00423         EFAB_POPULATE_QWORD_6 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00424 #define EFAB_POPULATE_QWORD_4( qword, ... ) \
00425         EFAB_POPULATE_QWORD_5 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00426 #define EFAB_POPULATE_QWORD_3( qword, ... ) \
00427         EFAB_POPULATE_QWORD_4 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00428 #define EFAB_POPULATE_QWORD_2( qword, ... ) \
00429         EFAB_POPULATE_QWORD_3 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00430 #define EFAB_POPULATE_QWORD_1( qword, ... ) \
00431         EFAB_POPULATE_QWORD_2 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00432 #define EFAB_ZERO_QWORD( qword ) \
00433         EFAB_POPULATE_QWORD_1 ( qword, EFAB_DUMMY_FIELD, 0 )
00434 #define EFAB_SET_QWORD( qword ) \
00435         EFAB_POPULATE_QWORD_2 ( qword, \
00436                                 EFAB_DWORD_0, 0xffffffff, \
00437                                 EFAB_DWORD_1, 0xffffffff )
00438 
00439 /* Populate a dword field with various numbers of arguments */
00440 #define EFAB_POPULATE_DWORD_10 EFAB_POPULATE_DWORD
00441 #define EFAB_POPULATE_DWORD_9( dword, ... ) \
00442         EFAB_POPULATE_DWORD_10 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00443 #define EFAB_POPULATE_DWORD_8( dword, ... ) \
00444         EFAB_POPULATE_DWORD_9 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00445 #define EFAB_POPULATE_DWORD_7( dword, ... ) \
00446         EFAB_POPULATE_DWORD_8 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00447 #define EFAB_POPULATE_DWORD_6( dword, ... ) \
00448         EFAB_POPULATE_DWORD_7 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00449 #define EFAB_POPULATE_DWORD_5( dword, ... ) \
00450         EFAB_POPULATE_DWORD_6 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00451 #define EFAB_POPULATE_DWORD_4( dword, ... ) \
00452         EFAB_POPULATE_DWORD_5 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00453 #define EFAB_POPULATE_DWORD_3( dword, ... ) \
00454         EFAB_POPULATE_DWORD_4 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00455 #define EFAB_POPULATE_DWORD_2( dword, ... ) \
00456         EFAB_POPULATE_DWORD_3 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00457 #define EFAB_POPULATE_DWORD_1( dword, ... ) \
00458         EFAB_POPULATE_DWORD_2 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
00459 #define EFAB_ZERO_DWORD( dword ) \
00460         EFAB_POPULATE_DWORD_1 ( dword, EFAB_DUMMY_FIELD, 0 )
00461 #define EFAB_SET_DWORD( dword ) \
00462         EFAB_POPULATE_DWORD_1 ( dword, EFAB_DWORD_0, 0xffffffff )
00463 
00464 /*
00465  * Modify a named field within an already-populated structure.  Used
00466  * for read-modify-write operations.
00467  *
00468  */
00469 
00470 #define EFAB_INSERT_FIELD64( ... )                                      \
00471         cpu_to_le64 ( EFAB_INSERT_FIELD_NATIVE ( __VA_ARGS__ ) )
00472 
00473 #define EFAB_INSERT_FIELD32( ... )                                      \
00474         cpu_to_le32 ( EFAB_INSERT_FIELD_NATIVE ( __VA_ARGS__ ) )
00475 
00476 #define EFAB_INPLACE_MASK64( min, max, field )                          \
00477         EFAB_INSERT_FIELD64 ( min, max, field, EFAB_MASK64 ( field ) )
00478 
00479 #define EFAB_INPLACE_MASK32( min, max, field )                          \
00480         EFAB_INSERT_FIELD32 ( min, max, field, EFAB_MASK32 ( field ) )
00481 
00482 #define EFAB_SET_OWORD_FIELD64( oword, field, value ) do {                    \
00483         (oword).u64[0] = ( ( (oword).u64[0]                                   \
00484                              & ~EFAB_INPLACE_MASK64 (  0,  63, field ) )      \
00485                            | EFAB_INSERT_FIELD64 (  0,  63, field, value ) ); \
00486         (oword).u64[1] = ( ( (oword).u64[1]                                   \
00487                              & ~EFAB_INPLACE_MASK64 ( 64, 127, field ) )      \
00488                            | EFAB_INSERT_FIELD64 ( 64, 127, field, value ) ); \
00489         } while ( 0 )
00490 
00491 #define EFAB_SET_QWORD_FIELD64( qword, field, value ) do {                    \
00492         (qword).u64[0] = ( ( (qword).u64[0]                                   \
00493                              & ~EFAB_INPLACE_MASK64 (  0,  63, field ) )      \
00494                            | EFAB_INSERT_FIELD64 (  0,  63, field, value ) ); \
00495         } while ( 0 )
00496 
00497 #define EFAB_SET_OWORD_FIELD32( oword, field, value ) do {                    \
00498         (oword).u32[0] = ( ( (oword).u32[0]                                   \
00499                              & ~EFAB_INPLACE_MASK32 (  0,  31, field ) )      \
00500                            | EFAB_INSERT_FIELD32 (  0,  31, field, value ) ); \
00501         (oword).u32[1] = ( ( (oword).u32[1]                                   \
00502                              & ~EFAB_INPLACE_MASK32 ( 32,  63, field ) )      \
00503                            | EFAB_INSERT_FIELD32 ( 32,  63, field, value ) ); \
00504         (oword).u32[2] = ( ( (oword).u32[2]                                   \
00505                              & ~EFAB_INPLACE_MASK32 ( 64,  95, field ) )      \
00506                            | EFAB_INSERT_FIELD32 ( 64,  95, field, value ) ); \
00507         (oword).u32[3] = ( ( (oword).u32[3]                                   \
00508                              & ~EFAB_INPLACE_MASK32 ( 96, 127, field ) )      \
00509                            | EFAB_INSERT_FIELD32 ( 96, 127, field, value ) ); \
00510         } while ( 0 )
00511 
00512 #define EFAB_SET_QWORD_FIELD32( qword, field, value ) do {                    \
00513         (qword).u32[0] = ( ( (qword).u32[0]                                   \
00514                              & ~EFAB_INPLACE_MASK32 (  0,  31, field ) )      \
00515                            | EFAB_INSERT_FIELD32 (  0,  31, field, value ) ); \
00516         (qword).u32[1] = ( ( (qword).u32[1]                                   \
00517                              & ~EFAB_INPLACE_MASK32 ( 32,  63, field ) )      \
00518                            | EFAB_INSERT_FIELD32 ( 32,  63, field, value ) ); \
00519         } while ( 0 )
00520 
00521 #define EFAB_SET_DWORD_FIELD( dword, field, value ) do {                      \
00522         (dword).u32[0] = ( ( (dword).u32[0]                                   \
00523                              & ~EFAB_INPLACE_MASK32 (  0,  31, field ) )      \
00524                            | EFAB_INSERT_FIELD32 (  0,  31, field, value ) ); \
00525         } while ( 0 )
00526 
00527 #if ( BITS_PER_LONG == 64 )
00528 #define EFAB_SET_OWORD_FIELD EFAB_SET_OWORD_FIELD64
00529 #define EFAB_SET_QWORD_FIELD EFAB_SET_QWORD_FIELD64
00530 #else
00531 #define EFAB_SET_OWORD_FIELD EFAB_SET_OWORD_FIELD32
00532 #define EFAB_SET_QWORD_FIELD EFAB_SET_QWORD_FIELD32
00533 #endif
00534 
00535 /* Used to avoid compiler warnings about shift range exceeding width
00536  * of the data types when dma_addr_t is only 32 bits wide.
00537  */
00538 #define DMA_ADDR_T_WIDTH        ( 8 * sizeof ( dma_addr_t ) )
00539 #define EFAB_DMA_TYPE_WIDTH( width ) \
00540         ( ( (width) < DMA_ADDR_T_WIDTH ) ? (width) : DMA_ADDR_T_WIDTH )
00541 #define EFAB_DMA_MAX_MASK ( ( DMA_ADDR_T_WIDTH == 64 ) ? \
00542                             ~( ( uint64_t ) 0 ) : ~( ( uint32_t ) 0 ) )
00543 #define EFAB_DMA_MASK(mask) ( (mask) & EFAB_DMA_MAX_MASK )
00544 
00545 #endif /* EFAB_BITFIELD_H */
00546 
00547 /*
00548  * Local variables:
00549  *  c-basic-offset: 8
00550  *  c-indent-level: 8
00551  *  tab-width: 8
00552  * End:
00553  */