xref: /illumos-gate/usr/src/uts/common/io/sfxge/efsys.h (revision 49ef7e0638c8b771d8a136eae78b1c0f99acc8e0)
1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2008-2016 Solarflare Communications Inc.
3*49ef7e06SGarrett D'Amore  * All rights reserved.
4*49ef7e06SGarrett D'Amore  *
5*49ef7e06SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
6*49ef7e06SGarrett D'Amore  * modification, are permitted provided that the following conditions are met:
7*49ef7e06SGarrett D'Amore  *
8*49ef7e06SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright notice,
9*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer.
10*49ef7e06SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright notice,
11*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer in the documentation
12*49ef7e06SGarrett D'Amore  *    and/or other materials provided with the distribution.
13*49ef7e06SGarrett D'Amore  *
14*49ef7e06SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15*49ef7e06SGarrett D'Amore  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16*49ef7e06SGarrett D'Amore  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*49ef7e06SGarrett D'Amore  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18*49ef7e06SGarrett D'Amore  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19*49ef7e06SGarrett D'Amore  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20*49ef7e06SGarrett D'Amore  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21*49ef7e06SGarrett D'Amore  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22*49ef7e06SGarrett D'Amore  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23*49ef7e06SGarrett D'Amore  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24*49ef7e06SGarrett D'Amore  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*49ef7e06SGarrett D'Amore  *
26*49ef7e06SGarrett D'Amore  * The views and conclusions contained in the software and documentation are
27*49ef7e06SGarrett D'Amore  * those of the authors and should not be interpreted as representing official
28*49ef7e06SGarrett D'Amore  * policies, either expressed or implied, of the FreeBSD Project.
29*49ef7e06SGarrett D'Amore  */
30*49ef7e06SGarrett D'Amore 
31*49ef7e06SGarrett D'Amore #ifndef	_SYS_EFSYS_H
32*49ef7e06SGarrett D'Amore #define	_SYS_EFSYS_H
33*49ef7e06SGarrett D'Amore 
34*49ef7e06SGarrett D'Amore #ifdef	__cplusplus
35*49ef7e06SGarrett D'Amore extern "C" {
36*49ef7e06SGarrett D'Amore #endif
37*49ef7e06SGarrett D'Amore 
38*49ef7e06SGarrett D'Amore #include <sys/types.h>
39*49ef7e06SGarrett D'Amore #include <sys/sysmacros.h>
40*49ef7e06SGarrett D'Amore #include <sys/ddi.h>
41*49ef7e06SGarrett D'Amore #include <sys/sunddi.h>
42*49ef7e06SGarrett D'Amore #include <sys/cpuvar.h>
43*49ef7e06SGarrett D'Amore #include <sys/disp.h>
44*49ef7e06SGarrett D'Amore #include <sys/sdt.h>
45*49ef7e06SGarrett D'Amore #include <sys/kstat.h>
46*49ef7e06SGarrett D'Amore #include <sys/crc32.h>
47*49ef7e06SGarrett D'Amore #include <sys/note.h>
48*49ef7e06SGarrett D'Amore #include <sys/byteorder.h>
49*49ef7e06SGarrett D'Amore 
50*49ef7e06SGarrett D'Amore #define	EFSYS_HAS_UINT64 1
51*49ef7e06SGarrett D'Amore #define	EFSYS_USE_UINT64 0
52*49ef7e06SGarrett D'Amore #define	EFSYS_HAS_SSE2_M128 0
53*49ef7e06SGarrett D'Amore #ifdef	_BIG_ENDIAN
54*49ef7e06SGarrett D'Amore #define	EFSYS_IS_BIG_ENDIAN 1
55*49ef7e06SGarrett D'Amore #endif
56*49ef7e06SGarrett D'Amore #ifdef	_LITTLE_ENDIAN
57*49ef7e06SGarrett D'Amore #define	EFSYS_IS_LITTLE_ENDIAN 1
58*49ef7e06SGarrett D'Amore #endif
59*49ef7e06SGarrett D'Amore #include "efx_types.h"
60*49ef7e06SGarrett D'Amore 
61*49ef7e06SGarrett D'Amore /* Modifiers used for Windows builds */
62*49ef7e06SGarrett D'Amore #define	__in
63*49ef7e06SGarrett D'Amore #define	__in_opt
64*49ef7e06SGarrett D'Amore #define	__in_ecount(_n)
65*49ef7e06SGarrett D'Amore #define	__in_ecount_opt(_n)
66*49ef7e06SGarrett D'Amore #define	__in_bcount(_n)
67*49ef7e06SGarrett D'Amore #define	__in_bcount_opt(_n)
68*49ef7e06SGarrett D'Amore 
69*49ef7e06SGarrett D'Amore #define	__out
70*49ef7e06SGarrett D'Amore #define	__out_opt
71*49ef7e06SGarrett D'Amore #define	__out_ecount(_n)
72*49ef7e06SGarrett D'Amore #define	__out_ecount_opt(_n)
73*49ef7e06SGarrett D'Amore #define	__out_bcount(_n)
74*49ef7e06SGarrett D'Amore #define	__out_bcount_opt(_n)
75*49ef7e06SGarrett D'Amore #define	__out_bcount_part(_n, _l)
76*49ef7e06SGarrett D'Amore #define	__out_bcount_part_opt(_n, _l)
77*49ef7e06SGarrett D'Amore 
78*49ef7e06SGarrett D'Amore #define	__deref_out
79*49ef7e06SGarrett D'Amore 
80*49ef7e06SGarrett D'Amore #define	__inout
81*49ef7e06SGarrett D'Amore #define	__inout_opt
82*49ef7e06SGarrett D'Amore #define	__inout_ecount(_n)
83*49ef7e06SGarrett D'Amore #define	__inout_ecount_opt(_n)
84*49ef7e06SGarrett D'Amore #define	__inout_bcount(_n)
85*49ef7e06SGarrett D'Amore #define	__inout_bcount_opt(_n)
86*49ef7e06SGarrett D'Amore #define	__inout_bcount_full_opt(_n)
87*49ef7e06SGarrett D'Amore 
88*49ef7e06SGarrett D'Amore #define	__deref_out_bcount_opt(n)
89*49ef7e06SGarrett D'Amore 
90*49ef7e06SGarrett D'Amore #define	__checkReturn
91*49ef7e06SGarrett D'Amore #define	__success(_x)
92*49ef7e06SGarrett D'Amore 
93*49ef7e06SGarrett D'Amore #define	__drv_when(_p, _c)
94*49ef7e06SGarrett D'Amore 
95*49ef7e06SGarrett D'Amore /* Code inclusion options */
96*49ef7e06SGarrett D'Amore 
97*49ef7e06SGarrett D'Amore 
98*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_NAMES 1
99*49ef7e06SGarrett D'Amore 
100*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_SIENA 1
101*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_HUNTINGTON 1
102*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MEDFORD 0
103*49ef7e06SGarrett D'Amore #if DEBUG
104*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_CHECK_REG 1
105*49ef7e06SGarrett D'Amore #else
106*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_CHECK_REG 0
107*49ef7e06SGarrett D'Amore #endif
108*49ef7e06SGarrett D'Amore 
109*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MCDI 1
110*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MCDI_LOGGING 0
111*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MCDI_PROXY_AUTH 0
112*49ef7e06SGarrett D'Amore 
113*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MAC_STATS 1
114*49ef7e06SGarrett D'Amore 
115*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_LOOPBACK 1
116*49ef7e06SGarrett D'Amore 
117*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MON_MCDI 1
118*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_MON_STATS 1
119*49ef7e06SGarrett D'Amore 
120*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_PHY_STATS 1
121*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_BIST 1
122*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_PHY_LED_CONTROL 1
123*49ef7e06SGarrett D'Amore 
124*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_VPD 1
125*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_NVRAM 1
126*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_BOOTCFG 1
127*49ef7e06SGarrett D'Amore 
128*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_DIAG 0
129*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_WOL 1
130*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_RX_SCALE 1
131*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_QSTATS 1
132*49ef7e06SGarrett D'Amore 
133*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_EV_PREFETCH 0
134*49ef7e06SGarrett D'Amore 
135*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_DECODE_INTR_FATAL 1
136*49ef7e06SGarrett D'Amore 
137*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_FILTER 1
138*49ef7e06SGarrett D'Amore 
139*49ef7e06SGarrett D'Amore #define	EFSYS_OPT_LICENSING 0
140*49ef7e06SGarrett D'Amore 
141*49ef7e06SGarrett D'Amore /* ID */
142*49ef7e06SGarrett D'Amore 
143*49ef7e06SGarrett D'Amore typedef struct __efsys_identifier_s	efsys_identifier_t;
144*49ef7e06SGarrett D'Amore 
145*49ef7e06SGarrett D'Amore /* DMA */
146*49ef7e06SGarrett D'Amore 
147*49ef7e06SGarrett D'Amore typedef uint64_t		efsys_dma_addr_t;
148*49ef7e06SGarrett D'Amore 
149*49ef7e06SGarrett D'Amore typedef struct efsys_mem_s {
150*49ef7e06SGarrett D'Amore 	ddi_dma_handle_t	esm_dma_handle; /* DMA memory allocate/bind */
151*49ef7e06SGarrett D'Amore 	ddi_acc_handle_t	esm_acc_handle;	/* DMA memory read/write */
152*49ef7e06SGarrett D'Amore 	caddr_t			esm_base;
153*49ef7e06SGarrett D'Amore 	efsys_dma_addr_t	esm_addr;
154*49ef7e06SGarrett D'Amore 	size_t			esm_size;
155*49ef7e06SGarrett D'Amore 	size_t			esm_used;
156*49ef7e06SGarrett D'Amore } efsys_mem_t;
157*49ef7e06SGarrett D'Amore 
158*49ef7e06SGarrett D'Amore 
159*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_ZERO(_esmp, _size)					\
160*49ef7e06SGarrett D'Amore 	(void) bzero((_esmp)->esm_base, (_size))
161*49ef7e06SGarrett D'Amore 
162*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_READD(_esmp, _offset, _edp)				\
163*49ef7e06SGarrett D'Amore 	do {								\
164*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
165*49ef7e06SGarrett D'Amore 									\
166*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
167*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)));	\
168*49ef7e06SGarrett D'Amore 									\
169*49ef7e06SGarrett D'Amore 		addr = (void *)((_esmp)->esm_base + (_offset));		\
170*49ef7e06SGarrett D'Amore 									\
171*49ef7e06SGarrett D'Amore 		(_edp)->ed_u32[0] = ddi_get32((_esmp)->esm_acc_handle,	\
172*49ef7e06SGarrett D'Amore 		    addr);						\
173*49ef7e06SGarrett D'Amore 									\
174*49ef7e06SGarrett D'Amore 		DTRACE_PROBE2(mem_readd, unsigned int, (_offset),	\
175*49ef7e06SGarrett D'Amore 		    uint32_t, (_edp)->ed_u32[0]);			\
176*49ef7e06SGarrett D'Amore 									\
177*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
178*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
179*49ef7e06SGarrett D'Amore 
180*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_READQ(_esmp, _offset, _eqp)				\
181*49ef7e06SGarrett D'Amore 	do {								\
182*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
183*49ef7e06SGarrett D'Amore 									\
184*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
185*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)));	\
186*49ef7e06SGarrett D'Amore 									\
187*49ef7e06SGarrett D'Amore 		addr = (void *)((_esmp)->esm_base + (_offset));		\
188*49ef7e06SGarrett D'Amore 									\
189*49ef7e06SGarrett D'Amore 		(_eqp)->eq_u32[0] = ddi_get32((_esmp)->esm_acc_handle,	\
190*49ef7e06SGarrett D'Amore 		    addr++);						\
191*49ef7e06SGarrett D'Amore 		(_eqp)->eq_u32[1] = ddi_get32((_esmp)->esm_acc_handle,	\
192*49ef7e06SGarrett D'Amore 		    addr);						\
193*49ef7e06SGarrett D'Amore 									\
194*49ef7e06SGarrett D'Amore 		DTRACE_PROBE3(mem_readq, unsigned int, (_offset),	\
195*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[1],			\
196*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[0]);			\
197*49ef7e06SGarrett D'Amore 									\
198*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
199*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
200*49ef7e06SGarrett D'Amore 
201*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_READO(_esmp, _offset, _eop)				\
202*49ef7e06SGarrett D'Amore 	do {								\
203*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
204*49ef7e06SGarrett D'Amore 									\
205*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
206*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)));	\
207*49ef7e06SGarrett D'Amore 									\
208*49ef7e06SGarrett D'Amore 		addr = (void *)((_esmp)->esm_base + (_offset));		\
209*49ef7e06SGarrett D'Amore 									\
210*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[0] = ddi_get32((_esmp)->esm_acc_handle,	\
211*49ef7e06SGarrett D'Amore 		    addr++);						\
212*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[1] = ddi_get32((_esmp)->esm_acc_handle,	\
213*49ef7e06SGarrett D'Amore 		    addr++);						\
214*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[2] = ddi_get32((_esmp)->esm_acc_handle,	\
215*49ef7e06SGarrett D'Amore 		    addr++);						\
216*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[3] = ddi_get32((_esmp)->esm_acc_handle,	\
217*49ef7e06SGarrett D'Amore 		    addr);						\
218*49ef7e06SGarrett D'Amore 									\
219*49ef7e06SGarrett D'Amore 		DTRACE_PROBE5(mem_reado, unsigned int, (_offset),	\
220*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[3],			\
221*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[2],			\
222*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[1],			\
223*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[0]);			\
224*49ef7e06SGarrett D'Amore 									\
225*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
226*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
227*49ef7e06SGarrett D'Amore 
228*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_WRITED(_esmp, _offset, _edp)				\
229*49ef7e06SGarrett D'Amore 	do {								\
230*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
231*49ef7e06SGarrett D'Amore 									\
232*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
233*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)));	\
234*49ef7e06SGarrett D'Amore 									\
235*49ef7e06SGarrett D'Amore 		DTRACE_PROBE2(mem_writed, unsigned int, (_offset),	\
236*49ef7e06SGarrett D'Amore 		    uint32_t, (_edp)->ed_u32[0]);			\
237*49ef7e06SGarrett D'Amore 									\
238*49ef7e06SGarrett D'Amore 		addr = (void *)((_esmp)->esm_base + (_offset));		\
239*49ef7e06SGarrett D'Amore 									\
240*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr,		\
241*49ef7e06SGarrett D'Amore 		    (_edp)->ed_u32[0]);					\
242*49ef7e06SGarrett D'Amore 									\
243*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
244*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
245*49ef7e06SGarrett D'Amore 
246*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_WRITEQ(_esmp, _offset, _eqp)				\
247*49ef7e06SGarrett D'Amore 	do {								\
248*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
249*49ef7e06SGarrett D'Amore 									\
250*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
251*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)));	\
252*49ef7e06SGarrett D'Amore 									\
253*49ef7e06SGarrett D'Amore 		DTRACE_PROBE3(mem_writeq, unsigned int, (_offset),	\
254*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[1],			\
255*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[0]);			\
256*49ef7e06SGarrett D'Amore 									\
257*49ef7e06SGarrett D'Amore 		addr = (void *)((_esmp)->esm_base + (_offset));		\
258*49ef7e06SGarrett D'Amore 									\
259*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr++,		\
260*49ef7e06SGarrett D'Amore 		    (_eqp)->eq_u32[0]);					\
261*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr,		\
262*49ef7e06SGarrett D'Amore 		    (_eqp)->eq_u32[1]);					\
263*49ef7e06SGarrett D'Amore 									\
264*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
265*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
266*49ef7e06SGarrett D'Amore 
267*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_WRITEO(_esmp, _offset, _eop)				\
268*49ef7e06SGarrett D'Amore 	do {								\
269*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
270*49ef7e06SGarrett D'Amore 									\
271*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
272*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)));	\
273*49ef7e06SGarrett D'Amore 									\
274*49ef7e06SGarrett D'Amore 		DTRACE_PROBE5(mem_writeo, unsigned int, (_offset),	\
275*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[3],			\
276*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[2],			\
277*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[1],			\
278*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[0]);			\
279*49ef7e06SGarrett D'Amore 									\
280*49ef7e06SGarrett D'Amore 		addr = (void *)((_esmp)->esm_base + (_offset));		\
281*49ef7e06SGarrett D'Amore 									\
282*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr++,		\
283*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[0]);					\
284*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr++,		\
285*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[1]);					\
286*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr++,		\
287*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[2]);					\
288*49ef7e06SGarrett D'Amore 		ddi_put32((_esmp)->esm_acc_handle, addr,		\
289*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[3]);					\
290*49ef7e06SGarrett D'Amore 									\
291*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
292*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
293*49ef7e06SGarrett D'Amore 
294*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_ADDR(_esmp)						\
295*49ef7e06SGarrett D'Amore 	((_esmp)->esm_addr)
296*49ef7e06SGarrett D'Amore 
297*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_IS_NULL(_esmp)					\
298*49ef7e06SGarrett D'Amore 	((_esmp)->esm_base == NULL)
299*49ef7e06SGarrett D'Amore 
300*49ef7e06SGarrett D'Amore /* BAR */
301*49ef7e06SGarrett D'Amore 
302*49ef7e06SGarrett D'Amore typedef struct efsys_bar_s {
303*49ef7e06SGarrett D'Amore 	kmutex_t		esb_lock;
304*49ef7e06SGarrett D'Amore 	ddi_acc_handle_t	esb_handle;
305*49ef7e06SGarrett D'Amore 	caddr_t			esb_base;
306*49ef7e06SGarrett D'Amore } efsys_bar_t;
307*49ef7e06SGarrett D'Amore 
308*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_READD(_esbp, _offset, _edp, _lock)			\
309*49ef7e06SGarrett D'Amore 	do {								\
310*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
311*49ef7e06SGarrett D'Amore 									\
312*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
313*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)));	\
314*49ef7e06SGarrett D'Amore 									\
315*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
316*49ef7e06SGarrett D'Amore 		if (_lock)						\
317*49ef7e06SGarrett D'Amore 			mutex_enter(&((_esbp)->esb_lock));		\
318*49ef7e06SGarrett D'Amore 									\
319*49ef7e06SGarrett D'Amore 		addr = (void *)((_esbp)->esb_base + (_offset));		\
320*49ef7e06SGarrett D'Amore 									\
321*49ef7e06SGarrett D'Amore 		(_edp)->ed_u32[0] = ddi_get32((_esbp)->esb_handle,	\
322*49ef7e06SGarrett D'Amore 		    addr);						\
323*49ef7e06SGarrett D'Amore 									\
324*49ef7e06SGarrett D'Amore 		DTRACE_PROBE2(bar_readd, unsigned int, (_offset),	\
325*49ef7e06SGarrett D'Amore 		    uint32_t, (_edp)->ed_u32[0]);			\
326*49ef7e06SGarrett D'Amore 									\
327*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
328*49ef7e06SGarrett D'Amore 		if (_lock)						\
329*49ef7e06SGarrett D'Amore 			mutex_exit(&((_esbp)->esb_lock));		\
330*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
331*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
332*49ef7e06SGarrett D'Amore 
333*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_READQ(_esbp, _offset, _eqp)				\
334*49ef7e06SGarrett D'Amore 	do {								\
335*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
336*49ef7e06SGarrett D'Amore 									\
337*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
338*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)));	\
339*49ef7e06SGarrett D'Amore 									\
340*49ef7e06SGarrett D'Amore 		mutex_enter(&((_esbp)->esb_lock));			\
341*49ef7e06SGarrett D'Amore 									\
342*49ef7e06SGarrett D'Amore 		addr = (void *)((_esbp)->esb_base + (_offset));		\
343*49ef7e06SGarrett D'Amore 									\
344*49ef7e06SGarrett D'Amore 		(_eqp)->eq_u32[0] = ddi_get32((_esbp)->esb_handle,	\
345*49ef7e06SGarrett D'Amore 		    addr++);						\
346*49ef7e06SGarrett D'Amore 		(_eqp)->eq_u32[1] = ddi_get32((_esbp)->esb_handle,	\
347*49ef7e06SGarrett D'Amore 		    addr);						\
348*49ef7e06SGarrett D'Amore 									\
349*49ef7e06SGarrett D'Amore 		DTRACE_PROBE3(bar_readq, unsigned int, (_offset),	\
350*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[1],			\
351*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[0]);			\
352*49ef7e06SGarrett D'Amore 									\
353*49ef7e06SGarrett D'Amore 		mutex_exit(&((_esbp)->esb_lock));			\
354*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
355*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
356*49ef7e06SGarrett D'Amore 
357*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_READO(_esbp, _offset, _eop, _lock)			\
358*49ef7e06SGarrett D'Amore 	do {								\
359*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
360*49ef7e06SGarrett D'Amore 									\
361*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
362*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)));	\
363*49ef7e06SGarrett D'Amore 									\
364*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
365*49ef7e06SGarrett D'Amore 		if (_lock)						\
366*49ef7e06SGarrett D'Amore 			mutex_enter(&((_esbp)->esb_lock));		\
367*49ef7e06SGarrett D'Amore 									\
368*49ef7e06SGarrett D'Amore 		addr = (void *)((_esbp)->esb_base + (_offset));		\
369*49ef7e06SGarrett D'Amore 									\
370*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[0] = ddi_get32((_esbp)->esb_handle,	\
371*49ef7e06SGarrett D'Amore 		    addr++);						\
372*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[1] = ddi_get32((_esbp)->esb_handle,	\
373*49ef7e06SGarrett D'Amore 		    addr++);						\
374*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[2] = ddi_get32((_esbp)->esb_handle,	\
375*49ef7e06SGarrett D'Amore 		    addr++);						\
376*49ef7e06SGarrett D'Amore 		(_eop)->eo_u32[3] = ddi_get32((_esbp)->esb_handle,	\
377*49ef7e06SGarrett D'Amore 		    addr);						\
378*49ef7e06SGarrett D'Amore 									\
379*49ef7e06SGarrett D'Amore 		DTRACE_PROBE5(bar_reado, unsigned int, (_offset),	\
380*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[3],			\
381*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[2],			\
382*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[1],			\
383*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[0]);			\
384*49ef7e06SGarrett D'Amore 									\
385*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
386*49ef7e06SGarrett D'Amore 		if (_lock)						\
387*49ef7e06SGarrett D'Amore 			mutex_exit(&((_esbp)->esb_lock));		\
388*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
389*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
390*49ef7e06SGarrett D'Amore 
391*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_WRITED(_esbp, _offset, _edp, _lock)			\
392*49ef7e06SGarrett D'Amore 	do {								\
393*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
394*49ef7e06SGarrett D'Amore 									\
395*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
396*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)));	\
397*49ef7e06SGarrett D'Amore 									\
398*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
399*49ef7e06SGarrett D'Amore 		if (_lock)						\
400*49ef7e06SGarrett D'Amore 			mutex_enter(&((_esbp)->esb_lock));		\
401*49ef7e06SGarrett D'Amore 									\
402*49ef7e06SGarrett D'Amore 		DTRACE_PROBE2(bar_writed, unsigned int, (_offset),	\
403*49ef7e06SGarrett D'Amore 		    uint32_t, (_edp)->ed_u32[0]);			\
404*49ef7e06SGarrett D'Amore 									\
405*49ef7e06SGarrett D'Amore 		addr = (void *)((_esbp)->esb_base + (_offset));		\
406*49ef7e06SGarrett D'Amore 									\
407*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr,			\
408*49ef7e06SGarrett D'Amore 		    (_edp)->ed_u32[0]);					\
409*49ef7e06SGarrett D'Amore 									\
410*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
411*49ef7e06SGarrett D'Amore 		if (_lock)						\
412*49ef7e06SGarrett D'Amore 			mutex_exit(&((_esbp)->esb_lock));		\
413*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
414*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
415*49ef7e06SGarrett D'Amore 
416*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_WRITEQ(_esbp, _offset, _eqp)				\
417*49ef7e06SGarrett D'Amore 	do {								\
418*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
419*49ef7e06SGarrett D'Amore 									\
420*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
421*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)));	\
422*49ef7e06SGarrett D'Amore 									\
423*49ef7e06SGarrett D'Amore 		mutex_enter(&((_esbp)->esb_lock));			\
424*49ef7e06SGarrett D'Amore 									\
425*49ef7e06SGarrett D'Amore 		DTRACE_PROBE3(bar_writeq, unsigned int, (_offset),	\
426*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[1],			\
427*49ef7e06SGarrett D'Amore 		    uint32_t, (_eqp)->eq_u32[0]);			\
428*49ef7e06SGarrett D'Amore 									\
429*49ef7e06SGarrett D'Amore 		addr = (void *)((_esbp)->esb_base + (_offset));		\
430*49ef7e06SGarrett D'Amore 									\
431*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr++,			\
432*49ef7e06SGarrett D'Amore 		    (_eqp)->eq_u32[0]);					\
433*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr,			\
434*49ef7e06SGarrett D'Amore 		    (_eqp)->eq_u32[1]);					\
435*49ef7e06SGarrett D'Amore 									\
436*49ef7e06SGarrett D'Amore 		mutex_exit(&((_esbp)->esb_lock));			\
437*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
438*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
439*49ef7e06SGarrett D'Amore 
440*49ef7e06SGarrett D'Amore /*
441*49ef7e06SGarrett D'Amore  * Guarantees 64bit aligned 64bit writes to write combined BAR mapping
442*49ef7e06SGarrett D'Amore  * (required by PIO hardware)
443*49ef7e06SGarrett D'Amore  */
444*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_WC_WRITEQ(_esbp, _offset, _eqp)			\
445*49ef7e06SGarrett D'Amore 	do {								\
446*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
447*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)));	\
448*49ef7e06SGarrett D'Amore 									\
449*49ef7e06SGarrett D'Amore 		(void) (_esbp);						\
450*49ef7e06SGarrett D'Amore 									\
451*49ef7e06SGarrett D'Amore 		/* FIXME: Perform a 64-bit write */			\
452*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);					\
453*49ef7e06SGarrett D'Amore 									\
454*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
455*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
456*49ef7e06SGarrett D'Amore 
457*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_WRITEO(_esbp, _offset, _eop, _lock)			\
458*49ef7e06SGarrett D'Amore 	do {								\
459*49ef7e06SGarrett D'Amore 		uint32_t *addr;						\
460*49ef7e06SGarrett D'Amore 									\
461*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
462*49ef7e06SGarrett D'Amore 		ASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)));	\
463*49ef7e06SGarrett D'Amore 									\
464*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
465*49ef7e06SGarrett D'Amore 		if (_lock)						\
466*49ef7e06SGarrett D'Amore 			mutex_enter(&((_esbp)->esb_lock));		\
467*49ef7e06SGarrett D'Amore 									\
468*49ef7e06SGarrett D'Amore 		DTRACE_PROBE5(bar_writeo, unsigned int, (_offset),	\
469*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[3],			\
470*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[2],			\
471*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[1],			\
472*49ef7e06SGarrett D'Amore 		    uint32_t, (_eop)->eo_u32[0]);			\
473*49ef7e06SGarrett D'Amore 									\
474*49ef7e06SGarrett D'Amore 		addr = (void *)((_esbp)->esb_base + (_offset));		\
475*49ef7e06SGarrett D'Amore 									\
476*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr++,			\
477*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[0]);					\
478*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr++,			\
479*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[1]);					\
480*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr++,			\
481*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[2]);					\
482*49ef7e06SGarrett D'Amore 		ddi_put32((_esbp)->esb_handle, addr,			\
483*49ef7e06SGarrett D'Amore 		    (_eop)->eo_u32[3]);					\
484*49ef7e06SGarrett D'Amore 									\
485*49ef7e06SGarrett D'Amore 		_NOTE(CONSTANTCONDITION)				\
486*49ef7e06SGarrett D'Amore 		if (_lock)						\
487*49ef7e06SGarrett D'Amore 			mutex_exit(&((_esbp)->esb_lock));		\
488*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
489*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
490*49ef7e06SGarrett D'Amore 
491*49ef7e06SGarrett D'Amore /* Use the standard octo-word write for doorbell writes */
492*49ef7e06SGarrett D'Amore #define	EFSYS_BAR_DOORBELL_WRITEO(_esbp, _offset, _eop)			\
493*49ef7e06SGarrett D'Amore 	do {								\
494*49ef7e06SGarrett D'Amore 		EFSYS_BAR_WRITEO((_esbp), (_offset), (_eop), B_FALSE);	\
495*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
496*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
497*49ef7e06SGarrett D'Amore 
498*49ef7e06SGarrett D'Amore /* SPIN */
499*49ef7e06SGarrett D'Amore 
500*49ef7e06SGarrett D'Amore #define	EFSYS_SPIN(_us)							\
501*49ef7e06SGarrett D'Amore 	drv_usecwait(_us)
502*49ef7e06SGarrett D'Amore 
503*49ef7e06SGarrett D'Amore /* TODO: Perhaps this should use delay(9F)? */
504*49ef7e06SGarrett D'Amore #define	EFSYS_SLEEP	EFSYS_SPIN
505*49ef7e06SGarrett D'Amore 
506*49ef7e06SGarrett D'Amore /* BARRIERS */
507*49ef7e06SGarrett D'Amore 
508*49ef7e06SGarrett D'Amore /* Strict ordering guaranteed by devacc.devacc_attr_dataorder */
509*49ef7e06SGarrett D'Amore #define	EFSYS_MEM_READ_BARRIER()	membar_consumer()
510*49ef7e06SGarrett D'Amore /* TODO: Is ddi_put32() properly barriered? */
511*49ef7e06SGarrett D'Amore #define	EFSYS_PIO_WRITE_BARRIER()
512*49ef7e06SGarrett D'Amore 
513*49ef7e06SGarrett D'Amore /* DMA SYNC */
514*49ef7e06SGarrett D'Amore /*
515*49ef7e06SGarrett D'Amore  * It could be cheaper to sync entire map than calculate offset and
516*49ef7e06SGarrett D'Amore  * size. If so, below macros should be updated to ignore these arguments
517*49ef7e06SGarrett D'Amore  * and sync entire map.
518*49ef7e06SGarrett D'Amore  */
519*49ef7e06SGarrett D'Amore #define	EFSYS_DMA_SYNC_FOR_KERNEL(_esmp, _offset, _size)		\
520*49ef7e06SGarrett D'Amore 	(void) ddi_dma_sync((_esmp)->esm_dma_handle,			\
521*49ef7e06SGarrett D'Amore 	    (_offset), (_size), DDI_DMA_SYNC_FORKERNEL)
522*49ef7e06SGarrett D'Amore 
523*49ef7e06SGarrett D'Amore #define	EFSYS_DMA_SYNC_FOR_DEVICE(_esmp, _offset, _size)		\
524*49ef7e06SGarrett D'Amore 	(void) ddi_dma_sync((_esmp)->esm_dma_handle,			\
525*49ef7e06SGarrett D'Amore 	    (_offset), (_size), DDI_DMA_SYNC_FORDEV)
526*49ef7e06SGarrett D'Amore 
527*49ef7e06SGarrett D'Amore /* TIMESTAMP */
528*49ef7e06SGarrett D'Amore 
529*49ef7e06SGarrett D'Amore typedef	clock_t	efsys_timestamp_t;
530*49ef7e06SGarrett D'Amore 
531*49ef7e06SGarrett D'Amore /* TODO: Arguably this could use gethrtime */
532*49ef7e06SGarrett D'Amore #define	EFSYS_TIMESTAMP(_usp)						\
533*49ef7e06SGarrett D'Amore 	do {								\
534*49ef7e06SGarrett D'Amore 		*(_usp) = drv_hztousec(ddi_get_lbolt());		\
535*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
536*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
537*49ef7e06SGarrett D'Amore 
538*49ef7e06SGarrett D'Amore /* KMEM */
539*49ef7e06SGarrett D'Amore 
540*49ef7e06SGarrett D'Amore #define	EFSYS_KMEM_ALLOC(_esip, _size, _p)				\
541*49ef7e06SGarrett D'Amore 	do {								\
542*49ef7e06SGarrett D'Amore 		(_esip) = (_esip);					\
543*49ef7e06SGarrett D'Amore 		(_p) = kmem_zalloc((_size), KM_NOSLEEP);		\
544*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
545*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
546*49ef7e06SGarrett D'Amore 
547*49ef7e06SGarrett D'Amore #define	EFSYS_KMEM_FREE(_esip, _size, _p)				\
548*49ef7e06SGarrett D'Amore 	do {								\
549*49ef7e06SGarrett D'Amore 		(_esip) = (_esip);					\
550*49ef7e06SGarrett D'Amore 		kmem_free((_p), (_size));				\
551*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
552*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
553*49ef7e06SGarrett D'Amore 
554*49ef7e06SGarrett D'Amore /* LOCK */
555*49ef7e06SGarrett D'Amore 
556*49ef7e06SGarrett D'Amore typedef kmutex_t	efsys_lock_t;
557*49ef7e06SGarrett D'Amore 
558*49ef7e06SGarrett D'Amore #define	EFSYS_LOCK_MAGIC	0x000010c4
559*49ef7e06SGarrett D'Amore 
560*49ef7e06SGarrett D'Amore #define	EFSYS_LOCK(_lockp, _state)					\
561*49ef7e06SGarrett D'Amore 	do {								\
562*49ef7e06SGarrett D'Amore 		mutex_enter(_lockp);					\
563*49ef7e06SGarrett D'Amore 		(_state) = EFSYS_LOCK_MAGIC;				\
564*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
565*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
566*49ef7e06SGarrett D'Amore 
567*49ef7e06SGarrett D'Amore #define	EFSYS_UNLOCK(_lockp, _state)					\
568*49ef7e06SGarrett D'Amore 	do {								\
569*49ef7e06SGarrett D'Amore 		if ((_state) != EFSYS_LOCK_MAGIC)			\
570*49ef7e06SGarrett D'Amore 			ASSERT(B_FALSE);				\
571*49ef7e06SGarrett D'Amore 		mutex_exit(_lockp);					\
572*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
573*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
574*49ef7e06SGarrett D'Amore 
575*49ef7e06SGarrett D'Amore /* STAT */
576*49ef7e06SGarrett D'Amore 
577*49ef7e06SGarrett D'Amore typedef kstat_named_t		efsys_stat_t;
578*49ef7e06SGarrett D'Amore 
579*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_INCR(_knp, _delta) 					\
580*49ef7e06SGarrett D'Amore 	do {								\
581*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) += (_delta);			\
582*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
583*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
584*49ef7e06SGarrett D'Amore 
585*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_DECR(_knp, _delta) 					\
586*49ef7e06SGarrett D'Amore 	do {								\
587*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) -= (_delta);			\
588*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
589*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
590*49ef7e06SGarrett D'Amore 
591*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_SET(_knp, _val)					\
592*49ef7e06SGarrett D'Amore 	do {								\
593*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) = (_val);				\
594*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
595*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
596*49ef7e06SGarrett D'Amore 
597*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_SET_QWORD(_knp, _valp)				\
598*49ef7e06SGarrett D'Amore 	do {								\
599*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) = LE_64((_valp)->eq_u64[0]);	\
600*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
601*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
602*49ef7e06SGarrett D'Amore 
603*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_SET_DWORD(_knp, _valp)				\
604*49ef7e06SGarrett D'Amore 	do {								\
605*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) = LE_32((_valp)->ed_u32[0]);	\
606*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
607*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
608*49ef7e06SGarrett D'Amore 
609*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_INCR_QWORD(_knp, _valp)				\
610*49ef7e06SGarrett D'Amore 	do {								\
611*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) += LE_64((_valp)->eq_u64[0]);	\
612*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
613*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
614*49ef7e06SGarrett D'Amore 
615*49ef7e06SGarrett D'Amore #define	EFSYS_STAT_SUBR_QWORD(_knp, _valp)				\
616*49ef7e06SGarrett D'Amore 	do {								\
617*49ef7e06SGarrett D'Amore 		((_knp)->value.ui64) -= LE_64((_valp)->eq_u64[0]);	\
618*49ef7e06SGarrett D'Amore 	_NOTE(CONSTANTCONDITION)					\
619*49ef7e06SGarrett D'Amore 	} while (B_FALSE)
620*49ef7e06SGarrett D'Amore 
621*49ef7e06SGarrett D'Amore /* ERR */
622*49ef7e06SGarrett D'Amore 
623*49ef7e06SGarrett D'Amore extern void	sfxge_err(efsys_identifier_t *, unsigned int,
624*49ef7e06SGarrett D'Amore 		    uint32_t, uint32_t);
625*49ef7e06SGarrett D'Amore 
626*49ef7e06SGarrett D'Amore #if EFSYS_OPT_DECODE_INTR_FATAL
627*49ef7e06SGarrett D'Amore #define	EFSYS_ERR(_esip, _code, _dword0, _dword1)			\
628*49ef7e06SGarrett D'Amore 	sfxge_err((_esip), (_code), (_dword0), (_dword1))
629*49ef7e06SGarrett D'Amore #endif
630*49ef7e06SGarrett D'Amore 
631*49ef7e06SGarrett D'Amore /* PROBE */
632*49ef7e06SGarrett D'Amore 
633*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE(_name)						\
634*49ef7e06SGarrett D'Amore 	DTRACE_PROBE(_name)
635*49ef7e06SGarrett D'Amore 
636*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE1(_name, _type1, _arg1)				\
637*49ef7e06SGarrett D'Amore 	DTRACE_PROBE1(_name, _type1, _arg1)
638*49ef7e06SGarrett D'Amore 
639*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE2(_name, _type1, _arg1, _type2, _arg2)		\
640*49ef7e06SGarrett D'Amore 	DTRACE_PROBE2(_name, _type1, _arg1, _type2, _arg2)
641*49ef7e06SGarrett D'Amore 
642*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE3(_name, _type1, _arg1, _type2, _arg2,		\
643*49ef7e06SGarrett D'Amore 	    _type3, _arg3)						\
644*49ef7e06SGarrett D'Amore 	DTRACE_PROBE3(_name, _type1, _arg1, _type2, _arg2,		\
645*49ef7e06SGarrett D'Amore 	    _type3, _arg3)
646*49ef7e06SGarrett D'Amore 
647*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE4(_name, _type1, _arg1, _type2, _arg2,		\
648*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4)				\
649*49ef7e06SGarrett D'Amore 	DTRACE_PROBE4(_name, _type1, _arg1, _type2, _arg2,		\
650*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4)
651*49ef7e06SGarrett D'Amore 
652*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE5(_name, _type1, _arg1, _type2, _arg2,		\
653*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4, _type5, _arg5)		\
654*49ef7e06SGarrett D'Amore 	DTRACE_PROBE5(_name, _type1, _arg1, _type2, _arg2,		\
655*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4, _type5, _arg5)
656*49ef7e06SGarrett D'Amore 
657*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE6(_name, _type1, _arg1, _type2, _arg2,		\
658*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4, _type5, _arg5,		\
659*49ef7e06SGarrett D'Amore 	    _type6, _arg6)						\
660*49ef7e06SGarrett D'Amore 	DTRACE_PROBE6(_name, _type1, _arg1, _type2, _arg2,		\
661*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4, _type5, _arg5,		\
662*49ef7e06SGarrett D'Amore 	    _type6, _arg6)
663*49ef7e06SGarrett D'Amore 
664*49ef7e06SGarrett D'Amore #define	EFSYS_PROBE7(_name, _type1, _arg1, _type2, _arg2,		\
665*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4, _type5, _arg5,		\
666*49ef7e06SGarrett D'Amore 	    _type6, _arg6, _type7, _arg7)				\
667*49ef7e06SGarrett D'Amore 	DTRACE_PROBE7(_name, _type1, _arg1, _type2, _arg2,		\
668*49ef7e06SGarrett D'Amore 	    _type3, _arg3, _type4, _arg4, _type5, _arg5,		\
669*49ef7e06SGarrett D'Amore 	    _type6, _arg6, _type7, _arg7)
670*49ef7e06SGarrett D'Amore 
671*49ef7e06SGarrett D'Amore /* ASSERT */
672*49ef7e06SGarrett D'Amore 
673*49ef7e06SGarrett D'Amore #define	EFSYS_ASSERT(_exp)		ASSERT(_exp)
674*49ef7e06SGarrett D'Amore #define	EFSYS_ASSERT3U(_x, _op, _y)	ASSERT3U(_x, _op, _y)
675*49ef7e06SGarrett D'Amore #define	EFSYS_ASSERT3S(_x, _op, _y)	ASSERT3S(_x, _op, _y)
676*49ef7e06SGarrett D'Amore #define	EFSYS_ASSERT3P(_x, _op, _y)	ASSERT3P(_x, _op, _y)
677*49ef7e06SGarrett D'Amore 
678*49ef7e06SGarrett D'Amore /* ROTATE */
679*49ef7e06SGarrett D'Amore 
680*49ef7e06SGarrett D'Amore #define	EFSYS_HAS_ROTL_DWORD 0
681*49ef7e06SGarrett D'Amore 
682*49ef7e06SGarrett D'Amore #ifdef	__cplusplus
683*49ef7e06SGarrett D'Amore }
684*49ef7e06SGarrett D'Amore #endif
685*49ef7e06SGarrett D'Amore 
686*49ef7e06SGarrett D'Amore #endif	/* _SYS_EFSYS_H */
687