xref: /titanic_50/usr/src/uts/sun4v/sys/vnet.h (revision ff17c8bf86c3e567734be83f90267edee20f580f)
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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _VNET_H
28 #define	_VNET_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/vnet_res.h>
37 #include <sys/vnet_mailbox.h>
38 #include <sys/modhash.h>
39 
40 #define	VNET_SUCCESS		(0)	/* successful return */
41 #define	VNET_FAILURE		(-1)	/* unsuccessful return */
42 
43 #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
44 
45 #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
46 #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
47 #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
48 #define	VNET_LDC_MTU		64		/* ldc mtu */
49 
50 
51 #define	IS_BROADCAST(ehp) \
52 		(ether_cmp(&ehp->ether_dhost, &etherbroadcastaddr) == 0)
53 #define	IS_MULTICAST(ehp) \
54 		((ehp->ether_dhost.ether_addr_octet[0] & 01) == 1)
55 
56 #define	VNET_MATCH_RES(vresp, vnetp)	\
57 	(ether_cmp(vresp->local_macaddr, vnetp->curr_macaddr) == 0)
58 
59 /*
60  * A vnet resource structure.
61  */
62 typedef struct vnet_res {
63 	struct vnet_res		*nextp;		/* next resource in the list */
64 	mac_register_t		macreg;		/* resource's mac_reg */
65 	vio_net_res_type_t	type;		/* resource type */
66 	ether_addr_t		local_macaddr;	/* resource's macaddr */
67 	ether_addr_t		rem_macaddr;	/* resource's remote macaddr */
68 	uint32_t		flags;		/* resource flags */
69 	uint32_t		refcnt;		/* reference count */
70 	struct	vnet		*vnetp;		/* back pointer to vnet */
71 } vnet_res_t;
72 
73 #define	VNET_DDS_TASK_ADD_SHARE		0x01
74 #define	VNET_DDS_TASK_DEL_SHARE		0x02
75 #define	VNET_DDS_TASK_REL_SHARE		0x04
76 
77 /* An instance specific DDS structure */
78 typedef struct vnet_dds_info {
79 	kmutex_t	lock;		/* lock for this structure */
80 	uint8_t		task_flags;	/* flags for taskq */
81 	uint8_t		dds_req_id;	/* DDS message request id */
82 	vio_dds_msg_t	dmsg;		/* Pending DDS message */
83 	dev_info_t	*hio_dip;	/* Hybrid device's dip */
84 	uint64_t	hio_cookie;	/* Hybrid device's cookie */
85 	ddi_taskq_t	*dds_taskqp;	/* Taskq's used for DDS */
86 	struct vnet	*vnetp;		/* Back pointer to vnetp */
87 } vnet_dds_info_t;
88 
89 #define	VNET_NFDB_HASH	64
90 
91 #define	KEY_HASH(key, addr) \
92 	(key = (((uint64_t)(addr[0])) << 40) | \
93 	(((uint64_t)(addr[1])) << 32) | \
94 	(((uint64_t)(addr[2])) << 24) | \
95 	(((uint64_t)(addr[3])) << 16) | \
96 	(((uint64_t)(addr[4])) << 8) | \
97 	((uint64_t)(addr[5])));
98 
99 
100 /* rwlock macros */
101 #define	READ_ENTER(x)	rw_enter(x, RW_READER)
102 #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
103 #define	RW_EXIT(x)	rw_exit(x)
104 
105 #define	VLAN_ID_KEY(key)	((mod_hash_key_t)(uintptr_t)(key))
106 
107 /*
108  * vnet instance state information
109  */
110 typedef struct vnet {
111 	int			instance;	/* instance # */
112 	dev_info_t		*dip;		/* dev_info */
113 	uint64_t		reg;		/* reg prop value */
114 	struct vnet		*nextp;		/* next in list */
115 	mac_handle_t		mh;		/* handle to GLDv3 mac module */
116 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
117 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
118 	void			*vgenhdl;	/* Handle for vgen */
119 
120 	uint32_t		fdb_nchains;	/* # of hash chains in fdbtbl */
121 	mod_hash_t		*fdb_hashp;	/* forwarding database */
122 	vnet_res_t		*vsw_fp;	/* cached fdb entry of vsw */
123 	krwlock_t		vsw_fp_rw;	/* lock to protect vsw_fp */
124 	uint32_t		max_frame_size;	/* max frame size supported */
125 
126 	uint16_t		default_vlan_id; /* default vlan id */
127 	uint16_t		pvid;		/* port vlan id (untagged) */
128 	uint16_t		*vids;		/* vlan ids (tagged) */
129 	uint16_t		nvids;		/* # of vids */
130 
131 	uint32_t		flags;		/* interface flags */
132 	vnet_res_t		*hio_fp;	/* Hybrid IO resource */
133 	vnet_res_t		*vres_list;	/* Resource list */
134 	vnet_dds_info_t		vdds_info;	/* DDS related info */
135 	krwlock_t		vrwlock;	/* Resource list lock */
136 	ddi_taskq_t		*taskqp;	/* Resource taskq */
137 } vnet_t;
138 
139 #define	VNET_STARTED	0x01
140 
141 #ifdef DEBUG
142 /*
143  * debug levels:
144  * DBG_LEVEL1:	Function entry/exit tracing
145  * DBG_LEVEL2:	Info messages
146  * DBG_LEVEL3:	Warning messages
147  * DBG_LEVEL4:	Error messages
148  */
149 
150 enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
151 	    DBG_ERR = 0x08 };
152 
153 #define	DBG1(...)	do {						\
154 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
155 				debug_printf(__func__, __VA_ARGS__);	\
156 			    }						\
157 			_NOTE(CONSTCOND) } while (0)
158 
159 #define	DBG2(...)	do {						\
160 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
161 				debug_printf(__func__, __VA_ARGS__);	\
162 			    }						\
163 			_NOTE(CONSTCOND) } while (0)
164 
165 #define	DWARN(...)	do {						\
166 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
167 				debug_printf(__func__, __VA_ARGS__);	\
168 			    }						\
169 			_NOTE(CONSTCOND) } while (0)
170 
171 #define	DERR(...)	do {						\
172 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
173 				debug_printf(__func__, __VA_ARGS__);	\
174 			    }						\
175 			_NOTE(CONSTCOND) } while (0)
176 
177 #else
178 
179 #define	DBG1(...)	if (0)	do { } while (0)
180 #define	DBG2(...)	if (0)	do { } while (0)
181 #define	DWARN(...)	if (0)	do { } while (0)
182 #define	DERR(...)	if (0)	do { } while (0)
183 
184 #endif
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 
190 #endif	/* _VNET_H */
191