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