xref: /illumos-gate/usr/src/uts/common/sys/nxge/nxge_impl.h (revision 1bd6825caba5ece2838569ea639756aee59675a7)
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_NXGE_NXGE_IMPL_H
27 #define	_SYS_NXGE_NXGE_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * NIU HV API version definitions.
37  */
38 #define	NIU_MAJOR_VER		1
39 #define	NIU_MINOR_VER		1
40 
41 /*
42  * NIU HV API v1.0 definitions
43  */
44 #define	N2NIU_RX_LP_CONF		0x142
45 #define	N2NIU_RX_LP_INFO		0x143
46 #define	N2NIU_TX_LP_CONF		0x144
47 #define	N2NIU_TX_LP_INFO		0x145
48 
49 #ifndef _ASM
50 
51 #include	<sys/types.h>
52 #include	<sys/byteorder.h>
53 #include	<sys/debug.h>
54 #include	<sys/stropts.h>
55 #include	<sys/stream.h>
56 #include	<sys/strlog.h>
57 #ifndef	COSIM
58 #include	<sys/strsubr.h>
59 #endif
60 #include	<sys/cmn_err.h>
61 #include	<sys/vtrace.h>
62 #include	<sys/kmem.h>
63 #include	<sys/ddi.h>
64 #include	<sys/sunddi.h>
65 #include	<sys/strsun.h>
66 #include	<sys/stat.h>
67 #include	<sys/cpu.h>
68 #include	<sys/kstat.h>
69 #include	<inet/common.h>
70 #include	<inet/ip.h>
71 #include	<sys/dlpi.h>
72 #include	<inet/nd.h>
73 #include	<netinet/in.h>
74 #include	<sys/ethernet.h>
75 #include	<sys/vlan.h>
76 #include	<sys/pci.h>
77 #include	<sys/taskq.h>
78 #include	<sys/atomic.h>
79 
80 #include 	<sys/nxge/nxge_defs.h>
81 #include 	<sys/nxge/nxge_hw.h>
82 #include 	<sys/nxge/nxge_mac.h>
83 #include	<sys/nxge/nxge_mii.h>
84 #include	<sys/nxge/nxge_fm.h>
85 #if !defined(IODIAG)
86 #include	<sys/netlb.h>
87 #endif
88 
89 #include	<sys/ddi_intr.h>
90 
91 #if	defined(_KERNEL)
92 #include 	<sys/mac.h>
93 #include	<sys/mac_impl.h>
94 #include	<sys/mac_ether.h>
95 #endif
96 
97 #if	defined(sun4v)
98 #include	<sys/hypervisor_api.h>
99 #include 	<sys/machsystm.h>
100 #include 	<sys/hsvc.h>
101 #endif
102 
103 #include 	<sys/dld.h>
104 
105 /*
106  * Handy macros (taken from bge driver)
107  */
108 #define	RBR_SIZE			4
109 #define	DMA_COMMON_CHANNEL(area)	((area.dma_channel))
110 #define	DMA_COMMON_VPTR(area)		((area.kaddrp))
111 #define	DMA_COMMON_VPTR_INDEX(area, index)	\
112 					(((char *)(area.kaddrp)) + \
113 					(index * RBR_SIZE))
114 #define	DMA_COMMON_HANDLE(area)		((area.dma_handle))
115 #define	DMA_COMMON_ACC_HANDLE(area)	((area.acc_handle))
116 #define	DMA_COMMON_IOADDR(area)		((area.dma_cookie.dmac_laddress))
117 #define	DMA_COMMON_IOADDR_INDEX(area, index)	\
118 					((area.dma_cookie.dmac_laddress) + \
119 						(index * RBR_SIZE))
120 
121 #define	DMA_NPI_HANDLE(area)		((area.npi_handle)
122 
123 #define	DMA_COMMON_SYNC(area, flag)	((void) ddi_dma_sync((area).dma_handle,\
124 						(area).offset, (area).alength, \
125 						(flag)))
126 #define	DMA_COMMON_SYNC_OFFSET(area, bufoffset, len, flag)	\
127 					((void) ddi_dma_sync((area).dma_handle,\
128 					(area.offset + bufoffset), len, \
129 					(flag)))
130 
131 #define	DMA_COMMON_SYNC_RBR_DESC(area, index, flag)	\
132 				((void) ddi_dma_sync((area).dma_handle,\
133 				(index * RBR_SIZE), RBR_SIZE,	\
134 				(flag)))
135 
136 #define	DMA_COMMON_SYNC_RBR_DESC_MULTI(area, index, count, flag)	\
137 			((void) ddi_dma_sync((area).dma_handle,\
138 			(index * RBR_SIZE), count * RBR_SIZE,	\
139 				(flag)))
140 #define	DMA_COMMON_SYNC_ENTRY(area, index, flag)	\
141 				((void) ddi_dma_sync((area).dma_handle,\
142 				(index * (area).block_size),	\
143 				(area).block_size, \
144 				(flag)))
145 
146 #define	NEXT_ENTRY(index, wrap)		((index + 1) & wrap)
147 #define	NEXT_ENTRY_PTR(ptr, first, last)	\
148 					((ptr == last) ? first : (ptr + 1))
149 
150 /*
151  * NPI related macros
152  */
153 #define	NXGE_DEV_NPI_HANDLE(nxgep)	(nxgep->npi_handle)
154 
155 #define	NPI_PCI_ACC_HANDLE_SET(nxgep, ah) (nxgep->npi_pci_handle.regh = ah)
156 #define	NPI_PCI_ADD_HANDLE_SET(nxgep, ap) (nxgep->npi_pci_handle.regp = ap)
157 
158 #define	NPI_ACC_HANDLE_SET(nxgep, ah)	(nxgep->npi_handle.regh = ah)
159 #define	NPI_ADD_HANDLE_SET(nxgep, ap)	\
160 		nxgep->npi_handle.is_vraddr = B_FALSE;	\
161 		nxgep->npi_handle.function.instance = nxgep->instance;   \
162 		nxgep->npi_handle.function.function = nxgep->function_num;   \
163 		nxgep->npi_handle.nxgep = (void *) nxgep;   \
164 		nxgep->npi_handle.regp = ap;
165 
166 #define	NPI_REG_ACC_HANDLE_SET(nxgep, ah) (nxgep->npi_reg_handle.regh = ah)
167 #define	NPI_REG_ADD_HANDLE_SET(nxgep, ap)	\
168 		nxgep->npi_reg_handle.is_vraddr = B_FALSE;	\
169 		nxgep->npi_handle.function.instance = nxgep->instance;   \
170 		nxgep->npi_handle.function.function = nxgep->function_num;   \
171 		nxgep->npi_reg_handle.nxgep = (void *) nxgep;   \
172 		nxgep->npi_reg_handle.regp = ap;
173 
174 #define	NPI_MSI_ACC_HANDLE_SET(nxgep, ah) (nxgep->npi_msi_handle.regh = ah)
175 #define	NPI_MSI_ADD_HANDLE_SET(nxgep, ap) (nxgep->npi_msi_handle.regp = ap)
176 
177 #define	NPI_VREG_ACC_HANDLE_SET(nxgep, ah) (nxgep->npi_vreg_handle.regh = ah)
178 #define	NPI_VREG_ADD_HANDLE_SET(nxgep, ap)	\
179 		nxgep->npi_vreg_handle.is_vraddr = B_TRUE; \
180 		nxgep->npi_handle.function.instance = nxgep->instance;   \
181 		nxgep->npi_handle.function.function = nxgep->function_num;   \
182 		nxgep->npi_vreg_handle.nxgep = (void *) nxgep;   \
183 		nxgep->npi_vreg_handle.regp = ap;
184 
185 #define	NPI_V2REG_ACC_HANDLE_SET(nxgep, ah) (nxgep->npi_v2reg_handle.regh = ah)
186 #define	NPI_V2REG_ADD_HANDLE_SET(nxgep, ap)	\
187 		nxgep->npi_v2reg_handle.is_vraddr = B_TRUE; \
188 		nxgep->npi_handle.function.instance = nxgep->instance;   \
189 		nxgep->npi_handle.function.function = nxgep->function_num;   \
190 		nxgep->npi_v2reg_handle.nxgep = (void *) nxgep;   \
191 		nxgep->npi_v2reg_handle.regp = ap;
192 
193 #define	NPI_PCI_ACC_HANDLE_GET(nxgep) (nxgep->npi_pci_handle.regh)
194 #define	NPI_PCI_ADD_HANDLE_GET(nxgep) (nxgep->npi_pci_handle.regp)
195 #define	NPI_ACC_HANDLE_GET(nxgep) (nxgep->npi_handle.regh)
196 #define	NPI_ADD_HANDLE_GET(nxgep) (nxgep->npi_handle.regp)
197 #define	NPI_REG_ACC_HANDLE_GET(nxgep) (nxgep->npi_reg_handle.regh)
198 #define	NPI_REG_ADD_HANDLE_GET(nxgep) (nxgep->npi_reg_handle.regp)
199 #define	NPI_MSI_ACC_HANDLE_GET(nxgep) (nxgep->npi_msi_handle.regh)
200 #define	NPI_MSI_ADD_HANDLE_GET(nxgep) (nxgep->npi_msi_handle.regp)
201 #define	NPI_VREG_ACC_HANDLE_GET(nxgep) (nxgep->npi_vreg_handle.regh)
202 #define	NPI_VREG_ADD_HANDLE_GET(nxgep) (nxgep->npi_vreg_handle.regp)
203 #define	NPI_V2REG_ACC_HANDLE_GET(nxgep) (nxgep->npi_v2reg_handle.regh)
204 #define	NPI_V2REG_ADD_HANDLE_GET(nxgep) (nxgep->npi_v2reg_handle.regp)
205 
206 #define	NPI_DMA_ACC_HANDLE_SET(dmap, ah) (dmap->npi_handle.regh = ah)
207 #define	NPI_DMA_ACC_HANDLE_GET(dmap) 	(dmap->npi_handle.regh)
208 
209 /*
210  * DMA handles.
211  */
212 #define	NXGE_DESC_D_HANDLE_GET(desc)	(desc.dma_handle)
213 #define	NXGE_DESC_D_IOADD_GET(desc)	(desc.dma_cookie.dmac_laddress)
214 #define	NXGE_DMA_IOADD_GET(dma_cookie) (dma_cookie.dmac_laddress)
215 #define	NXGE_DMA_AREA_IOADD_GET(dma_area) (dma_area.dma_cookie.dmac_laddress)
216 
217 #define	LDV_ON(ldv, vector)	((vector >> ldv) & 0x1)
218 #define	LDV2_ON_1(ldv, vector)	((vector >> (ldv - 64)) & 0x1)
219 #define	LDV2_ON_2(ldv, vector)	(((vector >> 5) >> (ldv - 64)) & 0x1)
220 
221 typedef uint32_t		nxge_status_t;
222 
223 typedef enum  {
224 	IDLE,
225 	PROGRESS,
226 	CONFIGURED
227 } dev_func_shared_t;
228 
229 typedef enum  {
230 	DVMA,
231 	DMA,
232 	SDMA
233 } dma_method_t;
234 
235 typedef enum  {
236 	BKSIZE_4K,
237 	BKSIZE_8K,
238 	BKSIZE_16K,
239 	BKSIZE_32K
240 } nxge_rx_block_size_t;
241 
242 #ifdef TX_ONE_BUF
243 #define	TX_BCOPY_MAX 1514
244 #else
245 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
246 #define	TX_BCOPY_MAX	4096
247 #define	TX_BCOPY_SIZE	4096
248 #else
249 #define	TX_BCOPY_MAX	2048
250 #define	TX_BCOPY_SIZE	2048
251 #endif
252 #endif
253 
254 #define	TX_STREAM_MIN 512
255 #define	TX_FASTDVMA_MIN 1024
256 
257 /*
258  * Send repeated FMA ereports or display messages about some non-fatal
259  * hardware errors only the the first NXGE_ERROR_SHOW_MAX -1 times
260  */
261 #define	NXGE_ERROR_SHOW_MAX	2
262 
263 
264 /*
265  * Defaults
266  */
267 #define	NXGE_RDC_RCR_THRESHOLD		8
268 #define	NXGE_RDC_RCR_TIMEOUT		16
269 
270 #define	NXGE_RDC_RCR_THRESHOLD_MAX	1024
271 #define	NXGE_RDC_RCR_TIMEOUT_MAX	64
272 #define	NXGE_RDC_RCR_THRESHOLD_MIN	1
273 #define	NXGE_RDC_RCR_TIMEOUT_MIN	1
274 #define	NXGE_RCR_FULL_HEADER		1
275 
276 #define	NXGE_IS_VLAN_PACKET(ptr)				\
277 	((((struct ether_vlan_header *)ptr)->ether_tpid) ==	\
278 	htons(VLAN_ETHERTYPE))
279 
280 typedef enum {
281 	NONE,
282 	SMALL,
283 	MEDIUM,
284 	LARGE
285 } dma_size_t;
286 
287 typedef enum {
288 	USE_NONE,
289 	USE_BCOPY,
290 	USE_DVMA,
291 	USE_DMA,
292 	USE_SDMA
293 } dma_type_t;
294 
295 typedef enum {
296 	NOT_IN_USE,
297 	HDR_BUF,
298 	MTU_BUF,
299 	RE_ASSEMBLY_BUF,
300 	FREE_BUF
301 } rx_page_state_t;
302 
303 struct _nxge_block_mv_t {
304 	uint32_t msg_type;
305 	dma_type_t dma_type;
306 };
307 
308 typedef struct _nxge_block_mv_t nxge_block_mv_t, *p_nxge_block_mv_t;
309 
310 typedef enum {
311 	NIU_TYPE_NONE = 0,
312 
313 	NEPTUNE_4_1GC =
314 	    (NXGE_PORT_1G_COPPER |
315 	    (NXGE_PORT_1G_COPPER << 4) |
316 	    (NXGE_PORT_1G_COPPER << 8) |
317 	    (NXGE_PORT_1G_COPPER << 12)),
318 
319 	NEPTUNE_2_10GF =
320 	    (NXGE_PORT_10G_FIBRE |
321 	    (NXGE_PORT_10G_FIBRE << 4) |
322 	    (NXGE_PORT_NONE << 8) |
323 	    (NXGE_PORT_NONE << 12)),
324 
325 	NEPTUNE_2_10GF_2_1GC =
326 	    (NXGE_PORT_10G_FIBRE |
327 	    (NXGE_PORT_10G_FIBRE << 4) |
328 	    (NXGE_PORT_1G_COPPER << 8) |
329 	    (NXGE_PORT_1G_COPPER << 12)),
330 
331 	NEPTUNE_1_10GF_3_1GC =
332 	    (NXGE_PORT_10G_FIBRE |
333 	    (NXGE_PORT_1G_COPPER << 4) |
334 	    (NXGE_PORT_1G_COPPER << 8) |
335 	    (NXGE_PORT_1G_COPPER << 12)),
336 
337 	NEPTUNE_1_1GC_1_10GF_2_1GC =
338 	    (NXGE_PORT_1G_COPPER |
339 	    (NXGE_PORT_10G_FIBRE << 4) |
340 	    (NXGE_PORT_1G_COPPER << 8) |
341 	    (NXGE_PORT_1G_COPPER << 12)),
342 
343 	NEPTUNE_2_1GRF =
344 	    (NXGE_PORT_NONE |
345 	    (NXGE_PORT_NONE << 4) |
346 	    (NXGE_PORT_1G_RGMII_FIBER << 8) |
347 	    (NXGE_PORT_1G_RGMII_FIBER << 12)),
348 
349 	NEPTUNE_2_10GF_2_1GRF =
350 	    (NXGE_PORT_10G_FIBRE |
351 	    (NXGE_PORT_10G_FIBRE << 4) |
352 	    (NXGE_PORT_1G_RGMII_FIBER << 8) |
353 	    (NXGE_PORT_1G_RGMII_FIBER << 12)),
354 
355 	N2_NIU =
356 	    (NXGE_PORT_RSVD |
357 	    (NXGE_PORT_RSVD << 4) |
358 	    (NXGE_PORT_RSVD << 8) |
359 	    (NXGE_PORT_RSVD << 12))
360 
361 } niu_type_t;
362 
363 typedef enum {
364 	P_NEPTUNE_NONE,
365 	P_NEPTUNE_GENERIC,
366 	P_NEPTUNE_ATLAS_2PORT,
367 	P_NEPTUNE_ATLAS_4PORT,
368 	P_NEPTUNE_MARAMBA_P0,
369 	P_NEPTUNE_MARAMBA_P1,
370 	P_NEPTUNE_ALONSO,
371 	P_NEPTUNE_NIU
372 } platform_type_t;
373 
374 #define	NXGE_IS_VALID_NEPTUNE_TYPE(nxgep) \
375 	(((nxgep->platform_type) == P_NEPTUNE_ATLAS_2PORT) || \
376 	    ((nxgep->platform_type) == P_NEPTUNE_ATLAS_4PORT) || \
377 	    ((nxgep->platform_type) == P_NEPTUNE_MARAMBA_P0) || \
378 	    ((nxgep->platform_type) == P_NEPTUNE_MARAMBA_P1) || \
379 	    ((nxgep->platform_type) == P_NEPTUNE_GENERIC) || \
380 	    ((nxgep->platform_type) == P_NEPTUNE_ALONSO))
381 
382 #define	NXGE_IS_XAUI_PLATFORM(nxgep) \
383 	(((nxgep->platform_type) == P_NEPTUNE_NIU) || \
384 	    ((nxgep->platform_type) == P_NEPTUNE_MARAMBA_P0) || \
385 	    ((nxgep->platform_type) == P_NEPTUNE_MARAMBA_P1))
386 
387 
388 typedef enum {
389 	CFG_DEFAULT = 0,	/* default cfg */
390 	CFG_EQUAL,	/* Equal */
391 	CFG_FAIR,	/* Equal */
392 	CFG_CLASSIFY,
393 	CFG_L2_CLASSIFY,
394 	CFG_L3_CLASSIFY,
395 	CFG_L3_DISTRIBUTE,
396 	CFG_L3_WEB,
397 	CFG_L3_TCAM,
398 	CFG_NOT_SPECIFIED,
399 	CFG_CUSTOM	/* Custom */
400 } cfg_type_t;
401 
402 typedef enum {
403 	NO_MSG = 0x0,		/* No message output or storage. */
404 	CONSOLE = 0x1,		/* Messages are go to the console. */
405 	BUFFER = 0x2,		/* Messages are go to the system buffer. */
406 	CON_BUF = 0x3,		/* Messages are go to the console and */
407 				/* system buffer. */
408 	VERBOSE = 0x4		/* Messages are go out only in VERBOSE node. */
409 } out_msg_t, *p_out_msg_t;
410 
411 typedef enum {
412 	DBG_NO_MSG = 0x0,	/* No message output or storage. */
413 	DBG_CONSOLE = 0x1,	/* Messages are go to the console. */
414 	DBG_BUFFER = 0x2,	/* Messages are go to the system buffer. */
415 	DBG_CON_BUF = 0x3,	/* Messages are go to the console and */
416 				/* system buffer. */
417 	STR_LOG = 4		/* Sessage sent to streams logging driver. */
418 } out_dbgmsg_t, *p_out_dbgmsg_t;
419 
420 
421 
422 #if defined(_KERNEL) || defined(COSIM)
423 
424 typedef struct ether_addr ether_addr_st, *p_ether_addr_t;
425 typedef struct ether_header ether_header_t, *p_ether_header_t;
426 typedef queue_t *p_queue_t;
427 
428 #if !defined(IODIAG)
429 typedef mblk_t *p_mblk_t;
430 #endif
431 
432 /*
433  * Generic phy table to support different phy types.
434  */
435 typedef struct _nxge_xcvr_table {
436 	nxge_status_t	(*serdes_init)	();	/* Serdes init routine */
437 	nxge_status_t	(*xcvr_init)	();	/* xcvr init routine */
438 	nxge_status_t	(*link_intr_stop) ();	/* Link intr disable routine */
439 	nxge_status_t	(*link_intr_start) ();	/* Link intr enable routine */
440 	nxge_status_t	(*check_link) ();	/* Link check routine */
441 
442 	uint32_t	xcvr_inuse;
443 } nxge_xcvr_table_t, *p_nxge_xcvr_table_t;
444 
445 /*
446  * Common DMA data elements.
447  */
448 struct _nxge_dma_common_t {
449 	uint16_t		dma_channel;
450 	void			*kaddrp;
451 	void			*first_kaddrp;
452 	void			*last_kaddrp;
453 	void			*ioaddr_pp;
454 	void			*first_ioaddr_pp;
455 	void			*last_ioaddr_pp;
456 	ddi_dma_cookie_t 	dma_cookie;
457 	uint32_t		ncookies;
458 
459 	nxge_block_mv_t		msg_dma_flags;
460 	ddi_dma_handle_t	dma_handle;
461 	nxge_os_acc_handle_t	acc_handle;
462 	npi_handle_t		npi_handle;
463 
464 	size_t			block_size;
465 	uint32_t		nblocks;
466 	size_t			alength;
467 	uint_t			offset;
468 	uint_t			dma_chunk_index;
469 	void			*orig_ioaddr_pp;
470 	uint64_t		orig_vatopa;
471 	void			*orig_kaddrp;
472 	size_t			orig_alength;
473 	boolean_t		contig_alloc_type;
474 };
475 
476 typedef struct _nxge_t nxge_t, *p_nxge_t;
477 typedef struct _nxge_dma_common_t nxge_dma_common_t, *p_nxge_dma_common_t;
478 
479 typedef struct _nxge_dma_pool_t {
480 	p_nxge_dma_common_t	*dma_buf_pool_p;
481 	uint32_t		ndmas;
482 	uint32_t		*num_chunks;
483 	boolean_t		buf_allocated;
484 } nxge_dma_pool_t, *p_nxge_dma_pool_t;
485 
486 /*
487  * Each logical device (69):
488  *	- LDG #
489  *	- flag bits
490  *	- masks.
491  *	- interrupt handler function.
492  *
493  * Generic system interrupt handler with two arguments:
494  *	(nxge_sys_intr_t)
495  *	Per device instance data structure
496  *	Logical group data structure.
497  *
498  * Logical device interrupt handler with two arguments:
499  *	(nxge_ldv_intr_t)
500  *	Per device instance data structure
501  *	Logical device number
502  */
503 typedef struct	_nxge_ldg_t nxge_ldg_t, *p_nxge_ldg_t;
504 typedef struct	_nxge_ldv_t nxge_ldv_t, *p_nxge_ldv_t;
505 typedef uint_t	(*nxge_sys_intr_t)(void *arg1, void *arg2);
506 typedef uint_t	(*nxge_ldv_intr_t)(void *arg1, void *arg2);
507 
508 /*
509  * Each logical device Group (64) needs to have the following
510  * configurations:
511  *	- timer counter (6 bits)
512  *	- timer resolution (20 bits, number of system clocks)
513  *	- system data (7 bits)
514  */
515 struct _nxge_ldg_t {
516 	uint8_t			ldg;		/* logical group number */
517 	uint8_t			vldg_index;
518 	boolean_t		arm;
519 	boolean_t		interrupted;
520 	uint16_t		ldg_timer;	/* counter */
521 	uint8_t			func;
522 	uint8_t			vector;
523 	uint8_t			intdata;
524 	uint8_t			nldvs;
525 	p_nxge_ldv_t		ldvp;
526 	nxge_sys_intr_t		sys_intr_handler;
527 	uint_t			(*ih_cb_func)(caddr_t, caddr_t);
528 	p_nxge_t		nxgep;
529 };
530 
531 struct _nxge_ldv_t {
532 	uint8_t			ldg_assigned;
533 	uint8_t			ldv;
534 	boolean_t		is_rxdma;
535 	boolean_t		is_txdma;
536 	boolean_t		is_mif;
537 	boolean_t		is_mac;
538 	boolean_t		is_syserr;
539 	boolean_t		use_timer;
540 	uint8_t			channel;
541 	uint8_t			vdma_index;
542 	uint8_t			func;
543 	p_nxge_ldg_t		ldgp;
544 	uint8_t			ldv_flags;
545 	boolean_t		is_leve;
546 	boolean_t		is_edge;
547 	uint8_t			ldv_ldf_masks;
548 	nxge_ldv_intr_t		ldv_intr_handler;
549 	uint_t			(*ih_cb_func)(caddr_t, caddr_t);
550 	p_nxge_t		nxgep;
551 };
552 #endif
553 
554 typedef struct _nxge_logical_page_t {
555 	uint16_t		dma;
556 	uint16_t		page;
557 	boolean_t		valid;
558 	uint64_t		mask;
559 	uint64_t		value;
560 	uint64_t		reloc;
561 	uint32_t		handle;
562 } nxge_logical_page_t, *p_nxge_logical_page_t;
563 
564 /*
565  * (Internal) return values from ioctl subroutines.
566  */
567 enum nxge_ioc_reply {
568 	IOC_INVAL = -1,				/* bad, NAK with EINVAL	*/
569 	IOC_DONE,				/* OK, reply sent	*/
570 	IOC_ACK,				/* OK, just send ACK	*/
571 	IOC_REPLY,				/* OK, just send reply	*/
572 	IOC_RESTART_ACK,			/* OK, restart & ACK	*/
573 	IOC_RESTART_REPLY			/* OK, restart & reply	*/
574 };
575 
576 typedef struct _pci_cfg_t {
577 	uint16_t vendorid;
578 	uint16_t devid;
579 	uint16_t command;
580 	uint16_t status;
581 	uint8_t  revid;
582 	uint8_t  res0;
583 	uint16_t junk1;
584 	uint8_t  cache_line;
585 	uint8_t  latency;
586 	uint8_t  header;
587 	uint8_t  bist;
588 	uint32_t base;
589 	uint32_t base14;
590 	uint32_t base18;
591 	uint32_t base1c;
592 	uint32_t base20;
593 	uint32_t base24;
594 	uint32_t base28;
595 	uint32_t base2c;
596 	uint32_t base30;
597 	uint32_t res1[2];
598 	uint8_t int_line;
599 	uint8_t int_pin;
600 	uint8_t	min_gnt;
601 	uint8_t max_lat;
602 } pci_cfg_t, *p_pci_cfg_t;
603 
604 #if defined(_KERNEL) || defined(COSIM)
605 
606 typedef struct _dev_regs_t {
607 	nxge_os_acc_handle_t	nxge_pciregh;	/* PCI config DDI IO handle */
608 	p_pci_cfg_t		nxge_pciregp;	/* mapped PCI registers */
609 
610 	nxge_os_acc_handle_t	nxge_regh;	/* device DDI IO (BAR 0) */
611 	void			*nxge_regp;	/* mapped device registers */
612 
613 	nxge_os_acc_handle_t	nxge_msix_regh;	/* MSI/X DDI handle (BAR 2) */
614 	void 			*nxge_msix_regp; /* MSI/X register */
615 
616 	nxge_os_acc_handle_t	nxge_vir_regh;	/* virtualization (BAR 4) */
617 	unsigned char		*nxge_vir_regp;	/* virtualization register */
618 
619 	nxge_os_acc_handle_t	nxge_vir2_regh;	/* second virtualization */
620 	unsigned char		*nxge_vir2_regp; /* second virtualization */
621 
622 	nxge_os_acc_handle_t	nxge_romh;	/* fcode rom handle */
623 	unsigned char		*nxge_romp;	/* fcode pointer */
624 } dev_regs_t, *p_dev_regs_t;
625 
626 
627 typedef struct _nxge_mac_addr_t {
628 	ether_addr_t	addr;
629 	uint_t		flags;
630 } nxge_mac_addr_t;
631 
632 /*
633  * The hardware supports 1 unique MAC and 16 alternate MACs (num_mmac)
634  * for each XMAC port and supports 1 unique MAC and 7 alternate MACs
635  * for each BMAC port.  The number of MACs assigned by the factory is
636  * different and is as follows,
637  * 	BMAC port:		   num_factory_mmac = num_mmac = 7
638  *	XMAC port on a 2-port NIC: num_factory_mmac = num_mmac - 1 = 15
639  *	XMAC port on a 4-port NIC: num_factory_mmac = 7
640  * So num_factory_mmac is smaller than num_mmac.  nxge_m_mmac_add uses
641  * num_mmac and nxge_m_mmac_reserve uses num_factory_mmac.
642  *
643  * total_factory_macs is the total number of factory MACs, including
644  * the unique MAC, assigned to a Neptune based NIC card, it is 32.
645  */
646 typedef struct _nxge_mmac_t {
647 	uint8_t		total_factory_macs;
648 	uint8_t		num_mmac;
649 	uint8_t		num_factory_mmac;
650 	nxge_mac_addr_t	mac_pool[XMAC_MAX_ADDR_ENTRY];
651 	ether_addr_t	factory_mac_pool[XMAC_MAX_ADDR_ENTRY];
652 	uint8_t		naddrfree;  /* number of alt mac addr available */
653 } nxge_mmac_t;
654 
655 /*
656  * mmac stats structure
657  */
658 typedef struct _nxge_mmac_stats_t {
659 	uint8_t mmac_max_cnt;
660 	uint8_t	mmac_avail_cnt;
661 	struct ether_addr mmac_avail_pool[16];
662 } nxge_mmac_stats_t, *p_nxge_mmac_stats_t;
663 
664 #define	NXGE_MAX_MMAC_ADDRS	32
665 #define	NXGE_NUM_MMAC_ADDRS	8
666 #define	NXGE_NUM_OF_PORTS_QUAD	4
667 #define	NXGE_NUM_OF_PORTS_DUAL	2
668 
669 #define	NXGE_QGC_LP_BM_STR		"501-7606"
670 #define	NXGE_2XGF_LP_BM_STR		"501-7283"
671 #define	NXGE_QGC_PEM_BM_STR		"501-7765"
672 #define	NXGE_2XGF_PEM_BM_STR		"501-7626"
673 #define	NXGE_ALONSO_BM_STR		"373-0202-01"
674 #define	NXGE_ALONSO_MODEL_STR		"SUNW,CP3220"
675 #define	NXGE_RFEM_BM_STR		"501-7961-01"
676 #define	NXGE_RFEM_MODEL_STR		"SUNW,pcie-rfem"
677 #define	NXGE_ARTM_BM_STR		"375-3544-01"
678 #define	NXGE_ARTM_MODEL_STR		"SUNW,pcie-artm"
679 #define	NXGE_EROM_LEN			1048576
680 
681 #endif
682 
683 #include 	<sys/nxge/nxge_common_impl.h>
684 #include 	<sys/nxge/nxge_common.h>
685 #include	<sys/nxge/nxge_txc.h>
686 #include	<sys/nxge/nxge_rxdma.h>
687 #include	<sys/nxge/nxge_txdma.h>
688 #include	<sys/nxge/nxge_fflp.h>
689 #include	<sys/nxge/nxge_ipp.h>
690 #include	<sys/nxge/nxge_zcp.h>
691 #include	<sys/nxge/nxge_fzc.h>
692 #include	<sys/nxge/nxge_flow.h>
693 #include	<sys/nxge/nxge_virtual.h>
694 
695 #include	<npi_espc.h>
696 #include	<npi_vir.h>
697 
698 #include 	<sys/nxge/nxge.h>
699 
700 #include	<sys/modctl.h>
701 #include	<sys/pattr.h>
702 
703 extern int secpolicy_net_config(const cred_t *, boolean_t);
704 extern void nxge_fm_report_error(p_nxge_t, uint8_t,
705 			uint8_t, nxge_fm_ereport_id_t);
706 extern int fm_check_acc_handle(ddi_acc_handle_t);
707 extern int fm_check_dma_handle(ddi_dma_handle_t);
708 
709 /* nxge_classify.c */
710 nxge_status_t nxge_classify_init(p_nxge_t);
711 nxge_status_t nxge_classify_uninit(p_nxge_t);
712 nxge_status_t nxge_set_hw_classify_config(p_nxge_t);
713 nxge_status_t nxge_classify_exit_sw(p_nxge_t);
714 
715 /* nxge_fflp.c */
716 void nxge_put_tcam(p_nxge_t, p_mblk_t);
717 void nxge_get_tcam(p_nxge_t, p_mblk_t);
718 nxge_status_t nxge_classify_init_hw(p_nxge_t);
719 nxge_status_t nxge_classify_init_sw(p_nxge_t);
720 nxge_status_t nxge_fflp_ip_class_config_all(p_nxge_t);
721 nxge_status_t nxge_fflp_ip_class_config(p_nxge_t, tcam_class_t,
722 				    uint32_t);
723 
724 nxge_status_t nxge_fflp_ip_class_config_get(p_nxge_t,
725 				    tcam_class_t,
726 				    uint32_t *);
727 
728 nxge_status_t nxge_cfg_ip_cls_flow_key(p_nxge_t, tcam_class_t,
729 				    uint32_t);
730 
731 nxge_status_t nxge_fflp_ip_usr_class_config(p_nxge_t, tcam_class_t,
732 				    uint32_t);
733 
734 uint64_t nxge_classify_get_cfg_value(p_nxge_t, uint8_t, uint8_t);
735 nxge_status_t nxge_add_flow(p_nxge_t, flow_resource_t *);
736 nxge_status_t nxge_fflp_config_tcam_enable(p_nxge_t);
737 nxge_status_t nxge_fflp_config_tcam_disable(p_nxge_t);
738 
739 nxge_status_t nxge_fflp_config_hash_lookup_enable(p_nxge_t);
740 nxge_status_t nxge_fflp_config_hash_lookup_disable(p_nxge_t);
741 
742 nxge_status_t nxge_fflp_config_llc_snap_enable(p_nxge_t);
743 nxge_status_t nxge_fflp_config_llc_snap_disable(p_nxge_t);
744 
745 nxge_status_t nxge_logical_mac_assign_rdc_table(p_nxge_t, uint8_t);
746 nxge_status_t nxge_fflp_config_vlan_table(p_nxge_t, uint16_t);
747 
748 nxge_status_t nxge_fflp_set_hash1(p_nxge_t, uint32_t);
749 
750 nxge_status_t nxge_fflp_set_hash2(p_nxge_t, uint16_t);
751 
752 nxge_status_t nxge_fflp_init_hostinfo(p_nxge_t);
753 
754 void nxge_handle_tcam_fragment_bug(p_nxge_t);
755 nxge_status_t nxge_fflp_hw_reset(p_nxge_t);
756 nxge_status_t nxge_fflp_handle_sys_errors(p_nxge_t);
757 nxge_status_t nxge_zcp_handle_sys_errors(p_nxge_t);
758 
759 /* nxge_kstats.c */
760 void nxge_init_statsp(p_nxge_t);
761 void nxge_setup_kstats(p_nxge_t);
762 void nxge_destroy_kstats(p_nxge_t);
763 int nxge_port_kstat_update(kstat_t *, int);
764 void nxge_save_cntrs(p_nxge_t);
765 
766 int nxge_m_stat(void *arg, uint_t, uint64_t *);
767 
768 /* nxge_hw.c */
769 void
770 nxge_hw_ioctl(p_nxge_t, queue_t *, mblk_t *, struct iocblk *);
771 void nxge_loopback_ioctl(p_nxge_t, queue_t *, mblk_t *, struct iocblk *);
772 nxge_status_t nxge_global_reset(p_nxge_t);
773 uint_t nxge_intr(void *, void *);
774 void nxge_intr_enable(p_nxge_t);
775 void nxge_intr_disable(p_nxge_t);
776 void nxge_hw_blank(void *arg, time_t, uint_t);
777 void nxge_hw_id_init(p_nxge_t);
778 void nxge_hw_init_niu_common(p_nxge_t);
779 void nxge_intr_hw_enable(p_nxge_t);
780 void nxge_intr_hw_disable(p_nxge_t);
781 void nxge_hw_stop(p_nxge_t);
782 void nxge_check_hw_state(p_nxge_t);
783 
784 void nxge_rxdma_channel_put64(nxge_os_acc_handle_t,
785 	void *, uint32_t, uint16_t,
786 	uint64_t);
787 uint64_t nxge_rxdma_channel_get64(nxge_os_acc_handle_t, void *,
788 	uint32_t, uint16_t);
789 
790 
791 void nxge_get32(p_nxge_t, p_mblk_t);
792 void nxge_put32(p_nxge_t, p_mblk_t);
793 
794 void nxge_hw_set_mac_modes(p_nxge_t);
795 
796 /* nxge_send.c. */
797 uint_t nxge_reschedule(caddr_t);
798 
799 /* nxge_rxdma.c */
800 nxge_status_t nxge_rxdma_cfg_rdcgrp_default_rdc(p_nxge_t,
801 					    uint8_t, uint8_t);
802 
803 nxge_status_t nxge_rxdma_cfg_port_default_rdc(p_nxge_t,
804 				    uint8_t, uint8_t);
805 nxge_status_t nxge_rxdma_cfg_rcr_threshold(p_nxge_t, uint8_t,
806 				    uint16_t);
807 nxge_status_t nxge_rxdma_cfg_rcr_timeout(p_nxge_t, uint8_t,
808 				    uint16_t, uint8_t);
809 
810 /* nxge_ndd.c */
811 void nxge_get_param_soft_properties(p_nxge_t);
812 void nxge_copy_hw_default_to_param(p_nxge_t);
813 void nxge_copy_param_hw_to_config(p_nxge_t);
814 void nxge_setup_param(p_nxge_t);
815 void nxge_init_param(p_nxge_t);
816 void nxge_destroy_param(p_nxge_t);
817 boolean_t nxge_check_rxdma_rdcgrp_member(p_nxge_t, uint8_t, uint8_t);
818 boolean_t nxge_check_rxdma_port_member(p_nxge_t, uint8_t);
819 boolean_t nxge_check_rdcgrp_port_member(p_nxge_t, uint8_t);
820 
821 boolean_t nxge_check_txdma_port_member(p_nxge_t, uint8_t);
822 
823 int nxge_param_get_generic(p_nxge_t, queue_t *, mblk_t *, caddr_t);
824 int nxge_param_set_generic(p_nxge_t, queue_t *, mblk_t *, char *, caddr_t);
825 int nxge_get_default(p_nxge_t, queue_t *, p_mblk_t, caddr_t);
826 int nxge_set_default(p_nxge_t, queue_t *, p_mblk_t, char *, caddr_t);
827 int nxge_nd_get_names(p_nxge_t, queue_t *, p_mblk_t, caddr_t);
828 int nxge_mk_mblk_tail_space(p_mblk_t, p_mblk_t *, size_t);
829 long nxge_strtol(char *, char **, int);
830 boolean_t nxge_param_get_instance(queue_t *, mblk_t *);
831 void nxge_param_ioctl(p_nxge_t, queue_t *, mblk_t *, struct iocblk *);
832 boolean_t nxge_nd_load(caddr_t *, char *, pfi_t, pfi_t, caddr_t);
833 void nxge_nd_free(caddr_t *);
834 int nxge_nd_getset(p_nxge_t, queue_t *, caddr_t, p_mblk_t);
835 
836 nxge_status_t nxge_set_lb_normal(p_nxge_t);
837 boolean_t nxge_set_lb(p_nxge_t, queue_t *, p_mblk_t);
838 boolean_t nxge_param_link_update(p_nxge_t);
839 int nxge_param_set_ip_opt(p_nxge_t, queue_t *, mblk_t *, char *, caddr_t);
840 int nxge_dld_get_ip_opt(p_nxge_t, caddr_t);
841 int nxge_param_rx_intr_pkts(p_nxge_t, queue_t *,
842 	mblk_t *, char *, caddr_t);
843 int nxge_param_rx_intr_time(p_nxge_t, queue_t *,
844 	mblk_t *, char *, caddr_t);
845 
846 
847 /* nxge_virtual.c */
848 nxge_status_t nxge_cntlops(dev_info_t *, nxge_ctl_enum_t, void *, void *);
849 void nxge_common_lock_get(p_nxge_t);
850 void nxge_common_lock_free(p_nxge_t);
851 
852 nxge_status_t nxge_get_config_properties(p_nxge_t);
853 void nxge_get_xcvr_properties(p_nxge_t);
854 void nxge_init_vlan_config(p_nxge_t);
855 void nxge_init_mac_config(p_nxge_t);
856 
857 
858 void nxge_init_logical_devs(p_nxge_t);
859 int nxge_init_ldg_intrs(p_nxge_t);
860 
861 void nxge_set_ldgimgmt(p_nxge_t, uint32_t, boolean_t,
862 	uint32_t);
863 
864 void nxge_init_fzc_txdma_channels(p_nxge_t);
865 
866 nxge_status_t nxge_init_fzc_txdma_channel(p_nxge_t, uint16_t,
867 	p_tx_ring_t, p_tx_mbox_t);
868 nxge_status_t nxge_init_fzc_txdma_port(p_nxge_t);
869 
870 nxge_status_t nxge_init_fzc_rxdma_channel(p_nxge_t, uint16_t,
871 	p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t);
872 
873 nxge_status_t nxge_init_fzc_rdc_tbl(p_nxge_t);
874 nxge_status_t nxge_init_fzc_rx_common(p_nxge_t);
875 nxge_status_t nxge_init_fzc_rxdma_port(p_nxge_t);
876 
877 nxge_status_t nxge_init_fzc_rxdma_channel_pages(p_nxge_t,
878 	uint16_t, p_rx_rbr_ring_t);
879 nxge_status_t nxge_init_fzc_rxdma_channel_red(p_nxge_t,
880 	uint16_t, p_rx_rcr_ring_t);
881 
882 nxge_status_t nxge_init_fzc_rxdma_channel_clrlog(p_nxge_t,
883 	uint16_t, p_rx_rbr_ring_t);
884 
885 
886 nxge_status_t nxge_init_fzc_txdma_channel_pages(p_nxge_t,
887 	uint16_t, p_tx_ring_t);
888 
889 nxge_status_t nxge_init_fzc_txdma_channel_drr(p_nxge_t, uint16_t,
890 	p_tx_ring_t);
891 
892 nxge_status_t nxge_init_fzc_txdma_port(p_nxge_t);
893 
894 void nxge_init_fzc_ldg_num(p_nxge_t);
895 void nxge_init_fzc_sys_int_data(p_nxge_t);
896 void nxge_init_fzc_ldg_int_timer(p_nxge_t);
897 nxge_status_t nxge_intr_mask_mgmt_set(p_nxge_t, boolean_t on);
898 
899 /* MAC functions */
900 nxge_status_t nxge_mac_init(p_nxge_t);
901 nxge_status_t nxge_link_init(p_nxge_t);
902 nxge_status_t nxge_xif_init(p_nxge_t);
903 nxge_status_t nxge_pcs_init(p_nxge_t);
904 nxge_status_t nxge_mac_ctrl_init(p_nxge_t);
905 nxge_status_t nxge_serdes_init(p_nxge_t);
906 nxge_status_t nxge_serdes_reset(p_nxge_t);
907 nxge_status_t nxge_xcvr_find(p_nxge_t);
908 nxge_status_t nxge_get_xcvr_type(p_nxge_t);
909 nxge_status_t nxge_setup_xcvr_table(p_nxge_t);
910 nxge_status_t nxge_xcvr_init(p_nxge_t);
911 nxge_status_t nxge_tx_mac_init(p_nxge_t);
912 nxge_status_t nxge_rx_mac_init(p_nxge_t);
913 nxge_status_t nxge_tx_mac_enable(p_nxge_t);
914 nxge_status_t nxge_tx_mac_disable(p_nxge_t);
915 nxge_status_t nxge_rx_mac_enable(p_nxge_t);
916 nxge_status_t nxge_rx_mac_disable(p_nxge_t);
917 nxge_status_t nxge_tx_mac_reset(p_nxge_t);
918 nxge_status_t nxge_rx_mac_reset(p_nxge_t);
919 nxge_status_t nxge_link_intr(p_nxge_t, link_intr_enable_t);
920 nxge_status_t nxge_mii_xcvr_init(p_nxge_t);
921 nxge_status_t nxge_mii_xcvr_fiber_init(p_nxge_t);
922 nxge_status_t nxge_mii_read(p_nxge_t, uint8_t,
923 			uint8_t, uint16_t *);
924 nxge_status_t nxge_mii_write(p_nxge_t, uint8_t,
925 			uint8_t, uint16_t);
926 nxge_status_t nxge_mdio_read(p_nxge_t, uint8_t, uint8_t,
927 			uint16_t, uint16_t *);
928 nxge_status_t nxge_mdio_write(p_nxge_t, uint8_t,
929 			uint8_t, uint16_t, uint16_t);
930 nxge_status_t nxge_mii_check(p_nxge_t, mii_bmsr_t,
931 			mii_bmsr_t, nxge_link_state_t *);
932 nxge_status_t nxge_pcs_check(p_nxge_t, uint8_t portn, nxge_link_state_t *);
933 nxge_status_t nxge_add_mcast_addr(p_nxge_t, struct ether_addr *);
934 nxge_status_t nxge_del_mcast_addr(p_nxge_t, struct ether_addr *);
935 nxge_status_t nxge_set_mac_addr(p_nxge_t, struct ether_addr *);
936 nxge_status_t nxge_check_bcm8704_link(p_nxge_t, boolean_t *);
937 void nxge_link_is_down(p_nxge_t);
938 void nxge_link_is_up(p_nxge_t);
939 nxge_status_t nxge_link_monitor(p_nxge_t, link_mon_enable_t);
940 uint32_t crc32_mchash(p_ether_addr_t);
941 nxge_status_t nxge_set_promisc(p_nxge_t, boolean_t);
942 nxge_status_t nxge_mac_handle_sys_errors(p_nxge_t);
943 nxge_status_t nxge_10g_link_led_on(p_nxge_t);
944 nxge_status_t nxge_10g_link_led_off(p_nxge_t);
945 nxge_status_t nxge_scan_ports_phy(p_nxge_t, p_nxge_hw_list_t);
946 boolean_t nxge_is_valid_local_mac(ether_addr_st);
947 nxge_status_t nxge_mac_set_framesize(p_nxge_t);
948 
949 /* espc (sprom) prototypes */
950 nxge_status_t nxge_espc_mac_addrs_get(p_nxge_t);
951 nxge_status_t nxge_espc_num_macs_get(p_nxge_t, uint8_t *);
952 nxge_status_t nxge_espc_num_ports_get(p_nxge_t);
953 nxge_status_t nxge_espc_phy_type_get(p_nxge_t);
954 nxge_status_t nxge_espc_verify_chksum(p_nxge_t);
955 void nxge_espc_get_next_mac_addr(uint8_t *, uint8_t, struct ether_addr *);
956 void nxge_vpd_info_get(p_nxge_t);
957 
958 
959 void nxge_debug_msg(p_nxge_t, uint64_t, char *, ...);
960 int nxge_get_nports(p_nxge_t);
961 
962 uint64_t hv_niu_rx_logical_page_conf(uint64_t, uint64_t,
963 	uint64_t, uint64_t);
964 #pragma weak	hv_niu_rx_logical_page_conf
965 
966 uint64_t hv_niu_rx_logical_page_info(uint64_t, uint64_t,
967 	uint64_t *, uint64_t *);
968 #pragma weak	hv_niu_rx_logical_page_info
969 
970 uint64_t hv_niu_tx_logical_page_conf(uint64_t, uint64_t,
971 	uint64_t, uint64_t);
972 #pragma weak	hv_niu_tx_logical_page_conf
973 
974 uint64_t hv_niu_tx_logical_page_info(uint64_t, uint64_t,
975 	uint64_t *, uint64_t *);
976 #pragma weak	hv_niu_tx_logical_page_info
977 
978 #ifdef NXGE_DEBUG
979 char *nxge_dump_packet(char *, int);
980 #endif
981 
982 #endif	/* !_ASM */
983 
984 #ifdef	__cplusplus
985 }
986 #endif
987 
988 #endif	/* _SYS_NXGE_NXGE_IMPL_H */
989