xref: /titanic_50/usr/src/uts/sun4v/io/niumx/niumx_var.h (revision a24e89c4a1eec8361718d94a6275e6720643284e)
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_NIUMX_VAR_H
27 #define	_SYS_NIUMX_VAR_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 typedef enum {	/* same sequence as niumx_debug_sym[] */
34 	/*  0 */ DBG_ATTACH,
35 	/*  1 */ DBG_MAP,
36 	/*  2 */ DBG_CTLOPS,
37 	/*  3 */ DBG_INTROPS,
38 	/*  4 */ DBG_A_INTX,
39 	/*  5 */ DBG_R_INTX,
40 	/*  6 */ DBG_INTR,
41 	/*  7 */ DBG_DMA_ALLOCH,
42 	/*  8 */ DBG_DMA_BINDH,
43 	/*  9 */ DBG_DMA_UNBINDH,
44 	/* 10 */ DBG_CHK_MOD
45 } niumx_debug_bit_t;
46 
47 #if defined(DEBUG)
48 #define	DBG niumx_dbg
49 extern void niumx_dbg(niumx_debug_bit_t bit, dev_info_t *dip, char *fmt, ...);
50 #else
51 #define	DBG 0 &&
52 #endif	/* DEBUG */
53 
54 typedef uint64_t devhandle_t;
55 #define	NIUMX_DEVHDLE_MASK	0xFFFFFFF
56 typedef uint32_t cpuid_t;
57 typedef uint32_t devino_t;
58 typedef	uint64_t sysino_t;
59 
60 /*
61  * The following structure represents an interrupt handler control block for
62  * each interrupt added via ddi_intr_add_handler().
63  */
64 typedef struct niumx_ih {
65 	dev_info_t	*ih_dip;	/* devinfo structure */
66 	uint32_t	ih_inum;	/* interrupt index, from leaf */
67 	sysino_t	ih_sysino;	/* System virtual inumber, from HV */
68 	cpuid_t		ih_cpuid;	/* cpu that ino is targeting */
69 	uint_t		(*ih_hdlr)();	/* interrupt handler */
70 	caddr_t		ih_arg1;	/* interrupt handler argument #1 */
71 	caddr_t		ih_arg2;	/* interrupt handler argument #2 */
72 	struct niumx_ih	*ih_next;	/* next in the chain */
73 } niumx_ih_t;
74 
75 typedef struct niumx_devstate {
76 	dev_info_t *dip;
77 	devhandle_t	niumx_dev_hdl;	/* device handle */
78 	kmutex_t niumx_mutex;
79 	int niumx_fm_cap;
80 	ddi_iblock_cookie_t niumx_fm_ibc;
81 } niumx_devstate_t;
82 
83 #define	NIUMX_MAX_INTRS	64
84 
85 /*
86  * flags for overloading dmai_inuse field of the dma request structure:
87  */
88 #define	dmai_pfnlst		dmai_iopte
89 #define	dmai_pfn0		dmai_sbi
90 #define	dmai_roffset		dmai_pool
91 
92 #define	NIUMX_PAGE_SHIFT		13
93 #define	NIUMX_PAGE_SIZE		(1 << NIUMX_PAGE_SHIFT)
94 #define	NIUMX_PAGE_MASK		~(NIUMX_PAGE_SIZE - 1)
95 #define	NIUMX_PAGE_OFFSET		(NIUMX_PAGE_SIZE - 1)
96 #define	NIUMX_PTOB(x)		(((uint64_t)(x)) << NIUMX_PAGE_SHIFT)
97 
98 /* for "ranges" property */
99 typedef struct niumx_ranges {
100 	uint32_t child_hi;
101 	uint32_t child_lo;
102 	uint32_t parent_hi;
103 	uint32_t parent_lo;
104 	uint32_t size_hi;
105 	uint32_t size_lo;
106 } niumx_ranges_t;
107 
108 /* IPL of 6 for networking devices */
109 #define	NIUMX_DEFAULT_PIL	6
110 
111 typedef struct {
112 	uint32_t addr_high;
113 	uint32_t addr_low;
114 	uint32_t size_high;
115 	uint32_t size_low;
116 } niu_regspec_t;
117 
118 /*
119  * HV INTR  API versioning.
120  *
121  * Currently NIU nexus driver supports version 1.0
122  */
123 #define	NIUMX_INTR_MAJOR_VER_1	0x1ull
124 #define	NIUMX_INTR_MAJOR_VER	NIUMX_INTR_MAJOR_VER_1
125 
126 #define	NIUMX_INTR_MINOR_VER_0	0x0ull
127 #define	NIUMX_INTR_MINOR_VER	NIUMX_INTR_MINOR_VER_0
128 
129 #define	NAMEINST(dip)   ddi_driver_name(dip), ddi_get_instance(dip)
130 #define	DIP_TO_HANDLE(dip) \
131 		((niumx_devstate_t *)DIP_TO_STATE(dip))->niumx_dev_hdl
132 #define	DIP_TO_INST(dip)	ddi_get_instance(dip)
133 #define	INST_TO_STATE(inst)	ddi_get_soft_state(niumx_state, inst)
134 #define	DIP_TO_STATE(dip)	INST_TO_STATE(DIP_TO_INST(dip))
135 
136 #ifdef	__cplusplus
137 }
138 #endif
139 
140 #endif	/* _SYS_NIUMX_VAR_H */
141