xref: /illumos-gate/usr/src/uts/common/io/hxge/hxge_common_impl.h (revision 22f5594a529d50114d839d4ddecc2c499731a3d7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_HXGE_HXGE_COMMON_IMPL_H
27 #define	_SYS_HXGE_HXGE_COMMON_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #define	HPI_REGH(hpi_handle)		(hpi_handle.regh)
36 #define	HPI_REGP(hpi_handle)		(hpi_handle.regp)
37 
38 #define		NO_DEBUG	0x0000000000000000ULL
39 #define		RX_CTL		0x0000000000000001ULL
40 #define		TX_CTL		0x0000000000000002ULL
41 #define		OBP_CTL		0x0000000000000004ULL
42 #define		VPD_CTL		0x0000000000000008ULL
43 #define		DDI_CTL		0x0000000000000010ULL
44 #define		MEM_CTL		0x0000000000000020ULL
45 #define		IOC_CTL		0x0000000000000040ULL
46 #define		MOD_CTL		0x0000000000000080ULL
47 #define		DMA_CTL		0x0000000000000100ULL
48 #define		STR_CTL		0x0000000000000200ULL
49 #define		INT_CTL		0x0000000000000400ULL
50 #define		SYSERR_CTL	0x0000000000000800ULL
51 #define		KST_CTL		0x0000000000001000ULL
52 #define		FCRAM_CTL	0x0000000000002000ULL
53 #define		MAC_CTL		0x0000000000004000ULL
54 #define		DMA2_CTL	0x0000000000008000ULL
55 #define		RX2_CTL		0x0000000000010000ULL
56 #define		TX2_CTL		0x0000000000020000ULL
57 #define		MEM2_CTL	0x0000000000040000ULL
58 #define		MEM3_CTL	0x0000000000080000ULL
59 #define		NEMO_CTL	0x0000000000100000ULL
60 #define		NDD_CTL		0x0000000000200000ULL
61 #define		NDD2_CTL	0x0000000000400000ULL
62 #define		PFC_CTL		0x0000000000800000ULL
63 #define		CFG_CTL		0x0000000001000000ULL
64 #define		CFG2_CTL	0x0000000002000000ULL
65 #define		VIR_CTL		0x0000000004000000ULL
66 #define		VIR2_CTL	0x0000000008000000ULL
67 #define		HXGE_NOTE	0x0000000010000000ULL
68 #define		HXGE_ERR_CTL	0x0000000020000000ULL
69 #define		MAC_INT_CTL	0x0000000040000000ULL
70 #define		RX_INT_CTL	0x0000000080000000ULL
71 #define		TX_ERR_CTL	0x0000000100000000ULL
72 #define		DDI_INT_CTL	0x0000000200000000ULL
73 #define		DUMP_ALWAYS	0x2000000000000000ULL
74 
75 /* HPI Debug and Error defines */
76 #define		HPI_RDC_CTL	0x0000000000000001ULL
77 #define		HPI_TDC_CTL	0x0000000000000002ULL
78 #define		HPI_VMAC_CTL	0x0000000000000004ULL
79 #define		HPI_PFC_CTL	0x0000000000000008ULL
80 #define		HPI_VIR_CTL	0x0000000000000010ULL
81 #define		HPI_PIO_CTL	0x0000000000000020ULL
82 #define		HPI_VIO_CTL	0x0000000000000040ULL
83 #define		HPI_REG_CTL	0x0000000000000080ULL
84 #define		HPI_ERR_CTL	0x0000000000000100ULL
85 
86 #include <sys/types.h>
87 #include <sys/ddi.h>
88 #include <sys/sunddi.h>
89 #include <sys/dditypes.h>
90 #include <sys/ethernet.h>
91 
92 #ifdef HXGE_DEBUG
93 #define	HXGE_DEBUG_MSG(params) hxge_debug_msg params
94 #else
95 #define	HXGE_DEBUG_MSG(params)
96 #endif
97 
98 #define	HXGE_ERROR_MSG(params)	hxge_debug_msg params
99 
100 typedef kmutex_t			hxge_os_mutex_t;
101 typedef	krwlock_t			hxge_os_rwlock_t;
102 
103 typedef	dev_info_t			hxge_dev_info_t;
104 typedef	ddi_iblock_cookie_t 		hxge_intr_cookie_t;
105 
106 typedef ddi_acc_handle_t		hxge_os_acc_handle_t;
107 typedef	hxge_os_acc_handle_t		hpi_reg_handle_t;
108 #if defined(__i386)
109 typedef	uint32_t			hpi_reg_ptr_t;
110 #else
111 typedef	uint64_t			hpi_reg_ptr_t;
112 #endif
113 
114 typedef ddi_dma_handle_t		hxge_os_dma_handle_t;
115 typedef struct _hxge_dma_common_t	hxge_os_dma_common_t;
116 typedef struct _hxge_block_mv_t		hxge_os_block_mv_t;
117 typedef frtn_t				hxge_os_frtn_t;
118 
119 #define	HXGE_MUTEX_DRIVER		MUTEX_DRIVER
120 #define	MUTEX_INIT(lock, name, type, arg)	\
121 					mutex_init(lock, name, type, arg)
122 #define	MUTEX_ENTER(lock)		mutex_enter(lock)
123 #define	MUTEX_TRY_ENTER(lock)		mutex_tryenter(lock)
124 #define	MUTEX_EXIT(lock)		mutex_exit(lock)
125 #define	MUTEX_DESTROY(lock)		mutex_destroy(lock)
126 
127 #define	RW_INIT(lock, name, type, arg)	rw_init(lock, name, type, arg)
128 #define	RW_ENTER_WRITER(lock)		rw_enter(lock, RW_WRITER)
129 #define	RW_ENTER_READER(lock)		rw_enter(lock, RW_READER)
130 #define	RW_TRY_ENTER(lock, type)	rw_tryenter(lock, type)
131 #define	RW_EXIT(lock)			rw_exit(lock)
132 #define	RW_DESTROY(lock)		rw_destroy(lock)
133 #define	KMEM_ALLOC(size, flag)		kmem_alloc(size, flag)
134 #define	KMEM_ZALLOC(size, flag)		kmem_zalloc(size, flag)
135 #define	KMEM_FREE(buf, size)		kmem_free(buf, size)
136 
137 #define	HXGE_DELAY(microseconds)	 (drv_usecwait(microseconds))
138 
139 /*
140  * HXGE_HPI_PIO_READ32 and HXGE_HPI_PIO_READ64 should not be called directly
141  * on 32 bit platforms
142  */
143 #define	HXGE_HPI_PIO_READ32(hpi_handle, offset)		\
144 	(ddi_get32(HPI_REGH(hpi_handle),		\
145 	(uint32_t *)(HPI_REGP(hpi_handle) + offset)))
146 
147 #if defined(__i386)
148 #define	HXGE_HPI_PIO_READ64(hpi_handle, offset)		\
149 	(ddi_get64(HPI_REGH(hpi_handle),		\
150 	(uint64_t *)(HPI_REGP(hpi_handle) + (uint32_t)offset)))
151 #else
152 #define	HXGE_HPI_PIO_READ64(hpi_handle, offset)		\
153 	(ddi_get64(HPI_REGH(hpi_handle),		\
154 	(uint64_t *)(HPI_REGP(hpi_handle) + offset)))
155 #endif
156 
157 #if defined(__i386)
158 
159 #define	HXGE_HPI_PIO_WRITE32(hpi_handle, offset, data) {	\
160 	MUTEX_ENTER(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
161 	ddi_put32(HPI_REGH(hpi_handle),				\
162 	    (uint32_t *)(HPI_REGP(hpi_handle) +			\
163 	    (uint32_t)offset), data);				\
164 	MUTEX_EXIT(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
165 }
166 #define	HXGE_HPI_PIO_WRITE64(hpi_handle, offset, data) {	\
167 	MUTEX_ENTER(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
168 	ddi_put64(HPI_REGH(hpi_handle),				\
169 	    (uint64_t *)(HPI_REGP(hpi_handle) +			\
170 	    (uint32_t)offset), data);				\
171 	MUTEX_EXIT(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
172 }
173 #define	HXGE_MEM_PIO_READ64(hpi_handle, val_p) {		\
174 	MUTEX_ENTER(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
175 	*(val_p) = ddi_get64(HPI_REGH(hpi_handle),		\
176 	    (uint64_t *)HPI_REGP(hpi_handle));			\
177 	MUTEX_EXIT(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
178 }
179 #define	HXGE_MEM_PIO_WRITE64(hpi_handle, data) {		\
180 	MUTEX_ENTER(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
181 	ddi_put64(HPI_REGH(hpi_handle),				\
182 	    (uint64_t *)HPI_REGP(hpi_handle), data);		\
183 	MUTEX_EXIT(&((hxge_t *)hpi_handle.hxgep)->pio_lock);	\
184 }
185 #define	HXGE_REG_RD64(handle, offset, val_p) {			\
186 	MUTEX_ENTER(&((hxge_t *)handle.hxgep)->pio_lock);	\
187 	*(val_p) = HXGE_HPI_PIO_READ64(handle, offset);		\
188 	MUTEX_EXIT(&((hxge_t *)handle.hxgep)->pio_lock);	\
189 }
190 #define	HXGE_REG_RD32(handle, offset, val_p) {			\
191 	MUTEX_ENTER(&((hxge_t *)handle.hxgep)->pio_lock);	\
192 	*(val_p) = HXGE_HPI_PIO_READ32(handle, offset);		\
193 	MUTEX_EXIT(&((hxge_t *)handle.hxgep)->pio_lock);	\
194 }
195 
196 #else
197 
198 #define	HXGE_HPI_PIO_WRITE32(hpi_handle, offset, data)		\
199 	(ddi_put32(HPI_REGH(hpi_handle),			\
200 	(uint32_t *)(HPI_REGP(hpi_handle) + offset), data))
201 #define	HXGE_HPI_PIO_WRITE64(hpi_handle, offset, data)		\
202 	(ddi_put64(HPI_REGH(hpi_handle),			\
203 	(uint64_t *)(HPI_REGP(hpi_handle) + offset), data))
204 #define	HXGE_MEM_PIO_READ64(hpi_handle, val_p) {		\
205 	*(val_p) = ddi_get64(HPI_REGH(hpi_handle),		\
206 		(uint64_t *)HPI_REGP(hpi_handle));		\
207 }
208 #define	HXGE_MEM_PIO_WRITE64(hpi_handle, data)			\
209 	(ddi_put64(HPI_REGH(hpi_handle),			\
210 		(uint64_t *)HPI_REGP(hpi_handle), data))
211 #define	HXGE_REG_RD64(handle, offset, val_p) {			\
212 	*(val_p) = HXGE_HPI_PIO_READ64(handle, offset);		\
213 }
214 #define	HXGE_REG_RD32(handle, offset, val_p) {			\
215 	*(val_p) = HXGE_HPI_PIO_READ32(handle, offset);		\
216 }
217 
218 #endif
219 
220 #define	HXGE_REG_WR64(handle, offset, val) {			\
221 	HXGE_HPI_PIO_WRITE64(handle, (offset), (val));		\
222 }
223 #define	HXGE_REG_WR32(handle, offset, val) {			\
224 	HXGE_HPI_PIO_WRITE32(handle, (offset), (val));		\
225 }
226 
227 #define	FM_SERVICE_RESTORED(hxgep)				\
228 	if (DDI_FM_EREPORT_CAP(hxgep->fm_capabilities))		\
229 		ddi_fm_service_impact(hxgep->dip, DDI_SERVICE_RESTORED)
230 #define	HXGE_FM_REPORT_ERROR(hxgep, chan, ereport_id)		\
231 	if (DDI_FM_EREPORT_CAP(hxgep->fm_capabilities))		\
232 		hxge_fm_report_error(hxgep, chan, ereport_id)
233 
234 #ifdef	__cplusplus
235 }
236 #endif
237 
238 #endif	/* _SYS_HXGE_HXGE_COMMON_IMPL_H */
239