xref: /titanic_52/usr/src/uts/sun4v/sys/vnet.h (revision f657cd55755084dade71fb0c1d9f51994c226a70)
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 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/vnet_res.h>
35 #include <sys/vnet_mailbox.h>
36 #include <sys/modhash.h>
37 
38 #define	VNET_SUCCESS		(0)	/* successful return */
39 #define	VNET_FAILURE		(-1)	/* unsuccessful return */
40 
41 #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
42 
43 #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
44 #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
45 #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
46 #define	VNET_LDC_MTU		64		/* ldc mtu */
47 
48 
49 #define	IS_BROADCAST(ehp) \
50 		(ether_cmp(&ehp->ether_dhost, &etherbroadcastaddr) == 0)
51 #define	IS_MULTICAST(ehp) \
52 		((ehp->ether_dhost.ether_addr_octet[0] & 01) == 1)
53 
54 #define	VNET_MATCH_RES(vresp, vnetp)	\
55 	(ether_cmp(vresp->local_macaddr, vnetp->curr_macaddr) == 0)
56 
57 typedef struct vnet_hio_stats {
58 	/* Link Input/Output stats */
59 	uint64_t	ipackets;	/* # rx packets */
60 	uint64_t	ierrors;	/* # rx error */
61 	uint64_t	opackets;	/* # tx packets */
62 	uint64_t	oerrors;	/* # tx error */
63 
64 	/* MIB II variables */
65 	uint64_t	rbytes;		/* # bytes received */
66 	uint64_t	obytes;		/* # bytes transmitted */
67 	uint32_t	multircv;	/* # multicast packets received */
68 	uint32_t	multixmt;	/* # multicast packets for xmit */
69 	uint32_t	brdcstrcv;	/* # broadcast packets received */
70 	uint32_t	brdcstxmt;	/* # broadcast packets for xmit */
71 	uint32_t	norcvbuf;	/* # rcv packets discarded */
72 	uint32_t	noxmtbuf;	/* # xmit packets discarded */
73 } vnet_hio_stats_t;
74 
75 typedef struct vnet_hio_kstats {
76 	/* Link Input/Output stats */
77 	kstat_named_t	ipackets;
78 	kstat_named_t	ipackets64;
79 	kstat_named_t	ierrors;
80 	kstat_named_t	opackets;
81 	kstat_named_t	opackets64;
82 	kstat_named_t	oerrors;
83 
84 	/* required by kstat for MIB II objects(RFC 1213) */
85 	kstat_named_t	rbytes; 	/* MIB - ifInOctets */
86 	kstat_named_t	rbytes64;
87 	kstat_named_t	obytes; 	/* MIB - ifOutOctets */
88 	kstat_named_t	obytes64;
89 	kstat_named_t	multircv; 	/* MIB - ifInNUcastPkts */
90 	kstat_named_t	multixmt; 	/* MIB - ifOutNUcastPkts */
91 	kstat_named_t	brdcstrcv;	/* MIB - ifInNUcastPkts */
92 	kstat_named_t	brdcstxmt;	/* MIB - ifOutNUcastPkts */
93 	kstat_named_t	norcvbuf; 	/* MIB - ifInDiscards */
94 	kstat_named_t	noxmtbuf; 	/* MIB - ifOutDiscards */
95 } vnet_hio_kstats_t;
96 
97 /*
98  * A vnet resource structure.
99  */
100 typedef struct vnet_res {
101 	struct vnet_res		*nextp;		/* next resource in the list */
102 	mac_register_t		macreg;		/* resource's mac_reg */
103 	vio_net_res_type_t	type;		/* resource type */
104 	ether_addr_t		local_macaddr;	/* resource's macaddr */
105 	ether_addr_t		rem_macaddr;	/* resource's remote macaddr */
106 	uint32_t		flags;		/* resource flags */
107 	uint32_t		refcnt;		/* reference count */
108 	struct	vnet		*vnetp;		/* back pointer to vnet */
109 	kstat_t			*ksp;		/* hio kstats */
110 } vnet_res_t;
111 
112 #define	VNET_DDS_TASK_ADD_SHARE		0x01
113 #define	VNET_DDS_TASK_DEL_SHARE		0x02
114 #define	VNET_DDS_TASK_REL_SHARE		0x04
115 
116 /* An instance specific DDS structure */
117 typedef struct vnet_dds_info {
118 	kmutex_t	lock;		/* lock for this structure */
119 	uint8_t		task_flags;	/* flags for taskq */
120 	uint8_t		dds_req_id;	/* DDS message request id */
121 	vio_dds_msg_t	dmsg;		/* Pending DDS message */
122 	dev_info_t	*hio_dip;	/* Hybrid device's dip */
123 	uint64_t	hio_cookie;	/* Hybrid device's cookie */
124 	ddi_taskq_t	*dds_taskqp;	/* Taskq's used for DDS */
125 	struct vnet	*vnetp;		/* Back pointer to vnetp */
126 } vnet_dds_info_t;
127 
128 #define	VNET_NFDB_HASH	64
129 
130 #define	KEY_HASH(key, addr) \
131 	(key = (((uint64_t)(addr[0])) << 40) | \
132 	(((uint64_t)(addr[1])) << 32) | \
133 	(((uint64_t)(addr[2])) << 24) | \
134 	(((uint64_t)(addr[3])) << 16) | \
135 	(((uint64_t)(addr[4])) << 8) | \
136 	((uint64_t)(addr[5])));
137 
138 
139 /* rwlock macros */
140 #define	READ_ENTER(x)	rw_enter(x, RW_READER)
141 #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
142 #define	RW_EXIT(x)	rw_exit(x)
143 
144 #define	VLAN_ID_KEY(key)	((mod_hash_key_t)(uintptr_t)(key))
145 
146 /*
147  * vnet instance state information
148  */
149 typedef struct vnet {
150 	int			instance;	/* instance # */
151 	dev_info_t		*dip;		/* dev_info */
152 	uint64_t		reg;		/* reg prop value */
153 	struct vnet		*nextp;		/* next in list */
154 	mac_handle_t		mh;		/* handle to GLDv3 mac module */
155 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
156 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
157 	void			*vgenhdl;	/* Handle for vgen */
158 
159 	uint32_t		fdb_nchains;	/* # of hash chains in fdbtbl */
160 	mod_hash_t		*fdb_hashp;	/* forwarding database */
161 	vnet_res_t		*vsw_fp;	/* cached fdb entry of vsw */
162 	krwlock_t		vsw_fp_rw;	/* lock to protect vsw_fp */
163 	uint32_t		mtu;		/* mtu of the device */
164 
165 	uint16_t		default_vlan_id; /* default vlan id */
166 	uint16_t		pvid;		/* port vlan id (untagged) */
167 	uint16_t		*vids;		/* vlan ids (tagged) */
168 	uint16_t		nvids;		/* # of vids */
169 
170 	uint32_t		flags;		/* interface flags */
171 	vnet_res_t		*hio_fp;	/* Hybrid IO resource */
172 	vnet_res_t		*vres_list;	/* Resource list */
173 	vnet_dds_info_t		vdds_info;	/* DDS related info */
174 	krwlock_t		vrwlock;	/* Resource list lock */
175 	ddi_taskq_t		*taskqp;	/* Resource taskq */
176 } vnet_t;
177 
178 #define	VNET_STARTED	0x01
179 
180 #ifdef DEBUG
181 /*
182  * debug levels:
183  * DBG_LEVEL1:	Function entry/exit tracing
184  * DBG_LEVEL2:	Info messages
185  * DBG_LEVEL3:	Warning messages
186  * DBG_LEVEL4:	Error messages
187  */
188 
189 enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
190 	    DBG_ERR = 0x08 };
191 
192 #define	DBG1(...)	do {						\
193 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
194 				debug_printf(__func__, __VA_ARGS__);	\
195 			    }						\
196 			_NOTE(CONSTCOND) } while (0)
197 
198 #define	DBG2(...)	do {						\
199 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
200 				debug_printf(__func__, __VA_ARGS__);	\
201 			    }						\
202 			_NOTE(CONSTCOND) } while (0)
203 
204 #define	DWARN(...)	do {						\
205 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
206 				debug_printf(__func__, __VA_ARGS__);	\
207 			    }						\
208 			_NOTE(CONSTCOND) } while (0)
209 
210 #define	DERR(...)	do {						\
211 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
212 				debug_printf(__func__, __VA_ARGS__);	\
213 			    }						\
214 			_NOTE(CONSTCOND) } while (0)
215 
216 #else
217 
218 #define	DBG1(...)	if (0)	do { } while (0)
219 #define	DBG2(...)	if (0)	do { } while (0)
220 #define	DWARN(...)	if (0)	do { } while (0)
221 #define	DERR(...)	if (0)	do { } while (0)
222 
223 #endif
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif	/* _VNET_H */
230