xref: /illumos-gate/usr/src/uts/common/sys/nxge/nxge_common_impl.h (revision adfcba552dfc70ff685a2e8703fe1761b244f3e8)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_NXGE_NXGE_COMMON_IMPL_H
27 #define	_SYS_NXGE_NXGE_COMMON_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #define	NPI_REGH(npi_handle)		(npi_handle.regh)
36 #define	NPI_REGP(npi_handle)		(npi_handle.regp)
37 
38 #if defined(NXGE_DEBUG_DMA) || defined(NXGE_DEBUG_TXC)
39 #define	__NXGE_STATIC
40 #define	__NXGE_INLINE
41 #else
42 #define	__NXGE_STATIC			static
43 #define	__NXGE_INLINE			inline
44 #endif
45 
46 #ifdef	AXIS_DEBUG
47 #define	AXIS_WAIT			(100000)
48 #define	AXIS_LONG_WAIT			(100000)
49 #define	AXIS_WAIT_W			(80000)
50 #define	AXIS_WAIT_R			(100000)
51 #define	AXIS_WAIT_LOOP			(4000)
52 #define	AXIS_WAIT_PER_LOOP		(AXIS_WAIT_R/AXIS_WAIT_LOOP)
53 #endif
54 
55 #define	NO_DEBUG	0x0000000000000000ULL
56 #define	MDT_CTL		0x0000000000000001ULL
57 #define	RX_CTL		0x0000000000000002ULL
58 #define	TX_CTL		0x0000000000000004ULL
59 #define	OBP_CTL		0x0000000000000008ULL
60 
61 #define	VPD_CTL		0x0000000000000010ULL
62 #define	DDI_CTL		0x0000000000000020ULL
63 #define	MEM_CTL		0x0000000000000040ULL
64 #define	SAP_CTL		0x0000000000000080ULL
65 
66 #define	IOC_CTL		0x0000000000000100ULL
67 #define	MOD_CTL		0x0000000000000200ULL
68 #define	DMA_CTL		0x0000000000000400ULL
69 #define	STR_CTL		0x0000000000000800ULL
70 
71 #define	INT_CTL		0x0000000000001000ULL
72 #define	SYSERR_CTL	0x0000000000002000ULL
73 #define	KST_CTL		0x0000000000004000ULL
74 #define	PCS_CTL		0x0000000000008000ULL
75 
76 #define	MII_CTL		0x0000000000010000ULL
77 #define	MIF_CTL		0x0000000000020000ULL
78 #define	FCRAM_CTL	0x0000000000040000ULL
79 #define	MAC_CTL		0x0000000000080000ULL
80 
81 #define	IPP_CTL		0x0000000000100000ULL
82 #define	DMA2_CTL	0x0000000000200000ULL
83 #define	RX2_CTL		0x0000000000400000ULL
84 #define	TX2_CTL		0x0000000000800000ULL
85 
86 #define	MEM2_CTL	0x0000000001000000ULL
87 #define	MEM3_CTL	0x0000000002000000ULL
88 #define	NXGE_CTL	0x0000000004000000ULL
89 #define	NDD_CTL		0x0000000008000000ULL
90 #define	NDD2_CTL	0x0000000010000000ULL
91 
92 #define	TCAM_CTL	0x0000000020000000ULL
93 #define	CFG_CTL		0x0000000040000000ULL
94 #define	CFG2_CTL	0x0000000080000000ULL
95 
96 #define	FFLP_CTL	TCAM_CTL | FCRAM_CTL
97 
98 #define	VIR_CTL		0x0000000100000000ULL
99 #define	VIR2_CTL	0x0000000200000000ULL
100 
101 #define	NXGE_NOTE	0x0000001000000000ULL
102 #define	NXGE_ERR_CTL	0x0000002000000000ULL
103 
104 #define	DUMP_ALWAYS	0x2000000000000000ULL
105 
106 /* NPI Debug and Error defines */
107 #define	NPI_RDC_CTL	0x0000000000000001ULL
108 #define	NPI_TDC_CTL	0x0000000000000002ULL
109 #define	NPI_TXC_CTL	0x0000000000000004ULL
110 #define	NPI_IPP_CTL	0x0000000000000008ULL
111 
112 #define	NPI_XPCS_CTL	0x0000000000000010ULL
113 #define	NPI_PCS_CTL	0x0000000000000020ULL
114 #define	NPI_ESR_CTL	0x0000000000000040ULL
115 #define	NPI_BMAC_CTL	0x0000000000000080ULL
116 #define	NPI_XMAC_CTL	0x0000000000000100ULL
117 #define	NPI_MAC_CTL	NPI_BMAC_CTL | NPI_XMAC_CTL
118 
119 #define	NPI_ZCP_CTL	0x0000000000000200ULL
120 #define	NPI_TCAM_CTL	0x0000000000000400ULL
121 #define	NPI_FCRAM_CTL	0x0000000000000800ULL
122 #define	NPI_FFLP_CTL	NPI_TCAM_CTL | NPI_FCRAM_CTL
123 
124 #define	NPI_VIR_CTL	0x0000000000001000ULL
125 #define	NPI_PIO_CTL	0x0000000000002000ULL
126 #define	NPI_VIO_CTL	0x0000000000004000ULL
127 
128 #define	NPI_REG_CTL	0x0000000040000000ULL
129 #define	NPI_CTL		0x0000000080000000ULL
130 #define	NPI_ERR_CTL	0x0000000080000000ULL
131 
132 #if defined(SOLARIS) && defined(_KERNEL)
133 
134 #include <sys/types.h>
135 #include <sys/ddi.h>
136 #include <sys/sunddi.h>
137 #include <sys/dditypes.h>
138 #include <sys/ethernet.h>
139 
140 #ifdef NXGE_DEBUG
141 #define	NXGE_DEBUG_MSG(params) nxge_debug_msg params
142 #else
143 #define	NXGE_DEBUG_MSG(params)
144 #endif
145 
146 #if 1
147 #define	NXGE_ERROR_MSG(params)	nxge_debug_msg params
148 #define	NXGE_WARN_MSG(params)	nxge_debug_msg params
149 #else
150 #define	NXGE_ERROR_MSG(params)
151 #define	NXGE_WARN_MSG(params)
152 #endif
153 
154 typedef kmutex_t			nxge_os_mutex_t;
155 typedef	krwlock_t			nxge_os_rwlock_t;
156 
157 typedef	dev_info_t			nxge_dev_info_t;
158 typedef	ddi_iblock_cookie_t 		nxge_intr_cookie_t;
159 
160 typedef ddi_acc_handle_t		nxge_os_acc_handle_t;
161 typedef	nxge_os_acc_handle_t		npi_reg_handle_t;
162 #if defined(__i386)
163 typedef	uint32_t			npi_reg_ptr_t;
164 #else
165 typedef uint64_t			npi_reg_ptr_t;
166 #endif
167 
168 typedef ddi_dma_handle_t		nxge_os_dma_handle_t;
169 typedef struct _nxge_dma_common_t	nxge_os_dma_common_t;
170 typedef struct _nxge_block_mv_t		nxge_os_block_mv_t;
171 typedef frtn_t				nxge_os_frtn_t;
172 
173 #define	NXGE_MUTEX_DRIVER		MUTEX_DRIVER
174 #define	MUTEX_INIT(lock, name, type, arg) \
175 	mutex_init(lock, name, type, arg)
176 #define	MUTEX_ENTER(lock)		mutex_enter(lock)
177 #define	MUTEX_TRY_ENTER(lock)		mutex_tryenter(lock)
178 #define	MUTEX_EXIT(lock)		mutex_exit(lock)
179 #define	MUTEX_DESTROY(lock)		mutex_destroy(lock)
180 
181 #define	RW_INIT(lock, name, type, arg)	rw_init(lock, name, type, arg)
182 #define	RW_ENTER_WRITER(lock)		rw_enter(lock, RW_WRITER)
183 #define	RW_ENTER_READER(lock)		rw_enter(lock, RW_READER)
184 #define	RW_TRY_ENTER(lock, type)	rw_tryenter(lock, type)
185 #define	RW_EXIT(lock)			rw_exit(lock)
186 #define	RW_DESTROY(lock)		rw_destroy(lock)
187 #define	KMEM_ALLOC(size, flag)		kmem_alloc(size, flag)
188 #define	KMEM_ZALLOC(size, flag)		kmem_zalloc(size, flag)
189 #define	KMEM_FREE(buf, size)		kmem_free(buf, size)
190 
191 #define	NXGE_DELAY(microseconds)	 (drv_usecwait(microseconds))
192 
193 #define	NXGE_PIO_READ8(handle, devaddr, offset) \
194 	(ddi_get8(handle, (uint8_t *)((caddr_t)devaddr + offset)))
195 
196 #define	NXGE_PIO_READ16(handle, devaddr, offset) \
197 	(ddi_get16(handle, (uint16_t *)((caddr_t)devaddr + offset)))
198 
199 #define	NXGE_PIO_READ32(handle, devaddr, offset) \
200 	(ddi_get32(handle, (uint32_t *)((caddr_t)devaddr + offset)))
201 
202 #define	NXGE_PIO_READ64(handle, devaddr, offset) \
203 	(ddi_get64(handle, (uint64_t *)((caddr_t)devaddr + offset)))
204 
205 #define	NXGE_PIO_WRITE8(handle, devaddr, offset, data) \
206 	(ddi_put8(handle, (uint8_t *)((caddr_t)devaddr + offset), data))
207 
208 #define	NXGE_PIO_WRITE16(handle, devaddr, offset, data) \
209 	(ddi_get16(handle, (uint16_t *)((caddr_t)devaddr + offset), data))
210 
211 #define	NXGE_PIO_WRITE32(handle, devaddr, offset, data)	\
212 	(ddi_put32(handle, (uint32_t *)((caddr_t)devaddr + offset), data))
213 
214 #define	NXGE_PIO_WRITE64(handle, devaddr, offset, data) \
215 	(ddi_put64(handle, (uint64_t *)((caddr_t)devaddr + offset), data))
216 
217 #define	NXGE_NPI_PIO_READ8(npi_handle, offset) \
218 	(ddi_get8(NPI_REGH(npi_handle),	\
219 	(uint8_t *)(NPI_REGP(npi_handle) + offset)))
220 
221 #define	NXGE_NPI_PIO_READ16(npi_handle, offset) \
222 	(ddi_get16(NPI_REGH(npi_handle), \
223 	(uint16_t *)(NPI_REGP(npi_handle) + offset)))
224 
225 #define	NXGE_NPI_PIO_READ32(npi_handle, offset) \
226 	(ddi_get32(NPI_REGH(npi_handle), \
227 	(uint32_t *)(NPI_REGP(npi_handle) + offset)))
228 
229 #if defined(__i386)
230 #define	NXGE_NPI_PIO_READ64(npi_handle, offset)		\
231 	(ddi_get64(NPI_REGH(npi_handle),		\
232 	(uint64_t *)(NPI_REGP(npi_handle) + (uint32_t)offset)))
233 #else
234 #define	NXGE_NPI_PIO_READ64(npi_handle, offset)		\
235 	(ddi_get64(NPI_REGH(npi_handle),		\
236 	(uint64_t *)(NPI_REGP(npi_handle) + offset)))
237 #endif
238 
239 #define	NXGE_NPI_PIO_WRITE8(npi_handle, offset, data)	\
240 	(ddi_put8(NPI_REGH(npi_handle),			\
241 	(uint8_t *)(NPI_REGP(npi_handle) + offset), data))
242 
243 #define	NXGE_NPI_PIO_WRITE16(npi_handle, offset, data)	\
244 	(ddi_put16(NPI_REGH(npi_handle),		\
245 	(uint16_t *)(NPI_REGP(npi_handle) + offset), data))
246 
247 #define	NXGE_NPI_PIO_WRITE32(npi_handle, offset, data)	\
248 	(ddi_put32(NPI_REGH(npi_handle),		\
249 	(uint32_t *)(NPI_REGP(npi_handle) + offset), data))
250 
251 #if defined(__i386)
252 #define	NXGE_NPI_PIO_WRITE64(npi_handle, offset, data)	\
253 	(ddi_put64(NPI_REGH(npi_handle),		\
254 	(uint64_t *)(NPI_REGP(npi_handle) + (uint32_t)offset), data))
255 #else
256 #define	NXGE_NPI_PIO_WRITE64(npi_handle, offset, data)	\
257 	(ddi_put64(NPI_REGH(npi_handle),		\
258 	(uint64_t *)(NPI_REGP(npi_handle) + offset), data))
259 #endif
260 
261 #define	NXGE_MEM_PIO_READ8(npi_handle)		\
262 	(ddi_get8(NPI_REGH(npi_handle), (uint8_t *)NPI_REGP(npi_handle)))
263 
264 #define	NXGE_MEM_PIO_READ16(npi_handle)		\
265 	(ddi_get16(NPI_REGH(npi_handle), (uint16_t *)NPI_REGP(npi_handle)))
266 
267 #define	NXGE_MEM_PIO_READ32(npi_handle)		\
268 	(ddi_get32(NPI_REGH(npi_handle), (uint32_t *)NPI_REGP(npi_handle)))
269 
270 #define	NXGE_MEM_PIO_READ64(npi_handle)		\
271 	(ddi_get64(NPI_REGH(npi_handle), (uint64_t *)NPI_REGP(npi_handle)))
272 
273 #define	NXGE_MEM_PIO_WRITE8(npi_handle, data)	\
274 	(ddi_put8(NPI_REGH(npi_handle), (uint8_t *)NPI_REGP(npi_handle), data))
275 
276 #define	NXGE_MEM_PIO_WRITE16(npi_handle, data)	\
277 		(ddi_put16(NPI_REGH(npi_handle),	\
278 		(uint16_t *)NPI_REGP(npi_handle), data))
279 
280 #define	NXGE_MEM_PIO_WRITE32(npi_handle, data)	\
281 		(ddi_put32(NPI_REGH(npi_handle),	\
282 		(uint32_t *)NPI_REGP(npi_handle), data))
283 
284 #define	NXGE_MEM_PIO_WRITE64(npi_handle, data)	\
285 		(ddi_put64(NPI_REGH(npi_handle),	\
286 		(uint64_t *)NPI_REGP(npi_handle), data))
287 
288 #define	SERVICE_LOST		DDI_SERVICE_LOST
289 #define	SERVICE_DEGRADED	DDI_SERVICE_DEGRADED
290 #define	SERVICE_UNAFFECTED	DDI_SERVICE_UNAFFECTED
291 #define	SERVICE_RESTORED	DDI_SERVICE_RESTORED
292 
293 #define	DATAPATH_FAULT		DDI_DATAPATH_FAULT
294 #define	DEVICE_FAULT		DDI_DEVICE_FAULT
295 #define	EXTERNAL_FAULT		DDI_EXTERNAL_FAULT
296 
297 #define	NOTE_LINK_UP		DL_NOTE_LINK_UP
298 #define	NOTE_LINK_DOWN		DL_NOTE_LINK_DOWN
299 #define	NOTE_SPEED		DL_NOTE_SPEED
300 #define	NOTE_PHYS_ADDR		DL_NOTE_PHYS_ADDR
301 #define	NOTE_AGGR_AVAIL		DL_NOTE_AGGR_AVAIL
302 #define	NOTE_AGGR_UNAVAIL	DL_NOTE_AGGR_UNAVAIL
303 
304 #define	FM_REPORT_FAULT(nxgep, impact, location, msg)\
305 		ddi_dev_report_fault(nxgep->dip, impact, location, msg)
306 #define	FM_CHECK_DEV_HANDLE(nxgep)\
307 		ddi_check_acc_handle(nxgep->dev_regs->nxge_regh)
308 #define	FM_GET_DEVSTATE(nxgep)\
309 		ddi_get_devstate(nxgep->dip)
310 #define	FM_SERVICE_RESTORED(nxgep)\
311 		ddi_fm_service_impact(nxgep->dip, DDI_SERVICE_RESTORED)
312 #define	NXGE_FM_REPORT_ERROR(nxgep, portn, chan, ereport_id)\
313 		nxge_fm_report_error(nxgep, portn, chan, ereport_id)
314 #define	FM_CHECK_ACC_HANDLE(nxgep, handle)\
315 		fm_check_acc_handle(handle)
316 #define	FM_CHECK_DMA_HANDLE(nxgep, handle)\
317 		fm_check_dma_handle(handle)
318 
319 #endif
320 
321 #if defined(REG_TRACE)
322 #define	NXGE_REG_RD64(handle, offset, val_p) {\
323 	*(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\
324 	npi_rtrace_update(handle, B_FALSE, &npi_rtracebuf, (uint32_t)offset, \
325 			(uint64_t)(*(val_p)));\
326 }
327 #elif defined(REG_SHOW)
328 	/*
329 	 * Send 0xbadbad to tell rs_show_reg that we do not have
330 	 * a valid RTBUF index to pass
331 	 */
332 #define	NXGE_REG_RD64(handle, offset, val_p) {\
333 	*(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\
334 	rt_show_reg(0xbadbad, B_FALSE, (uint32_t)offset, (uint64_t)(*(val_p)));\
335 }
336 #elif defined(AXIS_DEBUG) && !defined(LEGION)
337 #define	NXGE_REG_RD64(handle, offset, val_p) {\
338 	int	n;				\
339 	for (n = 0; n < AXIS_WAIT_LOOP; n++) {	\
340 		*(val_p) = 0;		\
341 		*(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\
342 		if (*(val_p) != (~0)) { \
343 			break; \
344 		}	\
345 		drv_usecwait(AXIS_WAIT_PER_LOOP); \
346 		if (n < 20) { \
347 			cmn_err(CE_WARN, "NXGE_REG_RD64: loop %d " \
348 			"REG 0x%x(0x%llx)", \
349 			n, offset, *val_p);\
350 		}	\
351 	} \
352 	if (n >= AXIS_WAIT_LOOP) {	\
353 		cmn_err(CE_WARN, "(FATAL)NXGE_REG_RD64 on offset 0x%x " \
354 			"with -1!!!", offset); \
355 	}	\
356 }
357 #else
358 
359 #define	NXGE_REG_RD64(handle, offset, val_p) {\
360 	*(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\
361 }
362 #endif
363 
364 /*
365  *	 In COSIM mode, we could loop for very long time when polling
366  *  for the completion of a Clause45 frame MDIO operations. Display
367  *  one rtrace line for each poll can result in messy screen.  Add
368  *  this MACRO for no rtrace show.
369  */
370 #define	NXGE_REG_RD64_NO_SHOW(handle, offset, val_p) {\
371 	*(val_p) = NXGE_NPI_PIO_READ64(handle, offset);\
372 }
373 
374 
375 #if defined(REG_TRACE)
376 #define	NXGE_REG_WR64(handle, offset, val) {\
377 	NXGE_NPI_PIO_WRITE64(handle, (offset), (val));\
378 	npi_rtrace_update(handle, B_TRUE, &npi_rtracebuf, (uint32_t)offset,\
379 				(uint64_t)(val));\
380 }
381 #elif defined(REG_SHOW)
382 /*
383  * Send 0xbadbad to tell rs_show_reg that we do not have
384  * a valid RTBUF index to pass
385  */
386 #define	NXGE_REG_WR64(handle, offset, val) {\
387 	NXGE_NPI_PIO_WRITE64(handle, offset, (val));\
388 	rt_show_reg(0xbadbad, B_TRUE, (uint32_t)offset, (uint64_t)(val));\
389 }
390 #else
391 #define	NXGE_REG_WR64(handle, offset, val) {\
392 	NXGE_NPI_PIO_WRITE64(handle, (offset), (val));\
393 }
394 #endif
395 
396 #ifdef	__cplusplus
397 }
398 #endif
399 
400 #endif	/* _SYS_NXGE_NXGE_COMMON_IMPL_H */
401