Merge branch 'master' of /pub/scm/gpxe
[gpxe.git] / src / drivers / net / etherfabric.h
blob950f8de269c22b8fd27479a5a0062a251e407cbd
1 /**************************************************************************
3 * GPL net driver for Level 5 Etherfabric network cards
5 * Written by Michael Brown <mbrown@fensystems.co.uk>
7 * Copyright Fen Systems Ltd. 2005
8 * Copyright Level 5 Networks Inc. 2005
10 * This software may be used and distributed according to the terms of
11 * the GNU General Public License (GPL), incorporated herein by
12 * reference. Drivers based on or derived from this code fall under
13 * the GPL and must retain the authorship, copyright and license
14 * notice. This file is not a complete program and may only be used
15 * when the entire operating system is licensed under the GPL.
17 **************************************************************************
20 #ifndef EFAB_BITFIELD_H
21 #define EFAB_BITFIELD_H
23 /** @file
25 * Etherfabric bitfield access
27 * Etherfabric NICs make extensive use of bitfields up to 128 bits
28 * wide. Since there is no native 128-bit datatype on most systems,
29 * and since 64-bit datatypes are inefficient on 32-bit systems and
30 * vice versa, we wrap accesses in a way that uses the most efficient
31 * datatype.
33 * The NICs are PCI devices and therefore little-endian. Since most
34 * of the quantities that we deal with are DMAed to/from host memory,
35 * we define our datatypes (efab_oword_t, efab_qword_t and
36 * efab_dword_t) to be little-endian.
38 * In the less common case of using PIO for individual register
39 * writes, we construct the little-endian datatype in host memory and
40 * then use non-swapping equivalents of writel/writeq, rather than
41 * constructing a native-endian datatype and relying on the implicit
42 * byte-swapping done by writel/writeq. (We use a similar strategy
43 * for register reads.)
46 /** Dummy field low bit number */
47 #define EFAB_DUMMY_FIELD_LBN 0
48 /** Dummy field width */
49 #define EFAB_DUMMY_FIELD_WIDTH 0
50 /** Dword 0 low bit number */
51 #define EFAB_DWORD_0_LBN 0
52 /** Dword 0 width */
53 #define EFAB_DWORD_0_WIDTH 32
54 /** Dword 1 low bit number */
55 #define EFAB_DWORD_1_LBN 32
56 /** Dword 1 width */
57 #define EFAB_DWORD_1_WIDTH 32
58 /** Dword 2 low bit number */
59 #define EFAB_DWORD_2_LBN 64
60 /** Dword 2 width */
61 #define EFAB_DWORD_2_WIDTH 32
62 /** Dword 3 low bit number */
63 #define EFAB_DWORD_3_LBN 96
64 /** Dword 3 width */
65 #define EFAB_DWORD_3_WIDTH 32
67 /** Specified attribute (e.g. LBN) of the specified field */
68 #define EFAB_VAL(field,attribute) field ## _ ## attribute
69 /** Low bit number of the specified field */
70 #define EFAB_LOW_BIT( field ) EFAB_VAL ( field, LBN )
71 /** Bit width of the specified field */
72 #define EFAB_WIDTH( field ) EFAB_VAL ( field, WIDTH )
73 /** High bit number of the specified field */
74 #define EFAB_HIGH_BIT(field) ( EFAB_LOW_BIT(field) + EFAB_WIDTH(field) - 1 )
75 /** Mask equal in width to the specified field.
77 * For example, a field with width 5 would have a mask of 0x1f.
79 * The maximum width mask that can be generated is 64 bits.
81 #define EFAB_MASK64( field ) \
82 ( EFAB_WIDTH(field) == 64 ? ~( ( uint64_t ) 0 ) : \
83 ( ( ( ( ( uint64_t ) 1 ) << EFAB_WIDTH(field) ) ) - 1 ) )
85 /** Mask equal in width to the specified field.
87 * For example, a field with width 5 would have a mask of 0x1f.
89 * The maximum width mask that can be generated is 32 bits. Use
90 * EFAB_MASK64 for higher width fields.
92 #define EFAB_MASK32( field ) \
93 ( EFAB_WIDTH(field) == 32 ? ~( ( uint32_t ) 0 ) : \
94 ( ( ( ( ( uint32_t ) 1 ) << EFAB_WIDTH(field) ) ) - 1 ) )
96 /** A doubleword (i.e. 4 byte) datatype
98 * This datatype is defined to be little-endian.
100 typedef union efab_dword {
101 uint32_t u32[1];
102 uint32_t opaque; /* For bitwise operations between two efab_dwords */
103 } efab_dword_t;
105 /** A quadword (i.e. 8 byte) datatype
107 * This datatype is defined to be little-endian.
109 typedef union efab_qword {
110 uint64_t u64[1];
111 uint32_t u32[2];
112 efab_dword_t dword[2];
113 } efab_qword_t;
116 * An octword (eight-word, i.e. 16 byte) datatype
118 * This datatype is defined to be little-endian.
120 typedef union efab_oword {
121 uint64_t u64[2];
122 efab_qword_t qword[2];
123 uint32_t u32[4];
124 efab_dword_t dword[4];
125 } efab_oword_t;
127 /** Format string for printing an efab_dword_t */
128 #define EFAB_DWORD_FMT "%08x"
130 /** Format string for printing an efab_qword_t */
131 #define EFAB_QWORD_FMT "%08x:%08x"
133 /** Format string for printing an efab_oword_t */
134 #define EFAB_OWORD_FMT "%08x:%08x:%08x:%08x"
136 /** printk parameters for printing an efab_dword_t */
137 #define EFAB_DWORD_VAL(dword) \
138 ( ( unsigned int ) le32_to_cpu ( (dword).u32[0] ) )
140 /** printk parameters for printing an efab_qword_t */
141 #define EFAB_QWORD_VAL(qword) \
142 ( ( unsigned int ) le32_to_cpu ( (qword).u32[1] ) ), \
143 ( ( unsigned int ) le32_to_cpu ( (qword).u32[0] ) )
145 /** printk parameters for printing an efab_oword_t */
146 #define EFAB_OWORD_VAL(oword) \
147 ( ( unsigned int ) le32_to_cpu ( (oword).u32[3] ) ), \
148 ( ( unsigned int ) le32_to_cpu ( (oword).u32[2] ) ), \
149 ( ( unsigned int ) le32_to_cpu ( (oword).u32[1] ) ), \
150 ( ( unsigned int ) le32_to_cpu ( (oword).u32[0] ) )
153 * Extract bit field portion [low,high) from the native-endian element
154 * which contains bits [min,max).
156 * For example, suppose "element" represents the high 32 bits of a
157 * 64-bit value, and we wish to extract the bits belonging to the bit
158 * field occupying bits 28-45 of this 64-bit value.
160 * Then EFAB_EXTRACT ( element, 32, 63, 28, 45 ) would give
162 * ( element ) << 4
164 * The result will contain the relevant bits filled in in the range
165 * [0,high-low), with garbage in bits [high-low+1,...).
167 #define EFAB_EXTRACT_NATIVE( native_element, min ,max ,low ,high ) \
168 ( ( ( low > max ) || ( high < min ) ) ? 0 : \
169 ( ( low > min ) ? \
170 ( (native_element) >> ( low - min ) ) : \
171 ( (native_element) << ( min - low ) ) ) )
174 * Extract bit field portion [low,high) from the 64-bit little-endian
175 * element which contains bits [min,max)
177 #define EFAB_EXTRACT64( element, min, max, low, high ) \
178 EFAB_EXTRACT_NATIVE ( le64_to_cpu(element), min, max, low, high )
181 * Extract bit field portion [low,high) from the 32-bit little-endian
182 * element which contains bits [min,max)
184 #define EFAB_EXTRACT32( element, min, max, low, high ) \
185 EFAB_EXTRACT_NATIVE ( le32_to_cpu(element), min, max, low, high )
187 #define EFAB_EXTRACT_OWORD64( oword, low, high ) \
188 ( EFAB_EXTRACT64 ( (oword).u64[0], 0, 63, low, high ) | \
189 EFAB_EXTRACT64 ( (oword).u64[1], 64, 127, low, high ) )
191 #define EFAB_EXTRACT_QWORD64( qword, low, high ) \
192 ( EFAB_EXTRACT64 ( (qword).u64[0], 0, 63, low, high ) )
194 #define EFAB_EXTRACT_OWORD32( oword, low, high ) \
195 ( EFAB_EXTRACT32 ( (oword).u32[0], 0, 31, low, high ) | \
196 EFAB_EXTRACT32 ( (oword).u32[1], 32, 63, low, high ) | \
197 EFAB_EXTRACT32 ( (oword).u32[2], 64, 95, low, high ) | \
198 EFAB_EXTRACT32 ( (oword).u32[3], 96, 127, low, high ) )
200 #define EFAB_EXTRACT_QWORD32( qword, low, high ) \
201 ( EFAB_EXTRACT32 ( (qword).u32[0], 0, 31, low, high ) | \
202 EFAB_EXTRACT32 ( (qword).u32[1], 32, 63, low, high ) )
204 #define EFAB_EXTRACT_DWORD( dword, low, high ) \
205 ( EFAB_EXTRACT32 ( (dword).u32[0], 0, 31, low, high ) )
207 #define EFAB_OWORD_FIELD64( oword, field ) \
208 ( EFAB_EXTRACT_OWORD64 ( oword, EFAB_LOW_BIT ( field ), \
209 EFAB_HIGH_BIT ( field ) ) & \
210 EFAB_MASK64 ( field ) )
212 #define EFAB_QWORD_FIELD64( qword, field ) \
213 ( EFAB_EXTRACT_QWORD64 ( qword, EFAB_LOW_BIT ( field ), \
214 EFAB_HIGH_BIT ( field ) ) & \
215 EFAB_MASK64 ( field ) )
217 #define EFAB_OWORD_FIELD32( oword, field ) \
218 ( EFAB_EXTRACT_OWORD32 ( oword, EFAB_LOW_BIT ( field ), \
219 EFAB_HIGH_BIT ( field ) ) & \
220 EFAB_MASK32 ( field ) )
222 #define EFAB_QWORD_FIELD32( qword, field ) \
223 ( EFAB_EXTRACT_QWORD32 ( qword, EFAB_LOW_BIT ( field ), \
224 EFAB_HIGH_BIT ( field ) ) & \
225 EFAB_MASK32 ( field ) )
227 #define EFAB_DWORD_FIELD( dword, field ) \
228 ( EFAB_EXTRACT_DWORD ( dword, EFAB_LOW_BIT ( field ), \
229 EFAB_HIGH_BIT ( field ) ) & \
230 EFAB_MASK32 ( field ) )
232 #define EFAB_OWORD_IS_ZERO64( oword ) \
233 ( ! ( (oword).u64[0] || (oword).u64[1] ) )
235 #define EFAB_QWORD_IS_ZERO64( qword ) \
236 ( ! ( (qword).u64[0] ) )
238 #define EFAB_OWORD_IS_ZERO32( oword ) \
239 ( ! ( (oword).u32[0] || (oword).u32[1] || \
240 (oword).u32[2] || (oword).u32[3] ) )
242 #define EFAB_QWORD_IS_ZERO32( qword ) \
243 ( ! ( (qword).u32[0] || (qword).u32[1] ) )
245 #define EFAB_DWORD_IS_ZERO( dword ) \
246 ( ! ( (dword).u32[0] ) )
248 #define EFAB_OWORD_IS_ALL_ONES64( oword ) \
249 ( ( (oword).u64[0] & (oword).u64[1] ) == ~( ( uint64_t ) 0 ) )
251 #define EFAB_QWORD_IS_ALL_ONES64( qword ) \
252 ( (qword).u64[0] == ~( ( uint64_t ) 0 ) )
254 #define EFAB_OWORD_IS_ALL_ONES32( oword ) \
255 ( ( (oword).u32[0] & (oword).u32[1] & \
256 (oword).u32[2] & (oword).u32[3] ) == ~( ( uint32_t ) 0 ) )
258 #define EFAB_QWORD_IS_ALL_ONES32( qword ) \
259 ( ( (qword).u32[0] & (qword).u32[1] ) == ~( ( uint32_t ) 0 ) )
261 #define EFAB_DWORD_IS_ALL_ONES( dword ) \
262 ( (dword).u32[0] == ~( ( uint32_t ) 0 ) )
264 #if ( BITS_PER_LONG == 64 )
265 #define EFAB_OWORD_FIELD EFAB_OWORD_FIELD64
266 #define EFAB_QWORD_FIELD EFAB_QWORD_FIELD64
267 #define EFAB_OWORD_IS_ZERO EFAB_OWORD_IS_ZERO64
268 #define EFAB_QWORD_IS_ZERO EFAB_QWORD_IS_ZERO64
269 #define EFAB_OWORD_IS_ALL_ONES EFAB_OWORD_IS_ALL_ONES64
270 #define EFAB_QWORD_IS_ALL_ONES EFAB_QWORD_IS_ALL_ONES64
271 #else
272 #define EFAB_OWORD_FIELD EFAB_OWORD_FIELD32
273 #define EFAB_QWORD_FIELD EFAB_QWORD_FIELD32
274 #define EFAB_OWORD_IS_ZERO EFAB_OWORD_IS_ZERO32
275 #define EFAB_QWORD_IS_ZERO EFAB_QWORD_IS_ZERO32
276 #define EFAB_OWORD_IS_ALL_ONES EFAB_OWORD_IS_ALL_ONES32
277 #define EFAB_QWORD_IS_ALL_ONES EFAB_QWORD_IS_ALL_ONES32
278 #endif
281 * Construct bit field portion
283 * Creates the portion of the bit field [low,high) that lies within
284 * the range [min,max).
286 #define EFAB_INSERT_NATIVE64( min, max, low, high, value ) \
287 ( ( ( low > max ) || ( high < min ) ) ? 0 : \
288 ( ( low > min ) ? \
289 ( ( ( uint64_t ) (value) ) << ( low - min ) ) : \
290 ( ( ( uint64_t ) (value) ) >> ( min - low ) ) ) )
292 #define EFAB_INSERT_NATIVE32( min, max, low, high, value ) \
293 ( ( ( low > max ) || ( high < min ) ) ? 0 : \
294 ( ( low > min ) ? \
295 ( ( ( uint32_t ) (value) ) << ( low - min ) ) : \
296 ( ( ( uint32_t ) (value) ) >> ( min - low ) ) ) )
298 #define EFAB_INSERT_NATIVE( min, max, low, high, value ) \
299 ( ( ( ( max - min ) >= 32 ) || \
300 ( ( high - low ) >= 32 ) ) \
301 ? EFAB_INSERT_NATIVE64 ( min, max, low, high, value ) \
302 : EFAB_INSERT_NATIVE32 ( min, max, low, high, value ) )
305 * Construct bit field portion
307 * Creates the portion of the named bit field that lies within the
308 * range [min,max).
310 #define EFAB_INSERT_FIELD_NATIVE( min, max, field, value ) \
311 EFAB_INSERT_NATIVE ( min, max, EFAB_LOW_BIT ( field ), \
312 EFAB_HIGH_BIT ( field ), value )
315 * Construct bit field
317 * Creates the portion of the named bit fields that lie within the
318 * range [min,max).
320 #define EFAB_INSERT_FIELDS_NATIVE( min, max, \
321 field1, value1, \
322 field2, value2, \
323 field3, value3, \
324 field4, value4, \
325 field5, value5, \
326 field6, value6, \
327 field7, value7, \
328 field8, value8, \
329 field9, value9, \
330 field10, value10 ) \
331 ( EFAB_INSERT_FIELD_NATIVE ( min, max, field1, value1 ) | \
332 EFAB_INSERT_FIELD_NATIVE ( min, max, field2, value2 ) | \
333 EFAB_INSERT_FIELD_NATIVE ( min, max, field3, value3 ) | \
334 EFAB_INSERT_FIELD_NATIVE ( min, max, field4, value4 ) | \
335 EFAB_INSERT_FIELD_NATIVE ( min, max, field5, value5 ) | \
336 EFAB_INSERT_FIELD_NATIVE ( min, max, field6, value6 ) | \
337 EFAB_INSERT_FIELD_NATIVE ( min, max, field7, value7 ) | \
338 EFAB_INSERT_FIELD_NATIVE ( min, max, field8, value8 ) | \
339 EFAB_INSERT_FIELD_NATIVE ( min, max, field9, value9 ) | \
340 EFAB_INSERT_FIELD_NATIVE ( min, max, field10, value10 ) )
342 #define EFAB_INSERT_FIELDS64( ... ) \
343 cpu_to_le64 ( EFAB_INSERT_FIELDS_NATIVE ( __VA_ARGS__ ) )
345 #define EFAB_INSERT_FIELDS32( ... ) \
346 cpu_to_le32 ( EFAB_INSERT_FIELDS_NATIVE ( __VA_ARGS__ ) )
348 #define EFAB_POPULATE_OWORD64( oword, ... ) do { \
349 (oword).u64[0] = EFAB_INSERT_FIELDS64 ( 0, 63, __VA_ARGS__ );\
350 (oword).u64[1] = EFAB_INSERT_FIELDS64 ( 64, 127, __VA_ARGS__ );\
351 } while ( 0 )
353 #define EFAB_POPULATE_QWORD64( qword, ... ) do { \
354 (qword).u64[0] = EFAB_INSERT_FIELDS64 ( 0, 63, __VA_ARGS__ );\
355 } while ( 0 )
357 #define EFAB_POPULATE_OWORD32( oword, ... ) do { \
358 (oword).u32[0] = EFAB_INSERT_FIELDS32 ( 0, 31, __VA_ARGS__ );\
359 (oword).u32[1] = EFAB_INSERT_FIELDS32 ( 32, 63, __VA_ARGS__ );\
360 (oword).u32[2] = EFAB_INSERT_FIELDS32 ( 64, 95, __VA_ARGS__ );\
361 (oword).u32[3] = EFAB_INSERT_FIELDS32 ( 96, 127, __VA_ARGS__ );\
362 } while ( 0 )
364 #define EFAB_POPULATE_QWORD32( qword, ... ) do { \
365 (qword).u32[0] = EFAB_INSERT_FIELDS32 ( 0, 31, __VA_ARGS__ );\
366 (qword).u32[1] = EFAB_INSERT_FIELDS32 ( 32, 63, __VA_ARGS__ );\
367 } while ( 0 )
369 #define EFAB_POPULATE_DWORD( dword, ... ) do { \
370 (dword).u32[0] = EFAB_INSERT_FIELDS32 ( 0, 31, __VA_ARGS__ );\
371 } while ( 0 )
373 #if ( BITS_PER_LONG == 64 )
374 #define EFAB_POPULATE_OWORD EFAB_POPULATE_OWORD64
375 #define EFAB_POPULATE_QWORD EFAB_POPULATE_QWORD64
376 #else
377 #define EFAB_POPULATE_OWORD EFAB_POPULATE_OWORD32
378 #define EFAB_POPULATE_QWORD EFAB_POPULATE_QWORD32
379 #endif
381 /* Populate an octword field with various numbers of arguments */
382 #define EFAB_POPULATE_OWORD_10 EFAB_POPULATE_OWORD
383 #define EFAB_POPULATE_OWORD_9( oword, ... ) \
384 EFAB_POPULATE_OWORD_10 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
385 #define EFAB_POPULATE_OWORD_8( oword, ... ) \
386 EFAB_POPULATE_OWORD_9 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
387 #define EFAB_POPULATE_OWORD_7( oword, ... ) \
388 EFAB_POPULATE_OWORD_8 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
389 #define EFAB_POPULATE_OWORD_6( oword, ... ) \
390 EFAB_POPULATE_OWORD_7 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
391 #define EFAB_POPULATE_OWORD_5( oword, ... ) \
392 EFAB_POPULATE_OWORD_6 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
393 #define EFAB_POPULATE_OWORD_4( oword, ... ) \
394 EFAB_POPULATE_OWORD_5 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
395 #define EFAB_POPULATE_OWORD_3( oword, ... ) \
396 EFAB_POPULATE_OWORD_4 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
397 #define EFAB_POPULATE_OWORD_2( oword, ... ) \
398 EFAB_POPULATE_OWORD_3 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
399 #define EFAB_POPULATE_OWORD_1( oword, ... ) \
400 EFAB_POPULATE_OWORD_2 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
401 #define EFAB_ZERO_OWORD( oword ) \
402 EFAB_POPULATE_OWORD_1 ( oword, EFAB_DUMMY_FIELD, 0 )
403 #define EFAB_SET_OWORD( oword ) \
404 EFAB_POPULATE_OWORD_4 ( oword, \
405 EFAB_DWORD_0, 0xffffffff, \
406 EFAB_DWORD_1, 0xffffffff, \
407 EFAB_DWORD_2, 0xffffffff, \
408 EFAB_DWORD_3, 0xffffffff )
410 /* Populate a quadword field with various numbers of arguments */
411 #define EFAB_POPULATE_QWORD_10 EFAB_POPULATE_QWORD
412 #define EFAB_POPULATE_QWORD_9( qword, ... ) \
413 EFAB_POPULATE_QWORD_10 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
414 #define EFAB_POPULATE_QWORD_8( qword, ... ) \
415 EFAB_POPULATE_QWORD_9 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
416 #define EFAB_POPULATE_QWORD_7( qword, ... ) \
417 EFAB_POPULATE_QWORD_8 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
418 #define EFAB_POPULATE_QWORD_6( qword, ... ) \
419 EFAB_POPULATE_QWORD_7 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
420 #define EFAB_POPULATE_QWORD_5( qword, ... ) \
421 EFAB_POPULATE_QWORD_6 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
422 #define EFAB_POPULATE_QWORD_4( qword, ... ) \
423 EFAB_POPULATE_QWORD_5 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
424 #define EFAB_POPULATE_QWORD_3( qword, ... ) \
425 EFAB_POPULATE_QWORD_4 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
426 #define EFAB_POPULATE_QWORD_2( qword, ... ) \
427 EFAB_POPULATE_QWORD_3 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
428 #define EFAB_POPULATE_QWORD_1( qword, ... ) \
429 EFAB_POPULATE_QWORD_2 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
430 #define EFAB_ZERO_QWORD( qword ) \
431 EFAB_POPULATE_QWORD_1 ( qword, EFAB_DUMMY_FIELD, 0 )
432 #define EFAB_SET_QWORD( qword ) \
433 EFAB_POPULATE_QWORD_2 ( qword, \
434 EFAB_DWORD_0, 0xffffffff, \
435 EFAB_DWORD_1, 0xffffffff )
437 /* Populate a dword field with various numbers of arguments */
438 #define EFAB_POPULATE_DWORD_10 EFAB_POPULATE_DWORD
439 #define EFAB_POPULATE_DWORD_9( dword, ... ) \
440 EFAB_POPULATE_DWORD_10 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
441 #define EFAB_POPULATE_DWORD_8( dword, ... ) \
442 EFAB_POPULATE_DWORD_9 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
443 #define EFAB_POPULATE_DWORD_7( dword, ... ) \
444 EFAB_POPULATE_DWORD_8 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
445 #define EFAB_POPULATE_DWORD_6( dword, ... ) \
446 EFAB_POPULATE_DWORD_7 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
447 #define EFAB_POPULATE_DWORD_5( dword, ... ) \
448 EFAB_POPULATE_DWORD_6 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
449 #define EFAB_POPULATE_DWORD_4( dword, ... ) \
450 EFAB_POPULATE_DWORD_5 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
451 #define EFAB_POPULATE_DWORD_3( dword, ... ) \
452 EFAB_POPULATE_DWORD_4 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
453 #define EFAB_POPULATE_DWORD_2( dword, ... ) \
454 EFAB_POPULATE_DWORD_3 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
455 #define EFAB_POPULATE_DWORD_1( dword, ... ) \
456 EFAB_POPULATE_DWORD_2 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
457 #define EFAB_ZERO_DWORD( dword ) \
458 EFAB_POPULATE_DWORD_1 ( dword, EFAB_DUMMY_FIELD, 0 )
459 #define EFAB_SET_DWORD( dword ) \
460 EFAB_POPULATE_DWORD_1 ( dword, EFAB_DWORD_0, 0xffffffff )
463 * Modify a named field within an already-populated structure. Used
464 * for read-modify-write operations.
468 #define EFAB_INSERT_FIELD64( ... ) \
469 cpu_to_le64 ( EFAB_INSERT_FIELD_NATIVE ( __VA_ARGS__ ) )
471 #define EFAB_INSERT_FIELD32( ... ) \
472 cpu_to_le32 ( EFAB_INSERT_FIELD_NATIVE ( __VA_ARGS__ ) )
474 #define EFAB_INPLACE_MASK64( min, max, field ) \
475 EFAB_INSERT_FIELD64 ( min, max, field, EFAB_MASK64 ( field ) )
477 #define EFAB_INPLACE_MASK32( min, max, field ) \
478 EFAB_INSERT_FIELD32 ( min, max, field, EFAB_MASK32 ( field ) )
480 #define EFAB_SET_OWORD_FIELD64( oword, field, value ) do { \
481 (oword).u64[0] = ( ( (oword).u64[0] \
482 & ~EFAB_INPLACE_MASK64 ( 0, 63, field ) ) \
483 | EFAB_INSERT_FIELD64 ( 0, 63, field, value ) ); \
484 (oword).u64[1] = ( ( (oword).u64[1] \
485 & ~EFAB_INPLACE_MASK64 ( 64, 127, field ) ) \
486 | EFAB_INSERT_FIELD64 ( 64, 127, field, value ) ); \
487 } while ( 0 )
489 #define EFAB_SET_QWORD_FIELD64( qword, field, value ) do { \
490 (qword).u64[0] = ( ( (qword).u64[0] \
491 & ~EFAB_INPLACE_MASK64 ( 0, 63, field ) ) \
492 | EFAB_INSERT_FIELD64 ( 0, 63, field, value ) ); \
493 } while ( 0 )
495 #define EFAB_SET_OWORD_FIELD32( oword, field, value ) do { \
496 (oword).u32[0] = ( ( (oword).u32[0] \
497 & ~EFAB_INPLACE_MASK32 ( 0, 31, field ) ) \
498 | EFAB_INSERT_FIELD32 ( 0, 31, field, value ) ); \
499 (oword).u32[1] = ( ( (oword).u32[1] \
500 & ~EFAB_INPLACE_MASK32 ( 32, 63, field ) ) \
501 | EFAB_INSERT_FIELD32 ( 32, 63, field, value ) ); \
502 (oword).u32[2] = ( ( (oword).u32[2] \
503 & ~EFAB_INPLACE_MASK32 ( 64, 95, field ) ) \
504 | EFAB_INSERT_FIELD32 ( 64, 95, field, value ) ); \
505 (oword).u32[3] = ( ( (oword).u32[3] \
506 & ~EFAB_INPLACE_MASK32 ( 96, 127, field ) ) \
507 | EFAB_INSERT_FIELD32 ( 96, 127, field, value ) ); \
508 } while ( 0 )
510 #define EFAB_SET_QWORD_FIELD32( qword, field, value ) do { \
511 (qword).u32[0] = ( ( (qword).u32[0] \
512 & ~EFAB_INPLACE_MASK32 ( 0, 31, field ) ) \
513 | EFAB_INSERT_FIELD32 ( 0, 31, field, value ) ); \
514 (qword).u32[1] = ( ( (qword).u32[1] \
515 & ~EFAB_INPLACE_MASK32 ( 32, 63, field ) ) \
516 | EFAB_INSERT_FIELD32 ( 32, 63, field, value ) ); \
517 } while ( 0 )
519 #define EFAB_SET_DWORD_FIELD( dword, field, value ) do { \
520 (dword).u32[0] = ( ( (dword).u32[0] \
521 & ~EFAB_INPLACE_MASK32 ( 0, 31, field ) ) \
522 | EFAB_INSERT_FIELD32 ( 0, 31, field, value ) ); \
523 } while ( 0 )
525 #if ( BITS_PER_LONG == 64 )
526 #define EFAB_SET_OWORD_FIELD EFAB_SET_OWORD_FIELD64
527 #define EFAB_SET_QWORD_FIELD EFAB_SET_QWORD_FIELD64
528 #else
529 #define EFAB_SET_OWORD_FIELD EFAB_SET_OWORD_FIELD32
530 #define EFAB_SET_QWORD_FIELD EFAB_SET_QWORD_FIELD32
531 #endif
533 /* Used to avoid compiler warnings about shift range exceeding width
534 * of the data types when dma_addr_t is only 32 bits wide.
536 #define DMA_ADDR_T_WIDTH ( 8 * sizeof ( dma_addr_t ) )
537 #define EFAB_DMA_TYPE_WIDTH( width ) \
538 ( ( (width) < DMA_ADDR_T_WIDTH ) ? (width) : DMA_ADDR_T_WIDTH )
539 #define EFAB_DMA_MAX_MASK ( ( DMA_ADDR_T_WIDTH == 64 ) ? \
540 ~( ( uint64_t ) 0 ) : ~( ( uint32_t ) 0 ) )
541 #define EFAB_DMA_MASK(mask) ( (mask) & EFAB_DMA_MAX_MASK )
543 #endif /* EFAB_BITFIELD_H */
546 * Local variables:
547 * c-basic-offset: 8
548 * c-indent-level: 8
549 * tab-width: 8
550 * End: