Make gpxe build.
[gpxe/hramrach.git] / src / drivers / net / etherfabric.h
blob9657eb7e8084ec8c63bddc210f2c74da90cc5be2
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 FILE_LICENCE ( GPL_ANY );
22 #ifndef EFAB_BITFIELD_H
23 #define EFAB_BITFIELD_H
25 /** @file
27 * Etherfabric bitfield access
29 * Etherfabric NICs make extensive use of bitfields up to 128 bits
30 * wide. Since there is no native 128-bit datatype on most systems,
31 * and since 64-bit datatypes are inefficient on 32-bit systems and
32 * vice versa, we wrap accesses in a way that uses the most efficient
33 * datatype.
35 * The NICs are PCI devices and therefore little-endian. Since most
36 * of the quantities that we deal with are DMAed to/from host memory,
37 * we define our datatypes (efab_oword_t, efab_qword_t and
38 * efab_dword_t) to be little-endian.
40 * In the less common case of using PIO for individual register
41 * writes, we construct the little-endian datatype in host memory and
42 * then use non-swapping equivalents of writel/writeq, rather than
43 * constructing a native-endian datatype and relying on the implicit
44 * byte-swapping done by writel/writeq. (We use a similar strategy
45 * for register reads.)
48 /** Dummy field low bit number */
49 #define EFAB_DUMMY_FIELD_LBN 0
50 /** Dummy field width */
51 #define EFAB_DUMMY_FIELD_WIDTH 0
52 /** Dword 0 low bit number */
53 #define EFAB_DWORD_0_LBN 0
54 /** Dword 0 width */
55 #define EFAB_DWORD_0_WIDTH 32
56 /** Dword 1 low bit number */
57 #define EFAB_DWORD_1_LBN 32
58 /** Dword 1 width */
59 #define EFAB_DWORD_1_WIDTH 32
60 /** Dword 2 low bit number */
61 #define EFAB_DWORD_2_LBN 64
62 /** Dword 2 width */
63 #define EFAB_DWORD_2_WIDTH 32
64 /** Dword 3 low bit number */
65 #define EFAB_DWORD_3_LBN 96
66 /** Dword 3 width */
67 #define EFAB_DWORD_3_WIDTH 32
69 /** Specified attribute (e.g. LBN) of the specified field */
70 #define EFAB_VAL(field,attribute) field ## _ ## attribute
71 /** Low bit number of the specified field */
72 #define EFAB_LOW_BIT( field ) EFAB_VAL ( field, LBN )
73 /** Bit width of the specified field */
74 #define EFAB_WIDTH( field ) EFAB_VAL ( field, WIDTH )
75 /** High bit number of the specified field */
76 #define EFAB_HIGH_BIT(field) ( EFAB_LOW_BIT(field) + EFAB_WIDTH(field) - 1 )
77 /** Mask equal in width to the specified field.
79 * For example, a field with width 5 would have a mask of 0x1f.
81 * The maximum width mask that can be generated is 64 bits.
83 #define EFAB_MASK64( field ) \
84 ( EFAB_WIDTH(field) == 64 ? ~( ( uint64_t ) 0 ) : \
85 ( ( ( ( ( uint64_t ) 1 ) << EFAB_WIDTH(field) ) ) - 1 ) )
87 /** Mask equal in width to the specified field.
89 * For example, a field with width 5 would have a mask of 0x1f.
91 * The maximum width mask that can be generated is 32 bits. Use
92 * EFAB_MASK64 for higher width fields.
94 #define EFAB_MASK32( field ) \
95 ( EFAB_WIDTH(field) == 32 ? ~( ( uint32_t ) 0 ) : \
96 ( ( ( ( ( uint32_t ) 1 ) << EFAB_WIDTH(field) ) ) - 1 ) )
98 /** A doubleword (i.e. 4 byte) datatype
100 * This datatype is defined to be little-endian.
102 typedef union efab_dword {
103 uint32_t u32[1];
104 uint32_t opaque; /* For bitwise operations between two efab_dwords */
105 } efab_dword_t;
107 /** A quadword (i.e. 8 byte) datatype
109 * This datatype is defined to be little-endian.
111 typedef union efab_qword {
112 uint64_t u64[1];
113 uint32_t u32[2];
114 efab_dword_t dword[2];
115 } efab_qword_t;
118 * An octword (eight-word, i.e. 16 byte) datatype
120 * This datatype is defined to be little-endian.
122 typedef union efab_oword {
123 uint64_t u64[2];
124 efab_qword_t qword[2];
125 uint32_t u32[4];
126 efab_dword_t dword[4];
127 } efab_oword_t;
129 /** Format string for printing an efab_dword_t */
130 #define EFAB_DWORD_FMT "%08x"
132 /** Format string for printing an efab_qword_t */
133 #define EFAB_QWORD_FMT "%08x:%08x"
135 /** Format string for printing an efab_oword_t */
136 #define EFAB_OWORD_FMT "%08x:%08x:%08x:%08x"
138 /** printk parameters for printing an efab_dword_t */
139 #define EFAB_DWORD_VAL(dword) \
140 ( ( unsigned int ) le32_to_cpu ( (dword).u32[0] ) )
142 /** printk parameters for printing an efab_qword_t */
143 #define EFAB_QWORD_VAL(qword) \
144 ( ( unsigned int ) le32_to_cpu ( (qword).u32[1] ) ), \
145 ( ( unsigned int ) le32_to_cpu ( (qword).u32[0] ) )
147 /** printk parameters for printing an efab_oword_t */
148 #define EFAB_OWORD_VAL(oword) \
149 ( ( unsigned int ) le32_to_cpu ( (oword).u32[3] ) ), \
150 ( ( unsigned int ) le32_to_cpu ( (oword).u32[2] ) ), \
151 ( ( unsigned int ) le32_to_cpu ( (oword).u32[1] ) ), \
152 ( ( unsigned int ) le32_to_cpu ( (oword).u32[0] ) )
155 * Extract bit field portion [low,high) from the native-endian element
156 * which contains bits [min,max).
158 * For example, suppose "element" represents the high 32 bits of a
159 * 64-bit value, and we wish to extract the bits belonging to the bit
160 * field occupying bits 28-45 of this 64-bit value.
162 * Then EFAB_EXTRACT ( element, 32, 63, 28, 45 ) would give
164 * ( element ) << 4
166 * The result will contain the relevant bits filled in in the range
167 * [0,high-low), with garbage in bits [high-low+1,...).
169 #define EFAB_EXTRACT_NATIVE( native_element, min ,max ,low ,high ) \
170 ( ( ( low > max ) || ( high < min ) ) ? 0 : \
171 ( ( low > min ) ? \
172 ( (native_element) >> ( low - min ) ) : \
173 ( (native_element) << ( min - low ) ) ) )
176 * Extract bit field portion [low,high) from the 64-bit little-endian
177 * element which contains bits [min,max)
179 #define EFAB_EXTRACT64( element, min, max, low, high ) \
180 EFAB_EXTRACT_NATIVE ( le64_to_cpu(element), min, max, low, high )
183 * Extract bit field portion [low,high) from the 32-bit little-endian
184 * element which contains bits [min,max)
186 #define EFAB_EXTRACT32( element, min, max, low, high ) \
187 EFAB_EXTRACT_NATIVE ( le32_to_cpu(element), min, max, low, high )
189 #define EFAB_EXTRACT_OWORD64( oword, low, high ) \
190 ( EFAB_EXTRACT64 ( (oword).u64[0], 0, 63, low, high ) | \
191 EFAB_EXTRACT64 ( (oword).u64[1], 64, 127, low, high ) )
193 #define EFAB_EXTRACT_QWORD64( qword, low, high ) \
194 ( EFAB_EXTRACT64 ( (qword).u64[0], 0, 63, low, high ) )
196 #define EFAB_EXTRACT_OWORD32( oword, low, high ) \
197 ( EFAB_EXTRACT32 ( (oword).u32[0], 0, 31, low, high ) | \
198 EFAB_EXTRACT32 ( (oword).u32[1], 32, 63, low, high ) | \
199 EFAB_EXTRACT32 ( (oword).u32[2], 64, 95, low, high ) | \
200 EFAB_EXTRACT32 ( (oword).u32[3], 96, 127, low, high ) )
202 #define EFAB_EXTRACT_QWORD32( qword, low, high ) \
203 ( EFAB_EXTRACT32 ( (qword).u32[0], 0, 31, low, high ) | \
204 EFAB_EXTRACT32 ( (qword).u32[1], 32, 63, low, high ) )
206 #define EFAB_EXTRACT_DWORD( dword, low, high ) \
207 ( EFAB_EXTRACT32 ( (dword).u32[0], 0, 31, low, high ) )
209 #define EFAB_OWORD_FIELD64( oword, field ) \
210 ( EFAB_EXTRACT_OWORD64 ( oword, EFAB_LOW_BIT ( field ), \
211 EFAB_HIGH_BIT ( field ) ) & \
212 EFAB_MASK64 ( field ) )
214 #define EFAB_QWORD_FIELD64( qword, field ) \
215 ( EFAB_EXTRACT_QWORD64 ( qword, EFAB_LOW_BIT ( field ), \
216 EFAB_HIGH_BIT ( field ) ) & \
217 EFAB_MASK64 ( field ) )
219 #define EFAB_OWORD_FIELD32( oword, field ) \
220 ( EFAB_EXTRACT_OWORD32 ( oword, EFAB_LOW_BIT ( field ), \
221 EFAB_HIGH_BIT ( field ) ) & \
222 EFAB_MASK32 ( field ) )
224 #define EFAB_QWORD_FIELD32( qword, field ) \
225 ( EFAB_EXTRACT_QWORD32 ( qword, EFAB_LOW_BIT ( field ), \
226 EFAB_HIGH_BIT ( field ) ) & \
227 EFAB_MASK32 ( field ) )
229 #define EFAB_DWORD_FIELD( dword, field ) \
230 ( EFAB_EXTRACT_DWORD ( dword, EFAB_LOW_BIT ( field ), \
231 EFAB_HIGH_BIT ( field ) ) & \
232 EFAB_MASK32 ( field ) )
234 #define EFAB_OWORD_IS_ZERO64( oword ) \
235 ( ! ( (oword).u64[0] || (oword).u64[1] ) )
237 #define EFAB_QWORD_IS_ZERO64( qword ) \
238 ( ! ( (qword).u64[0] ) )
240 #define EFAB_OWORD_IS_ZERO32( oword ) \
241 ( ! ( (oword).u32[0] || (oword).u32[1] || \
242 (oword).u32[2] || (oword).u32[3] ) )
244 #define EFAB_QWORD_IS_ZERO32( qword ) \
245 ( ! ( (qword).u32[0] || (qword).u32[1] ) )
247 #define EFAB_DWORD_IS_ZERO( dword ) \
248 ( ! ( (dword).u32[0] ) )
250 #define EFAB_OWORD_IS_ALL_ONES64( oword ) \
251 ( ( (oword).u64[0] & (oword).u64[1] ) == ~( ( uint64_t ) 0 ) )
253 #define EFAB_QWORD_IS_ALL_ONES64( qword ) \
254 ( (qword).u64[0] == ~( ( uint64_t ) 0 ) )
256 #define EFAB_OWORD_IS_ALL_ONES32( oword ) \
257 ( ( (oword).u32[0] & (oword).u32[1] & \
258 (oword).u32[2] & (oword).u32[3] ) == ~( ( uint32_t ) 0 ) )
260 #define EFAB_QWORD_IS_ALL_ONES32( qword ) \
261 ( ( (qword).u32[0] & (qword).u32[1] ) == ~( ( uint32_t ) 0 ) )
263 #define EFAB_DWORD_IS_ALL_ONES( dword ) \
264 ( (dword).u32[0] == ~( ( uint32_t ) 0 ) )
266 #if ( BITS_PER_LONG == 64 )
267 #define EFAB_OWORD_FIELD EFAB_OWORD_FIELD64
268 #define EFAB_QWORD_FIELD EFAB_QWORD_FIELD64
269 #define EFAB_OWORD_IS_ZERO EFAB_OWORD_IS_ZERO64
270 #define EFAB_QWORD_IS_ZERO EFAB_QWORD_IS_ZERO64
271 #define EFAB_OWORD_IS_ALL_ONES EFAB_OWORD_IS_ALL_ONES64
272 #define EFAB_QWORD_IS_ALL_ONES EFAB_QWORD_IS_ALL_ONES64
273 #else
274 #define EFAB_OWORD_FIELD EFAB_OWORD_FIELD32
275 #define EFAB_QWORD_FIELD EFAB_QWORD_FIELD32
276 #define EFAB_OWORD_IS_ZERO EFAB_OWORD_IS_ZERO32
277 #define EFAB_QWORD_IS_ZERO EFAB_QWORD_IS_ZERO32
278 #define EFAB_OWORD_IS_ALL_ONES EFAB_OWORD_IS_ALL_ONES32
279 #define EFAB_QWORD_IS_ALL_ONES EFAB_QWORD_IS_ALL_ONES32
280 #endif
283 * Construct bit field portion
285 * Creates the portion of the bit field [low,high) that lies within
286 * the range [min,max).
288 #define EFAB_INSERT_NATIVE64( min, max, low, high, value ) \
289 ( ( ( low > max ) || ( high < min ) ) ? 0 : \
290 ( ( low > min ) ? \
291 ( ( ( uint64_t ) (value) ) << ( low - min ) ) : \
292 ( ( ( uint64_t ) (value) ) >> ( min - low ) ) ) )
294 #define EFAB_INSERT_NATIVE32( min, max, low, high, value ) \
295 ( ( ( low > max ) || ( high < min ) ) ? 0 : \
296 ( ( low > min ) ? \
297 ( ( ( uint32_t ) (value) ) << ( low - min ) ) : \
298 ( ( ( uint32_t ) (value) ) >> ( min - low ) ) ) )
300 #define EFAB_INSERT_NATIVE( min, max, low, high, value ) \
301 ( ( ( ( max - min ) >= 32 ) || \
302 ( ( high - low ) >= 32 ) ) \
303 ? EFAB_INSERT_NATIVE64 ( min, max, low, high, value ) \
304 : EFAB_INSERT_NATIVE32 ( min, max, low, high, value ) )
307 * Construct bit field portion
309 * Creates the portion of the named bit field that lies within the
310 * range [min,max).
312 #define EFAB_INSERT_FIELD_NATIVE( min, max, field, value ) \
313 EFAB_INSERT_NATIVE ( min, max, EFAB_LOW_BIT ( field ), \
314 EFAB_HIGH_BIT ( field ), value )
317 * Construct bit field
319 * Creates the portion of the named bit fields that lie within the
320 * range [min,max).
322 #define EFAB_INSERT_FIELDS_NATIVE( min, max, \
323 field1, value1, \
324 field2, value2, \
325 field3, value3, \
326 field4, value4, \
327 field5, value5, \
328 field6, value6, \
329 field7, value7, \
330 field8, value8, \
331 field9, value9, \
332 field10, value10 ) \
333 ( EFAB_INSERT_FIELD_NATIVE ( min, max, field1, value1 ) | \
334 EFAB_INSERT_FIELD_NATIVE ( min, max, field2, value2 ) | \
335 EFAB_INSERT_FIELD_NATIVE ( min, max, field3, value3 ) | \
336 EFAB_INSERT_FIELD_NATIVE ( min, max, field4, value4 ) | \
337 EFAB_INSERT_FIELD_NATIVE ( min, max, field5, value5 ) | \
338 EFAB_INSERT_FIELD_NATIVE ( min, max, field6, value6 ) | \
339 EFAB_INSERT_FIELD_NATIVE ( min, max, field7, value7 ) | \
340 EFAB_INSERT_FIELD_NATIVE ( min, max, field8, value8 ) | \
341 EFAB_INSERT_FIELD_NATIVE ( min, max, field9, value9 ) | \
342 EFAB_INSERT_FIELD_NATIVE ( min, max, field10, value10 ) )
344 #define EFAB_INSERT_FIELDS64( ... ) \
345 cpu_to_le64 ( EFAB_INSERT_FIELDS_NATIVE ( __VA_ARGS__ ) )
347 #define EFAB_INSERT_FIELDS32( ... ) \
348 cpu_to_le32 ( EFAB_INSERT_FIELDS_NATIVE ( __VA_ARGS__ ) )
350 #define EFAB_POPULATE_OWORD64( oword, ... ) do { \
351 (oword).u64[0] = EFAB_INSERT_FIELDS64 ( 0, 63, __VA_ARGS__ );\
352 (oword).u64[1] = EFAB_INSERT_FIELDS64 ( 64, 127, __VA_ARGS__ );\
353 } while ( 0 )
355 #define EFAB_POPULATE_QWORD64( qword, ... ) do { \
356 (qword).u64[0] = EFAB_INSERT_FIELDS64 ( 0, 63, __VA_ARGS__ );\
357 } while ( 0 )
359 #define EFAB_POPULATE_OWORD32( oword, ... ) do { \
360 (oword).u32[0] = EFAB_INSERT_FIELDS32 ( 0, 31, __VA_ARGS__ );\
361 (oword).u32[1] = EFAB_INSERT_FIELDS32 ( 32, 63, __VA_ARGS__ );\
362 (oword).u32[2] = EFAB_INSERT_FIELDS32 ( 64, 95, __VA_ARGS__ );\
363 (oword).u32[3] = EFAB_INSERT_FIELDS32 ( 96, 127, __VA_ARGS__ );\
364 } while ( 0 )
366 #define EFAB_POPULATE_QWORD32( qword, ... ) do { \
367 (qword).u32[0] = EFAB_INSERT_FIELDS32 ( 0, 31, __VA_ARGS__ );\
368 (qword).u32[1] = EFAB_INSERT_FIELDS32 ( 32, 63, __VA_ARGS__ );\
369 } while ( 0 )
371 #define EFAB_POPULATE_DWORD( dword, ... ) do { \
372 (dword).u32[0] = EFAB_INSERT_FIELDS32 ( 0, 31, __VA_ARGS__ );\
373 } while ( 0 )
375 #if ( BITS_PER_LONG == 64 )
376 #define EFAB_POPULATE_OWORD EFAB_POPULATE_OWORD64
377 #define EFAB_POPULATE_QWORD EFAB_POPULATE_QWORD64
378 #else
379 #define EFAB_POPULATE_OWORD EFAB_POPULATE_OWORD32
380 #define EFAB_POPULATE_QWORD EFAB_POPULATE_QWORD32
381 #endif
383 /* Populate an octword field with various numbers of arguments */
384 #define EFAB_POPULATE_OWORD_10 EFAB_POPULATE_OWORD
385 #define EFAB_POPULATE_OWORD_9( oword, ... ) \
386 EFAB_POPULATE_OWORD_10 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
387 #define EFAB_POPULATE_OWORD_8( oword, ... ) \
388 EFAB_POPULATE_OWORD_9 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
389 #define EFAB_POPULATE_OWORD_7( oword, ... ) \
390 EFAB_POPULATE_OWORD_8 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
391 #define EFAB_POPULATE_OWORD_6( oword, ... ) \
392 EFAB_POPULATE_OWORD_7 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
393 #define EFAB_POPULATE_OWORD_5( oword, ... ) \
394 EFAB_POPULATE_OWORD_6 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
395 #define EFAB_POPULATE_OWORD_4( oword, ... ) \
396 EFAB_POPULATE_OWORD_5 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
397 #define EFAB_POPULATE_OWORD_3( oword, ... ) \
398 EFAB_POPULATE_OWORD_4 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
399 #define EFAB_POPULATE_OWORD_2( oword, ... ) \
400 EFAB_POPULATE_OWORD_3 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
401 #define EFAB_POPULATE_OWORD_1( oword, ... ) \
402 EFAB_POPULATE_OWORD_2 ( oword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
403 #define EFAB_ZERO_OWORD( oword ) \
404 EFAB_POPULATE_OWORD_1 ( oword, EFAB_DUMMY_FIELD, 0 )
405 #define EFAB_SET_OWORD( oword ) \
406 EFAB_POPULATE_OWORD_4 ( oword, \
407 EFAB_DWORD_0, 0xffffffff, \
408 EFAB_DWORD_1, 0xffffffff, \
409 EFAB_DWORD_2, 0xffffffff, \
410 EFAB_DWORD_3, 0xffffffff )
412 /* Populate a quadword field with various numbers of arguments */
413 #define EFAB_POPULATE_QWORD_10 EFAB_POPULATE_QWORD
414 #define EFAB_POPULATE_QWORD_9( qword, ... ) \
415 EFAB_POPULATE_QWORD_10 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
416 #define EFAB_POPULATE_QWORD_8( qword, ... ) \
417 EFAB_POPULATE_QWORD_9 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
418 #define EFAB_POPULATE_QWORD_7( qword, ... ) \
419 EFAB_POPULATE_QWORD_8 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
420 #define EFAB_POPULATE_QWORD_6( qword, ... ) \
421 EFAB_POPULATE_QWORD_7 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
422 #define EFAB_POPULATE_QWORD_5( qword, ... ) \
423 EFAB_POPULATE_QWORD_6 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
424 #define EFAB_POPULATE_QWORD_4( qword, ... ) \
425 EFAB_POPULATE_QWORD_5 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
426 #define EFAB_POPULATE_QWORD_3( qword, ... ) \
427 EFAB_POPULATE_QWORD_4 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
428 #define EFAB_POPULATE_QWORD_2( qword, ... ) \
429 EFAB_POPULATE_QWORD_3 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
430 #define EFAB_POPULATE_QWORD_1( qword, ... ) \
431 EFAB_POPULATE_QWORD_2 ( qword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
432 #define EFAB_ZERO_QWORD( qword ) \
433 EFAB_POPULATE_QWORD_1 ( qword, EFAB_DUMMY_FIELD, 0 )
434 #define EFAB_SET_QWORD( qword ) \
435 EFAB_POPULATE_QWORD_2 ( qword, \
436 EFAB_DWORD_0, 0xffffffff, \
437 EFAB_DWORD_1, 0xffffffff )
439 /* Populate a dword field with various numbers of arguments */
440 #define EFAB_POPULATE_DWORD_10 EFAB_POPULATE_DWORD
441 #define EFAB_POPULATE_DWORD_9( dword, ... ) \
442 EFAB_POPULATE_DWORD_10 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
443 #define EFAB_POPULATE_DWORD_8( dword, ... ) \
444 EFAB_POPULATE_DWORD_9 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
445 #define EFAB_POPULATE_DWORD_7( dword, ... ) \
446 EFAB_POPULATE_DWORD_8 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
447 #define EFAB_POPULATE_DWORD_6( dword, ... ) \
448 EFAB_POPULATE_DWORD_7 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
449 #define EFAB_POPULATE_DWORD_5( dword, ... ) \
450 EFAB_POPULATE_DWORD_6 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
451 #define EFAB_POPULATE_DWORD_4( dword, ... ) \
452 EFAB_POPULATE_DWORD_5 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
453 #define EFAB_POPULATE_DWORD_3( dword, ... ) \
454 EFAB_POPULATE_DWORD_4 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
455 #define EFAB_POPULATE_DWORD_2( dword, ... ) \
456 EFAB_POPULATE_DWORD_3 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
457 #define EFAB_POPULATE_DWORD_1( dword, ... ) \
458 EFAB_POPULATE_DWORD_2 ( dword, EFAB_DUMMY_FIELD, 0, __VA_ARGS__ )
459 #define EFAB_ZERO_DWORD( dword ) \
460 EFAB_POPULATE_DWORD_1 ( dword, EFAB_DUMMY_FIELD, 0 )
461 #define EFAB_SET_DWORD( dword ) \
462 EFAB_POPULATE_DWORD_1 ( dword, EFAB_DWORD_0, 0xffffffff )
465 * Modify a named field within an already-populated structure. Used
466 * for read-modify-write operations.
470 #define EFAB_INSERT_FIELD64( ... ) \
471 cpu_to_le64 ( EFAB_INSERT_FIELD_NATIVE ( __VA_ARGS__ ) )
473 #define EFAB_INSERT_FIELD32( ... ) \
474 cpu_to_le32 ( EFAB_INSERT_FIELD_NATIVE ( __VA_ARGS__ ) )
476 #define EFAB_INPLACE_MASK64( min, max, field ) \
477 EFAB_INSERT_FIELD64 ( min, max, field, EFAB_MASK64 ( field ) )
479 #define EFAB_INPLACE_MASK32( min, max, field ) \
480 EFAB_INSERT_FIELD32 ( min, max, field, EFAB_MASK32 ( field ) )
482 #define EFAB_SET_OWORD_FIELD64( oword, field, value ) do { \
483 (oword).u64[0] = ( ( (oword).u64[0] \
484 & ~EFAB_INPLACE_MASK64 ( 0, 63, field ) ) \
485 | EFAB_INSERT_FIELD64 ( 0, 63, field, value ) ); \
486 (oword).u64[1] = ( ( (oword).u64[1] \
487 & ~EFAB_INPLACE_MASK64 ( 64, 127, field ) ) \
488 | EFAB_INSERT_FIELD64 ( 64, 127, field, value ) ); \
489 } while ( 0 )
491 #define EFAB_SET_QWORD_FIELD64( qword, field, value ) do { \
492 (qword).u64[0] = ( ( (qword).u64[0] \
493 & ~EFAB_INPLACE_MASK64 ( 0, 63, field ) ) \
494 | EFAB_INSERT_FIELD64 ( 0, 63, field, value ) ); \
495 } while ( 0 )
497 #define EFAB_SET_OWORD_FIELD32( oword, field, value ) do { \
498 (oword).u32[0] = ( ( (oword).u32[0] \
499 & ~EFAB_INPLACE_MASK32 ( 0, 31, field ) ) \
500 | EFAB_INSERT_FIELD32 ( 0, 31, field, value ) ); \
501 (oword).u32[1] = ( ( (oword).u32[1] \
502 & ~EFAB_INPLACE_MASK32 ( 32, 63, field ) ) \
503 | EFAB_INSERT_FIELD32 ( 32, 63, field, value ) ); \
504 (oword).u32[2] = ( ( (oword).u32[2] \
505 & ~EFAB_INPLACE_MASK32 ( 64, 95, field ) ) \
506 | EFAB_INSERT_FIELD32 ( 64, 95, field, value ) ); \
507 (oword).u32[3] = ( ( (oword).u32[3] \
508 & ~EFAB_INPLACE_MASK32 ( 96, 127, field ) ) \
509 | EFAB_INSERT_FIELD32 ( 96, 127, field, value ) ); \
510 } while ( 0 )
512 #define EFAB_SET_QWORD_FIELD32( qword, field, value ) do { \
513 (qword).u32[0] = ( ( (qword).u32[0] \
514 & ~EFAB_INPLACE_MASK32 ( 0, 31, field ) ) \
515 | EFAB_INSERT_FIELD32 ( 0, 31, field, value ) ); \
516 (qword).u32[1] = ( ( (qword).u32[1] \
517 & ~EFAB_INPLACE_MASK32 ( 32, 63, field ) ) \
518 | EFAB_INSERT_FIELD32 ( 32, 63, field, value ) ); \
519 } while ( 0 )
521 #define EFAB_SET_DWORD_FIELD( dword, field, value ) do { \
522 (dword).u32[0] = ( ( (dword).u32[0] \
523 & ~EFAB_INPLACE_MASK32 ( 0, 31, field ) ) \
524 | EFAB_INSERT_FIELD32 ( 0, 31, field, value ) ); \
525 } while ( 0 )
527 #if ( BITS_PER_LONG == 64 )
528 #define EFAB_SET_OWORD_FIELD EFAB_SET_OWORD_FIELD64
529 #define EFAB_SET_QWORD_FIELD EFAB_SET_QWORD_FIELD64
530 #else
531 #define EFAB_SET_OWORD_FIELD EFAB_SET_OWORD_FIELD32
532 #define EFAB_SET_QWORD_FIELD EFAB_SET_QWORD_FIELD32
533 #endif
535 /* Used to avoid compiler warnings about shift range exceeding width
536 * of the data types when dma_addr_t is only 32 bits wide.
538 #define DMA_ADDR_T_WIDTH ( 8 * sizeof ( dma_addr_t ) )
539 #define EFAB_DMA_TYPE_WIDTH( width ) \
540 ( ( (width) < DMA_ADDR_T_WIDTH ) ? (width) : DMA_ADDR_T_WIDTH )
541 #define EFAB_DMA_MAX_MASK ( ( DMA_ADDR_T_WIDTH == 64 ) ? \
542 ~( ( uint64_t ) 0 ) : ~( ( uint32_t ) 0 ) )
543 #define EFAB_DMA_MASK(mask) ( (mask) & EFAB_DMA_MAX_MASK )
545 #endif /* EFAB_BITFIELD_H */
548 * Local variables:
549 * c-basic-offset: 8
550 * c-indent-level: 8
551 * tab-width: 8
552 * End: