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