xref: /titanic_50/usr/src/uts/sun4v/sys/vnet.h (revision 142c9f13e148d687426ed2d4e8bd93717eeaebbc)
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 #define	VNET_SUCCESS		(0)	/* successful return */
37 #define	VNET_FAILURE		(-1)	/* unsuccessful return */
38 
39 #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
40 
41 #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
42 #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
43 #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
44 #define	VNET_LDC_MTU		64		/* ldc mtu */
45 
46 #define	VNET_VNETPORT		1		/* port connected to a vnet */
47 #define	VNET_VSWPORT		2		/* port connected to vsw */
48 
49 /*
50  * vnet proxy transport layer information. There is one instance of this for
51  * every transport being used by a vnet device and a list of these transports
52  * is maintained by vnet.
53  */
54 typedef struct vp_tl {
55 	struct vp_tl		*nextp;			/* next in list */
56 	mac_register_t		*macp;			/* transport ops */
57 	char			name[LIFNAMSIZ];	/* device name */
58 	major_t			major;			/* driver major # */
59 	uint_t			instance;		/* dev instance */
60 } vp_tl_t;
61 
62 /*
63  * Forwarding database entry. Each port of a vnet device will have an entry in
64  * the fdb. Reference count is bumped up while sending a packet destined to a
65  * port corresponding to the fdb entry.
66  */
67 typedef struct vnet_fdbe {
68 	uint8_t		type;	/* VNET_VNETPORT or VNET_VSWPORT ? */
69 	uint32_t	refcnt;	/* reference count */
70 	void		*txarg;	/* arg to the transmit func */
71 	mac_tx_t 	m_tx;	/* transmit function */
72 } vnet_fdbe_t;
73 
74 #define	VNET_NFDB_HASH	64
75 
76 #define	KEY_HASH(key, addr) \
77 	(key = ((((uint64_t)(addr)->ether_addr_octet[0]) << 40) | \
78 	(((uint64_t)(addr)->ether_addr_octet[1]) << 32) | \
79 	(((uint64_t)(addr)->ether_addr_octet[2]) << 24) | \
80 	(((uint64_t)(addr)->ether_addr_octet[3]) << 16) | \
81 	(((uint64_t)(addr)->ether_addr_octet[4]) << 8) | \
82 	((uint64_t)(addr)->ether_addr_octet[5])));
83 
84 /* rwlock macros */
85 #define	READ_ENTER(x)	rw_enter(x, RW_READER)
86 #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
87 #define	RW_EXIT(x)	rw_exit(x)
88 
89 #define	VLAN_ID_KEY(key)	((mod_hash_key_t)(uintptr_t)(key))
90 
91 /*
92  * vnet instance state information
93  */
94 typedef struct vnet {
95 	int			instance;	/* instance # */
96 	dev_info_t		*dip;		/* dev_info */
97 	struct vnet		*nextp;		/* next in list */
98 	mac_handle_t 		mh;		/* handle to GLDv3 mac module */
99 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
100 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
101 	vp_tl_t			*tlp;		/* list of vp_tl */
102 	krwlock_t		trwlock;	/* lock for vp_tl list */
103 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
104 
105 	uint32_t		fdb_nchains;	/* # of hash chains in fdbtbl */
106 	mod_hash_t		*fdb_hashp;	/* forwarding database */
107 	vnet_fdbe_t		*vsw_fp;	/* cached fdb entry of vsw */
108 	krwlock_t		vsw_fp_rw;	/* lock to protect vsw_fp */
109 	uint32_t		max_frame_size;	/* max frame size supported */
110 
111 	uint16_t		default_vlan_id; /* default vlan id */
112 	uint16_t		pvid;		/* port vlan id (untagged) */
113 	uint16_t		*vids;		/* vlan ids (tagged) */
114 	uint16_t		nvids;		/* # of vids */
115 } vnet_t;
116 
117 #ifdef DEBUG
118 /*
119  * debug levels:
120  * DBG_LEVEL1:	Function entry/exit tracing
121  * DBG_LEVEL2:	Info messages
122  * DBG_LEVEL3:	Warning messages
123  * DBG_LEVEL4:	Error messages
124  */
125 
126 enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
127 	    DBG_ERR = 0x08 };
128 
129 #define	DBG1(...)	do {						\
130 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
131 				debug_printf(__func__, __VA_ARGS__);	\
132 			    }						\
133 			_NOTE(CONSTCOND) } while (0)
134 
135 #define	DBG2(...)	do {						\
136 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
137 				debug_printf(__func__, __VA_ARGS__);	\
138 			    }						\
139 			_NOTE(CONSTCOND) } while (0)
140 
141 #define	DWARN(...)	do {						\
142 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
143 				debug_printf(__func__, __VA_ARGS__);	\
144 			    }						\
145 			_NOTE(CONSTCOND) } while (0)
146 
147 #define	DERR(...)	do {						\
148 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
149 				debug_printf(__func__, __VA_ARGS__);	\
150 			    }						\
151 			_NOTE(CONSTCOND) } while (0)
152 
153 #else
154 
155 #define	DBG1(...)	if (0)	do { } while (0)
156 #define	DBG2(...)	if (0)	do { } while (0)
157 #define	DWARN(...)	if (0)	do { } while (0)
158 #define	DERR(...)	if (0)	do { } while (0)
159 
160 #endif
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif	/* _VNET_H */
167