xref: /freebsd/sys/dev/sfxge/common/efx_types.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2007-2016 Solarflare Communications Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  *    this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  *    this list of conditions and the following disclaimer in the documentation
14  *    and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * The views and conclusions contained in the software and documentation are
29  * those of the authors and should not be interpreted as representing official
30  * policies, either expressed or implied, of the FreeBSD Project.
31  *
32  * Ackowledgement to Fen Systems Ltd.
33  */
34 
35 #ifndef	_SYS_EFX_TYPES_H
36 #define	_SYS_EFX_TYPES_H
37 
38 #include "efsys.h"
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Bitfield access
46  *
47  * Solarflare NICs make extensive use of bitfields up to 128 bits
48  * wide.  Since there is no native 128-bit datatype on most systems,
49  * and since 64-bit datatypes are inefficient on 32-bit systems and
50  * vice versa, we wrap accesses in a way that uses the most efficient
51  * datatype.
52  *
53  * The NICs are PCI devices and therefore little-endian.  Since most
54  * of the quantities that we deal with are DMAed to/from host memory,
55  * we define	our datatypes (efx_oword_t, efx_qword_t and efx_dword_t)
56  * to be little-endian.
57  *
58  * In the less common case of using PIO for individual register
59  * writes, we construct the little-endian datatype in host memory and
60  * then use non-swapping register access primitives, rather than
61  * constructing a native-endian datatype and relying on implicit
62  * byte-swapping.  (We use a similar strategy for register reads.)
63  */
64 
65 /*
66  * NOTE: Field definitions here and elsewhere are done in terms of a lowest
67  *       bit number (LBN) and a width.
68  */
69 
70 #define	EFX_DUMMY_FIELD_LBN 0
71 #define	EFX_DUMMY_FIELD_WIDTH 0
72 
73 #define	EFX_BYTE_0_LBN 0
74 #define	EFX_BYTE_0_WIDTH 8
75 
76 #define	EFX_BYTE_1_LBN 8
77 #define	EFX_BYTE_1_WIDTH 8
78 
79 #define	EFX_BYTE_2_LBN 16
80 #define	EFX_BYTE_2_WIDTH 8
81 
82 #define	EFX_BYTE_3_LBN 24
83 #define	EFX_BYTE_3_WIDTH 8
84 
85 #define	EFX_BYTE_4_LBN 32
86 #define	EFX_BYTE_4_WIDTH 8
87 
88 #define	EFX_BYTE_5_LBN 40
89 #define	EFX_BYTE_5_WIDTH 8
90 
91 #define	EFX_BYTE_6_LBN 48
92 #define	EFX_BYTE_6_WIDTH 8
93 
94 #define	EFX_BYTE_7_LBN 56
95 #define	EFX_BYTE_7_WIDTH 8
96 
97 #define	EFX_WORD_0_LBN 0
98 #define	EFX_WORD_0_WIDTH 16
99 
100 #define	EFX_WORD_1_LBN 16
101 #define	EFX_WORD_1_WIDTH 16
102 
103 #define	EFX_WORD_2_LBN 32
104 #define	EFX_WORD_2_WIDTH 16
105 
106 #define	EFX_WORD_3_LBN 48
107 #define	EFX_WORD_3_WIDTH 16
108 
109 #define	EFX_DWORD_0_LBN 0
110 #define	EFX_DWORD_0_WIDTH 32
111 
112 #define	EFX_DWORD_1_LBN 32
113 #define	EFX_DWORD_1_WIDTH 32
114 
115 #define	EFX_DWORD_2_LBN 64
116 #define	EFX_DWORD_2_WIDTH 32
117 
118 #define	EFX_DWORD_3_LBN 96
119 #define	EFX_DWORD_3_WIDTH 32
120 
121 /*
122  * There are intentionally no EFX_QWORD_0 or EFX_QWORD_1 field definitions
123  * here as the implementaion of EFX_QWORD_FIELD and EFX_OWORD_FIELD do not
124  * support field widths larger than 32 bits.
125  */
126 
127 /* Specified attribute (i.e. LBN ow WIDTH) of the specified field */
128 #define	EFX_VAL(_field, _attribute)					\
129 	_field ## _ ## _attribute
130 
131 /* Lowest bit number of the specified field */
132 #define	EFX_LOW_BIT(_field)						\
133 	EFX_VAL(_field, LBN)
134 
135 /* Width of the specified field */
136 #define	EFX_WIDTH(_field)						\
137 	EFX_VAL(_field, WIDTH)
138 
139 /* Highest bit number of the specified field */
140 #define	EFX_HIGH_BIT(_field)						\
141 	(EFX_LOW_BIT(_field) + EFX_WIDTH(_field) - 1)
142 
143 /*
144  * 64-bit mask equal in width to the specified field.
145  *
146  * For example, a field with width 5 would have a mask of 0x000000000000001f.
147  */
148 #define	EFX_MASK64(_field)						\
149 	((EFX_WIDTH(_field) == 64) ? ~((uint64_t)0) :			\
150 	    (((((uint64_t)1) << EFX_WIDTH(_field))) - 1))
151 /*
152  * 32-bit mask equal in width to the specified field.
153  *
154  * For example, a field with width 5 would have a mask of 0x0000001f.
155  */
156 #define	EFX_MASK32(_field)						\
157 	((EFX_WIDTH(_field) == 32) ? ~((uint32_t)0) :			\
158 	    (((((uint32_t)1) << EFX_WIDTH(_field))) - 1))
159 
160 /*
161  * 16-bit mask equal in width to the specified field.
162  *
163  * For example, a field with width 5 would have a mask of 0x001f.
164  */
165 #define	EFX_MASK16(_field)						\
166 	((EFX_WIDTH(_field) == 16) ? 0xffffu :				\
167 	    (uint16_t)((1 << EFX_WIDTH(_field)) - 1))
168 
169 /*
170  * 8-bit mask equal in width to the specified field.
171  *
172  * For example, a field with width 5 would have a mask of 0x1f.
173  */
174 #define	EFX_MASK8(_field)						\
175 	((uint8_t)((1 << EFX_WIDTH(_field)) - 1))
176 
177 #pragma pack(1)
178 
179 /*
180  * A byte (i.e. 8-bit) datatype
181  */
182 typedef union efx_byte_u {
183 	uint8_t eb_u8[1];
184 } efx_byte_t;
185 
186 /*
187  * A word (i.e. 16-bit) datatype
188  *
189  * This datatype is defined to be little-endian.
190  */
191 typedef union efx_word_u {
192 	efx_byte_t ew_byte[2];
193 	uint16_t ew_u16[1];
194 	uint8_t ew_u8[2];
195 } efx_word_t;
196 
197 /*
198  * A doubleword (i.e. 32-bit) datatype
199  *
200  * This datatype is defined to be little-endian.
201  */
202 typedef union efx_dword_u {
203 	efx_byte_t ed_byte[4];
204 	efx_word_t ed_word[2];
205 	uint32_t ed_u32[1];
206 	uint16_t ed_u16[2];
207 	uint8_t ed_u8[4];
208 } efx_dword_t;
209 
210 /*
211  * A quadword (i.e. 64-bit) datatype
212  *
213  * This datatype is defined to be little-endian.
214  */
215 typedef union efx_qword_u {
216 	efx_byte_t eq_byte[8];
217 	efx_word_t eq_word[4];
218 	efx_dword_t eq_dword[2];
219 #if EFSYS_HAS_UINT64
220 	uint64_t eq_u64[1];
221 #endif
222 	uint32_t eq_u32[2];
223 	uint16_t eq_u16[4];
224 	uint8_t eq_u8[8];
225 } efx_qword_t;
226 
227 /*
228  * An octword (i.e. 128-bit) datatype
229  *
230  * This datatype is defined to be little-endian.
231  */
232 typedef union efx_oword_u {
233 	efx_byte_t eo_byte[16];
234 	efx_word_t eo_word[8];
235 	efx_dword_t eo_dword[4];
236 	efx_qword_t eo_qword[2];
237 #if EFSYS_HAS_SSE2_M128
238 	__m128i eo_u128[1];
239 #endif
240 #if EFSYS_HAS_UINT64
241 	uint64_t eo_u64[2];
242 #endif
243 	uint32_t eo_u32[4];
244 	uint16_t eo_u16[8];
245 	uint8_t eo_u8[16];
246 } efx_oword_t;
247 
248 #pragma pack()
249 
250 #define	__SWAP16(_x)				\
251 	((((_x) & 0xff) << 8) |			\
252 	(((_x) >> 8) & 0xff))
253 
254 #define	__SWAP32(_x)				\
255 	((__SWAP16((_x) & 0xffff) << 16) |	\
256 	__SWAP16(((_x) >> 16) & 0xffff))
257 
258 #define	__SWAP64(_x)				\
259 	((__SWAP32((_x) & 0xffffffff) << 32) |	\
260 	__SWAP32(((_x) >> 32) & 0xffffffff))
261 
262 #define	__NOSWAP16(_x)		(_x)
263 #define	__NOSWAP32(_x)		(_x)
264 #define	__NOSWAP64(_x)		(_x)
265 
266 #if EFSYS_IS_BIG_ENDIAN
267 
268 #define	__CPU_TO_LE_16(_x)	((uint16_t)__SWAP16(_x))
269 #define	__LE_TO_CPU_16(_x)	((uint16_t)__SWAP16(_x))
270 #define	__CPU_TO_BE_16(_x)	((uint16_t)__NOSWAP16(_x))
271 #define	__BE_TO_CPU_16(_x)	((uint16_t)__NOSWAP16(_x))
272 
273 #define	__CPU_TO_LE_32(_x)	((uint32_t)__SWAP32(_x))
274 #define	__LE_TO_CPU_32(_x)	((uint32_t)__SWAP32(_x))
275 #define	__CPU_TO_BE_32(_x)	((uint32_t)__NOSWAP32(_x))
276 #define	__BE_TO_CPU_32(_x)	((uint32_t)__NOSWAP32(_x))
277 
278 #define	__CPU_TO_LE_64(_x)	((uint64_t)__SWAP64(_x))
279 #define	__LE_TO_CPU_64(_x)	((uint64_t)__SWAP64(_x))
280 #define	__CPU_TO_BE_64(_x)	((uint64_t)__NOSWAP64(_x))
281 #define	__BE_TO_CPU_64(_x)	((uint64_t)__NOSWAP64(_x))
282 
283 #elif EFSYS_IS_LITTLE_ENDIAN
284 
285 #define	__CPU_TO_LE_16(_x)	((uint16_t)__NOSWAP16(_x))
286 #define	__LE_TO_CPU_16(_x)	((uint16_t)__NOSWAP16(_x))
287 #define	__CPU_TO_BE_16(_x)	((uint16_t)__SWAP16(_x))
288 #define	__BE_TO_CPU_16(_x)	((uint16_t)__SWAP16(_x))
289 
290 #define	__CPU_TO_LE_32(_x)	((uint32_t)__NOSWAP32(_x))
291 #define	__LE_TO_CPU_32(_x)	((uint32_t)__NOSWAP32(_x))
292 #define	__CPU_TO_BE_32(_x)	((uint32_t)__SWAP32(_x))
293 #define	__BE_TO_CPU_32(_x)	((uint32_t)__SWAP32(_x))
294 
295 #define	__CPU_TO_LE_64(_x)	((uint64_t)__NOSWAP64(_x))
296 #define	__LE_TO_CPU_64(_x)	((uint64_t)__NOSWAP64(_x))
297 #define	__CPU_TO_BE_64(_x)	((uint64_t)__SWAP64(_x))
298 #define	__BE_TO_CPU_64(_x)	((uint64_t)__SWAP64(_x))
299 
300 #else
301 
302 #error "Neither of EFSYS_IS_{BIG,LITTLE}_ENDIAN is set"
303 
304 #endif
305 
306 #define	__NATIVE_8(_x)	(uint8_t)(_x)
307 
308 /* Format string for printing an efx_byte_t */
309 #define	EFX_BYTE_FMT "0x%02x"
310 
311 /* Format string for printing an efx_word_t */
312 #define	EFX_WORD_FMT "0x%04x"
313 
314 /* Format string for printing an efx_dword_t */
315 #define	EFX_DWORD_FMT "0x%08x"
316 
317 /* Format string for printing an efx_qword_t */
318 #define	EFX_QWORD_FMT "0x%08x:%08x"
319 
320 /* Format string for printing an efx_oword_t */
321 #define	EFX_OWORD_FMT "0x%08x:%08x:%08x:%08x"
322 
323 /* Parameters for printing an efx_byte_t */
324 #define	EFX_BYTE_VAL(_byte)					\
325 	((unsigned int)__NATIVE_8((_byte).eb_u8[0]))
326 
327 /* Parameters for printing an efx_word_t */
328 #define	EFX_WORD_VAL(_word)					\
329 	((unsigned int)__LE_TO_CPU_16((_word).ew_u16[0]))
330 
331 /* Parameters for printing an efx_dword_t */
332 #define	EFX_DWORD_VAL(_dword)					\
333 	((unsigned int)__LE_TO_CPU_32((_dword).ed_u32[0]))
334 
335 /* Parameters for printing an efx_qword_t */
336 #define	EFX_QWORD_VAL(_qword)					\
337 	((unsigned int)__LE_TO_CPU_32((_qword).eq_u32[1])),	\
338 	((unsigned int)__LE_TO_CPU_32((_qword).eq_u32[0]))
339 
340 /* Parameters for printing an efx_oword_t */
341 #define	EFX_OWORD_VAL(_oword)					\
342 	((unsigned int)__LE_TO_CPU_32((_oword).eo_u32[3])),	\
343 	((unsigned int)__LE_TO_CPU_32((_oword).eo_u32[2])),	\
344 	((unsigned int)__LE_TO_CPU_32((_oword).eo_u32[1])),	\
345 	((unsigned int)__LE_TO_CPU_32((_oword).eo_u32[0]))
346 
347 /*
348  * Stop lint complaining about some shifts.
349  */
350 #ifdef	__lint
351 extern int fix_lint;
352 #define	FIX_LINT(_x)	(_x + fix_lint)
353 #else
354 #define	FIX_LINT(_x)	(_x)
355 #endif
356 
357 /*
358  * Saturation arithmetic subtract with minimum equal to zero.
359  *
360  * Use saturating arithmetic to ensure a non-negative result. This
361  * avoids undefined behaviour (and compiler warnings) when used as a
362  * shift count.
363  */
364 #define	EFX_SSUB(_val, _sub) \
365 	((_val) > (_sub) ? ((_val) - (_sub)) : 0)
366 
367 /*
368  * Extract bit field portion [low,high) from the native-endian element
369  * which contains bits [min,max).
370  *
371  * For example, suppose "element" represents the high 32 bits of a
372  * 64-bit value, and we wish to extract the bits belonging to the bit
373  * field occupying bits 28-45 of this 64-bit value.
374  *
375  * Then EFX_EXTRACT(_element, 32, 63, 28, 45) would give
376  *
377  *   (_element) << 4
378  *
379  * The result will contain the relevant bits filled in in the range
380  * [0,high-low), with garbage in bits [high-low+1,...).
381  */
382 #define	EFX_EXTRACT_NATIVE(_element, _min, _max, _low, _high)		\
383 	((FIX_LINT(_low > _max) || FIX_LINT(_high < _min)) ?		\
384 		0U :							\
385 		((_low > _min) ?					\
386 			((_element) >> EFX_SSUB(_low, _min)) :		\
387 			((_element) << EFX_SSUB(_min, _low))))
388 
389 /*
390  * Extract bit field portion [low,high) from the 64-bit little-endian
391  * element which contains bits [min,max)
392  */
393 #define	EFX_EXTRACT64(_element, _min, _max, _low, _high)		\
394 	EFX_EXTRACT_NATIVE(__LE_TO_CPU_64(_element), _min, _max, _low, _high)
395 
396 /*
397  * Extract bit field portion [low,high) from the 32-bit little-endian
398  * element which contains bits [min,max)
399  */
400 #define	EFX_EXTRACT32(_element, _min, _max, _low, _high)		\
401 	EFX_EXTRACT_NATIVE(__LE_TO_CPU_32(_element), _min, _max, _low, _high)
402 
403 /*
404  * Extract bit field portion [low,high) from the 16-bit little-endian
405  * element which contains bits [min,max)
406  */
407 #define	EFX_EXTRACT16(_element, _min, _max, _low, _high)		\
408 	EFX_EXTRACT_NATIVE(__LE_TO_CPU_16(_element), _min, _max, _low, _high)
409 
410 /*
411  * Extract bit field portion [low,high) from the 8-bit
412  * element which contains bits [min,max)
413  */
414 #define	EFX_EXTRACT8(_element, _min, _max, _low, _high)			\
415 	EFX_EXTRACT_NATIVE(__NATIVE_8(_element), _min, _max, _low, _high)
416 
417 #define	EFX_EXTRACT_OWORD64(_oword, _low, _high)			\
418 	(EFX_EXTRACT64((_oword).eo_u64[0], FIX_LINT(0), FIX_LINT(63),	\
419 	    _low, _high) |						\
420 	EFX_EXTRACT64((_oword).eo_u64[1], FIX_LINT(64), FIX_LINT(127),	\
421 	    _low, _high))
422 
423 #define	EFX_EXTRACT_OWORD32(_oword, _low, _high)			\
424 	(EFX_EXTRACT32((_oword).eo_u32[0], FIX_LINT(0), FIX_LINT(31),	\
425 	    _low, _high) |						\
426 	EFX_EXTRACT32((_oword).eo_u32[1], FIX_LINT(32), FIX_LINT(63),	\
427 	    _low, _high) |						\
428 	EFX_EXTRACT32((_oword).eo_u32[2], FIX_LINT(64), FIX_LINT(95),	\
429 	    _low, _high) |						\
430 	EFX_EXTRACT32((_oword).eo_u32[3], FIX_LINT(96), FIX_LINT(127),	\
431 	    _low, _high))
432 
433 #define	EFX_EXTRACT_QWORD64(_qword, _low, _high)			\
434 	(EFX_EXTRACT64((_qword).eq_u64[0], FIX_LINT(0), FIX_LINT(63),	\
435 	    _low, _high))
436 
437 #define	EFX_EXTRACT_QWORD32(_qword, _low, _high)			\
438 	(EFX_EXTRACT32((_qword).eq_u32[0], FIX_LINT(0), FIX_LINT(31),	\
439 	    _low, _high) |						\
440 	EFX_EXTRACT32((_qword).eq_u32[1], FIX_LINT(32), FIX_LINT(63),	\
441 	    _low, _high))
442 
443 #define	EFX_EXTRACT_DWORD(_dword, _low, _high)				\
444 	(EFX_EXTRACT32((_dword).ed_u32[0], FIX_LINT(0), FIX_LINT(31),	\
445 	    _low, _high))
446 
447 #define	EFX_EXTRACT_WORD(_word, _low, _high)				\
448 	(EFX_EXTRACT16((_word).ew_u16[0], FIX_LINT(0), FIX_LINT(15),	\
449 	    _low, _high))
450 
451 #define	EFX_EXTRACT_BYTE(_byte, _low, _high)				\
452 	(EFX_EXTRACT8((_byte).eb_u8[0], FIX_LINT(0), FIX_LINT(7),	\
453 	    _low, _high))
454 
455 #define	EFX_OWORD_FIELD64(_oword, _field)				\
456 	((uint32_t)EFX_EXTRACT_OWORD64(_oword, EFX_LOW_BIT(_field),	\
457 	    EFX_HIGH_BIT(_field)) & EFX_MASK32(_field))
458 
459 #define	EFX_OWORD_FIELD32(_oword, _field)				\
460 	(EFX_EXTRACT_OWORD32(_oword, EFX_LOW_BIT(_field),		\
461 	    EFX_HIGH_BIT(_field)) & EFX_MASK32(_field))
462 
463 #define	EFX_QWORD_FIELD64(_qword, _field)				\
464 	((uint32_t)EFX_EXTRACT_QWORD64(_qword, EFX_LOW_BIT(_field),	\
465 	    EFX_HIGH_BIT(_field)) & EFX_MASK32(_field))
466 
467 #define	EFX_QWORD_FIELD32(_qword, _field)				\
468 	(EFX_EXTRACT_QWORD32(_qword, EFX_LOW_BIT(_field),		\
469 	    EFX_HIGH_BIT(_field)) & EFX_MASK32(_field))
470 
471 #define	EFX_DWORD_FIELD(_dword, _field)					\
472 	(EFX_EXTRACT_DWORD(_dword, EFX_LOW_BIT(_field),			\
473 	    EFX_HIGH_BIT(_field)) & EFX_MASK32(_field))
474 
475 #define	EFX_WORD_FIELD(_word, _field)					\
476 	(EFX_EXTRACT_WORD(_word, EFX_LOW_BIT(_field),			\
477 	    EFX_HIGH_BIT(_field)) & EFX_MASK16(_field))
478 
479 #define	EFX_BYTE_FIELD(_byte, _field)					\
480 	(EFX_EXTRACT_BYTE(_byte, EFX_LOW_BIT(_field),			\
481 	    EFX_HIGH_BIT(_field)) & EFX_MASK8(_field))
482 
483 #define	EFX_OWORD_IS_EQUAL64(_oword_a, _oword_b)			\
484 	((_oword_a).eo_u64[0] == (_oword_b).eo_u64[0] &&		\
485 	    (_oword_a).eo_u64[1] == (_oword_b).eo_u64[1])
486 
487 #define	EFX_OWORD_IS_EQUAL32(_oword_a, _oword_b)			\
488 	((_oword_a).eo_u32[0] == (_oword_b).eo_u32[0] &&		\
489 	    (_oword_a).eo_u32[1] == (_oword_b).eo_u32[1] &&		\
490 	    (_oword_a).eo_u32[2] == (_oword_b).eo_u32[2] &&		\
491 	    (_oword_a).eo_u32[3] == (_oword_b).eo_u32[3])
492 
493 #define	EFX_QWORD_IS_EQUAL64(_qword_a, _qword_b)			\
494 	((_qword_a).eq_u64[0] == (_qword_b).eq_u64[0])
495 
496 #define	EFX_QWORD_IS_EQUAL32(_qword_a, _qword_b)			\
497 	((_qword_a).eq_u32[0] == (_qword_b).eq_u32[0] &&		\
498 	    (_qword_a).eq_u32[1] == (_qword_b).eq_u32[1])
499 
500 #define	EFX_DWORD_IS_EQUAL(_dword_a, _dword_b)				\
501 	((_dword_a).ed_u32[0] == (_dword_b).ed_u32[0])
502 
503 #define	EFX_WORD_IS_EQUAL(_word_a, _word_b)				\
504 	((_word_a).ew_u16[0] == (_word_b).ew_u16[0])
505 
506 #define	EFX_BYTE_IS_EQUAL(_byte_a, _byte_b)				\
507 	((_byte_a).eb_u8[0] == (_byte_b).eb_u8[0])
508 
509 #define	EFX_OWORD_IS_ZERO64(_oword)					\
510 	(((_oword).eo_u64[0] |						\
511 	    (_oword).eo_u64[1]) == 0)
512 
513 #define	EFX_OWORD_IS_ZERO32(_oword)					\
514 	(((_oword).eo_u32[0] |						\
515 	    (_oword).eo_u32[1] |					\
516 	    (_oword).eo_u32[2] |					\
517 	    (_oword).eo_u32[3]) == 0)
518 
519 #define	EFX_QWORD_IS_ZERO64(_qword)					\
520 	(((_qword).eq_u64[0]) == 0)
521 
522 #define	EFX_QWORD_IS_ZERO32(_qword)					\
523 	(((_qword).eq_u32[0] |						\
524 	    (_qword).eq_u32[1]) == 0)
525 
526 #define	EFX_DWORD_IS_ZERO(_dword)					\
527 	(((_dword).ed_u32[0]) == 0)
528 
529 #define	EFX_WORD_IS_ZERO(_word)						\
530 	(((_word).ew_u16[0]) == 0)
531 
532 #define	EFX_BYTE_IS_ZERO(_byte)						\
533 	(((_byte).eb_u8[0]) == 0)
534 
535 #define	EFX_OWORD_IS_SET64(_oword)					\
536 	(((_oword).eo_u64[0] &						\
537 	    (_oword).eo_u64[1]) == ~((uint64_t)0))
538 
539 #define	EFX_OWORD_IS_SET32(_oword)					\
540 	(((_oword).eo_u32[0] &						\
541 	    (_oword).eo_u32[1] &					\
542 	    (_oword).eo_u32[2] &					\
543 	    (_oword).eo_u32[3]) == ~((uint32_t)0))
544 
545 #define	EFX_QWORD_IS_SET64(_qword)					\
546 	(((_qword).eq_u64[0]) == ~((uint64_t)0))
547 
548 #define	EFX_QWORD_IS_SET32(_qword)					\
549 	(((_qword).eq_u32[0] &						\
550 	    (_qword).eq_u32[1]) == ~((uint32_t)0))
551 
552 #define	EFX_DWORD_IS_SET(_dword)					\
553 	((_dword).ed_u32[0] == ~((uint32_t)0))
554 
555 #define	EFX_WORD_IS_SET(_word)						\
556 	((_word).ew_u16[0] == ~((uint16_t)0))
557 
558 #define	EFX_BYTE_IS_SET(_byte)						\
559 	((_byte).eb_u8[0] == ~((uint8_t)0))
560 
561 /*
562  * Construct bit field portion
563  *
564  * Creates the portion of the bit field [low,high) that lies within
565  * the range [min,max).
566  */
567 
568 #define	EFX_INSERT_NATIVE64(_min, _max, _low, _high, _value)		\
569 	(((_low > _max) || (_high < _min)) ?				\
570 		0U :							\
571 		((_low > _min) ?					\
572 			(((uint64_t)(_value)) << EFX_SSUB(_low, _min)) :\
573 			(((uint64_t)(_value)) >> EFX_SSUB(_min, _low))))
574 
575 #define	EFX_INSERT_NATIVE32(_min, _max, _low, _high, _value)		\
576 	(((_low > _max) || (_high < _min)) ?				\
577 		0U :							\
578 		((_low > _min) ?					\
579 			(((uint32_t)(_value)) << EFX_SSUB(_low, _min)) :\
580 			(((uint32_t)(_value)) >> EFX_SSUB(_min, _low))))
581 
582 #define	EFX_INSERT_NATIVE16(_min, _max, _low, _high, _value)		\
583 	(((_low > _max) || (_high < _min)) ?				\
584 		0U :							\
585 		(uint16_t)((_low > _min) ?				\
586 				((_value) << EFX_SSUB(_low, _min)) :	\
587 				((_value) >> EFX_SSUB(_min, _low))))
588 
589 #define	EFX_INSERT_NATIVE8(_min, _max, _low, _high, _value)		\
590 	(((_low > _max) || (_high < _min)) ?				\
591 		0U :							\
592 		(uint8_t)((_low > _min) ?				\
593 				((_value) << EFX_SSUB(_low, _min)) :	\
594 				((_value) >> EFX_SSUB(_min, _low))))
595 
596 /*
597  * Construct bit field portion
598  *
599  * Creates the portion of the named bit field that lies within the
600  * range [min,max).
601  */
602 #define	EFX_INSERT_FIELD_NATIVE64(_min, _max, _field, _value)		\
603 	EFX_INSERT_NATIVE64(_min, _max, EFX_LOW_BIT(_field),		\
604 	    EFX_HIGH_BIT(_field), _value)
605 
606 #define	EFX_INSERT_FIELD_NATIVE32(_min, _max, _field, _value)		\
607 	EFX_INSERT_NATIVE32(_min, _max, EFX_LOW_BIT(_field),		\
608 	    EFX_HIGH_BIT(_field), _value)
609 
610 #define	EFX_INSERT_FIELD_NATIVE16(_min, _max, _field, _value)		\
611 	EFX_INSERT_NATIVE16(_min, _max, EFX_LOW_BIT(_field),		\
612 	    EFX_HIGH_BIT(_field), _value)
613 
614 #define	EFX_INSERT_FIELD_NATIVE8(_min, _max, _field, _value)		\
615 	EFX_INSERT_NATIVE8(_min, _max, EFX_LOW_BIT(_field),		\
616 	    EFX_HIGH_BIT(_field), _value)
617 
618 /*
619  * Construct bit field
620  *
621  * Creates the portion of the named bit fields that lie within the
622  * range [min,max).
623  */
624 #define	EFX_INSERT_FIELDS64(_min, _max,					\
625 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
626 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
627 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
628 	    _field10, _value10)						\
629 	__CPU_TO_LE_64(							\
630 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field1, _value1) |	\
631 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field2, _value2) |	\
632 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field3, _value3) |	\
633 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field4, _value4) |	\
634 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field5, _value5) |	\
635 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field6, _value6) |	\
636 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field7, _value7) |	\
637 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field8, _value8) |	\
638 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field9, _value9) |	\
639 	    EFX_INSERT_FIELD_NATIVE64(_min, _max, _field10, _value10))
640 
641 #define	EFX_INSERT_FIELDS32(_min, _max,					\
642 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
643 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
644 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
645 	    _field10, _value10)						\
646 	__CPU_TO_LE_32(							\
647 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field1, _value1) |	\
648 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field2, _value2) |	\
649 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field3, _value3) |	\
650 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field4, _value4) |	\
651 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field5, _value5) |	\
652 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field6, _value6) |	\
653 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field7, _value7) |	\
654 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field8, _value8) |	\
655 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field9, _value9) |	\
656 	    EFX_INSERT_FIELD_NATIVE32(_min, _max, _field10, _value10))
657 
658 #define	EFX_INSERT_FIELDS16(_min, _max,					\
659 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
660 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
661 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
662 	    _field10, _value10)						\
663 	__CPU_TO_LE_16(							\
664 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field1, _value1) |	\
665 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field2, _value2) |	\
666 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field3, _value3) |	\
667 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field4, _value4) |	\
668 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field5, _value5) |	\
669 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field6, _value6) |	\
670 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field7, _value7) |	\
671 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field8, _value8) |	\
672 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field9, _value9) |	\
673 	    EFX_INSERT_FIELD_NATIVE16(_min, _max, _field10, _value10))
674 
675 #define	EFX_INSERT_FIELDS8(_min, _max,					\
676 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
677 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
678 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
679 	    _field10, _value10)						\
680 	__NATIVE_8(							\
681 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field1, _value1) |	\
682 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field2, _value2) |	\
683 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field3, _value3) |	\
684 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field4, _value4) |	\
685 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field5, _value5) |	\
686 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field6, _value6) |	\
687 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field7, _value7) |	\
688 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field8, _value8) |	\
689 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field9, _value9) |	\
690 	    EFX_INSERT_FIELD_NATIVE8(_min, _max, _field10, _value10))
691 
692 #define	EFX_POPULATE_OWORD64(_oword,					\
693 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
694 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
695 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
696 	    _field10, _value10)						\
697 	do {								\
698 		_NOTE(CONSTANTCONDITION)				\
699 		(_oword).eo_u64[0] = EFX_INSERT_FIELDS64(0, 63,		\
700 		    _field1, _value1, _field2, _value2,			\
701 		    _field3, _value3, _field4, _value4,			\
702 		    _field5, _value5, _field6, _value6,			\
703 		    _field7, _value7, _field8, _value8,			\
704 		    _field9, _value9, _field10, _value10);		\
705 		_NOTE(CONSTANTCONDITION)				\
706 		(_oword).eo_u64[1] = EFX_INSERT_FIELDS64(64, 127,	\
707 		    _field1, _value1, _field2, _value2,			\
708 		    _field3, _value3, _field4, _value4,			\
709 		    _field5, _value5, _field6, _value6,			\
710 		    _field7, _value7, _field8, _value8,			\
711 		    _field9, _value9, _field10, _value10);		\
712 	_NOTE(CONSTANTCONDITION)					\
713 	} while (B_FALSE)
714 
715 #define	EFX_POPULATE_OWORD32(_oword,					\
716 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
717 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
718 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
719 	    _field10, _value10)						\
720 	do {								\
721 		_NOTE(CONSTANTCONDITION)				\
722 		(_oword).eo_u32[0] = EFX_INSERT_FIELDS32(0, 31,		\
723 		    _field1, _value1, _field2, _value2,			\
724 		    _field3, _value3, _field4, _value4,			\
725 		    _field5, _value5, _field6, _value6,			\
726 		    _field7, _value7, _field8, _value8,			\
727 		    _field9, _value9, _field10, _value10);		\
728 		_NOTE(CONSTANTCONDITION)				\
729 		(_oword).eo_u32[1] = EFX_INSERT_FIELDS32(32, 63,	\
730 		    _field1, _value1, _field2, _value2,			\
731 		    _field3, _value3, _field4, _value4,			\
732 		    _field5, _value5, _field6, _value6,			\
733 		    _field7, _value7, _field8, _value8,			\
734 		    _field9, _value9, _field10, _value10);		\
735 		_NOTE(CONSTANTCONDITION)				\
736 		(_oword).eo_u32[2] = EFX_INSERT_FIELDS32(64, 95,	\
737 		    _field1, _value1, _field2, _value2,			\
738 		    _field3, _value3, _field4, _value4,			\
739 		    _field5, _value5, _field6, _value6,			\
740 		    _field7, _value7, _field8, _value8,			\
741 		    _field9, _value9, _field10, _value10);		\
742 		_NOTE(CONSTANTCONDITION)				\
743 		(_oword).eo_u32[3] = EFX_INSERT_FIELDS32(96, 127,	\
744 		    _field1, _value1, _field2, _value2,			\
745 		    _field3, _value3, _field4, _value4,			\
746 		    _field5, _value5, _field6, _value6,			\
747 		    _field7, _value7, _field8, _value8,			\
748 		    _field9, _value9, _field10, _value10);		\
749 	_NOTE(CONSTANTCONDITION)					\
750 	} while (B_FALSE)
751 
752 #define	EFX_POPULATE_QWORD64(_qword,					\
753 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
754 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
755 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
756 	    _field10, _value10)						\
757 	do {								\
758 		_NOTE(CONSTANTCONDITION)				\
759 		(_qword).eq_u64[0] = EFX_INSERT_FIELDS64(0, 63,		\
760 		    _field1, _value1, _field2, _value2,			\
761 		    _field3, _value3, _field4, _value4,			\
762 		    _field5, _value5, _field6, _value6,			\
763 		    _field7, _value7, _field8, _value8,			\
764 		    _field9, _value9, _field10, _value10);		\
765 	_NOTE(CONSTANTCONDITION)					\
766 	} while (B_FALSE)
767 
768 #define	EFX_POPULATE_QWORD32(_qword,					\
769 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
770 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
771 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
772 	    _field10, _value10)						\
773 	do {								\
774 		_NOTE(CONSTANTCONDITION)				\
775 		(_qword).eq_u32[0] = EFX_INSERT_FIELDS32(0, 31,		\
776 		    _field1, _value1, _field2, _value2,			\
777 		    _field3, _value3, _field4, _value4,			\
778 		    _field5, _value5, _field6, _value6,			\
779 		    _field7, _value7, _field8, _value8,			\
780 		    _field9, _value9, _field10, _value10);		\
781 		_NOTE(CONSTANTCONDITION)				\
782 		(_qword).eq_u32[1] = EFX_INSERT_FIELDS32(32, 63,	\
783 		    _field1, _value1, _field2, _value2,			\
784 		    _field3, _value3, _field4, _value4,			\
785 		    _field5, _value5, _field6, _value6,			\
786 		    _field7, _value7, _field8, _value8,			\
787 		    _field9, _value9, _field10, _value10);		\
788 	_NOTE(CONSTANTCONDITION)					\
789 	} while (B_FALSE)
790 
791 #define	EFX_POPULATE_DWORD(_dword,					\
792 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
793 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
794 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
795 	    _field10, _value10)						\
796 	do {								\
797 		_NOTE(CONSTANTCONDITION)				\
798 		(_dword).ed_u32[0] = EFX_INSERT_FIELDS32(0, 31,		\
799 		    _field1, _value1, _field2, _value2,			\
800 		    _field3, _value3, _field4, _value4,			\
801 		    _field5, _value5, _field6, _value6,			\
802 		    _field7, _value7, _field8, _value8,			\
803 		    _field9, _value9, _field10, _value10);		\
804 	_NOTE(CONSTANTCONDITION)					\
805 	} while (B_FALSE)
806 
807 #define	EFX_POPULATE_WORD(_word,					\
808 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
809 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
810 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
811 	    _field10, _value10)						\
812 	do {								\
813 		_NOTE(CONSTANTCONDITION)				\
814 		(_word).ew_u16[0] = EFX_INSERT_FIELDS16(0, 15,		\
815 		    _field1, _value1, _field2, _value2,			\
816 		    _field3, _value3, _field4, _value4,			\
817 		    _field5, _value5, _field6, _value6,			\
818 		    _field7, _value7, _field8, _value8,			\
819 		    _field9, _value9, _field10, _value10);		\
820 	_NOTE(CONSTANTCONDITION)					\
821 	} while (B_FALSE)
822 
823 #define	EFX_POPULATE_BYTE(_byte,					\
824 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
825 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
826 	    _field7, _value7, _field8, _value8,	_field9, _value9,	\
827 	    _field10, _value10)						\
828 	do {								\
829 		_NOTE(CONSTANTCONDITION)				\
830 		(_byte).eb_u8[0] = EFX_INSERT_FIELDS8(0, 7,		\
831 		    _field1, _value1, _field2, _value2,			\
832 		    _field3, _value3, _field4, _value4,			\
833 		    _field5, _value5, _field6, _value6,			\
834 		    _field7, _value7, _field8, _value8,			\
835 		    _field9, _value9, _field10, _value10);		\
836 	_NOTE(CONSTANTCONDITION)					\
837 	} while (B_FALSE)
838 
839 /* Populate an octword field with various numbers of arguments */
840 #define	EFX_POPULATE_OWORD_10 EFX_POPULATE_OWORD
841 
842 #define	EFX_POPULATE_OWORD_9(_oword,					\
843 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
844 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
845 	    _field7, _value7, _field8, _value8,	_field9, _value9)	\
846 	EFX_POPULATE_OWORD_10(_oword, EFX_DUMMY_FIELD, 0,		\
847 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
848 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
849 	    _field7, _value7, _field8, _value8,	_field9, _value9)
850 
851 #define	EFX_POPULATE_OWORD_8(_oword,					\
852 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
853 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
854 	    _field7, _value7, _field8, _value8)				\
855 	EFX_POPULATE_OWORD_9(_oword, EFX_DUMMY_FIELD, 0,		\
856 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
857 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
858 	    _field7, _value7, _field8, _value8)
859 
860 #define	EFX_POPULATE_OWORD_7(_oword,					\
861 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
862 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
863 	    _field7, _value7)						\
864 	EFX_POPULATE_OWORD_8(_oword, EFX_DUMMY_FIELD, 0,		\
865 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
866 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
867 	    _field7, _value7)
868 
869 #define	EFX_POPULATE_OWORD_6(_oword,					\
870 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
871 	    _field4, _value4, _field5, _value5,	_field6, _value6)	\
872 	EFX_POPULATE_OWORD_7(_oword, EFX_DUMMY_FIELD, 0,		\
873 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
874 	    _field4, _value4, _field5, _value5,	_field6, _value6)
875 
876 #define	EFX_POPULATE_OWORD_5(_oword,					\
877 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
878 	    _field4, _value4, _field5, _value5)				\
879 	EFX_POPULATE_OWORD_6(_oword, EFX_DUMMY_FIELD, 0,		\
880 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
881 	    _field4, _value4, _field5, _value5)
882 
883 #define	EFX_POPULATE_OWORD_4(_oword,					\
884 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
885 	    _field4, _value4)						\
886 	EFX_POPULATE_OWORD_5(_oword, EFX_DUMMY_FIELD, 0,		\
887 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
888 	    _field4, _value4)
889 
890 #define	EFX_POPULATE_OWORD_3(_oword,					\
891 	    _field1, _value1, _field2, _value2, _field3, _value3)	\
892 	EFX_POPULATE_OWORD_4(_oword, EFX_DUMMY_FIELD, 0,		\
893 	    _field1, _value1, _field2, _value2, _field3, _value3)
894 
895 #define	EFX_POPULATE_OWORD_2(_oword,					\
896 	    _field1, _value1, _field2, _value2)				\
897 	EFX_POPULATE_OWORD_3(_oword, EFX_DUMMY_FIELD, 0,		\
898 	    _field1, _value1, _field2, _value2)
899 
900 #define	EFX_POPULATE_OWORD_1(_oword,					\
901 	    _field1, _value1)						\
902 	EFX_POPULATE_OWORD_2(_oword, EFX_DUMMY_FIELD, 0,		\
903 	    _field1, _value1)
904 
905 #define	EFX_ZERO_OWORD(_oword)						\
906 	EFX_POPULATE_OWORD_1(_oword, EFX_DUMMY_FIELD, 0)
907 
908 #define	EFX_SET_OWORD(_oword)						\
909 	EFX_POPULATE_OWORD_4(_oword,					\
910 	    EFX_DWORD_0, 0xffffffff, EFX_DWORD_1, 0xffffffff,		\
911 	    EFX_DWORD_2, 0xffffffff, EFX_DWORD_3, 0xffffffff)
912 
913 /* Populate a quadword field with various numbers of arguments */
914 #define	EFX_POPULATE_QWORD_10 EFX_POPULATE_QWORD
915 
916 #define	EFX_POPULATE_QWORD_9(_qword,					\
917 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
918 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
919 	    _field7, _value7, _field8, _value8,	_field9, _value9)	\
920 	EFX_POPULATE_QWORD_10(_qword, EFX_DUMMY_FIELD, 0,		\
921 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
922 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
923 	    _field7, _value7, _field8, _value8,	_field9, _value9)
924 
925 #define	EFX_POPULATE_QWORD_8(_qword,					\
926 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
927 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
928 	    _field7, _value7, _field8, _value8)				\
929 	EFX_POPULATE_QWORD_9(_qword, EFX_DUMMY_FIELD, 0,		\
930 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
931 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
932 	    _field7, _value7, _field8, _value8)
933 
934 #define	EFX_POPULATE_QWORD_7(_qword,					\
935 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
936 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
937 	    _field7, _value7)						\
938 	EFX_POPULATE_QWORD_8(_qword, EFX_DUMMY_FIELD, 0,		\
939 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
940 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
941 	    _field7, _value7)
942 
943 #define	EFX_POPULATE_QWORD_6(_qword,					\
944 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
945 	    _field4, _value4, _field5, _value5,	_field6, _value6)	\
946 	EFX_POPULATE_QWORD_7(_qword, EFX_DUMMY_FIELD, 0,		\
947 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
948 	    _field4, _value4, _field5, _value5,	_field6, _value6)
949 
950 #define	EFX_POPULATE_QWORD_5(_qword,					\
951 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
952 	    _field4, _value4, _field5, _value5)				\
953 	EFX_POPULATE_QWORD_6(_qword, EFX_DUMMY_FIELD, 0,		\
954 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
955 	    _field4, _value4, _field5, _value5)
956 
957 #define	EFX_POPULATE_QWORD_4(_qword,					\
958 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
959 	    _field4, _value4)						\
960 	EFX_POPULATE_QWORD_5(_qword, EFX_DUMMY_FIELD, 0,		\
961 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
962 	    _field4, _value4)
963 
964 #define	EFX_POPULATE_QWORD_3(_qword,					\
965 	    _field1, _value1, _field2, _value2, _field3, _value3)	\
966 	EFX_POPULATE_QWORD_4(_qword, EFX_DUMMY_FIELD, 0,		\
967 	    _field1, _value1, _field2, _value2, _field3, _value3)
968 
969 #define	EFX_POPULATE_QWORD_2(_qword,					\
970 	    _field1, _value1, _field2, _value2)				\
971 	EFX_POPULATE_QWORD_3(_qword, EFX_DUMMY_FIELD, 0,		\
972 	    _field1, _value1, _field2, _value2)
973 
974 #define	EFX_POPULATE_QWORD_1(_qword,					\
975 	    _field1, _value1)						\
976 	EFX_POPULATE_QWORD_2(_qword, EFX_DUMMY_FIELD, 0,		\
977 	    _field1, _value1)
978 
979 #define	EFX_ZERO_QWORD(_qword)						\
980 	EFX_POPULATE_QWORD_1(_qword, EFX_DUMMY_FIELD, 0)
981 
982 #define	EFX_SET_QWORD(_qword)						\
983 	EFX_POPULATE_QWORD_2(_qword,					\
984 	    EFX_DWORD_0, 0xffffffff, EFX_DWORD_1, 0xffffffff)
985 
986 /* Populate a dword field with various numbers of arguments */
987 #define	EFX_POPULATE_DWORD_10 EFX_POPULATE_DWORD
988 
989 #define	EFX_POPULATE_DWORD_9(_dword,					\
990 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
991 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
992 	    _field7, _value7, _field8, _value8,	_field9, _value9)	\
993 	EFX_POPULATE_DWORD_10(_dword, EFX_DUMMY_FIELD, 0,		\
994 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
995 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
996 	    _field7, _value7, _field8, _value8,	_field9, _value9)
997 
998 #define	EFX_POPULATE_DWORD_8(_dword,					\
999 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1000 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1001 	    _field7, _value7, _field8, _value8)				\
1002 	EFX_POPULATE_DWORD_9(_dword, EFX_DUMMY_FIELD, 0,		\
1003 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1004 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1005 	    _field7, _value7, _field8, _value8)
1006 
1007 #define	EFX_POPULATE_DWORD_7(_dword,					\
1008 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1009 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1010 	    _field7, _value7)						\
1011 	EFX_POPULATE_DWORD_8(_dword, EFX_DUMMY_FIELD, 0,		\
1012 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1013 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1014 	    _field7, _value7)
1015 
1016 #define	EFX_POPULATE_DWORD_6(_dword,					\
1017 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1018 	    _field4, _value4, _field5, _value5,	_field6, _value6)	\
1019 	EFX_POPULATE_DWORD_7(_dword, EFX_DUMMY_FIELD, 0,		\
1020 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1021 	    _field4, _value4, _field5, _value5,	_field6, _value6)
1022 
1023 #define	EFX_POPULATE_DWORD_5(_dword,					\
1024 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1025 	    _field4, _value4, _field5, _value5)				\
1026 	EFX_POPULATE_DWORD_6(_dword, EFX_DUMMY_FIELD, 0,		\
1027 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1028 	    _field4, _value4, _field5, _value5)
1029 
1030 #define	EFX_POPULATE_DWORD_4(_dword,					\
1031 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1032 	    _field4, _value4)						\
1033 	EFX_POPULATE_DWORD_5(_dword, EFX_DUMMY_FIELD, 0,		\
1034 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1035 	    _field4, _value4)
1036 
1037 #define	EFX_POPULATE_DWORD_3(_dword,					\
1038 	    _field1, _value1, _field2, _value2, _field3, _value3)	\
1039 	EFX_POPULATE_DWORD_4(_dword, EFX_DUMMY_FIELD, 0,		\
1040 	    _field1, _value1, _field2, _value2, _field3, _value3)
1041 
1042 #define	EFX_POPULATE_DWORD_2(_dword,					\
1043 	    _field1, _value1, _field2, _value2)				\
1044 	EFX_POPULATE_DWORD_3(_dword, EFX_DUMMY_FIELD, 0,		\
1045 	    _field1, _value1, _field2, _value2)
1046 
1047 #define	EFX_POPULATE_DWORD_1(_dword,					\
1048 	    _field1, _value1)						\
1049 	EFX_POPULATE_DWORD_2(_dword, EFX_DUMMY_FIELD, 0,		\
1050 	    _field1, _value1)
1051 
1052 #define	EFX_ZERO_DWORD(_dword)						\
1053 	EFX_POPULATE_DWORD_1(_dword, EFX_DUMMY_FIELD, 0)
1054 
1055 #define	EFX_SET_DWORD(_dword)						\
1056 	EFX_POPULATE_DWORD_1(_dword,					\
1057 	    EFX_DWORD_0, 0xffffffff)
1058 
1059 /* Populate a word field with various numbers of arguments */
1060 #define	EFX_POPULATE_WORD_10 EFX_POPULATE_WORD
1061 
1062 #define	EFX_POPULATE_WORD_9(_word,					\
1063 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1064 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1065 	    _field7, _value7, _field8, _value8,	_field9, _value9)	\
1066 	EFX_POPULATE_WORD_10(_word, EFX_DUMMY_FIELD, 0,			\
1067 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1068 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1069 	    _field7, _value7, _field8, _value8,	_field9, _value9)
1070 
1071 #define	EFX_POPULATE_WORD_8(_word,					\
1072 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1073 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1074 	    _field7, _value7, _field8, _value8)				\
1075 	EFX_POPULATE_WORD_9(_word, EFX_DUMMY_FIELD, 0,			\
1076 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1077 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1078 	    _field7, _value7, _field8, _value8)
1079 
1080 #define	EFX_POPULATE_WORD_7(_word,					\
1081 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1082 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1083 	    _field7, _value7)						\
1084 	EFX_POPULATE_WORD_8(_word, EFX_DUMMY_FIELD, 0,			\
1085 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1086 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1087 	    _field7, _value7)
1088 
1089 #define	EFX_POPULATE_WORD_6(_word,					\
1090 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1091 	    _field4, _value4, _field5, _value5,	_field6, _value6)	\
1092 	EFX_POPULATE_WORD_7(_word, EFX_DUMMY_FIELD, 0,			\
1093 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1094 	    _field4, _value4, _field5, _value5,	_field6, _value6)
1095 
1096 #define	EFX_POPULATE_WORD_5(_word,					\
1097 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1098 	    _field4, _value4, _field5, _value5)				\
1099 	EFX_POPULATE_WORD_6(_word, EFX_DUMMY_FIELD, 0,			\
1100 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1101 	    _field4, _value4, _field5, _value5)
1102 
1103 #define	EFX_POPULATE_WORD_4(_word,					\
1104 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1105 	    _field4, _value4)						\
1106 	EFX_POPULATE_WORD_5(_word, EFX_DUMMY_FIELD, 0,			\
1107 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1108 	    _field4, _value4)
1109 
1110 #define	EFX_POPULATE_WORD_3(_word,					\
1111 	    _field1, _value1, _field2, _value2, _field3, _value3)	\
1112 	EFX_POPULATE_WORD_4(_word, EFX_DUMMY_FIELD, 0,			\
1113 	    _field1, _value1, _field2, _value2, _field3, _value3)
1114 
1115 #define	EFX_POPULATE_WORD_2(_word,					\
1116 	    _field1, _value1, _field2, _value2)				\
1117 	EFX_POPULATE_WORD_3(_word, EFX_DUMMY_FIELD, 0,			\
1118 	    _field1, _value1, _field2, _value2)
1119 
1120 #define	EFX_POPULATE_WORD_1(_word,					\
1121 	    _field1, _value1)						\
1122 	EFX_POPULATE_WORD_2(_word, EFX_DUMMY_FIELD, 0,			\
1123 	    _field1, _value1)
1124 
1125 #define	EFX_ZERO_WORD(_word)						\
1126 	EFX_POPULATE_WORD_1(_word, EFX_DUMMY_FIELD, 0)
1127 
1128 #define	EFX_SET_WORD(_word)						\
1129 	EFX_POPULATE_WORD_1(_word,					\
1130 	    EFX_WORD_0, 0xffff)
1131 
1132 /* Populate a byte field with various numbers of arguments */
1133 #define	EFX_POPULATE_BYTE_10 EFX_POPULATE_BYTE
1134 
1135 #define	EFX_POPULATE_BYTE_9(_byte,					\
1136 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1137 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1138 	    _field7, _value7, _field8, _value8,	_field9, _value9)	\
1139 	EFX_POPULATE_BYTE_10(_byte, EFX_DUMMY_FIELD, 0,			\
1140 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1141 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1142 	    _field7, _value7, _field8, _value8,	_field9, _value9)
1143 
1144 #define	EFX_POPULATE_BYTE_8(_byte,					\
1145 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1146 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1147 	    _field7, _value7, _field8, _value8)				\
1148 	EFX_POPULATE_BYTE_9(_byte, EFX_DUMMY_FIELD, 0,			\
1149 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1150 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1151 	    _field7, _value7, _field8, _value8)
1152 
1153 #define	EFX_POPULATE_BYTE_7(_byte,					\
1154 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1155 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1156 	    _field7, _value7)						\
1157 	EFX_POPULATE_BYTE_8(_byte, EFX_DUMMY_FIELD, 0,			\
1158 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1159 	    _field4, _value4, _field5, _value5,	_field6, _value6,	\
1160 	    _field7, _value7)
1161 
1162 #define	EFX_POPULATE_BYTE_6(_byte,					\
1163 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1164 	    _field4, _value4, _field5, _value5,	_field6, _value6)	\
1165 	EFX_POPULATE_BYTE_7(_byte, EFX_DUMMY_FIELD, 0,			\
1166 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1167 	    _field4, _value4, _field5, _value5,	_field6, _value6)
1168 
1169 #define	EFX_POPULATE_BYTE_5(_byte,					\
1170 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1171 	    _field4, _value4, _field5, _value5)				\
1172 	EFX_POPULATE_BYTE_6(_byte, EFX_DUMMY_FIELD, 0,			\
1173 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1174 	    _field4, _value4, _field5, _value5)
1175 
1176 #define	EFX_POPULATE_BYTE_4(_byte,					\
1177 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1178 	    _field4, _value4)						\
1179 	EFX_POPULATE_BYTE_5(_byte, EFX_DUMMY_FIELD, 0,			\
1180 	    _field1, _value1, _field2, _value2, _field3, _value3,	\
1181 	    _field4, _value4)
1182 
1183 #define	EFX_POPULATE_BYTE_3(_byte,					\
1184 	    _field1, _value1, _field2, _value2, _field3, _value3)	\
1185 	EFX_POPULATE_BYTE_4(_byte, EFX_DUMMY_FIELD, 0,			\
1186 	    _field1, _value1, _field2, _value2, _field3, _value3)
1187 
1188 #define	EFX_POPULATE_BYTE_2(_byte,					\
1189 	    _field1, _value1, _field2, _value2)				\
1190 	EFX_POPULATE_BYTE_3(_byte, EFX_DUMMY_FIELD, 0,			\
1191 	    _field1, _value1, _field2, _value2)
1192 
1193 #define	EFX_POPULATE_BYTE_1(_byte,					\
1194 	    _field1, _value1)						\
1195 	EFX_POPULATE_BYTE_2(_byte, EFX_DUMMY_FIELD, 0,			\
1196 	    _field1, _value1)
1197 
1198 #define	EFX_ZERO_BYTE(_byte)						\
1199 	EFX_POPULATE_BYTE_1(_byte, EFX_DUMMY_FIELD, 0)
1200 
1201 #define	EFX_SET_BYTE(_byte)						\
1202 	EFX_POPULATE_BYTE_1(_byte,					\
1203 	    EFX_BYTE_0, 0xff)
1204 
1205 /*
1206  * Modify a named field within an already-populated structure.  Used
1207  * for read-modify-write operations.
1208  */
1209 
1210 #define	EFX_INSERT_FIELD64(_min, _max, _field, _value)			\
1211 	__CPU_TO_LE_64(EFX_INSERT_FIELD_NATIVE64(_min, _max, _field, _value))
1212 
1213 #define	EFX_INSERT_FIELD32(_min, _max, _field, _value)			\
1214 	__CPU_TO_LE_32(EFX_INSERT_FIELD_NATIVE32(_min, _max, _field, _value))
1215 
1216 #define	EFX_INSERT_FIELD16(_min, _max, _field, _value)			\
1217 	__CPU_TO_LE_16(EFX_INSERT_FIELD_NATIVE16(_min, _max, _field, _value))
1218 
1219 #define	EFX_INSERT_FIELD8(_min, _max, _field, _value)			\
1220 	__NATIVE_8(EFX_INSERT_FIELD_NATIVE8(_min, _max, _field, _value))
1221 
1222 #define	EFX_INPLACE_MASK64(_min, _max, _field)				\
1223 	EFX_INSERT_FIELD64(_min, _max, _field, EFX_MASK64(_field))
1224 
1225 #define	EFX_INPLACE_MASK32(_min, _max, _field)				\
1226 	EFX_INSERT_FIELD32(_min, _max, _field, EFX_MASK32(_field))
1227 
1228 #define	EFX_INPLACE_MASK16(_min, _max, _field)				\
1229 	EFX_INSERT_FIELD16(_min, _max, _field, EFX_MASK16(_field))
1230 
1231 #define	EFX_INPLACE_MASK8(_min, _max, _field)				\
1232 	EFX_INSERT_FIELD8(_min, _max, _field, EFX_MASK8(_field))
1233 
1234 #define	EFX_SET_OWORD_FIELD64(_oword, _field, _value)			\
1235 	do {								\
1236 		_NOTE(CONSTANTCONDITION)				\
1237 		(_oword).eo_u64[0] = (((_oword).eo_u64[0] &		\
1238 		    ~EFX_INPLACE_MASK64(0, 63, _field)) |		\
1239 		    EFX_INSERT_FIELD64(0, 63, _field, _value));		\
1240 		_NOTE(CONSTANTCONDITION)				\
1241 		(_oword).eo_u64[1] = (((_oword).eo_u64[1] &		\
1242 		    ~EFX_INPLACE_MASK64(64, 127, _field)) |		\
1243 		    EFX_INSERT_FIELD64(64, 127, _field, _value));	\
1244 	_NOTE(CONSTANTCONDITION)					\
1245 	} while (B_FALSE)
1246 
1247 #define	EFX_SET_OWORD_FIELD32(_oword, _field, _value)			\
1248 	do {								\
1249 		_NOTE(CONSTANTCONDITION)				\
1250 		(_oword).eo_u32[0] = (((_oword).eo_u32[0] &		\
1251 		    ~EFX_INPLACE_MASK32(0, 31, _field)) |		\
1252 		    EFX_INSERT_FIELD32(0, 31, _field, _value));		\
1253 		_NOTE(CONSTANTCONDITION)				\
1254 		(_oword).eo_u32[1] = (((_oword).eo_u32[1] &		\
1255 		    ~EFX_INPLACE_MASK32(32, 63, _field)) |		\
1256 		    EFX_INSERT_FIELD32(32, 63, _field, _value));	\
1257 		_NOTE(CONSTANTCONDITION)				\
1258 		(_oword).eo_u32[2] = (((_oword).eo_u32[2] &		\
1259 		    ~EFX_INPLACE_MASK32(64, 95, _field)) |		\
1260 		    EFX_INSERT_FIELD32(64, 95, _field, _value));	\
1261 		_NOTE(CONSTANTCONDITION)				\
1262 		(_oword).eo_u32[3] = (((_oword).eo_u32[3] &		\
1263 		    ~EFX_INPLACE_MASK32(96, 127, _field)) |		\
1264 		    EFX_INSERT_FIELD32(96, 127, _field, _value));	\
1265 	_NOTE(CONSTANTCONDITION)					\
1266 	} while (B_FALSE)
1267 
1268 #define	EFX_SET_QWORD_FIELD64(_qword, _field, _value)			\
1269 	do {								\
1270 		_NOTE(CONSTANTCONDITION)				\
1271 		(_qword).eq_u64[0] = (((_qword).eq_u64[0] &		\
1272 		    ~EFX_INPLACE_MASK64(0, 63, _field)) |		\
1273 		    EFX_INSERT_FIELD64(0, 63, _field, _value));		\
1274 	_NOTE(CONSTANTCONDITION)					\
1275 	} while (B_FALSE)
1276 
1277 #define	EFX_SET_QWORD_FIELD32(_qword, _field, _value)			\
1278 	do {								\
1279 		_NOTE(CONSTANTCONDITION)				\
1280 		(_qword).eq_u32[0] = (((_qword).eq_u32[0] &		\
1281 		    ~EFX_INPLACE_MASK32(0, 31, _field)) |		\
1282 		    EFX_INSERT_FIELD32(0, 31, _field, _value));		\
1283 		_NOTE(CONSTANTCONDITION)				\
1284 		(_qword).eq_u32[1] = (((_qword).eq_u32[1] &		\
1285 		    ~EFX_INPLACE_MASK32(32, 63, _field)) |		\
1286 		    EFX_INSERT_FIELD32(32, 63, _field, _value));	\
1287 	_NOTE(CONSTANTCONDITION)					\
1288 	} while (B_FALSE)
1289 
1290 #define	EFX_SET_DWORD_FIELD(_dword, _field, _value)			\
1291 	do {								\
1292 		_NOTE(CONSTANTCONDITION)				\
1293 		(_dword).ed_u32[0] = (((_dword).ed_u32[0] &		\
1294 		    ~EFX_INPLACE_MASK32(0, 31, _field)) |		\
1295 		    EFX_INSERT_FIELD32(0, 31, _field, _value));		\
1296 	_NOTE(CONSTANTCONDITION)					\
1297 	} while (B_FALSE)
1298 
1299 #define	EFX_SET_WORD_FIELD(_word, _field, _value)			\
1300 	do {								\
1301 		_NOTE(CONSTANTCONDITION)				\
1302 		(_word).ew_u16[0] = (((_word).ew_u16[0] &		\
1303 		    ~EFX_INPLACE_MASK16(0, 15, _field)) |		\
1304 		    EFX_INSERT_FIELD16(0, 15, _field, _value));		\
1305 	_NOTE(CONSTANTCONDITION)					\
1306 	} while (B_FALSE)
1307 
1308 #define	EFX_SET_BYTE_FIELD(_byte, _field, _value)			\
1309 	do {								\
1310 		_NOTE(CONSTANTCONDITION)				\
1311 		(_byte).eb_u8[0] = (((_byte).eb_u8[0] &			\
1312 		    ~EFX_INPLACE_MASK8(0, 7, _field)) |			\
1313 		    EFX_INSERT_FIELD8(0, 7, _field, _value));		\
1314 	_NOTE(CONSTANTCONDITION)					\
1315 	} while (B_FALSE)
1316 
1317 /*
1318  * Set or clear a numbered bit within an octword.
1319  */
1320 
1321 #define	EFX_SHIFT64(_bit, _base)					\
1322 	(((_bit) >= (_base) && (_bit) < (_base) + 64) ?			\
1323 		((uint64_t)1 << EFX_SSUB((_bit), (_base))) :		\
1324 		0U)
1325 
1326 #define	EFX_SHIFT32(_bit, _base)					\
1327 	(((_bit) >= (_base) && (_bit) < (_base) + 32) ?			\
1328 		((uint32_t)1 << EFX_SSUB((_bit),(_base))) :		\
1329 		0U)
1330 
1331 #define	EFX_SHIFT16(_bit, _base)					\
1332 	(((_bit) >= (_base) && (_bit) < (_base) + 16) ?			\
1333 		(uint16_t)(1 << EFX_SSUB((_bit), (_base))) :		\
1334 		0U)
1335 
1336 #define	EFX_SHIFT8(_bit, _base)						\
1337 	(((_bit) >= (_base) && (_bit) < (_base) + 8) ?			\
1338 		(uint8_t)(1 << EFX_SSUB((_bit), (_base))) :		\
1339 		0U)
1340 
1341 #define	EFX_SET_OWORD_BIT64(_oword, _bit)				\
1342 	do {								\
1343 		_NOTE(CONSTANTCONDITION)				\
1344 		(_oword).eo_u64[0] |=					\
1345 		    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(0)));	\
1346 		(_oword).eo_u64[1] |=					\
1347 		    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(64)));	\
1348 	_NOTE(CONSTANTCONDITION)					\
1349 	} while (B_FALSE)
1350 
1351 #define	EFX_SET_OWORD_BIT32(_oword, _bit)				\
1352 	do {								\
1353 		_NOTE(CONSTANTCONDITION)				\
1354 		(_oword).eo_u32[0] |=					\
1355 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(0)));	\
1356 		(_oword).eo_u32[1] |=					\
1357 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(32)));	\
1358 		(_oword).eo_u32[2] |=					\
1359 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(64)));	\
1360 		(_oword).eo_u32[3] |=					\
1361 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(96)));	\
1362 	_NOTE(CONSTANTCONDITION)					\
1363 	} while (B_FALSE)
1364 
1365 #define	EFX_CLEAR_OWORD_BIT64(_oword, _bit)				\
1366 	do {								\
1367 		_NOTE(CONSTANTCONDITION)				\
1368 		(_oword).eo_u64[0] &=					\
1369 		    __CPU_TO_LE_64(~EFX_SHIFT64(_bit, FIX_LINT(0)));	\
1370 		(_oword).eo_u64[1] &=					\
1371 		    __CPU_TO_LE_64(~EFX_SHIFT64(_bit, FIX_LINT(64)));	\
1372 	_NOTE(CONSTANTCONDITION)					\
1373 	} while (B_FALSE)
1374 
1375 #define	EFX_CLEAR_OWORD_BIT32(_oword, _bit)				\
1376 	do {								\
1377 		_NOTE(CONSTANTCONDITION)				\
1378 		(_oword).eo_u32[0] &=					\
1379 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(0)));	\
1380 		(_oword).eo_u32[1] &=					\
1381 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(32)));	\
1382 		(_oword).eo_u32[2] &=					\
1383 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(64)));	\
1384 		(_oword).eo_u32[3] &=					\
1385 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(96)));	\
1386 	_NOTE(CONSTANTCONDITION)					\
1387 	} while (B_FALSE)
1388 
1389 #define	EFX_TEST_OWORD_BIT64(_oword, _bit)				\
1390 	(((_oword).eo_u64[0] &						\
1391 		    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(0)))) ||	\
1392 	((_oword).eo_u64[1] &						\
1393 		    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(64)))))
1394 
1395 #define	EFX_TEST_OWORD_BIT32(_oword, _bit)				\
1396 	(((_oword).eo_u32[0] &						\
1397 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(0)))) ||	\
1398 	((_oword).eo_u32[1] &						\
1399 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(32)))) ||	\
1400 	((_oword).eo_u32[2] &						\
1401 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(64)))) ||	\
1402 	((_oword).eo_u32[3] &						\
1403 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(96)))))
1404 
1405 #define	EFX_SET_QWORD_BIT64(_qword, _bit)				\
1406 	do {								\
1407 		_NOTE(CONSTANTCONDITION)				\
1408 		(_qword).eq_u64[0] |=					\
1409 		    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(0)));	\
1410 	_NOTE(CONSTANTCONDITION)					\
1411 	} while (B_FALSE)
1412 
1413 #define	EFX_SET_QWORD_BIT32(_qword, _bit)				\
1414 	do {								\
1415 		_NOTE(CONSTANTCONDITION)				\
1416 		(_qword).eq_u32[0] |=					\
1417 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(0)));	\
1418 		(_qword).eq_u32[1] |=					\
1419 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(32)));	\
1420 	_NOTE(CONSTANTCONDITION)					\
1421 	} while (B_FALSE)
1422 
1423 #define	EFX_CLEAR_QWORD_BIT64(_qword, _bit)				\
1424 	do {								\
1425 		_NOTE(CONSTANTCONDITION)				\
1426 		(_qword).eq_u64[0] &=					\
1427 		    __CPU_TO_LE_64(~EFX_SHIFT64(_bit, FIX_LINT(0)));	\
1428 	_NOTE(CONSTANTCONDITION)					\
1429 	} while (B_FALSE)
1430 
1431 #define	EFX_CLEAR_QWORD_BIT32(_qword, _bit)				\
1432 	do {								\
1433 		_NOTE(CONSTANTCONDITION)				\
1434 		(_qword).eq_u32[0] &=					\
1435 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(0)));	\
1436 		(_qword).eq_u32[1] &=					\
1437 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(32)));	\
1438 	_NOTE(CONSTANTCONDITION)					\
1439 	} while (B_FALSE)
1440 
1441 #define	EFX_TEST_QWORD_BIT64(_qword, _bit)				\
1442 	(((_qword).eq_u64[0] &						\
1443 		    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(0)))) != 0)
1444 
1445 #define	EFX_TEST_QWORD_BIT32(_qword, _bit)				\
1446 	(((_qword).eq_u32[0] &						\
1447 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(0)))) ||	\
1448 	((_qword).eq_u32[1] &						\
1449 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(32)))))
1450 
1451 #define	EFX_SET_DWORD_BIT(_dword, _bit)					\
1452 	do {								\
1453 		(_dword).ed_u32[0] |=					\
1454 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(0)));	\
1455 	_NOTE(CONSTANTCONDITION)					\
1456 	} while (B_FALSE)
1457 
1458 #define	EFX_CLEAR_DWORD_BIT(_dword, _bit)				\
1459 	do {								\
1460 		(_dword).ed_u32[0] &=					\
1461 		    __CPU_TO_LE_32(~EFX_SHIFT32(_bit, FIX_LINT(0)));	\
1462 	_NOTE(CONSTANTCONDITION)					\
1463 	} while (B_FALSE)
1464 
1465 #define	EFX_TEST_DWORD_BIT(_dword, _bit)				\
1466 	(((_dword).ed_u32[0] &						\
1467 		    __CPU_TO_LE_32(EFX_SHIFT32(_bit, FIX_LINT(0)))) != 0)
1468 
1469 #define	EFX_SET_WORD_BIT(_word, _bit)					\
1470 	do {								\
1471 		(_word).ew_u16[0] |=					\
1472 		    __CPU_TO_LE_16(EFX_SHIFT16(_bit, FIX_LINT(0)));	\
1473 	_NOTE(CONSTANTCONDITION)					\
1474 	} while (B_FALSE)
1475 
1476 #define	EFX_CLEAR_WORD_BIT(_word, _bit)					\
1477 	do {								\
1478 		(_word).ew_u32[0] &=					\
1479 		    __CPU_TO_LE_16(~EFX_SHIFT16(_bit, FIX_LINT(0)));	\
1480 	_NOTE(CONSTANTCONDITION)					\
1481 	} while (B_FALSE)
1482 
1483 #define	EFX_TEST_WORD_BIT(_word, _bit)					\
1484 	(((_word).ew_u16[0] &						\
1485 		    __CPU_TO_LE_16(EFX_SHIFT16(_bit, FIX_LINT(0)))) != 0)
1486 
1487 #define	EFX_SET_BYTE_BIT(_byte, _bit)					\
1488 	do {								\
1489 		(_byte).eb_u8[0] |=					\
1490 		    __NATIVE_8(EFX_SHIFT8(_bit, FIX_LINT(0)));		\
1491 	_NOTE(CONSTANTCONDITION)					\
1492 	} while (B_FALSE)
1493 
1494 #define	EFX_CLEAR_BYTE_BIT(_byte, _bit)					\
1495 	do {								\
1496 		(_byte).eb_u8[0] &=					\
1497 		    __NATIVE_8(~EFX_SHIFT8(_bit, FIX_LINT(0)));		\
1498 	_NOTE(CONSTANTCONDITION)					\
1499 	} while (B_FALSE)
1500 
1501 #define	EFX_TEST_BYTE_BIT(_byte, _bit)					\
1502 	(((_byte).eb_u8[0] &						\
1503 		    __NATIVE_8(EFX_SHIFT8(_bit, FIX_LINT(0)))) != 0)
1504 
1505 #define	EFX_OR_OWORD64(_oword1, _oword2)				\
1506 	do {								\
1507 		(_oword1).eo_u64[0] |= (_oword2).eo_u64[0];		\
1508 		(_oword1).eo_u64[1] |= (_oword2).eo_u64[1];		\
1509 	_NOTE(CONSTANTCONDITION)					\
1510 	} while (B_FALSE)
1511 
1512 #define	EFX_OR_OWORD32(_oword1, _oword2)				\
1513 	do {								\
1514 		(_oword1).eo_u32[0] |= (_oword2).eo_u32[0];		\
1515 		(_oword1).eo_u32[1] |= (_oword2).eo_u32[1];		\
1516 		(_oword1).eo_u32[2] |= (_oword2).eo_u32[2];		\
1517 		(_oword1).eo_u32[3] |= (_oword2).eo_u32[3];		\
1518 	_NOTE(CONSTANTCONDITION)					\
1519 	} while (B_FALSE)
1520 
1521 #define	EFX_AND_OWORD64(_oword1, _oword2)				\
1522 	do {								\
1523 		(_oword1).eo_u64[0] &= (_oword2).eo_u64[0];		\
1524 		(_oword1).eo_u64[1] &= (_oword2).eo_u64[1];		\
1525 	_NOTE(CONSTANTCONDITION)					\
1526 	} while (B_FALSE)
1527 
1528 #define	EFX_AND_OWORD32(_oword1, _oword2)				\
1529 	do {								\
1530 		(_oword1).eo_u32[0] &= (_oword2).eo_u32[0];		\
1531 		(_oword1).eo_u32[1] &= (_oword2).eo_u32[1];		\
1532 		(_oword1).eo_u32[2] &= (_oword2).eo_u32[2];		\
1533 		(_oword1).eo_u32[3] &= (_oword2).eo_u32[3];		\
1534 	_NOTE(CONSTANTCONDITION)					\
1535 	} while (B_FALSE)
1536 
1537 #define	EFX_OR_QWORD64(_qword1, _qword2)				\
1538 	do {								\
1539 		(_qword1).eq_u64[0] |= (_qword2).eq_u64[0];		\
1540 	_NOTE(CONSTANTCONDITION)					\
1541 	} while (B_FALSE)
1542 
1543 #define	EFX_OR_QWORD32(_qword1, _qword2)				\
1544 	do {								\
1545 		(_qword1).eq_u32[0] |= (_qword2).eq_u32[0];		\
1546 		(_qword1).eq_u32[1] |= (_qword2).eq_u32[1];		\
1547 	_NOTE(CONSTANTCONDITION)					\
1548 	} while (B_FALSE)
1549 
1550 #define	EFX_AND_QWORD64(_qword1, _qword2)				\
1551 	do {								\
1552 		(_qword1).eq_u64[0] &= (_qword2).eq_u64[0];		\
1553 	_NOTE(CONSTANTCONDITION)					\
1554 	} while (B_FALSE)
1555 
1556 #define	EFX_AND_QWORD32(_qword1, _qword2)				\
1557 	do {								\
1558 		(_qword1).eq_u32[0] &= (_qword2).eq_u32[0];		\
1559 		(_qword1).eq_u32[1] &= (_qword2).eq_u32[1];		\
1560 	_NOTE(CONSTANTCONDITION)					\
1561 	} while (B_FALSE)
1562 
1563 #define	EFX_OR_DWORD(_dword1, _dword2)					\
1564 	do {								\
1565 		(_dword1).ed_u32[0] |= (_dword2).ed_u32[0];		\
1566 	_NOTE(CONSTANTCONDITION)					\
1567 	} while (B_FALSE)
1568 
1569 #define	EFX_AND_DWORD(_dword1, _dword2)					\
1570 	do {								\
1571 		(_dword1).ed_u32[0] &= (_dword2).ed_u32[0];		\
1572 	_NOTE(CONSTANTCONDITION)					\
1573 	} while (B_FALSE)
1574 
1575 #define	EFX_OR_WORD(_word1, _word2)					\
1576 	do {								\
1577 		(_word1).ew_u16[0] |= (_word2).ew_u16[0];		\
1578 	_NOTE(CONSTANTCONDITION)					\
1579 	} while (B_FALSE)
1580 
1581 #define	EFX_AND_WORD(_word1, _word2)					\
1582 	do {								\
1583 		(_word1).ew_u16[0] &= (_word2).ew_u16[0];		\
1584 	_NOTE(CONSTANTCONDITION)					\
1585 	} while (B_FALSE)
1586 
1587 #define	EFX_OR_BYTE(_byte1, _byte2)					\
1588 	do {								\
1589 		(_byte1).eb_u8[0] |= (_byte2).eb_u8[0];			\
1590 	_NOTE(CONSTANTCONDITION)					\
1591 	} while (B_FALSE)
1592 
1593 #define	EFX_AND_BYTE(_byte1, _byte2)					\
1594 	do {								\
1595 		(_byte1).eb_u8[0] &= (_byte2).eb_u8[0];			\
1596 	_NOTE(CONSTANTCONDITION)					\
1597 	} while (B_FALSE)
1598 
1599 #if EFSYS_USE_UINT64
1600 #define	EFX_OWORD_FIELD		EFX_OWORD_FIELD64
1601 #define	EFX_QWORD_FIELD		EFX_QWORD_FIELD64
1602 #define	EFX_OWORD_IS_EQUAL	EFX_OWORD_IS_EQUAL64
1603 #define	EFX_QWORD_IS_EQUAL	EFX_QWORD_IS_EQUAL64
1604 #define	EFX_OWORD_IS_ZERO	EFX_OWORD_IS_ZERO64
1605 #define	EFX_QWORD_IS_ZERO	EFX_QWORD_IS_ZERO64
1606 #define	EFX_OWORD_IS_SET	EFX_OWORD_IS_SET64
1607 #define	EFX_QWORD_IS_SET	EFX_QWORD_IS_SET64
1608 #define	EFX_POPULATE_OWORD	EFX_POPULATE_OWORD64
1609 #define	EFX_POPULATE_QWORD	EFX_POPULATE_QWORD64
1610 #define	EFX_SET_OWORD_FIELD	EFX_SET_OWORD_FIELD64
1611 #define	EFX_SET_QWORD_FIELD	EFX_SET_QWORD_FIELD64
1612 #define	EFX_SET_OWORD_BIT	EFX_SET_OWORD_BIT64
1613 #define	EFX_CLEAR_OWORD_BIT	EFX_CLEAR_OWORD_BIT64
1614 #define	EFX_TEST_OWORD_BIT	EFX_TEST_OWORD_BIT64
1615 #define	EFX_SET_QWORD_BIT	EFX_SET_QWORD_BIT64
1616 #define	EFX_CLEAR_QWORD_BIT	EFX_CLEAR_QWORD_BIT64
1617 #define	EFX_TEST_QWORD_BIT	EFX_TEST_QWORD_BIT64
1618 #define	EFX_OR_OWORD		EFX_OR_OWORD64
1619 #define	EFX_AND_OWORD		EFX_AND_OWORD64
1620 #define	EFX_OR_QWORD		EFX_OR_QWORD64
1621 #define	EFX_AND_QWORD		EFX_AND_QWORD64
1622 #else
1623 #define	EFX_OWORD_FIELD		EFX_OWORD_FIELD32
1624 #define	EFX_QWORD_FIELD		EFX_QWORD_FIELD32
1625 #define	EFX_OWORD_IS_EQUAL	EFX_OWORD_IS_EQUAL32
1626 #define	EFX_QWORD_IS_EQUAL	EFX_QWORD_IS_EQUAL32
1627 #define	EFX_OWORD_IS_ZERO	EFX_OWORD_IS_ZERO32
1628 #define	EFX_QWORD_IS_ZERO	EFX_QWORD_IS_ZERO32
1629 #define	EFX_OWORD_IS_SET	EFX_OWORD_IS_SET32
1630 #define	EFX_QWORD_IS_SET	EFX_QWORD_IS_SET32
1631 #define	EFX_POPULATE_OWORD	EFX_POPULATE_OWORD32
1632 #define	EFX_POPULATE_QWORD	EFX_POPULATE_QWORD32
1633 #define	EFX_SET_OWORD_FIELD	EFX_SET_OWORD_FIELD32
1634 #define	EFX_SET_QWORD_FIELD	EFX_SET_QWORD_FIELD32
1635 #define	EFX_SET_OWORD_BIT	EFX_SET_OWORD_BIT32
1636 #define	EFX_CLEAR_OWORD_BIT	EFX_CLEAR_OWORD_BIT32
1637 #define	EFX_TEST_OWORD_BIT	EFX_TEST_OWORD_BIT32
1638 #define	EFX_SET_QWORD_BIT	EFX_SET_QWORD_BIT32
1639 #define	EFX_CLEAR_QWORD_BIT	EFX_CLEAR_QWORD_BIT32
1640 #define	EFX_TEST_QWORD_BIT	EFX_TEST_QWORD_BIT32
1641 #define	EFX_OR_OWORD		EFX_OR_OWORD32
1642 #define	EFX_AND_OWORD		EFX_AND_OWORD32
1643 #define	EFX_OR_QWORD		EFX_OR_QWORD32
1644 #define	EFX_AND_QWORD		EFX_AND_QWORD32
1645 #endif
1646 
1647 #ifdef	__cplusplus
1648 }
1649 #endif
1650 
1651 #endif	/* _SYS_EFX_TYPES_H */
1652